PortAudio wrapper for the Julia programming language, compatible with the JuliaAudio family of packages
Find a file
2016-03-20 03:23:28 -04:00
deps removes some unused dependencies and trying a new APT package name 2016-03-20 00:59:36 -04:00
examples Adjusted buffer length so buffer ends at the end of the ramp. 2014-06-28 16:33:34 -05:00
src adds better source/sink show method and more docs/examples to README 2016-03-20 03:23:28 -04:00
test removes commented-out old code 2016-03-20 00:28:56 -04:00
.gitignore adds coverage files to gitignore 2014-11-21 23:16:30 -05:00
.travis.yml adds sudo to travis config 2016-03-20 01:24:23 -04:00
LICENSE initial commit with some toy code 2013-12-11 20:18:36 -05:00
README.md adds better source/sink show method and more docs/examples to README 2016-03-20 03:23:28 -04:00
REQUIRE removes some unused dependencies and trying a new APT package name 2016-03-20 00:59:36 -04:00
runtests.sh adds runtests.sh script 2016-03-19 21:55:35 -04:00

PortAudio.jl

PortAudio.jl is a wrapper for libportaudio, which gives cross-platform access to audio devices. It is compatible with the types defined in SampleTypes.jl, so it provides PortAudioSink and PortAudioSource types, which can be read from and written to.

Opening a source or sink

The easiest way to open a source or sink is with the default PortAudioSource() and PortAudioSink() constructors, which will open a 2-channel stream to your system's default devices. The constructors also take a variety of positional arguments:

function PortAudioSink(eltype=Float32, sr=48000Hz, channels=2, bufsize=4096)

You can open a specific device by adding it as the first argument, either as a PortAudioDevice instance or by name.

function PortAudioSink(device::PortAudioDevice, args...)
function PortAudioSink(devname::AbstractString, args...)

You can get a list of your system's devices with the PortAudio.devices() function:

julia> PortAudio.devices()
6-element Array{PortAudio.PortAudioDevice,1}:
 PortAudio.PortAudioDevice("AirPlay","Core Audio",0,2,0)
 PortAudio.PortAudioDevice("Built-in Microph","Core Audio",2,0,1)
 PortAudio.PortAudioDevice("Built-in Output","Core Audio",0,2,2)
 PortAudio.PortAudioDevice("JackRouter","Core Audio",2,2,3)
 PortAudio.PortAudioDevice("After Effects 13.5","Core Audio",0,0,4)
 PortAudio.PortAudioDevice("Built-In Aggregate","Core Audio",2,2,5)

Reading and Writing

PortAudioSource and PortAudioSink are subtypes of SampleSource and SampleSink, respectively (from SampleTypes.jl). This means they support all the stream and buffer features defined there. You can read to a buffer with buf = read(source)

Examples

Set up an audio pass-through from microphone to speaker

source = PortAudioSource()
sink = PortAudioSink()
write(sink, source)

Open your built-in microphone and speaker by name

source = PortAudioSource("Built-in Microph")
sink = PortAudioSink("Built-in Output")
write(sink, source)

Record 10 seconds of audio and save to an ogg file

julia> using FileIO, SampleTypes, LibSndFile

julia> source = PortAudioSource("Built-in Microph")
PortAudio.PortAudioSource{Float32,SIUnits.SIQuantity{Int64,0,0,-1,0,0,0,0,0,0}}("Built-in Microph")
2 channels sampled at 48000 s⁻¹

julia> buf = read(source, 10s)
480000-frame, 2-channel SampleBuf{Float32, 2, SIUnits.SIQuantity{Int64,0,0,-1,0,0,0,0,0,0}}
10.0 s at 48000 s⁻¹
▁▄▂▃▅▃▂▄▃▂▂▁▁▂▂▁▁▄▃▁▁▄▂▁▁▁▄▃▁▁▃▃▁▁▁▁▁▁▁▁▄▄▄▄▄▂▂▂▁▃▃▁▃▄▂▁▁▁▁▃▃▂▁▁▁▁▁▁▃▃▂▂▁▃▃▃▁▁▁▁
▁▄▂▃▅▃▂▄▃▂▂▁▁▂▂▁▁▄▃▁▁▄▂▁▁▁▄▃▁▁▃▃▁▁▁▁▁▁▁▁▄▄▄▄▄▂▂▂▁▃▃▁▃▄▂▁▁▁▁▃▃▂▁▁▁▁▁▁▃▃▂▂▁▃▃▃▁▁▁▁

julia> save(joinpath(homedir(), "Desktop", "myvoice.ogg"), buf)