Methods list

Methods usage

Sound.SoundModule
Sound

Module that exports wrappers around audio methods in PortAudio.

  • sound and soundsc : methods for audio playback.
  • record : method for audio recording.
source
Sound.findpeaksFunction
findpeaks(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.

source
Sound.hannMethod
hann(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

source
Sound.hannMethod
hann(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)whereasSound.hann(n) == Matlab.hanning(n)`.

source
Sound.phase_vocoderFunction
phase_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 input
  • hopout::Real = 2*hopin : hop length for output
  • all2pi::Any = 2π*(0:100) multiples of 2π (used in PV-style freq search)
  • max_peak::Int = 50 : parameters for peak finding: number of peaks
  • eps_peak::Real = 0.005 : minimum height of peaks
  • nfft::Int = 2^12 : fft length
  • win::AbstractVector{<:Real} = hann(nfft) : window
  • T::Type = Float32 : data type
source
Sound.pick_outputMethod
pick_output( ; io_in::IO = stdin, io_out::IO = stdout)

Show available audio devices and prompt user to select output device.

source
Sound.recordFunction
data, 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 default
  • args : arguments to PortAudioStream; (1,0) for single-channel input by default
  • chat : show begin/end message? true by default

Output

  • data : Vector of length time * S
  • S : sample_rate of input stream
source
Sound.soundFunction
sound(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.

source
Sound.soundFunction
sound(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.

source
Sound.soundFunction
sound(:pick, x, S::Real = framerate(x); kwargs...)

Prompt user to pick output device, then play sound in x.

source
Sound.soundFunction
sound(output_device_index::Int, x, S::Real = framerate(x); kwargs...)

Play sound in x using devices()[output_device_index].

source
Sound.soundMethod
sound(sb::SampleBuf)

Play audio signal sb of type SampleBuf through default audio output device using the PortAudio package.

source
Sound.soundscFunction
soundsc(x, S::Real = framerate(x), args...; kwargs...)

Call sound after scaling x to have values in (-1,1).

source
Sound.soundscMethod
soundsc(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).

source