Simultaneous audio playback / recording.

661 views
Skip to first unread message

CrocoDuck O'Ducks

unread,
Jan 17, 2016, 2:47:05 PM1/17/16
to julia-users
Hi there!

I have a number MATLAB scripts that I use for electro-acoustic measurements (mainly impulse responses) and I would like to port them to JULIA. I also written the data acquisition in MATLAB. It works by streaming the test signal to the soundcard outputs while recording from the soundcard inputs. I would like to implement that as well. I was looking at AudioIO but there are few issues:

  • I cannot find documentation/examples on how to record from soundcard input.
  • I cannot find documentation/examples on selecting the audio device to use.
  • I cannot find documentation/examples on setting sampling variables (it is in my best interest to use the highest sample rate available).

Are these things possible with JULIA? I think I can use aplayer and arecord through JULIA (I am on Linux), but I was wishing to have all the code contained within JULIA.

Many thanks, I hope you can point me in the right direction.

STAR0SS

unread,
Jan 17, 2016, 5:01:04 PM1/17/16
to julia-users
When dealing with small packages you often need to look at the code, because the documentation is sometimes lacking.

AudioIO.jl uses the C library PortAudio, so in theory anything that can be done with PortAudio can be done in Julia, you need
to have the right wrappers for the C functions. It seems AudioIO.jl implementation isn't complete, so probably some things cannot
be done currently without getting your hands dirty (meaning reading the Julia code and the PortAudio doc and trying to understand what's going on).

if you look the constructor of PortAudioStream you can see you can change the sampling rate there (the PortAudioStream can then be passed to play it seems), 
however it call the default stream (Pa_OpenDefaultStream) so I'm not sure you can select the audio device.

There's also a get_portaudio_devices function, but it's not used anywhere it seems (you can search the repository to see where things are used)


I don't know much about PortAudio, so take that with a grain of salt, I'm just guessing.

CrocoDuck O'Ducks

unread,
Jan 18, 2016, 4:32:00 PM1/18/16
to julia-users
Thanks for the tips. I guess this is a sign of destiny: time for me to look deep into PortAudio.

Miguel Bazdresch

unread,
Jan 18, 2016, 5:33:20 PM1/18/16
to julia...@googlegroups.com
An alternative would be to interact with the sound card using sox (http://sox.sourceforge.net/). In the past, I used sox from Octave to record and play audio simultaneously. Let me know if you'd like to see the code; I can probably dig it out of my old backups.

-- mb

Spencer Russell

unread,
Jan 18, 2016, 6:42:30 PM1/18/16
to julia...@googlegroups.com
AudioIO is going to be going deprecated soon in favor of a family of packages that are each a bit more focused and simpler to interface with. They’re not quite release-ready but have been making a lot of progress lately, and I wanted folks to know what’s coming before you sink a bunch of time into working with the AudioIO implementation. Currently there’s a mostly working JACK library, and I’ll probably port over the PortAudio support from AudioIO after that.

-s

CrocoDuck O'Ducks

unread,
Jan 19, 2016, 7:15:45 PM1/19/16
to julia-users
I forgot about sox. Good point. I will look into and be back if I need your code as an example. Thanks!

CrocoDuck O'Ducks

unread,
Jan 19, 2016, 7:15:45 PM1/19/16
to julia-users
Wow! Sounds amazing! Can't wait for that!

CrocoDuck O'Ducks

unread,
Jan 24, 2016, 1:10:47 PM1/24/16
to julia-users
Ok cool people! I got the first prototype working:

# sinegen.jl

#=
 
Just a simple generator of sine waves. It even records stuff!
=#

using WAV

# User defined stuff:

# Define Sample Frequency:
Fs = 96000# Hz
# Define Frequency of Wave:
f
= 440 # Hz
# Define Duration:
T
= 10 #s

# Define Audio File variables:
nbits
= 32
# Format:
fformat
= "wav"

# Define Audio Driver and AudioDevice for playback
adriver
= "alsa"
adev
= "hw:1"

# Execute:

# Time window:
t
= (1/Fs) * collect(0:(T*Fs - 1)) #s
# Signal:
y
= sin(2π*f*t)

# File Name:
fname
= "Sine $f.$fformat"
# Save the sine wave:
wavwrite
(y,Fs,nbits,fname)

# Set Driver and device for sox:
ENV
["AUDIODRIVER"] = adriver
ENV
["AUDIODEV"] = adev

# And now, play it with sox from command line.
# run(`play -b $nbits -r $Fs $fname`)

# To record for a lenght of time T:
# run(`rec -b $nbits -r $Fs Output.wav trim 0 $T `)

# To play and record simultaneously:
run
(`play -b $nbits -r $Fs $fname` & `rec -b $nbits -r $Fs Output.wav trim 0 $T `)

It is using sox as suggested above. Do you have any particular suggestion about calling these two commands simultaneously in the last line?

Sebastian Kraft

unread,
Feb 3, 2016, 1:54:49 PM2/3/16
to julia-users

Hi,

in the last weeks I started a PortAudio.jl package (based on parts of the AudioIO.jl package). It is still under development and far from perfect, but should already work well for basic audio IO.

https://github.com/seebk/PortAudio.jl

Sebastian

CrocoDuck O'Ducks

unread,
Feb 4, 2016, 11:39:16 PM2/4/16
to julia-users
Wow! Seems it could do the job. I think I will test it soon. Thanks!

CrocoDuck O'Ducks

unread,
Feb 7, 2016, 10:51:35 AM2/7/16
to julia-users
I am starting looking into your module and... ehm... what is the proper way to install it?


On Wednesday, 3 February 2016 18:54:49 UTC, Sebastian Kraft wrote:

Sebastian Kraft

unread,
Feb 7, 2016, 11:31:57 AM2/7/16
to julia-users
Am Sonntag, 7. Februar 2016 16:51:35 UTC+1 schrieb CrocoDuck O'Ducks:
I am starting looking into your module and... ehm... what is the proper way to install it?

It's not a registered package, yet. Therefore, it requires the following steps:

Pkg.build("PortAudio")

 

CrocoDuck O'Ducks

unread,
Feb 7, 2016, 1:47:33 PM2/7/16
to julia-users
Thanks! The module is installed. I will make some experiment and report back!

CrocoDuck O'Ducks

unread,
Feb 15, 2016, 4:09:45 PM2/15/16
to julia-users
Sorry for the late reply, I am taking quite a lot of time to properly understand Julia while I learn it. Sir, your module is very nice! It seems to be working fine and I was able to get started pretty soon. JACK support! YUM!!! I already see how to design my script: make it write the .jackdrc file, make it launch jack, find the correct device ID and unleash the measurement process.

Thanks for your module, I think it will be very useful for me. Keep on the good work!


On Sunday, 7 February 2016 16:31:57 UTC, Sebastian Kraft wrote:
Reply all
Reply to author
Forward
0 new messages