Library
Module
AuditoryStimuli.AuditoryStimuli — ModuleA Julia package for generating auditory stimuli.
Signal generators
AuditoryStimuli.NoiseSource — TypeNoiseSource(eltype, samplerate, nchannels, std=1)NoiseSource is a multi-channel noise signal generator. The noise on each channel is independent.
Inputs
sampleratespecifies the sample rate of the signal specified in Hz.nchannelsspecifies the number of channels of the signal.stdspecifies the desired standard deviation of the signal.
Output
- SampleSource object
Example
source_object = NoiseSource(Float64, 48u"kHz", 2, 0.3)
wn = read(source_object, 480) # Specify number of samples of signal to generate
wn = read(source_object, 50u"ms") # Specify length of time of signal to generateAuditoryStimuli.CorrelatedNoiseSource — TypeCorrelatedNoiseSource(eltype, samplerate, nchannels, std, correlation)CorrelatedNoiseSource is a two-channel noise signal generator with controlled correlation between channels.
Inputs
sampleratespecifies the sample rate of the signal.nchannelsspecifies the number of channels of the signal.stdspecifies the desired standard deviation of the signal.correlationspecifies the desired correlation between the signals.
Output
- SampleSource object
Example
source_object = CorrelatedNoiseSource(Float64, 48000, 2, 0.3, 0.75)
cn = read(source_object, 480) # Specify number of samples of signal to generate
cn = read(source_object, 50u"ms") # Specify length of time of signal to generateAuditoryStimuli.SinusoidSource — TypeSinusoidSource(eltype, samplerate, freqs)SinusoidSource is a single-channel sine-tone signal generator. freqs can be an array of frequencies for a multi-frequency source, or a single frequency for a single sinusoid source.
Inputs
sampleratespecifies the sample rate of the signal.freqssinusoid frequencies to generate.
Output
- SampleSource object
Example
source_object = SinusoidSource(Float64, 48u"kHz", 200:200:2400)
cn = read(source_object, 50u"ms") # Generate 50 ms of harmonic stack audioOnline signal modifiers
AuditoryStimuli.Amplification — TypeAmplification(target, current, change_limit)Apply amplification to the signal.
This modifier allows the user to specify a target linear amplification value that will be applied to the signal. The modifier will then change the amplification of the signal until the desired amplification is achieved. The rate at which the amplification can be changed per frame is parameterised by the change_limit parameter.
To slowly ramp a signal to a desired value set the target amplification to the desired value, and the change_limit to a small value.
To instantly change the signal set the change_limit to infinity and modify the target value.
When initialising the modifier specify the desired starting point using the current parameter.
You can access the exact amplification at any time by querying the current parameter.
Inputs
targetdesired linear amplification factor to be applied to signal.currentlinear amplification currently applied to signal. Also used to specify the intial value for the process.change_limitmaximum change that can occur per frame.enableenable the modifier, if false the signal will be passed through without modification.
Example
amplify = Amplification(0.1, 0.0, 0.05)
attenuated_sound = modify(amplify, original_sound)AuditoryStimuli.Filter — TypeFilter(filters)Apply filter to the signal
Inputs
filtersarray of DSP filter objects.
Example
using DSP
responsetype = Bandpass(500, 4000; fs=48000)
designmethod = Butterworth(4)
zpg = digitalfilter(responsetype, designmethod)
f_left = DSP.Filters.DF2TFilter(zpg)
f_right = DSP.Filters.DF2TFilter(zpg)
bandpass = AuditoryStimuli.Filter([f_left, f_right])
filtered_sound = modify(bandpass, original_sound)AuditoryStimuli.AmplitudeModulation — TypeAmplitudeModulation(rate, phase, depth)Apply amplitude modulation to the signal
Inputs
rate(Hz) desired modulation rate to be applied to signal.phasephase of modulation to be applied to signal applied to signal. Defaults to pi so that modulation starts at a minimum.depthmodulation depth.
Example
modulate = AmplitudeModulation(1u"Hz")
modulated_sound = modify(modulate, original_sound)AuditoryStimuli.TimeDelay — TypeTimeDelay(channel, delay, enable, buffer)
TimeDelay(channel, delay, enable, buffer; samplerate)Apply a time delay to a specific channel.
Inputs
channelwhich channel should have a time delay applied.delaydelay to be applied in samples or unit of time.enableshould the modifier be enabled. Defaults to true.bufferinitial values with which to pad the time delay. Defaults to zeros.sampleratekeyword argument required if delay is specified in unit of time.
Example
itd = TimeDelay(2, 0.5u"ms", samplerate=48u"kHz")
sound_with_itd = modify(itd, original_sound)Offline Signal modifiers
AuditoryStimuli.ramp_on — Functionramp_on(data, number_samples)Apply a linear ramp to start of signal
AuditoryStimuli.ramp_off — Functionramp_off(data, number_samples)Apply a linear ramp to end of signal
Plotting
AuditoryStimuli.PlotSpectroTemporal — FunctionPlotSpectroTemporal(data, sample_rate)This function plots the time, spectrogram, and periodogram of a signal.
AuditoryStimuli.plot_cross_correlation — Functionplot_cross_correlation(x::SampleBuf, lags::Unitful.Time)Plot the cross correlation of a two channel audio signal.
Inputs
xdata in the form of SampledSignals.SampleBuf. Must be two channels of audio.lagstime range of lags to be used when plotting the cross correlation function. If lags=0, then the entire function will be used, effecively same as lags=Inf.
Example
correlation = 0.6
source = CorrelatedNoiseSource(Float64, 48u"kHz", 2, 0.1, correlation)
a = read(source, 3u"s")
plot_cross_correlation(a, lags=4u"ms")Signal Metrics
AuditoryStimuli.interaural_coherence — Functioninteraural_coherence(x::SampleBuf, lags::Unitful.Time)Compute the interaural coherence of a two channel sound signals.
Interaural coherence (IAC) is commonly defined as the peak of the cross-correlation coefficient of the signals at the two ears [1, 2]. It is commonly computed over a restricted range of lags of the cross-correlation function.
Inputs
xdata in the form of SampledSignals.SampleBuf. Must be two channels of audio.lagstime range of lags to be used for finding maximum in cross correlation function. If lags=0, then the entire function will be used, effecively same as lags=Inf.
References
- Chait, M., Poeppel, D., de Cheveigne, A., and Simon, J.Z. (2005). Human auditory cortical processing of changes in interaural correlation. J Neurosci 25, 8518-8527.
- Aaronson, N.L., and Hartmann, W.M. (2010). Interaural coherence for noise bands: waveforms and envelopes. J Acoust Soc Am 127, 1367-1372.
Example
correlation = 0.6
source = CorrelatedNoiseSource(Float64, 48000, 2, 0.1, correlation)
a = read(source, 3u"s")
@test interaural_coherence(a.data) ≈ correlation atol = 0.025Depreciated
AuditoryStimuli.bandpass_noise — Functionbandpass_noise(number_samples, number_channels, lower_bound, upper_bound, sample_rate; filter_order=14)Generates band pass noise with specified upper and lower bounds using a butterworth filter.
AuditoryStimuli.bandpass_filter — Functionbandpass_filter(AbstractArray, lower_bound, upper_bound, sample_rate; filter_order=14)
bandpass_filter(SampledSignal, lower_bound, upper_bound; filter_order=14)Signal will be filtered with bandpass butterworth filter between 'lowerbound' and `upperboundwith filter offilter_order`.
AuditoryStimuli.amplitude_modulate — Functionamplitude_modulate(data, modulation_frequency, sample_rate; phase=π)Amplitude modulates the signal
See wikipedia
AuditoryStimuli.ITD_modulate — FunctionITD_modulate(data, modulation_frequency, ITD_1, ITD_2, samplerate)Modulate an applied ITD
AuditoryStimuli.set_RMS — Functionset_RMS(data, desired_rms)Modify rms of signal to desired value
AuditoryStimuli.set_ITD — Functionset_ITD(data, number_samples)Introduce an ITD of number_samples