SpHr_SignalBinaural [ Flags ] fs,  destWaveName


Generates binaurally noises (or tones). All signals consist of two columns. The left-ear signal is in column 0. The right-ear signal is in column 1. 


Parameters

fs  Sampling frequency (Hz)


destWaveName  Signals are written to the wave specified by destWaveName. The wave is single precision and always overwritten. 


Flags

/Rows = rows

    Length of signal in rows. Same as /Pnts. Do not use with /Sec or /ms.


/Pnts = pnts

    Length of signal in points. Same as /Rows. Do not use with /Sec or /ms.


/Sec = seconds

    Length of signal in seconds (do not use with /Rows, /Pnts, or /ms).


/ms = ms

    Length of signal in milliseconds (do not use with /Rows, /Pnts, or /Sec ).


/dB = db

    Amplitude (RMS re: 20µPa) of signal in decibels (dB=20*log[Pa/2e-05]).


/Pa = pa

    Amplitude (RMS) of signal in Pascals. Do not use with /dB flag.


/NS = { seed [, seed2, seed3 ] }

    Values used to seed Mersenne Twister pseudorandom number generator. Copyright (C) 2004, Makoto Matsumoto and Takuji Nishimura, All rights reserved.

    seed2 and seed3 are used to generate binaurally independent signals and must be set if repeatable, independent, signals are to be generated. 

    If /NS is omitted, or any of the seeds are set to 0, a random seed is generated internally. 

    Passed double precision seeds are converted to signed long long integers but only positive values are used as seeds (see next comment).

    The arc4random number generator is used whenever a seed is set to a negative number. In these cases, abs(seed) is used.

    The variables V_Seed, V_Seed2, and V_Seed3 are set to the values of the seeds passed or generated internally (note that V_Seed2 and V_Seed3 are set even if they are unused).


/Sum [ = sum ]    

    Option to sum an existing wave, specified by destWaveName, with the newly generated wave. 

    sum = 0,  destWaveName will be overwritten, same as no /Sum flag.

    sum = 1,  If destWaveName already exists, new values will be summed. Same as /Sum flag alone.


/Buff = { front_ms [, back_ms ] }

    front_ms,  length of zero buffer, in milliseconds, added prior to the signal's onset. 

    back_ms,  length of zero buffer, in milliseconds, added after to the signal's offset. If not specified, a buffer equal in length to front_ms is used.


/Ramp = { onset_ms [, offset_ms ] }

    onset_ms,  length of onset Hanning ramp in milliseconds, adding no additional length to the signal.

    offset_ms,  length of onset Hanning ramp in milliseconds, adding no additional length to the signal. If not specified, a ramp equal in length to onset_ms is used.


/HP = { cornerHz [, order ] }

    High-pass filter with corner (-0 dB) frequency specified by cornerHz and order specified by order. For a 'brick-wall' filter, pass order = 0.


/LP = {cornerHz [, order ] }

    Low-pass filter with corner (-0 dB) frequency specified by cornerHz and order specified by order. For a 'brick-wall' filter, pass order = 0.


/Sp = { spectrum [, referenceHz ] }      (form 1)

    spectrum = 0,  flat (white) frequency response.

    spectrum = 1,  1/frequency (pink) frequency response.

    When spectrum = 1, referenceHz may be used to specified the reference frequency around which lower and higher magnitude values are scaled. When not specified, a default frequency of 1000 Hz is used.


/Sp = { interpType , units, MagSrcWave [, FreqSrcWave ] }     (form 2)

    interpType = 0,  MagSrcWave values are used to directly scale individual DFT magnitude values. MagSrcWave must have the same DFT-compatible number of points as the signal being generated.

    interpType = 1,  MagSrcWave values are linearly interpolated. Corresponding frequency values can be passed by: (1) the second column of MagSrcWave, (2) a second wave specified by FreqSrcWave, or (3) the x-scaling of MagSrcWave if x values range from zero to fs/2.

    interpType = 2,  MagSrcWave values are interpolated using a cubic spline. This interpolation may fail if ony 6 points to being interpolated. Corresponding frequency values are passed as described above.

    interpType = 4,  MagSrcWave values are quadratically interpolated. Corresponding frequency values are passed as described above.

    units = 0,  MagSrcWave values are in decibels (dB).

    units = 1,  MagSrcWave values are in Pascals (Pa).

    MagSrcWave,  Specification for wave of frequency-specific magnitude values. If MagSrcWave has two columns, the second column is assumed to specify corresponding frequency values.

    FreqSrcWave,  Specification for optional wave of frequency values corresponding to MagSrcWave.

