Update readme (#111)

* update readme

* Update README.md

Co-authored-by: Jeff Fessler <JeffFessler@users.noreply.github.com>

* Update src/PortAudio.jl

Co-authored-by: Jeff Fessler <JeffFessler@users.noreply.github.com>

* Update README.md

Co-authored-by: Jeff Fessler <JeffFessler@users.noreply.github.com>

Co-authored-by: Jeff Fessler <JeffFessler@users.noreply.github.com>
This commit is contained in:
bramtayl 2022-03-29 13:00:39 -04:00 committed by GitHub
parent 497567e329
commit 156eae0db8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 22 deletions

View file

@ -10,10 +10,14 @@ PortAudio.jl is a wrapper for [libportaudio](http://www.portaudio.com/), which g
## Opening a stream ## Opening a stream
The easiest way to open a source or sink is with the default `PortAudioStream()` constructor, which will open a 2-in, 2-out stream to your system's default device(s). The constructor can also take the input and output channel counts as positional arguments, or a variety of other keyword arguments. The easiest way to open a source or sink is with the default `PortAudioStream()` constructor,
which will open a 2-in, 2-out stream to your system's default device(s).
The constructor can also take the input and output channel counts as positional arguments,
or a variety of other keyword arguments.
If named keyword arguments `latency` or `samplerate` are unspecified, then PortAudio will use device defaults.
```julia ```julia
PortAudioStream(inchans=2, outchans=2; eltype=Float32, samplerate=48000Hz, latency=0.1, synced=false) PortAudioStream(inchans=2, outchans=2; eltype=Float32, samplerate=48000, latency=0.1)
``` ```
You can open a specific device by adding it as the first argument, either as a `PortAudioDevice` instance or by name. You can also give separate names or devices if you want different input and output devices You can open a specific device by adding it as the first argument, either as a `PortAudioDevice` instance or by name. You can also give separate names or devices if you want different input and output devices
@ -27,13 +31,16 @@ You can get a list of your system's devices with the `PortAudio.devices()` funct
```julia ```julia
julia> PortAudio.devices() julia> PortAudio.devices()
6-element Array{PortAudio.PortAudioDevice,1}: 14-element Vector{PortAudio.PortAudioDevice}:
PortAudio.PortAudioDevice("AirPlay","Core Audio",0,2,0) "sof-hda-dsp: - (hw:0,0)" 2→2
PortAudio.PortAudioDevice("Built-in Microph","Core Audio",2,0,1) "sof-hda-dsp: - (hw:0,3)" 0→2
PortAudio.PortAudioDevice("Built-in Output","Core Audio",0,2,2) "sof-hda-dsp: - (hw:0,4)" 0→2
PortAudio.PortAudioDevice("JackRouter","Core Audio",2,2,3) "sof-hda-dsp: - (hw:0,5)" 0→2
PortAudio.PortAudioDevice("After Effects 13.5","Core Audio",0,0,4)
PortAudio.PortAudioDevice("Built-In Aggregate","Core Audio",2,2,5) "upmix" 8→8
"vdownmix" 6→6
"dmix" 0→2
"default" 32→32
``` ```
## Reading and Writing ## Reading and Writing
@ -75,7 +82,7 @@ end
### Open your built-in microphone and speaker by name ### Open your built-in microphone and speaker by name
```julia ```julia
PortAudioStream("Built-in Microph", "Built-in Output") do stream PortAudioStream("default", "default") do stream
write(stream, stream) write(stream, stream)
end end
``` ```
@ -92,10 +99,9 @@ julia> using SampledSignals: s
julia> using FileIO: save julia> using FileIO: save
julia> stream = PortAudioStream(1, 0) # default input (e.g., built-in microphone) julia> stream = PortAudioStream(1, 0) # default input (e.g., built-in microphone)
PortAudio.PortAudioStream{Float32,SIUnits.SIQuantity{Int64,0,0,-1,0,0,0,0,0,0}} PortAudioStream{Float32}
Samplerate: 48000 s⁻¹ Samplerate: 44100.0Hz
Buffer Size: 4096 frames 2 channel source: "default"
2 channel source: "Built-in Microph"
julia> buf = read(stream, 10s) julia> buf = read(stream, 10s)
480000-frame, 2-channel SampleBuf{Float32, 2, SIUnits.SIQuantity{Int64,0,0,-1,0,0,0,0,0,0}} 480000-frame, 2-channel SampleBuf{Float32, 2, SIUnits.SIQuantity{Int64,0,0,-1,0,0,0,0,0,0}}
@ -114,7 +120,7 @@ julia> save(joinpath(homedir(), "Desktop", "myvoice.ogg"), buf)
using PortAudio, SampledSignals using PortAudio, SampledSignals
S = 8192 # sampling rate (samples / second) S = 8192 # sampling rate (samples / second)
x = cos.(2pi*(1:2S)*440/S) # A440 tone for 2 seconds x = cos.(2pi*(1:2S)*440/S) # A440 tone for 2 seconds
PortAudioStream(0, 2; samplerate=Float64(S)) do stream PortAudioStream(0, 2; samplerate=S) do stream
write(stream, x) write(stream, x)
end end
``` ```

View file

@ -730,20 +730,24 @@ function PortAudioStream(
output_device.output_bounds.high_latency, output_device.output_bounds.high_latency,
) )
end end
if samplerate === nothing samplerate = if samplerate === nothing
samplerate = combine_default_sample_rates( combine_default_sample_rates(
input_device, input_device,
input_device.default_sample_rate, input_device.default_sample_rate,
output_device, output_device,
output_device.default_sample_rate, output_device.default_sample_rate,
) )
else
float(samplerate)
end end
else else
if latency === nothing if latency === nothing
latency = input_device.input_bounds.high_latency latency = input_device.input_bounds.high_latency
end end
if samplerate === nothing samplerate = if samplerate === nothing
samplerate = input_device.default_sample_rate input_device.default_sample_rate
else
float(samplerate)
end end
end end
else else
@ -751,9 +755,11 @@ function PortAudioStream(
if latency === nothing if latency === nothing
latency = output_device.output_bounds.high_latency latency = output_device.output_bounds.high_latency
end end
if samplerate === nothing samplerate = if samplerate === nothing
samplerate = output_device.default_sample_rate output_device.default_sample_rate
end else
float(samplerate)
end
else else
throw(ArgumentError("Input or output must have at least 1 channel")) throw(ArgumentError("Input or output must have at least 1 channel"))
end end