Example: Harmonic Stack Complex

Harmonic stacks are often used to investigate pitch processing and streaming/grouping. Harmonic complexes contain a set of frequency components which are harmonics.

In this example we generate a harmonic stack which is modulated at 15 Hz.

Realtime Example

In this example we process the audio in 10 millisecond frames.

using AuditoryStimuli, Unitful, Plots, Pipe, DSP

# Specify the source, modifiers, and sink of our audio pipeline
stack_frequencies = 200:200:2400
source = SinusoidSource(Float64, 48u"kHz", stack_frequencies)
amp = Amplification(current=1/length(stack_frequencies),
am = AmplitudeModulation(15u"Hz")
sink = DummySampleSink(Float64, 48u"kHz", 1)

# Run real time audio processing
for frame = 1:100
    @pipe read(source, 0.01u"s") |> modify(amp, _) |> modify(am, _) |> write(sink, _)

# Validate the audio pipeline output
PlotSpectroTemporal(sink, frequency_limits = [0, 3000], time_limits = [0.135, 0.33])
Example block output

Offline Example

It is also possible to generate the audio in an offline (all in one step) manner. This may be useful for creating wav files for use in simpler experiments.

using AuditoryStimuli, Unitful, Plots, WAV

stack_frequencies = 200:200:2400
source = SinusoidSource(Float64, 48u"kHz", stack_frequencies)
am = AmplitudeModulation(15u"Hz")

audio = read(source, 1.0u"s")
modulated_audio = modify(am, audio)

# Write the audio to disk as a wav file
wavwrite(modulated_audio.data ./ length(stack_frequencies), "harmonic-stack.wav",Fs=48000)