/Sp2    Identical to as /Sp flag except that if the /Sp2 flag is used, /Sp1 controls the spectrum of the left channel (destWaveName[p][0]) and /Sp2 controls the spectrum of the right channel (destWaveName[p][1]).


/Ind = ind     (form 1)

    Binaural independence index of the left-ear and right-ear signals. In terms of interaural 'correlation' (IAC), a lower index generates a more highly correlated signal. Importantly, independence values (ind) differ when using this form of the /Ind flag in comparison with the form described below.

    ind = 0,  Left-ear and right-ear signals are identical.

    ind = 1,  Left-ear and right-ear signals are statistically independent.

    ind > 0, ind < 1,  signals are partially independent.


/Ind = { interpType , MagPhase, IndexSrcWave [, FreqSrcWave ] }     (form 2)

    MagPhase = 0 or >2, Magnitude and phase values are both shifted.

    MagPhase = 1, Only magnitude values are altered.

    MagPhase = 2, Only phase values are altered.

    interpType = 0,  IndexSrcWave values are used to directly alter individual DFT magnitude values. IndexSrcWave must therefore have the same DFT-compatible number of points as the signal being generated.

    interpType = 1,  IndexSrcWave values are linearly interpolated. Corresponding frequency values can be passed by: (1) the second column of IndexSrcWave, (2) a second wave specified by FreqSrcWave, or (3) the x-scaling of IndexSrcWave, if x values range from zero to fs/2.

    interpType = 2,  IndexSrcWave values are interpolated using a cubic spline. Corresponding frequency values are passed as described above.

    interpType = 4,  IndexSrcWave values are quadratically interpolated. Corresponding frequency values are passed as described above.

    IndexSrcWave,  Specification for a wave of frequency-specific independence indices.

    FreqSrcWave,  Specification for optional wave of frequency values corresponding to IndexSrcWave.


/InvP = invP     (form 1)

    Option to invert the phase of the right-ear noise signal.

    invP = 0,  no phase inversion, same as no flag.

    invP = 1,  Right-ear signal is inverted relative to the left-ear.


/InvP = { interpType , InvertSrcWave [, FreqSrcWave ] }   (form 2)

    interpType = 0,  InvertSrcWave values are used to directly alter DFT magnitude values. InvertSrcWave must have the same DFT-compatible number of points as the signal being generated.

    interpType = 1,  InvertSrcWave values are linearly interpolated. Corresponding frequency values can be passed by: (1) the second column of InvertSrcWave, (2) a second wave specified by FreqSrcWave, or (3) the x-scaling of InvertSrcWave, if x values range from zero to fs/2.

    interpType = 2,  InvertSrcWave values are interpolated using a cubic spline. Corresponding frequency values are passed as described above.

    interpType = 4,  InvertSrcWave values are quadratically interpolated. Corresponding frequency values are passed as described above.

    InvertSrcWave,  Specification for wave of phase inversion values. When interpolated, values above 0.5 are inverted.

    FreqSrcWave,  Specification for optional wave of frequency values corresponding to InvertSrcWave.


/ITD = itd    (form 1)

    Interaural time difference (ITD), in milliseconds (ms), imposed by inserting the nearest number of points. Positive values simulate a right-leading signal. Negative values simulate a left-leading signal.


/ITD={ itd, mode }   (form 2)

    mode = 0  ITD imposed by inserting the nearest number of points.

    mode = 1  ITD imposed by shifting phase.

    mode = 2  ITD imposed by shifting phase and ramping the signals at times corresponding to the nearest points. This option decreases the signal's length by the length of the ITD.

    itd,  ITD, always in milliseconds (ms). Positive values simulate a right-leading signal. Negative values simulate a left-leading signal.


