def make_tone(freq, db, dur, risefall, samplerate, caldb=100, calv=0.1):
    """
    Produce a pure tone signal 

    :param freq: Frequency of the tone to be produced (Hz)
    :type freq: int
    :param db: Intensity of the tone in dB SPL
    :type db: int
    :param dur: duration (seconds)
    :type dur: float
    :param risefall: linear rise fall of (seconds)
    :type risefall: float
    :param samplerate: generation frequency of tone (Hz)
    :type samplerate: int
    :param caldb: Reference intensity (dB SPL). Together with calv, provides a reference point for what intensity equals what output voltage level
    :type caldb: int
    :param calv: Reference voltage (V). Together with caldb, provides a reference point for what intensity equals what output voltage level
    :type calv: float
    :returns: tone, timevals -- the signal and the time index values
    """
    if risefall > dur:
        raise ValueError('Duration must be greater than risefall time')
    if samplerate <= 0:
        raise ValueError("Samplerate must be greater than 0")
    if caldb <= 0:
        raise ValueError("Calibration dB SPL must be greater than 0")

    npts = int(dur * samplerate)
    amp = (10 ** ((db - caldb) / 20) * calv)
    if USE_RMS:
        amp = amp * 1.414213562373

    if VERBOSE:
        print(
        "current dB: {}, fs: {}, current frequency: {} kHz, AO Amp: {:.6f}".format(db, samplerate, freq / 1000, amp))
        print("cal dB: {}, V at cal dB: {}".format(caldb, calv))

    tone = amp * np.sin((freq * dur) * np.linspace(0, 2 * np.pi, npts))

    # print 'tone max', np.amax(tone)  
    if risefall > 0:
        rf_npts = int(risefall * samplerate) // 2
        # print('amp {}, freq {}, npts {}, rf_npts {}'.format(amp,freq,npts,rf_npts))
        wnd = hann(rf_npts * 2)  # cosine taper
        tone[:rf_npts] = tone[:rf_npts] * wnd[:rf_npts]
        tone[-rf_npts:] = tone[-rf_npts:] * wnd[rf_npts:]

    timevals = np.arange(npts) / samplerate

    return tone, timevals
def make_tone ( freq , db , dur , risefall , samplerate , caldb = 100 , calv = 0.1 ) : if risefall > dur : raise ValueError ( 'Duration must be greater than risefall time' ) if samplerate <= 0 : raise ValueError ( "Samplerate must be greater than 0" ) if caldb <= 0 : raise ValueError ( "Calibration dB SPL must be greater than 0" ) npts = int ( dur * samplerate ) amp = ( 10 ** ( ( db - caldb ) / 20 ) * calv ) if USE_RMS : amp = amp * 1.414213562373 if VERBOSE : print ( "current dB: {}, fs: {}, current frequency: {} kHz, AO Amp: {:.6f}" . format ( db , samplerate , freq / 1000 , amp ) ) print ( "cal dB: {}, V at cal dB: {}" . format ( caldb , calv ) ) tone = amp * np . sin ( ( freq * dur ) * np . linspace ( 0 , 2 * np . pi , npts ) ) if risefall > 0 : rf_npts = int ( risefall * samplerate ) // 2 wnd = hann ( rf_npts * 2 ) tone [ : rf_npts ] = tone [ : rf_npts ] * wnd [ : rf_npts ] tone [ - rf_npts : ] = tone [ - rf_npts : ] * wnd [ rf_npts : ] timevals = np . arange ( npts ) / samplerate return tone , timevals
Produce a pure tone signal 

    :param freq: Frequency of the tone to be produced (Hz)
    :type freq: int
    :param db: Intensity of the tone in dB SPL
    :type db: int
    :param dur: duration (seconds)
    :type dur: float
    :param risefall: linear rise fall of (seconds)
    :type risefall: float
    :param samplerate: generation frequency of tone (Hz)
    :type samplerate: int
    :param caldb: Reference intensity (dB SPL). Together with calv, provides a reference point for what intensity equals what output voltage level
    :type caldb: int
    :param calv: Reference voltage (V). Together with caldb, provides a reference point for what intensity equals what output voltage level
    :type calv: float
    :returns: tone, timevals -- the signal and the time index values