Methods list
Sound.Sound
Sound.findpeaks
Sound.get_default_input_device
Sound.get_default_output_device
Sound.hann
Sound.hann
Sound.phase_vocoder
Sound.pick_output
Sound.record
Sound.sound
Sound.sound
Sound.sound
Sound.sound
Sound.sound
Sound.soundsc
Sound.soundsc
Methods usage
Sound.Sound
— ModuleSound
Module that exports wrappers around audio methods in PortAudio
.
sound
andsoundsc
: methods for audio playback.record
: method for audio recording.
Sound.findpeaks
— Functionfindpeaks(amp, max_peak::Int = 50, eps_peak::Real = 0.005)
Given a real-valued vector of amplitudes amp
, find up to max_peak
peaks. Ignores any amplitudes ≤ eps_peak * maxium(amp)
.
Returns a matrix with 3 columns where each row describes a peak.
Sound.get_default_input_device
— Methodget_default_input_device()
Determine current system-wide default input audio device.
Sound.get_default_output_device
— Methodget_default_output_device()
Determine current system-wide default output audio device.
Sound.hann
— Methodhann(x::AbstractFloat)
Hann window function (often called "Hanning" window function). This version is 0.5 * (1 + cospi(2x))
and used in [-0.5,+0.5]
. https://en.wikipedia.org/wiki/Hann_function
Sound.hann
— Methodhann(n::Int)
Return vector of n ≥ 2
samples of Hann window function equally spaced over [-0.5,+0.5]
. The first and last samples are zero for n ≥ 2
.
Caution. Matlab has both hann
and hanning
functions for which [0; hanning(n); 0] == hann(n+2)
.
DSP.hanning(n)
== Matlab.hann(n)whereas
Sound.hann(n) == Matlab.hanning(n)`.
Sound.phase_vocoder
— Functionphase_vocoder(x, sr = framerate(x); kwargs...)
Phase vocoder for time scaling of signal x
having sampling rate sr
in Hz. The time-stretch is determined by the ratio of hopin
and hopout
variables. For example, hopin=242
and hopout=161.3333
(integers are not required) increases the tempo by hopin/hopout = 1.5
. To slow down a comparable amount, choose hopin = 161.3333
, hopout = 242
.
Option
time::Real = length(x) * sr
: total time to process (in sec)hopin::Real = 121
: hop length for inputhopout::Real = 2*hopin
: hop length for outputall2pi::Any = 2π*(0:100)
multiples of 2π (used in PV-style freq search)max_peak::Int = 50
: parameters for peak finding: number of peakseps_peak::Real = 0.005
: minimum height of peaksnfft::Int = 2^12
: fft lengthwin::AbstractVector{<:Real} = hann(nfft)
: windowT::Type = Float32
: data type
Sound.pick_output
— Methodpick_output( ; io_in::IO = stdin, io_out::IO = stdout)
Show available audio devices and prompt user to select output device.
Sound.record
— Functiondata, S = record(time::Real = 5; input_device, args=(1,0), chat::Bool=true)
Record time
seconds of audio data using input_device
(typically defaults to the built-in microphone).
Input
time
: duration; 5 seconds by default
Option
input_device::PortAudioDevice = get_default_input_device()
system defaultargs
: arguments to PortAudioStream;(1,0)
for single-channel input by defaultchat
: show begin/end message?true
by default
Output
data
: Vector of lengthtime * S
S
:sample_rate
of input stream
Sound.sound
— Functionsound(x::AbstractVector, S::Real = framerate(x), args...; kwargs...)
Play monophonic audio signal x
at sampling rate S
samples per second through default audio output device using the PortAudio
package. Caller must specify S
unless a framerate
method is defined for x
.
Sound.sound
— Functionsound(x::AbstractMatrix, S::Real = framerate(x) [, output_device])
Play stereo audio signal x
at sampling rate S
samples per second through default audio output device using the PortAudio
package. Caller must specify S
unless a framerate
method is defined for x
.
Sound.sound
— Functionsound(:pick, x, S::Real = framerate(x); kwargs...)
Prompt user to pick output device, then play sound in x
.
Sound.sound
— Functionsound(output_device_index::Int, x, S::Real = framerate(x); kwargs...)
Play sound in x
using devices()[output_device_index]
.
Sound.sound
— Methodsound(sb::SampleBuf)
Play audio signal sb
of type SampleBuf
through default audio output device using the PortAudio
package.
Sound.soundsc
— Functionsoundsc(x, S::Real = framerate(x), args...; kwargs...)
Call sound
after scaling x
to have values in (-1,1)
.
Sound.soundsc
— Methodsoundsc(sb::SampleBuf)
Play audio signal sb
of type SampleBuf
through default audio output device using the PortAudio
package, after scaling the data to have values in (-1,1)
.