A module for generating sounds in python. |
sndlib
– Sound Synthesis Library
A module for generating sounds in python.
- sndlib.AMTone(frequency=1000, AMFreq=20, AMDepth=1, phase=0, AMPhase=0, level=60, duration=980, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Generate an amplitude modulated tone.
- Parameters:
- frequencyfloat
Carrier frequency in hertz.
- AMFreqfloat
Amplitude modulation frequency in Hz.
- AMDepthfloat
Amplitude modulation depth (a value of 1 corresponds to 100% modulation).
- phasefloat
Starting phase in radians.
- AMPhasefloat
Starting AM phase in radians.
- levelfloat
Average tone level in dB SPL. See notes.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channelstring (‘Right’, ‘Left’ or ‘Both’)
Channel in which the tone will be generated.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
Notes
For a fixed base amplitude, the average power of an AM tone (as defined in this function) increases proportionally with AM depth by a factor of 1+AMDepth^2/2 (Viemeister, 1979, Yost et al., 1989, Hartmann, 2004). This function compensates for this average increase in power. You can use the AMToneVarLev function if you want to generate AM tones varying in average power with AM depth.
References
[H]Hartmann, W. M. (2004). Signals, Sound, and Sensation. Springer Science & Business Media
[V79]Viemeister, N. F. (1979). Temporal modulation transfer functions based upon modulation thresholds. The Journal of the Acoustical Society of America, 66(5), 1364–1380. https://doi.org/10.1121/1.383531
[YSO]Yost, W., Sheft, S., & Opie, J. (1989). Modulation interference in detection and discrimination of amplitude modulation. The Journal of the Acoustical Society of America, 86(December 1989), 2138–2147. https://doi.org/10.1121/1.398474
Examples
>>> snd = AMTone(frequency=1000, AMFreq=20, AMDepth=1, phase=0, ... AMPhase=1.5*pi, level=65, duration=180, ramp=10, channel='Both', ... fs=48000, maxLevel=100)
- sndlib.AMToneIPD(frequency=1000, AMFreq=20, AMDepth=1, phase=0, AMPhase=0, phaseIPD=0, AMPhaseIPD=0, level=60, duration=980, ramp=10, channel='Right', fs=48000, maxLevel=101)[source]
Generate an amplitude modulated tone with an interaural phase difference (IPD) in the carrier and/or modulation phase.
- Parameters:
- frequencyfloat
Carrier frequency in hertz.
- AMFreqfloat
Amplitude modulation frequency in Hz.
- AMDepthfloat
Amplitude modulation depth (a value of 1 corresponds to 100% modulation).
- phasefloat
Starting phase in radians.
- AMPhasefloat
Starting AM phase in radians.
- phaseIPDfloat
IPD to apply to the carrier phase.
- AMPhaseIPDfloat
IPD to apply to the modulation phase.
- levelfloat
Average tone level in dB SPL. See notes.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channelstring (‘Right’, ‘Left’)
Channel in which the phase will be shifted.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
Notes
For a fixed base amplitude, the average power of an AM tone (as defined in this function) increases proportionally with AM depth by a factor of 1+AMDepth^2/2 (Viemeister, 1979, Yost et al., 1989, Hartmann, 2004). This function does not compensate for this average increase in power. You can use the AMTone function if you want to generate AM tones matched in average power irrespective of AM depth.
References
[H]Hartmann, W. M. (2004). Signals, Sound, and Sensation. Springer Science & Business Media
[V79]Viemeister, N. F. (1979). Temporal modulation transfer functions based upon modulation thresholds. The Journal of the Acoustical Society of America, 66(5), 1364–1380. https://doi.org/10.1121/1.383531
[YSO]Yost, W., Sheft, S., & Opie, J. (1989). Modulation interference in detection and discrimination of amplitude modulation. The Journal of the Acoustical Society of America, 86(December 1989), 2138–2147. https://doi.org/10.1121/1.398474
Examples
>>> snd = AMToneIPD(frequency=1000, AMFreq=20, AMDepth=1, phase=0, AMPhase=1.5*pi, ... phaseIPD=0, AMPhaseIPD=pi, level=65, ... duration=180, ramp=10, channel='Right', fs=48000, maxLevel=100)
- sndlib.AMToneVarLev(frequency=1000, AMFreq=20, AMDepth=1, phase=0, AMPhase=0, level=60, duration=980, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Generate an amplitude modulated (AM) tone.
- Parameters:
- frequencyfloat
Carrier frequency in hertz.
- AMFreqfloat
Amplitude modulation frequency in Hz.
- AMDepthfloat
Amplitude modulation depth (a value of 1 corresponds to 100% modulation).
- phasefloat
Starting phase in radians.
- AMPhasefloat
Starting AM phase in radians.
- levelfloat
Average level of the tone in dB SPL when the AMDepth is zero. The level of the tone will be higher when AMDepth is > zero. See notes.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channelstring (‘Right’, ‘Left’ or ‘Both’)
Channel in which the tone will be generated.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
Notes
For a fixed base amplitude, the average power of an AM tone (as defined in this function) increases proportionally with AM depth by a factor of 1+AMDepth^2/2 (Viemeister, 1979, Yost et al., 1989, Hartmann, 2004). This function does not compensate for this average increase in power. You can use the AMTone function if you want to generate AM tones matched in average power irrespective of AM depth.
References
[H]Hartmann, W. M. (2004). Signals, Sound, and Sensation. Springer Science & Business Media
[YSO]Yost, W., Sheft, S., & Opie, J. (1989). Modulation interference in detection and discrimination of amplitude modulation. The Journal of the Acoustical Society of America, 86(December 1989), 2138–2147. https://doi.org/10.1121/1.398474
Examples
>>> snd = AMToneVarLev(frequency=1000, AMFreq=20, AMDepth=1, phase=0, ... AMPhase=1.5*pi, level=65, duration=180, ramp=10, channel='Both', ... fs=48000, maxLevel=100)
- sndlib.ERBDistance(f1, f2)[source]
Compute the distance in equivalent rectangular bandwiths (ERBs) between f1 and f2.
- Parameters:
- f1float
frequency 1 in Hz
- f2float
frequency 2 in Hz
- Returns:
- deltaERBfloat
distance between f1 and f2 in ERBs
References
[GM]Glasberg, B. R., & Moore, B. C. J. (1990). Derivation of auditory filter shapes from notched-noise data. Hear. Res., 47(1-2), 103–38.
Examples
>>> ERBDistance(1000, 1200)
- sndlib.FMTone(fc=1000, fm=40, mi=1, phase=0, level=60, duration=180, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Generate a frequency modulated tone.
- Parameters:
- fcfloat
Carrier frequency in hertz. This is the frequency of the tone at fm zero crossing.
- fmfloat
Modulation frequency in Hz.
- mifloat
Modulation index, also called beta and is equal to deltaF/fm, where deltaF is the maximum deviation of the instantaneous frequency from the carrier frequency.
- phasefloat
Starting phase in radians.
- levelfloat
Tone level in dB SPL.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channel‘Right’, ‘Left’ or ‘Both’
Channel in which the tone will be generated.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
Examples
>>> snd = FMTone(fc=1000, fm=40, mi=1, phase=0, level=55, duration=180, ... ramp=10, channel='Both', fs=48000, maxLevel=100)
- sndlib.ITDShift(sig, f1, f2, ITD, channel, fs)[source]
Set the ITD of a sound within the frequency region bounded by ‘f1’ and ‘f2’
- Parameters:
- sigarray of floats
Input signal.
- f1float
The start point of the frequency region to be phase-shifted in hertz.
- f2float
The end point of the frequency region to be phase-shifted in hertz.
- ITDfloat
The amount of ITD shift in microseconds
- channelstring (‘Right’ or ‘Left’)
The channel in which to apply the shift.
- fsfloat
The sampling frequency of the sound.
- Returns:
- out2-dimensional array of floats
Examples
>>> noise = broadbandNoise(spectrumLevel=40, duration=180, ramp=10, ... channel='Both', fs=48000, maxLevel=100) >>> hp = ITDShift(sig=noise, f1=500, f2=600, ITD=5, channel='Left', fs=48000) #this generates a Dichotic Pitch
- sndlib.addSounds(snd1, snd2, delay, fs)[source]
Add or concatenate two sounds.
- Parameters:
- snd1array of floats
First sound.
- snd2array of floats
Second sound.
- delayfloat
Delay in milliseconds between the onset of ‘snd1’ and the onset of ‘snd2’
- fsfloat
Sampling frequency in hertz of the two sounds.
- Returns:
- snd2-dimensional array of floats
Examples
>>> snd1 = pureTone(frequency=440, phase=0, level=65, duration=180, ... ramp=10, channel='Right', fs=48000, maxLevel=100) >>> snd2 = pureTone(frequency=880, phase=0, level=65, duration=180, ... ramp=10, channel='Right', fs=48000, maxLevel=100) >>> snd = addSounds(snd1=snd1, snd2=snd2, delay=100, fs=48000)
- sndlib.binauralPureTone(frequency=1000, phase=0, level=60, duration=980, ramp=10, channel='Both', itd=0, itdRef='Right', ild=10, ildRef='Right', fs=48000, maxLevel=101)[source]
Generate a pure tone with an optional interaural time or level difference.
- Parameters:
- frequencyfloat
Tone frequency in hertz.
- phasefloat
Starting phase in radians.
- levelfloat
Tone level in dB SPL. If ‘ild’ is different than zero, this will be the level of the tone in the reference channel.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channelstring (‘Right’, ‘Left’ or ‘Both’)
Channel in which the tone will be generated.
- itdfloat
Interaural time difference, in microseconds.
- itdRef‘Right’, ‘Left’ or None
The reference channel for the ‘itd’. The interaural time difference will be applied to the other channel with respect to the reference channel.
- ildfloat
Interaural level difference in dB SPL.
- ildRef‘Right’, ‘Left’ or None
The reference channel for the ‘ild’. The level of the other channel will be icreased of attenuated by ‘ild’ dB SPL with respect to the reference channel.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> itdTone = binauralPureTone(frequency=440, phase=0, level=65, duration=180, ... ramp=10, channel='Both', itd=480, itdRef='Right', ild=0, ildRef=None, ... fs=48000, maxLevel=100) >>> ildTone = binauralPureTone(frequency=440, phase=0, level=65, duration=180, ... ramp=10, channel='Both', itd=0, itdRef=None, ild=-20, ildRef='Right', ... fs=48000, maxLevel=100)
- sndlib.broadbandNoise(spectrumLevel=25, duration=980, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Synthetise a broadband noise.
- Parameters:
- spectrumLevelfloat
Intensity spectrum level of the noise in dB SPL.
- durationfloat
Noise duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channelstring (“Right”, “Left”, “Both”, or “Dichotic”)
Channel in which the noise will be generated. If ‘Both’ the same noise will be generated in both channels. If ‘Dichotic’ the noise will be independent at the two ears.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> noise = broadbandNoise(spectrumLevel=40, duration=180, ramp=10, ... channel="Both", fs=48000, maxLevel=100)
- sndlib.camSinFMComplex(F0=150, lowHarm=1, highHarm=10, harmPhase='Sine', fm=5, deltaCams=1, fmPhase=3.141592653589793, level=60, duration=180, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Generate a complex tone frequency modulated with an exponential sinusoid.
- Parameters:
- F0float
Fundamental aarrier frequency in hertz.
- lowHarm: int
Lowest harmonic number.
- highHarm: int
Highest harmonic number.
- harmPhase: string
Harmonic phase relationship. One of ‘Sine’, ‘Cosine’, or ‘Alternating’.
- fmfloat
Modulation frequency in Hz.
- deltaCamsfloat
Frequency excursion in cam units (ERBn number scale).
- fmPhasefloat
Starting fmPhase in radians.
- levelfloat
Tone level in dB SPL.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channel‘Right’, ‘Left’ or ‘Both’
Channel in which the tone will be generated.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
Examples
>>> snd_peak = camSinFMComplex(F0=150, lowHarm=1, highHarm=10, harmPhase="Sine", fm=5, deltaCams=1, fmPhase=pi, level=60, ... duration=180, ramp=10, channel="Both", fs=48000, maxLevel=100) >>> snd_trough = camSinFMComplex(F0=150, lowHarm=1, highHarm=10, harmPhase="Sine", fm=5, deltaCams=1, fmPhase=0, level=60, ... duration=180, ramp=10, channel="Both", fs=48000, maxLevel=100)
- sndlib.camSinFMTone(fc=450, fm=5, deltaCams=1, fmPhase=3.141592653589793, startPhase=0, level=60, duration=180, ramp=10, channel='Both', fs=48000, maxLevel=100)[source]
Generate a tone frequency modulated with an exponential sinusoid.
- Parameters:
- fcfloat
Carrier frequency in hertz.
- fmfloat
Modulation frequency in Hz.
- deltaCamsfloat
Frequency excursion in cam units (ERBn number scale).
- fmPhasefloat
Starting fmPhase in radians.
- levelfloat
Tone level in dB SPL.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channel‘Right’, ‘Left’ or ‘Both’
Channel in which the tone will be generated.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
Examples
>>> tone_peak = camSinFMTone(fc=450, fm=5, deltaCams=1, fmPhase=pi, startPhase=0, level=60, ... duration=180, ramp=10, channel="Both", fs=48000, maxLevel=100) >>> tone_trough = camSinFMTone(fc=450, fm=5, deltaCams=1, fmPhase=0, startPhase=0, level=60, ... duration=180, ramp=10, channel="Both", fs=48000, maxLevel=100)
- sndlib.chirp(freqStart=440, ftype='linear', rate=500, level=60, duration=980, phase=0, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Synthetize a chirp, that is a tone with frequency changing linearly or exponentially over time with a give rate.
- Parameters:
- freqStartfloat
Starting frequency in hertz.
- ftypestring
If ‘linear’, the frequency will change linearly on a Hz scale. If ‘exponential’, the frequency will change exponentially on a cents scale.
- ratefloat
Rate of frequency change, Hz/s if ftype is ‘linear’, and cents/s if ftype is ‘exponential’.
- levelfloat
Level of the tone in dB SPL.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channelstring (‘Right’, ‘Left’ or ‘Both’)
Channel in which the tone will be generated.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> gl = chirp(freqStart=440, ftype='linear', rate=500, level=55, duration=980, phase=0, ramp=10, channel='Both', fs=48000, maxLevel=100)
- sndlib.complexTone(F0=220, harmPhase='Sine', lowHarm=1, highHarm=10, stretch=0, level=60, duration=980, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Synthetise a complex tone.
- Parameters:
- F0float
Tone fundamental frequency in hertz.
- harmPhaseone of ‘Sine’, ‘Cosine’, ‘Alternating’, ‘Random’, ‘Schroeder-’, ‘Schroeder+’
Phase relationship between the partials of the complex tone.
- lowHarmint
Lowest harmonic component number.
- highHarmint
Highest harmonic component number.
- stretchfloat
Harmonic stretch in %F0. Increase each harmonic frequency by a fixed value that is equal to (F0*stretch)/100. If ‘stretch’ is different than zero, an inhanmonic complex tone will be generated.
- levelfloat
The level of each partial in dB SPL.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channel‘Right’, ‘Left’, ‘Both’, ‘Odd Right’ or ‘Odd Left’
Channel in which the tone will be generated. If ‘channel’ if ‘Odd Right’, odd numbered harmonics will be presented to the right channel and even number harmonics to the left channel. The opposite is true if ‘channel’ is ‘Odd Left’.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> ct = complexTone(F0=440, harmPhase='Sine', lowHarm=3, highHarm=10, ... stretch=0, level=55, duration=180, ramp=10, channel='Both', ... fs=48000, maxLevel=100)
- sndlib.complexToneIPD(F0=220, harmPhase='Sine', lowHarm=1, highHarm=10, stretch=0, level=60, duration=980, ramp=10, IPD=3.14, targetEar='Right', fs=48000, maxLevel=101)[source]
Synthetise a complex tone with an interaural phase difference (IPD).
- Parameters:
- F0float
Tone fundamental frequency in hertz.
- harmPhaseone of ‘Sine’, ‘Cosine’, ‘Alternating’, ‘Random’, ‘Schroeder-’, ‘Schroeder+’
Phase relationship between the partials of the complex tone.
- lowHarmint
Lowest harmonic component number.
- highHarmint
Highest harmonic component number.
- stretchfloat
Harmonic stretch in %F0. Increase each harmonic frequency by a fixed value that is equal to (F0*stretch)/100. If ‘stretch’ is different than zero, an inhanmonic complex tone will be generated.
- levelfloat
The level of each partial in dB SPL.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- IPDfloat
Interaural phase difference, in radians.
- targetEarstring
The ear in which the phase will be shifted.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> ct = complexToneIPD(F0=440, harmPhase='Sine', lowHarm=3, highHarm=10, ... stretch=0, level=55, duration=180, ramp=10, IPD=3.14, targetEar="Right", ... fs=48000, maxLevel=100)
- sndlib.complexToneParallel(F0=220, harmPhase='Sine', lowHarm=1, highHarm=10, stretch=0, level=0, duration=980, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Synthetise a complex tone.
This function produces the same results of complexTone. The only difference is that it uses the multiprocessing Python module to exploit multicore processors and compute the partials in a parallel fashion. Notice that there is a substantial overhead in setting up the parallel computations. This means that for relatively short sounds (in the order of seconds), this function will actually be slower than complexTone.
- Parameters:
- F0float
Tone fundamental frequency in hertz.
- harmPhaseone of ‘Sine’, ‘Cosine’, ‘Alternating’, ‘Random’, ‘Schroeder-’, ‘Schroeder+’
Phase relationship between the partials of the complex tone.
- lowHarmint
Lowest harmonic component number.
- highHarmint
Highest harmonic component number.
- stretchfloat
Harmonic stretch in %F0. Increase each harmonic frequency by a fixed value that is equal to (F0*stretch)/100. If ‘stretch’ is different than zero, an inhanmonic complex tone will be generated.
- levelfloat
The level of each partial in dB SPL.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channel‘Right’, ‘Left’, ‘Both’, ‘Odd Right’ or ‘Odd Left’
Channel in which the tone will be generated. If ‘channel’ if ‘Odd Right’, odd numbered harmonics will be presented to the right channel and even number harmonics to the left channel. The opposite is true if ‘channel’ is ‘Odd Left’.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> ct = complexToneParallel(F0=440, harmPhase='Sine', lowHarm=3, highHarm=10, ... stretch=0, level=55, duration=180, ramp=10, channel='Both', ... fs=48000, maxLevel=100)
- sndlib.delayAdd(sig, delay, gain, iterations, configuration, fs)[source]
Delay and add algorithm for the generation of iterated rippled noise.
- Parameters:
- sigarray of floats
The signal to manipulate
- delayfloat
delay in seconds
- gainfloat
The gain to apply to the delayed signal
- iterationsint
The number of iterations of the delay-add cycle
- configurationstring
If ‘Add Same’, the output of iteration N-1 is added to delayed signal of the current iteration. If ‘Add Original’, the original signal is added to delayed signal of the current iteration.
- fsint
Sampling frequency in Hz.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
References
[YPS1996]Yost, W. A., Patterson, R., & Sheft, S. (1996). A time domain description for the pitch strength of iterated rippled noise. J. Acoust. Soc. Am., 99(2), 1066–78.
Examples
>>> noise = broadbandNoise(spectrumLevel=40, duration=180, ramp=10, ... channel='Both', fs=48000, maxLevel=100) >>> irn = delayAdd(sig=noise, delay=1/440, gain=1, iterations=6, configuration='Add Same', fs=48000)
- sndlib.dichoticNoiseFromSin(F0=300, lowHarm=1, highHarm=3, compLevel=30, narrowBandCompLevel=30, lowFreq=40, highFreq=2000, compSpacing=10, sigBandwidth=100, distanceUnit='Cent', phaseRelationship='NoSpi', dichoticDifference='IPD Stepped', dichoticDifferenceValue=3.141592653589793, duration=380, ramp=10, fs=48000, maxLevel=101)[source]
Generate Huggins pitch or narrow-band noise from random-phase sinusoids.
This function generates first noise by adding closely spaced sinusoids in a wide frequency range. Then, it can apply an interaural time difference (ITD), an interaural phase difference (IPD) or a level increase to harmonically related narrow frequency bands within the noise. In the first two cases (ITD and IPD) the result is a dichotic pitch. In the last case the pitch can also be heard monaurally; adjusting the level increase, its salience can be closely matched to that of a dichotic pitch.
- Parameters:
- F0float
Centre frequency of the fundamental in hertz.
- lowHarmint
Lowest harmonic component number.
- highHarmint
Highest harmonic component number.
- compLevelfloat
Level of each sinusoidal frequency component of the noise.
- lowFreqfloat
Lowest frequency in hertz of the noise.
- highFreqfloat
Highest frequency in hertz of the noise.
- compSpacingfloat
Spacing between the sinusoidal components used to generate the noise.
- sigBandwidthfloat
Width of each harmonically related frequency band.
- distanceUnitstring (one of ‘Hz’, ‘Cent’, ‘ERB’)
The unit of measure used for ‘compSpacing’ and ‘sigBandwidth’
- phaseRelationshipstring (‘NoSpi’ or ‘NpiSo’)
If NoSpi, the phase of the regions within each frequency band will be shifted. If NpiSo, the phase of the regions between each frequency band will be shifted.
- dichoticDifferencestring (‘IPD Stepped’, ‘IPD Random’, ‘ITD’, ‘ILD Right’, ‘ILD Left’)
Selects whether the decorrelation in the target regions will be achieved by applying a costant interaural phase shift (IPD), a random IPD shift, a costant interaural time difference (ITD), or a constant interaural level difference achieved by a level change in the right (‘ILD Right’) or the left (‘ILD Left’) ear.
- dichoticDifferenceValuefloat
For ‘IPD Stepped’, this is the phase offset, in radians, between the correlated and the uncorrelated regions. For ‘ITD’ this is the ITD in the transition region, in micro seconds. For ‘Random Phase’, the range of phase shift randomization in the uncorrelated regions. For ‘ILD Left’ or ‘ILD Right’ this is the level difference between the left and right ear in the uncorrelated regions.
- narrowBandCompLevelfloat
Level of the sinusoidal components in the frequency bands. If the ‘narrowBandCompLevel’ is greater than the level of the background noise (‘compLevel’), a complex tone consisting of narrowband noises in noise will be generated.
- durationfloat
Sound duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> s1 = dichoticNoiseFromSin(F0=300, lowHarm=1, highHarm=3, compLevel=30, narrowBandCompLevel=30, lowFreq=40, highFreq=2000, compSpacing=10, sigBandwidth=100, distanceUnit='Cent', phaseRelationship='NoSpi', dichoticDifference='IPD Stepped', dichoticDifferenceValue=pi, duration=380, ramp=10, fs=48000, maxLevel=101)
- sndlib.expAMNoise(fc=150, fm=2.5, deltaCents=1200, fmPhase=3.141592653589793, AMDepth=1, spectrumLevel=24, duration=480, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Generate a sinusoidally amplitude-modulated noise with an exponentially modulated AM frequency.
- Parameters:
- fcfloat
Carrier AM frequency in hertz.
- fmfloat
Modulation of the AM frequency in Hz.
- deltaCentsfloat
AM frequency excursion in cents. The instataneous AM frequency of the noise will vary from fc**(-deltaCents/1200) to fc**(deltaCents/1200).
- fmPhasefloat
Starting phase of the AM modulation in radians.
- AMDepthfloat
Amplitude modulation depth.
- spectrumLevelfloat
Noise spectrum level in dB SPL.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channel‘Right’, ‘Left’ or ‘Both’
Channel in which the tone will be generated.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
Examples
>>> snd = expAMNoise(fc=150, fm=2.5, deltaCents=1200, fmPhase=3.14, AMDepth = 1, spectrumLevel=24, duration=480, ramp=10, channel='Both', fs=48000, maxLevel=100)
- sndlib.expSinFMComplex(F0=150, lowHarm=1, highHarm=10, harmPhase='Sine', fm=40, deltaCents=1200, fmPhase=0, level=60, duration=180, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Generate a frequency-modulated complex tone with an exponential sinusoid.
- Parameters:
- fcfloat
Carrier frequency in hertz.
- fmfloat
Modulation frequency in Hz.
- deltaCentsfloat
- Frequency excursion in cents. The instataneous frequency of the tone
will vary from fc**(-deltaCents/1200) to fc**(+deltaCents/1200).
- fmPhasefloat
Starting fmPhase in radians.
- levelfloat
Tone level in dB SPL.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channel‘Right’, ‘Left’ or ‘Both’
Channel in which the tone will be generated.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
Examples
>>> tone_peak = expSinFMComplex(F0=150, lowHarm=1, highHarm=10, harmPhase="Sine", fm=5, deltaCents=300, fmPhase=pi, level=60, ... duration=180, ramp=10, channel="Both", fs=48000, maxLevel=101) >>> tone_trough = expSinFMComplex(F0=150, lowHarm=1, highHarm=10, harmPhase="Sine", fm=5, deltaCents=300, fmPhase=0, level=60, ... duration=180, ramp=10, channel="Both", fs=48000, maxLevel=101)
- sndlib.expSinFMTone(fc=450, fm=5, deltaCents=300, fmPhase=3.141592653589793, startPhase=0, level=60, duration=180, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Generate a frequency-modulated tone with an exponential sinusoid.
- Parameters:
- fcfloat
Carrier frequency in hertz.
- fmfloat
Modulation frequency in Hz.
- deltaCentsfloat
- Frequency excursion in cents. The instataneous frequency of the tone
will vary from fc**(-deltaCents/1200) to fc**(+deltaCents/1200).
- fmPhasefloat
Starting fmPhase in radians.
- levelfloat
Tone level in dB SPL.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channel‘Right’, ‘Left’ or ‘Both’
Channel in which the tone will be generated.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
Examples
>>> tone_peak = expSinFMTone(fc=450, fm=5, deltaCents=300, fmPhase=pi, level=60, ... duration=180, ramp=10, channel="Both", fs=48000, maxLevel=101) >>> tone_trough = expSinFMTone(fc=450, fm=5, deltaCents=300, fmPhase=0, level=60, ... duration=180, ramp=10, channel="Both", fs=48000, maxLevel=101)
- sndlib.fir2Filt(f1, f2, f3, f4, snd, fs)[source]
Filter signal with a fir2 filter.
This function designs and applies a fir2 filter to a sound. The frequency response of the ideal filter will transition from 0 to 1 between ‘f1’ and ‘f2’, and from 1 to zero between ‘f3’ and ‘f4’. The frequencies must be given in increasing order.
- Parameters:
- f1float
Frequency in hertz of the point at which the transition for the low-frequency cutoff ends.
- f2float
Frequency in hertz of the point at which the transition for the low-frequency cutoff starts.
- f3float
Frequency in hertz of the point at which the transition for the high-frequency cutoff starts.
- f4float
Frequency in hertz of the point at which the transition for the high-frequency cutoff ends.
- sndarray of floats
The sound to be filtered.
- fsint
Sampling frequency of ‘snd’.
- Returns:
- snd2-dimensional array of floats
Notes
If ‘f1’ and ‘f2’ are zero the filter will be lowpass. If ‘f3’ and ‘f4’ are equal to or greater than the nyquist frequency (fs/2) the filter will be highpass. In the other cases the filter will be bandpass.
The order of the filter (number of taps) is fixed at 256. This function uses internally ‘scipy.signal.firwin2’.
Examples
>>> noise = broadbandNoise(spectrumLevel=40, duration=180, ramp=10, ... channel='Both', fs=48000, maxLevel=100) >>> lpNoise = fir2Filt(f1=0, f2=0, f3=1000, f4=1200, ... snd=noise, fs=48000) #lowpass filter >>> hpNoise = fir2Filt(f1=5000, f2=6000, f3=24000, f4=26000, ... snd=noise, fs=48000) #highpass filter >>> bpNoise = fir2Filt(f1=400, f2=600, f3=4000, f4=4400, ... snd=noise, fs=48000) #bandpass filter
- sndlib.fm_complex1(midF0=140, harmPhase='Sine', lowHarm=1, highHarm=10, level=60, duration=430, ramp=10, fmFreq=1.25, fmDepth=40, fmStartPhase=4.71238898038469, fmStartTime=25, fmDuration=400, levelAdj=True, channel='Both', fs=48000, maxLevel=101)[source]
Synthetise a complex tone with an embedded FM starting and stopping at a chosen time after the tone onset.
- Parameters:
- midF0float
F0 at the FM zero crossing
- harmPhaseone of ‘Sine’, ‘Cosine’, ‘Alternating’, ‘Random’, ‘Schroeder-’, or ‘Schroeder+’
Phase relationship between the partials of the complex tone.
- lowHarmint
Lowest harmonic component number.
- highHarmint
Highest harmonic component number.
- levelfloat
The level of each partial in dB SPL.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- fmFreqfloat
FM frequency in Hz.
- fmDepthfloat
FM depth in %
- fmStartPhasefloat
Starting phase of FM
- fmStartTimefloat
Start of FM in ms after start of tone
- fmDurationfloat
Duration of FM, in ms
- levelAdjlogical
If True, scale the harmonic level so that for a complex tone within a bandpass filter the overall level does not change with F0 modulations.
- channel: ‘Right’, ‘Left’, ‘Both’, ‘Odd Right’ or ‘Odd Left’
Channel in which the tone will be generated. If ‘channel’ if ‘Odd Right’, odd numbered harmonics will be presented to the right channel and even number harmonics to the left channel. The opposite is true if ‘channel’ is ‘Odd Left’.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
Examples
>>> tone_up = fm_complex1(midF0=140, harmPhase="Sine", lowHarm=1, highHarm=10, level=60, duration=430, ramp=10, fmFreq=1.25, fmDepth=40, fmStartPhase=1.5*pi, fmStartTime=25, fmDuration=400, levelAdj=True, channel="Both", fs=48000, maxLevel=101) >>> tone_down = fm_complex1(midF0=140, harmPhase="Sine", lowHarm=1, highHarm=10, level=60, duration=430, ramp=10, fmFreq=1.25, fmDepth=40, fmStartPhase=0.5*pi, fmStartTime=25, fmDuration=400, levelAdj=True, channel="Both", fs=48000, maxLevel=101)
- sndlib.fm_complex2(midF0=140, harmPhase='Sine', lowHarm=1, highHarm=10, level=60, duration=430, ramp=10, fmFreq=1.25, fmDepth=40, fmStartPhase=4.71238898038469, fmStartTime=25, fmDuration=400, levelAdj=True, channel='Both', fs=48000, maxLevel=101)[source]
Synthetise a complex tone with an embedded FM starting and stopping at a chosen time after the tone onset.
- Parameters:
- midF0float
F0 at the FM zero crossing
- harmPhaseone of ‘Sine’, ‘Cosine’, ‘Alternating’, ‘Random’, ‘Schroeder-’, ‘Schroeder+’
Phase relationship between the partials of the complex tone.
- lowHarmint
Lowest harmonic component number.
- highHarmint
Highest harmonic component number.
- levelfloat
The level of each partial in dB SPL.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- fmFreqfloat
FM frequency in Hz.
- fmDepthfloat
FM depth in %
- fmStartPhasefloat
Starting phase of FM
- fmStartTimefloat
Start of FM in ms after start of tone
- fmDurationfloat
Duration of FM, in ms
- levelAdjlogical
If True, scale the harmonic level so that for a complex tone within a bandpass filter the overall level does not change with F0 modulations.
- channel: ‘Right’, ‘Left’, ‘Both’, ‘Odd Right’ or ‘Odd Left’
Channel in which the tone will be generated. If ‘channel’ if ‘Odd Right’, odd numbered harmonics will be presented to the right channel and even number harmonics to the left channel. The opposite is true if ‘channel’ is ‘Odd Left’.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
Examples
>>> tone_up = fm_complex2(midF0=140, harmPhase="Sine", lowHarm=1, highHarm=10, level=60, duration=430, ramp=10, fmFreq=1.25, fmDepth=40, fmStartPhase=1.5*pi, fmStartTime=25, fmDuration=400, levelAdj=True, channel="Both", fs=48000, maxLevel=101) >>> tone_down = fm_complex2(midF0=140, harmPhase="Sine", lowHarm=1, highHarm=10, level=60, duration=430, ramp=10, fmFreq=1.25, fmDepth=40, fmStartPhase=0.5*pi, fmStartTime=25, fmDuration=400, levelAdj=True, channel="Both", fs=48000, maxLevel=101)
- sndlib.freqFromERBInterval(f1, deltaERB)[source]
Compute the frequency, in Hz, corresponding to a distance, in equivalent rectangular bandwidths (ERBs), of ‘deltaERB’ from f1.
- Parameters:
- f1float
frequency at one end of the interval in Hz
- deltaERBfloat
distance in ERBs
- Returns:
- f2float
frequency at the other end of the interval in Hz
References
[GM]Glasberg, B. R., & Moore, B. C. J. (1990). Derivation of auditory filter shapes from notched-noise data. Hear. Res., 47(1-2), 103–38.
Examples
>>> freqFromERBInterval(100, 1.5) >>> freqFromERBInterval(100, -1.5) >>> #for several frequencies >>> freqFromERBInterval([100, 200, 300], 1.5) >>> # for several distances >>> freqFromERBInterval(100, [1, 1.5, 2])
- sndlib.gate(ramps, sig, fs)[source]
Impose onset and offset ramps to a sound.
- Parameters:
- rampsfloat
The duration of the ramps.
- sigarray of floats
The signal on which the ramps should be imposed.
- fsint
The sampling frequency os ‘sig’
- Returns:
- sigarray of floats
The ramped signal.
Examples
>>> noise = broadbandNoise(spectrumLevel=40, duration=200, ramp=0, ... channel='Both', fs=48000, maxLevel=100) >>> gate(ramps=10, sig=noise, fs=48000)
- sndlib.getRMS(sig, channel='each')[source]
Compute the root mean square (RMS) value of the signal.
- Parameters:
- sigarray of floats
The signal for which the RMS needs to be computed.
- channelstring or int
Either an integer indicating the channel number, ‘each’ for a list of the RMS values in each channel, or ‘all’ for the RMS across all channels.
- Returns:
- rmsfloat
The RMS of ‘sig’.
Examples
>>> pt = pureTone(frequency=440, phase=0, level=65, duration=180, ... ramp=10, channel="Right", fs=48000, maxLevel=100) >>> getRMS(pt, channel="each")
- sndlib.glide(freqStart=440, ftype='exponential', excursion=500, level=60, duration=180, phase=0, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Synthetize a rising or falling tone glide with frequency changing linearly or exponentially.
- Parameters:
- freqStartfloat
Starting frequency in hertz.
- ftypestring
If ‘linear’, the frequency will change linearly on a Hz scale. If ‘exponential’, the frequency will change exponentially on a cents scale.
- excursionfloat
If ftype is ‘linear’, excursion is the total frequency change in Hz. The final frequency will be freqStart + excursion. If ftype is ‘exponential’, excursion is the total frequency change in cents. The final frequency in Hz will be freqStart*2**(excursion/1200).
- levelfloat
Level of the tone in dB SPL.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channelstring (‘Right’, ‘Left’ or ‘Both’)
Channel in which the tone will be generated.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> gl = glide(freqStart=440, ftype='exponential', excursion=500, level=55, duration=180, phase=0, ramp=10, channel='Both', fs=48000, maxLevel=100)
- sndlib.harmComplFromNarrowbandNoise(F0=440, lowHarm=1, highHarm=8, level=40, bandwidth=80, bandwidthUnit='Hz', stretch=0, duration=180, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Generate an harmonic complex tone from narrow noise bands.
- Parameters:
- F0float
Fundamental frequency of the complex.
- lowHarmint
Lowest harmonic component number. The first component is #1.
- highHarmint
Highest harmonic component number.
- levelfloat
The spectrum level of the noise bands in dB SPL.
- bandwidthfloat
The width of each noise band.
- bandwidthUnitstring (‘Hz’, ‘Cent’, ‘ERB’)
Defines whether the bandwith of the noise bands is expressed in hertz (Hz), cents (Cent), or equivalent rectangular bandwidths (ERB).
- stretchfloat
Harmonic stretch in %F0. Increase each harmonic frequency by a fixed value that is equal to (F0*stretch)/100. If ‘stretch’ is different than zero, an inhanmonic complex tone will be generated.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channel‘Right’, ‘Left’, ‘Both’, ‘Odd Right’ or ‘Odd Left’
Channel in which the tone will be generated. If ‘channel’ if ‘Odd Right’, odd numbered harmonics will be presented to the right channel and even number harmonics to the left channel. The opposite is true if ‘channel’ is ‘Odd Left’.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- sndarray of floats
Examples
>>> c1 = harmComplFromNarrowbandNoise(F0=440, lowHarm=3, highHarm=8, level=40, bandwidth=80, bandwidthUnit="Hz", stretch=0, duration=180, ramp=10, channel='Both', fs=48000, maxLevel=100)
- sndlib.imposeLevelGlide(sig, deltaL, startTime, endTime, channel, fs)[source]
Impose a glide in level to a sound.
This function changes the level of a sound with a smooth transition (an amplitude ramp) between ‘startTime’ and ‘endTime’. If the signal input to the function has a level L, the signal output by the function will have a level L between time 0 and ‘startTime’, and a level L+deltaL between endTime and the end of the sound.
- Parameters:
- sigfloat
Sound on which to impose the level change.
- deltaLfloat
Magnitude of the level change in dB SPL.
- startTimefloat
Start of the level transition in milliseconds.
- endTimefloat
End of the level transition in milliseconds.
- channelstring (‘Right’, ‘Left’ or ‘Both’)
Channel to which apply the level transition.
- fsint
Samplig frequency of the sound in Hz.
- Returns:
- sndarray of floats
Examples
>>> pt = pureTone(frequency=440, phase=0, level=65, duration=180, ... ramp=10, channel='Right', fs=48000, maxLevel=100) >>> pt2 = imposeLevelGlide(sig=pt, deltaL=10, startTime=100, endTime=120, channel='Both', fs=48000)
- sndlib.intNCyclesFreq(freq, duration)[source]
Compute the frequency closest to ‘freq’ that has an integer number of cycles for the given sound duration.
- Parameters:
- frequencyfloat
Frequency in hertz.
- durationfloat
Duration of the sound, in milliseconds.
- Returns:
- adjFreqfloat
Examples
>>> intNCyclesFreq(freq=2.1, duration=1000) 2.0 >>> intNCyclesFreq(freq=2, duration=1000) 2.0
- sndlib.itdtoipd(itd, freq)[source]
Convert an interaural time difference to an equivalent interaural phase difference for a given frequency.
- Parameters:
- itdfloat
Interaural time difference in seconds.
- freqfloat
Frequency in hertz.
- Returns:
- ipdfloat
Examples
>>> itd = 300 #microseconds >>> itd = 300/1000000 #convert to seconds >>> itdtoipd(itd=itd, freq=1000)
- sndlib.joinSndISI(sndList, ISIList, fs)[source]
Join a list of sounds with given interstimulus intervals
- Parameters:
- sndListlist of arrays
The sounds to be joined.
- ISIListlist of floats
The interstimulus intervals between the sounds in milliseconds. This list should have one element less than the sndList.
- fsint
Sampling frequency of the sounds in Hz.
- Returns:
- sndarray of floats
Examples
>>> pt1 = pureTone(frequency=440, phase=0, level=65, duration=180, ... ramp=10, channel='Right', fs=48000, maxLevel=100) >>> pt2 = pureTone(frequency=440, phase=0, level=65, duration=180, ... ramp=10, channel='Right', fs=48000, maxLevel=100) >>> tone_seq = joinSndISI([pt1, pt2], [500], 48000)
- sndlib.makeAsynchChord(freqs, levels, phases, tonesDuration, tonesRamps, tonesChannel, SOA, fs, maxLevel)[source]
Generate an asynchronous chord.
This function will add a set of pure tones with a given stimulus onset asynchrony (SOA). The temporal order of the successive tones is random.
- Parameters:
- freqsarray or list of floats.
Frequencies of the chord components in hertz.
- levelsarray or list of floats.
Level of each chord component in dB SPL.
- phasesarray or list of floats.
Starting phase of each chord component.
- tonesDurationfloat
Duration of the tones composing the chord in milliseconds. All tones have the same duration.
- tonesRampsfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the tones will be tonesDuration+ramp*2.
- tonesChannelstring (‘Right’, ‘Left’ or ‘Both’)
Channel in which the tones will be generated.
- SOAfloat
Onset asynchrony between the chord components.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
Examples
>>> freqs = [250, 500, 1000] >>> levels = [50, 50, 50] >>> phases = [0, 0, 0] >>> c1 = makeAsynchChord(freqs=freqs, levels=levels, phases=phases, tonesDuration=180, tonesRamps=10, tonesChannel='Both', SOA=60, fs=48000, maxLevel=100)
- sndlib.makeBlueRef(sig, fs, refHz)[source]
Convert a white noise into a blue noise.
The spectrum level of the blue noise at the frequency ‘refHz’ will be equal to the spectrum level of the white noise input to the function.
- Parameters:
- sigarray of floats
The white noise to be turned into a blue noise.
- fsint
Sampling frequency of the sound.
- refHzint
Reference frequency in Hz. The amplitude of the other frequencies will be scaled with respect to the amplitude of this frequency.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> noise = broadbandNoise(spectrumLevel=40, duration=180, ramp=10, ... channel='Both', fs=48000, maxLevel=100) >>> noise = makeBlueRef(sig=noise, fs=48000, refHz=1000)
- sndlib.makeHugginsPitch(F0=300, lowHarm=1, highHarm=3, spectrumLevel=45, bandwidth=100, bandwidthUnit='Hz', dichoticDifference='IPD Stepped', dichoticDifferenceValue=3.141592653589793, phaseRelationship='NoSpi', stretch=0, noiseType='White', duration=480, ramp=10, fs=48000, maxLevel=101)[source]
Synthetise a complex Huggings Pitch.
- Parameters:
- F0float
The centre frequency of the F0 of the complex in hertz.
- lowHarmint
Lowest harmonic component number.
- highHarmint
Highest harmonic component number.
- spectrumLevelfloat
The spectrum level of the noise from which the Huggins pitch is derived in dB SPL. If ‘noiseType’ is ‘Pink’, the spectrum level will be equal to ‘spectrumLevel’ at 1 kHz.
- bandwidthfloat
Bandwidth of the frequency regions in which the phase transitions occurr.
- bandwidthUnitstring (‘Hz’, ‘Cent’, ‘ERB’)
Defines whether the bandwith of the decorrelated bands is expressed in hertz (Hz), cents (Cent), or equivalent rectangular bandwidths (ERB).
- dichoticDifferencestring (‘IPD Linear’, ‘IPD Stepped’, ‘IPD Random’, ‘ITD’)
Selects whether the decorrelation in the target regions will be achieved by applying a costant interaural phase shift (IPD), an costant interaural time difference (ITD), or a random IPD shift.
- dichoticDifferenceValuefloat
For ‘IPD Linear’ this is the phase difference between the start and the end of each transition region, in radians. For ‘IPD Stepped’, this is the phase offset, in radians, between the correlated and the uncorrelated regions. For ‘ITD’ this is the ITD in the transition region, in micro seconds. For ‘Random Phase’, the range of phase shift randomization in the uncorrelated regions.
- phaseRelationshipstring (‘NoSpi’ or ‘NpiSo’)
If NoSpi, the phase of the regions within each frequency band will be shifted. If NpiSo, the phase of the regions between each frequency band will be shifted.
- stretchfloat
Harmonic stretch in %F0. Increase each harmonic frequency by a fixed value that is equal to (F0*stretch)/100. If ‘stretch’ is different than zero, an inhanmonic complex tone will be generated.
- noiseTypestring (‘White’ or ‘Pink’)
The type of noise used to derive the Huggins Pitch.
- durationfloat
Complex duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
References
[CH]Cramer, E. M., & Huggins, W. H. (1958). Creation of Pitch through Binaural Interaction. J. Acoust. Soc. Am., 30(5), 413.
[AS]Akeroyd, M. A., & Summerfield, a Q. (2000). The lateralization of simple dichotic pitches. J. Acoust. Soc. Am., 108(1), 316–334.
[ZH]Zhang, P. X., & Hartmann, W. M. (2008). Lateralization of Huggins pitch. J. Acoust. Soc. Am., 124(6), 3873–87.
Examples
>>> hp = makeHugginsPitch(F0=300, lowHarm=1, highHarm=3, spectrumLevel=45, bandwidth=100, bandwidthUnit='Hz', dichoticDifference='IPD Stepped', dichoticDifferenceValue=pi, phaseRelationship='NoSpi', stretch=0, noiseType='White', duration=380, ramp=10, fs=48000, maxLevel=101)
- sndlib.makeIRN(delay=0.0022727272727272726, gain=1, iterations=6, configuration='Add Same', spectrumLevel=25, duration=280, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Synthetise a iterated rippled noise
- Parameters:
- delayfloat
delay in seconds
- gainfloat
The gain to apply to the delayed signal
- iterationsint
The number of iterations of the delay-add cycle
- configurationstring
If ‘Add Same’, the output of iteration N-1 is added to delayed signal of the current iteration. If ‘Add Original’, the original signal is added to delayed signal of the current iteration.
- spectrumLevelfloat
Intensity spectrum level of the noise in dB SPL.
- durationfloat
Noise duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channelstring (‘Right’, ‘Left’, ‘Both’, or ‘Dichotic’)
Channel in which the noise will be generated.
- fsint
Sampling frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> irn = makeIRN(delay=1/440, gain=1, iterations=6, configuration='Add Same', spectrumLevel=25, duration=280, ramp=10, channel='Both', fs=48000, maxLevel=101)
- sndlib.makePink(sig, fs)[source]
Convert a white noise into a pink noise.
The spectrum level of the pink noise at 1000 Hz will be equal to the spectrum level of the white noise input to the function.
- Parameters:
- sigarray of floats
The white noise to be turned into a pink noise.
- fsint
Sampling frequency of the sound.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> noise = broadbandNoise(spectrumLevel=40, duration=180, ramp=10, ... channel='Both', fs=48000, maxLevel=100) >>> noise = makePink(sig=noise, fs=48000)
- sndlib.makePinkRef(sig, fs, refHz)[source]
Convert a white noise into a pink noise.
The spectrum level of the pink noise at the frequency ‘refHz’ will be equal to the spectrum level of the white noise input to the function.
- Parameters:
- sigarray of floats
The white noise to be turned into a pink noise.
- fsint
Sampling frequency of the sound.
- refHzint
Reference frequency in Hz. The amplitude of the other frequencies will be scaled with respect to the amplitude of this frequency.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> noise = broadbandNoise(spectrumLevel=40, duration=180, ramp=10, ... channel='Both', fs=48000, maxLevel=100) >>> noise = makePinkRef(sig=noise, fs=48000, refHz=1000)
- sndlib.makeRedRef(sig, fs, refHz)[source]
Convert a white noise into a red noise.
The spectrum level of the red noise at the frequency ‘refHz’ will be equal to the spectrum level of the white noise input to the function.
- Parameters:
- sigarray of floats
The white noise to be turned into a red noise.
- fsint
Sampling frequency of the sound.
- refHzint
Reference frequency in Hz. The amplitude of the other frequencies will be scaled with respect to the amplitude of this frequency.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> noise = broadbandNoise(spectrumLevel=40, duration=180, ramp=10, ... channel='Both', fs=48000, maxLevel=100) >>> noise = makeRedRef(sig=noise, fs=48000, refHz=1000)
- sndlib.makeSilence(duration=1000, fs=48000)[source]
Generate a silence.
This function just fills an array with zeros for the desired duration.
- Parameters:
- durationfloat
Duration of the silence in milliseconds.
- fsint
Samplig frequency in Hz.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> sil = makeSilence(duration=200, fs=48000)
- sndlib.makeVioletRef(sig, fs, refHz)[source]
Convert a white noise into a violet noise.
The spectrum level of the violet noise at the frequency ‘refHz’ will be equal to the spectrum level of the white noise input to the function.
- Parameters:
- sigarray of floats
The white noise to be turned into a violet noise.
- fsint
Sampling frequency of the sound.
- refHzint
Reference frequency in Hz. The amplitude of the other frequencies will be scaled with respect to the amplitude of this frequency.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> noise = broadbandNoise(spectrumLevel=40, duration=180, ramp=10, ... channel='Both', fs=48000, maxLevel=100) >>> noise = makeVioletRef(sig=noise, fs=48000, refHz=1000)
- sndlib.nextpow2(x)[source]
Next power of two.
- Parameters:
- xint
Base number.
- Returns:
- outfloat
The power to which 2 should be raised.
Examples
>>> nextpow2(511) 9 >>> 2**9 512
- sndlib.phaseShift(sig, f1, f2, phaseShift, phaseShiftType, channel, fs)[source]
Shift the interaural phases of a sound within a given frequency region.
- Parameters:
- sigarray of floats
Input signal.
- f1float
The start point of the frequency region to be phase-shifted in hertz.
- f2float
The end point of the frequency region to be phase-shifted in hertz.
- phaseShiftfloat
The amount of phase shift in radians.
- phaseShiftTypestring (‘Linear’, ‘Step’, ‘Random’)
If ‘Linear’ the phase changes progressively on a linear Hz scale from X to X+’phaseShift’ from f1 to f2. If ‘Stepped’ ‘phaseShift’ is added as a constant to the phases from f1 to f2. If ‘Random’ a random phase shift from 0 to ‘phaseShift’ is added to each frequency component from f1 to f2.
- channelstring (one of ‘Right’, ‘Left’ or ‘Both’)
The channel in which to apply the phase shift.
- fsfloat
The sampling frequency of the sound.
- Returns:
- out2-dimensional array of floats
Examples
>>> noise = broadbandNoise(spectrumLevel=40, duration=180, ramp=10, ... channel='Both', fs=48000, maxLevel=100) >>> hp = phaseShift(sig=noise, f1=500, f2=600, phaseShift=3.14, phaseShiftType='Linear', channel='Left', fs=48000) #this generates a Dichotic Pitch
- sndlib.pinkNoiseFromSin(compLevel=23, lowCmp=100, highCmp=1000, spacing=20, duration=180, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Generate a pink noise by adding sinusoids spaced by a fixed interval in cents.
- Parameters:
- compLevelfloat
Level of each sinusoidal component in dB SPL.
- lowCmpfloat
Frequency of the lowest noise component in hertz.
- highCmpfloat
Frequency of the highest noise component in hertz.
- spacingfloat
Spacing between the frequencies of the sinusoidal components in hertz.
- durationfloat
Noise duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channelstring (‘Right’, ‘Left’ or ‘Both’)
Channel in which the noise will be generated.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> noise = pinkNoiseFromSin(compLevel=23, lowCmp=100, highCmp=1000, spacing=20, duration=180, ramp=10, channel='Both', fs=48000, maxLevel=100)
- sndlib.pinkNoiseFromSin2(compLevel=23, lowCmp=100, highCmp=1000, spacing=20, duration=180, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Generate a pink noise by adding sinusoids spaced by a fixed interval in cents.
This function should produce the same output of pinkNoiseFromSin, it simply uses a different algorithm that uses matrix operations instead of a for loop. It doesn’t seem to be much faster though.
- Parameters:
- compLevelfloat
Level of each sinusoidal component in dB SPL.
- lowCmpfloat
Frequency of the lowest noise component in hertz.
- highCmpfloat
Frequency of the highest noise component in hertz.
- spacingfloat
Spacing between the frequencies of the sinusoidal components in hertz.
- durationfloat
Noise duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channelstring (‘Right’, ‘Left’ or ‘Both’)
Channel in which the noise will be generated.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> noise = pinkNoiseFromSin2(compLevel=23, lowCmp=100, highCmp=1000, spacing=20, duration=180, ramp=10, channel='Both', fs=48000, maxLevel=100)
- sndlib.pureTone(frequency=1000, phase=0, level=60, duration=980, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Synthetise a pure tone.
- Parameters:
- frequencyfloat
Tone frequency in hertz.
- phasefloat
Starting phase in radians.
- levelfloat
Tone level in dB SPL.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channelstring (‘Right’, ‘Left’ or ‘Both’)
Channel in which the tone will be generated.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> pt = pureTone(frequency=440, phase=0, level=65, duration=180, ... ramp=10, channel='Right', fs=48000, maxLevel=100) >>> pt.shape (9600, 2)
- sndlib.scale(level, sig)[source]
Increase or decrease the amplitude of a sound signal.
- Parameters:
- levelfloat
Desired increment or decrement in dB SPL.
- signalarray of floats
Signal to scale.
- Returns:
- sig2-dimensional array of floats
Examples
>>> noise = broadbandNoise(spectrumLevel=40, duration=180, ramp=10, ... channel='Both', fs=48000, maxLevel=100) >>> noise = scale(level=-10, sig=noise) #reduce level by 10 dB
- sndlib.setLevel_(level, snd, maxLevel, channel='Both')[source]
Set the RMS level of a sound signal to a given value.
- Parameters:
- levelfloat
The desired RMS level of the signal in dB SPL.
- sndarray of floats
Signal whose level is to be set.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- channelstring (‘Right’, ‘Left’ or ‘Both’)
Channel in which the level will be set.
- Returns:
- sig2-dimensional array of floats
Examples
>>> import copy >>> pt = pureTone(frequency=1000, phase=0, level=60, duration=100, ... ramp=0, channel="Both", fs=48000, maxLevel=100) >>> pt2 = copy.copy(pt) #this function modifies the argument so make a copy! >>> pt2 = setLevel_(level=40, snd=pt2, maxLevel=100, channel="Both") #set spectrum level to 20 dB SPL >>> levDiff = 20*log10(getRMS(pt)[1]/getRMS(pt2)[1])
- sndlib.spectralModNoise(spectrumLevel=25, duration=980, ramp=10, modAmp=10, modFreq=1, phase='Random', channel='Both', fs=48000, maxLevel=101)[source]
Generate a broadband noise with a modulated spectral envelope. The modulation is sinuisoidal on a log2 frequency, and logarithmic amplitude (dB) scale.
- Parameters:
- spectrumLevelfloat
Intensity spectrum level of the noise in dB SPL (before modulation). Note that the shaped noise is scaled after shaping so as to have the same overall RMS level than the noise before shaping.
- durationfloat
Noise duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- modAmp: float
Modulation amplitude (peak-to-trough difference) in dB.
- modFreq: float
Modulation frequency in cycles-per-octave
- modPhase: string
Starting modulation phase
- channelstring (“Right”, “Left”, “Both”, or “Dichotic”)
Channel in which the noise will be generated. If ‘Both’ the same noise will be generated in both channels. If ‘Dichotic’ the noise will be independent at the two ears.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- sig2-dimensional array of floats
References
Andéol, G., Macpherson, E. A., & Sabin, A. T. (2013). Sound localization in noise and sensitivity to spectral shape. Hearing Research, 304, 20–27. https://doi.org/10.1016/j.heares.2013.06.001
Eddins, D. A., & Bero, E. M. (2007). Spectral modulation detection as a function of modulation frequency, carrier bandwidth, and carrier frequency region. The Journal of the Acoustical Society of America, 121(1), 363–372. https://doi.org/10.1121/1.2382347
Litvak, L. M., Spahr, A. J., Saoji, A. A., & Fridman, G. Y. (2007). Relationship between perception of spectral ripple and speech recognition in cochlear implant and vocoder listeners. The Journal of the Acoustical Society of America, 122(2), 982–991. https://doi.org/10.1121/1.2749413
Examples
>>> noise = spectralModNoise(spectrumLevel=40, duration=180, ramp=10, ... modAmp=10, modFreq=2, phase="Random", ... channel='Both', fs=48000, maxLevel=100)
- sndlib.steepNoise(frequency1=440, frequency2=660, level=60, duration=180, ramp=10, channel='Both', fs=48000, maxLevel=101)[source]
Synthetise band-limited noise from the addition of random-phase sinusoids.
- Parameters:
- frequency1float
Start frequency of the noise.
- frequency2float
End frequency of the noise.
- levelfloat
Noise spectrum level.
- durationfloat
Tone duration (excluding ramps) in milliseconds.
- rampfloat
Duration of the onset and offset ramps in milliseconds. The total duration of the sound will be duration+ramp*2.
- channelstring (‘Right’, ‘Left’ or ‘Both’)
Channel in which the tone will be generated.
- fsint
Samplig frequency in Hz.
- maxLevelfloat
Level in dB SPL output by the soundcard for a sinusoid of amplitude 1.
- Returns:
- snd2-dimensional array of floats
The array has dimensions (nSamples, 2).
Examples
>>> nbNoise = steepNoise(frequency1=440, frequency2=660, level=65, ... duration=180, ramp=10, channel='Right', fs=48000, maxLevel=100)