PortAudio wrapper for the Julia programming language, compatible with the JuliaAudio family of packages
Find a file
2016-03-22 02:03:43 -04:00
deps removes some unused dependencies and trying a new APT package name 2016-03-20 00:59:36 -04:00
examples adds audiometer example 2016-03-20 04:05:21 -04:00
src in-progress converting to callback API and supporting duplex streams 2016-03-22 02:03:43 -04:00
test adds some tests and fixes, test coverage at 95% 2016-03-20 05:09:56 -04:00
.gitignore adds some tests and fixes, test coverage at 95% 2016-03-20 05:09:56 -04: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 PortAudio to module list in last example so it's complete 2016-03-20 03:54:44 -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:

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.

PortAudioSink(device::PortAudioDevice, args...)
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. For example, if you load SampleTypes with using SampleTypes you can read 5 seconds to a buffer with buf = read(source, 5s), regardless of the sample rate of the device.

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 PortAudio, 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)