/ITD = { interpType , units, ITDSrcWave [, FreqSrcWave ] }   (form 3)

    interpType = 0,  ITDSrcWave values are used to directly alter DFT magnitude values. ITDSrcWave must have the same DFT-compatible number of points as the signal being generated.

    interpType = 1,  ITDSrcWave values are linearly interpolated. Corresponding frequency values can be passed by: (1) the second column of ITDSrcWave, (2) a second wave specified by FreqSrcWave, or (3) the x-scaling of ITDSrcWave, if x values range from zero to fs/2.

    interpType = 2,  ITDSrcWave values are interpolated using a cubic spline. Corresponding frequency values are passed as described above.

    interpType = 4,  ITDSrcWave values are quadratically interpolated. Corresponding frequency values are passed as described above.

    units = 0,  ITDs are in seconds (s).

    units = 1,  ITDs are in milliseconds (ms).

    units = 2,  ITDs are in microseconds (µs).

    ITDSrcWave,  Specification for wave of ITD values.

    FreqSrcWave,  Specification for an optional wave of frequency values corresponding to ITDSrcWave.


 /IPD = { ipd [, units ] }  (form 1)

    ipd,  Interaural phase difference (IPD). Positive values simulate a (frequency-specific) right-leading signal. Negative values simulate a (frequency-specific) left-leading signal.

    units = 0,  IPD values are in radians (±pi).

    units = 1,  IPD values are in cycles (±1).


/IPD = { interpType , units, IPDSrcWave [, FreqSrcWave ] }   (form 2)

    interpType = 0,  IPDSrcWave values are used to directly alter DFT magnitude values. IPDSrcWave must have the same DFT-compatible number of points as the signal being generated.

    interpType = 1,  IPDSrcWave values are linearly interpolated. Corresponding frequency values can be passed by: (1) the second column of IPDSrcWave, (2) a second wave specified by FreqSrcWave, or (3) the x-scaling of IPDSrcWave, if x values range from zero to fs/2.

    interpType = 2,  IPDSrcWave values interpolated using a cubic spline. Corresponding frequency values are passed as described above.

    interpType = 4,  IPDSrcWave values are quadratically interpolated. Corresponding frequency values are passed as described above.

    units = 0,  IPD values are in radians (±pi).

    units = 1,   IPD values are in cycles (±1).

    IPDSrcWave,  Specification for wave of IPD values.

    FreqSrcWave,  Specification for optional wave of frequency values corresponding to IPDSrcWave.


 /ILD = { ild [, units ] }  (form 1)

    ild,  Interaural level difference (ILD).

    units = 0,  ILD values are in decibels. Positive values simulate a right-leading signal. Negative values simulate a left-leading signal.

    units = 1,  ILD values are in Pascals. Values > 1 simulate a right-leading signal. Values < 1 simulate a left-leading signal.


/ILD = { interpType , units, ILDSrcWave [, FreqSrcWave ] }   (form 2)

    interpType = 0,  ILDSrcWave values are used to directly alter DFT magnitude values. ILDSrcWave must have the same DFT-compatible number of points as the signal being generated.

    interpType = 1,  ILDSrcWave values are linearly interpolated. Corresponding frequency values can be passed by: (1) the second column of ILDSrcWave, (2) a second wave specified by FreqSrcWave, or (3) the x-scaling of ILDSrcWave, if x values range from zero to fs/2.

    interpType = 2,  ILDSrcWave values are interpolated using a cubic spline. Corresponding frequency values are passed as described above.

    interpType = 4,  ILDSrcWave values are quadratically interpolated. Corresponding frequency values are passed as described above.

    units = 0,  ILD values are in decibels. Positive values simulate a right-leading signal. Negative values simulate a left-leading signal.

    units = 1,  ILD values are in Pascals. Values > 1 simulate a right-leading signal. Values < 1 simulate a left-leading signal.

    ILDSrcWave,  Specification for wave of ILD values.

    FreqSrcWave,  Specification for optional wave of frequency values corresponding to ILDSrcWave.


