Пример #1
0
def test_puretone_random_level():
    """ Check that pure tone can accept a random level as a parameter and handle its evaluation when synthesis() is
    called. We check this by making sure that the output RMS level is not the same from one sample to another. """
    synth = sy.PureTone()
    tempfunc = lambda: np.random.uniform(40, 60, 1)
    assert sg.rms(synth.synthesize_sequence(parameters=[{'level': tempfunc}])[0]) != \
           sg.rms(synth.synthesize_sequence(parameters=[{'level': tempfunc}])[0])
Пример #2
0
def test_rms_errors():
    """ Check that rms correctly handles an empty array"""
    try:
        sg.rms(np.array([0]))
        return False
    except ValueError:
        return True
Пример #3
0
def test_puretone_wiggled_level_with_random_variables():
    """ Check that we can construct a parameter dict, wiggle level to be various random variables, and then
    synthesize and get plausible output values. """
    synth = sy.PureTone()
    params = wiggle_parameters(dict(), 'level', [
        lambda: np.random.uniform(35, 45, 1),
        lambda: np.random.uniform(45, 55, 1)
    ])
    outs = synth.synthesize_sequence(parameters=params)
    assert sg.rms(outs[0]) < sg.rms(outs[1])
Пример #4
0
def test_dbspl_pure_tone_rms1():
    """ Check that pure tone with RMS 1 calibrates to 90.9 dB SPL"""
    x = sg.pure_tone(1000, 0, 1, int(48e3))
    x = x / sg.rms(x)
    np.testing.assert_approx_equal(sg.dbspl_pascal(x), 100, significant=1)
Пример #5
0
def test_amplify_by_zero_db():
    """ Check that rms does not change when amplifying a signal by 0 dB"""
    baseline_signal = sg.pure_tone(1000, 0, 1, int(48e3))
    amplified_signal = sg.amplify(baseline_signal, 0)
    assert sg.rms(baseline_signal) == sg.rms(amplified_signal)
Пример #6
0
def test_rms_pure_tone():
    """ Check that pure tone with peak 1 calibrates to 0.707 rms"""
    np.testing.assert_approx_equal(sg.rms(sg.pure_tone(1000, 0, 1, int(48e3))),
                                   0.707,
                                   significant=3)