Realtime Audio Processing with PortAudio.jl

538 views
Skip to first unread message

CrocoDuck O'Ducks

unread,
Feb 21, 2016, 10:44:50 AM2/21/16
to julia-users
Hi there!

I got into PortAudio.jl recently (see this thread). I would like to code realtime digital filters. By that I mean that I would like to acquire data from sound-card input(s) and, while the acquisition goes on, filter the acquired samples and write the result to the sound-card output(s). Latency does not need to be low. I have mostly loudspeaker pre-hemphasis applications for acoustic measurements in mind for that, that means I will time align what I need later on... I think the PortAudio module should make me able to do that... but I have not figured out how. Here what I have (very naively) tried:

iostream = open(devID, (max_input_channels, max_output_channels), sample_rate, buf_size)

# Use a loop. Ctrl + C to exit the loop.

doloop
= true

try
 
while doloop

    ibuffer
= read(iostream, buf_size) # Collect Input
    obuffer
= some_filtering_of(ibuffer) # Do some processing
    write
(iostream, obuffer) # Write it to output

 
end
catch excp

 
if isa(excp, InterruptException) # Ctrl + C generates an InterruptException
    doloop
= false
 
end

end

Of course, there are many problems with that (it is not collecting consecutive buffers, for example). I guess it can help you understanding what I have in mind though.

Sebastian Kraft

unread,
Feb 22, 2016, 2:50:39 AM2/22/16
to julia-users
Please only stick to the examples given in the Readme.md file. Single buffer IO is not working properly, yet.
My current plan is to extend open() so you can pass a callback function which does the processing asynchronously. However, it does not seem to work when C code is called in an @async block... Have to investigate that further in the next days...

CrocoDuck O'Ducks

unread,
Feb 22, 2016, 3:51:04 AM2/22/16
to julia-users
Cool! I will stay updated. Thanks!

Sebastian Kraft

unread,
Mar 13, 2016, 3:54:48 PM3/13/16
to julia-users
In the last days I added some code to allow realtime and asynchronous IO. I think it is still quite hackish, but absolutely have no clue how to pass something like a callback object in Julia. 

The thing is I want to open a stream and pass it an initialized "processor" object which is then doing the realtime processing in the background until the stream is closed. My current solution looks like shown in this example:

Maybe the whole concept of async IO as I have planned it is not possible in Julia?

Any ideas how this could be done more in a smart (Julia style) way?

Sebastian

Daniel Casimiro

unread,
Mar 14, 2016, 6:50:12 AM3/14/16
to julia-users
I use callback functions with CoreAudio to play WAV files on Mac OS X. My implementation in WAV.jl is not sophisticated, but it works reasonably well.

CrocoDuck O'Ducks

unread,
Mar 14, 2016, 5:40:05 PM3/14/16
to julia-users
Brilliantly cool! Thanks for notifying the update! I will test it very soon. I guess it would be possible to use this technique also to synthesize something. Like "white noise until CTRL + C is pressed", so to speak..
Reply all
Reply to author
Forward
0 new messages