/Tone = FreqHz     (form 1)

    Generates a pure tone having frequency (Hz) specified by FreqHz.

    The /Tone flag is incompatible with the following flags: /Swp, /NS, /InvP, /Sp, /Sp2, /Ind, /DFT, /LP, /HP and /Swp. The /Tone flag is also incompatible with the /ITD={ itd, mode } flag unless the mode flag is set to 0.


/Tone = { reserved, FreqSrcWave [, AmpSrcWave, PhiSrcWave ] }     (form 2)

    Generates a pure tones having frequencies, amplitudes, and phases specified by FreqSrcWave, FreqSrcWave, and PhiSrcWave.

    reserved, may specify units in the future. Use "" for reserved.

    FreqSrcWave,  Specification for wave of tone frequencies (Hz).

    AmpSrcWave,  Specification for wave of tone amplitudes (dB).

    PhiSrcWave,  Specification for wave of tone phases (radians).


/Swp = [ { F1, F2, TypeStr, refHzLimit } ]

    Generate a frequency sweeps

    F1, starting frequency (Hz)

    F2, ending frequency (Hz)

    typeStr = "log" - logarithmic sweep. Can also set typeStr to "ln", "exp" to obtain the same sweep. destWaveName= A*sin(((2*pi*F1*T)/ln(F2/F1))*(exp( (ln(F2/F1)*x)/T)-1));  /// A = amplitude, T = duration (s)

    typeStr = "linear" - linear sweep. Can also set typeStr to "lin". destWaveName= A*sin(2*pi*(F1*x+((k/2)*x^2))); where A = amplitude, T = duration (s), and k=(F2-F1)/T

    typeStr = "linear 1/f" - linear sweep with 1/frequency amplitude spectrum. Can also set typeStr to a combination of "linear, "lin" "1/f", and "pink". 

    refHzLimit  Reference frequency (Hz) for low frequency amplitude limit. refHzLimit is used only used when generating a linear sweep with 1/frequency amplitude spectrum (typeStr = "linear 1/f"). Frequencies below refHzLimit are limited in amplitude if they exceed the specified sweep amplitude. Low values can cause all amplitudes to decrease, especially when generating short sweeps. 

    The /Swp flag is incompatible with the following flags: /Tone, /NS, /InvP, /Sp, /Sp2, /Ind, /DFT, /LP, /HP and /Swp. The /Swp flag is also incompatible with the /ITD={ itd, mode } flag unless the mode flag is set to 0.


/DFT = { dft [, dftDestWave ] }

    dft = 0,  same as no /DFT flag, avoid using DFT when unnecessary, i.e., when no waves are passed via the /Sp, /Ind, InvP, /ITD, /IPD, /ILD flags.

    dft = 1,  use discrete Fourier transform even when unnecessary, such as when no waves are passed via the /Sp, /Ind, InvP, /ITD, /IPD, /ILD flags.

    If dftDestWave is present, the real and imaginary parts of the signals are written to the complex wave specified be dftDestWave before computing the inverse DFT and before the signals are ramped. The signals for the left and right channel are in columns 1 and 2, respectively.

    The variable V_DFT is set to 1 if the DFT was used to generate the signals. V_DFT is set to 0 if the DFT was not used.


Example

Function SpHr_SignalBinaural_Example()

    // Partially independent binaural noise burst in independent background signal

    variable fs = 48000

    SpHr_SignalBinaural/ms=400/Ramp=20/dB=30/HP=50/Sp=1/Ind=1 fs, NoiseBurst

    variable ITD = 0.2 // ms

    SpHr_SignalBinaural/Sum/ms=200/Ramp=20/dB=70/HP=50/Buff=100/Sp=1/Ind=0.1/ITD={ITD,1} fs, NoiseBurst

    Display/K=1 as "Binaural noise burst"

    AppendToGraph NoiseBurst[][0] /TN=LeftCh

    AppendToGraph NoiseBurst[][1] /TN=RightCh

    ModifyGraph lsize=0.5,rgb(LeftCh)=(0,0,65535)

    Label left "amplitude (\\U)"; Label bottom "time (\\U)"

End

Contact: Brian