예제 #1
0
def test_complex_tone_error():
    """ Check that complex_tone correctly throws an error if you provide freq and level arrays of different sizes"""
    try:
        sg.complex_tone(np.array([1, 2, 3]), np.array([1, 2]),
                        np.array([1, 2, 3]), 1, int(48e3))
        return False
    except Exception:
        return True
예제 #2
0
def test_cosine_ramp_durations():
    """ Check that cosine_ramp applied to a complex_tone can synthesize at a range of durations and sampling rates"""
    sg.cosine_ramp(
        sg.complex_tone(np.array([1, 2, 3]), np.array([1, 2, 3]),
                        np.array([1, 2, 3]), 1, int(48e3)), 0.1, int(48e3))
    sg.cosine_ramp(
        sg.complex_tone(np.array([1, 2, 3]), np.array([1, 2, 3]),
                        np.array([1, 2, 3]), 1, int(48e3)), 0.19923, int(48e3))
    sg.cosine_ramp(
        sg.complex_tone(np.array([1, 2, 3]), np.array([1, 2, 3]),
                        np.array([1, 2, 3]), 1, int(48e3)), 0.1, int(92332))
    sg.cosine_ramp(
        sg.complex_tone(np.array([1, 2, 3]), np.array([1, 2, 3]),
                        np.array([1, 2, 3]), 1, int(48e3)), 0.19923,
        int(92332))
예제 #3
0
def test_complextone_synthesize():
    """ Check that ComplexTone object can successfully synthesize and replicates standard complex tone synthesis"""
    synth = sy.ComplexTone()
    output = synth.synthesize(100, 1, 10, 50, 0, 1, 0.1, int(48e3))
    reference = sg.cosine_ramp(
        sg.complex_tone(100 * np.arange(1, 11), 50 * np.ones(10), np.zeros(10),
                        1, int(48e3)), 0.1, int(48e3))
    assert np.all(output == reference)
예제 #4
0
    def synthesize(self,
                   f0=100,
                   h_low=1,
                   h_high=10,
                   level=50,
                   phase=0,
                   dur=1,
                   dur_ramp=0.1,
                   fs=int(48e3),
                   **kwargs):
        """ Synthesizes a single instance of a complex tone with a raised-cosine ramp.

        The complex tone is synthesized with a consecutive series of harmonics from h_low to h_high. All components
        have the same level and the same phase.

        Args:
            f0 (float): F0 of complex tone, in Hz
            h_low (int): lowest harmonic number
            h_high (int): highest harmonic number
            level (float): level of complex tone per-component, in dB SPL
            phase (float): phase offset for every component, in degrees
            dur (float): duration, in seconds
            dur_ramp (float): duration of raised-cosine ramp, in seconds
            fs (int): sampling rate, in Hz

        Returns:
            output (array): complex tone
        """
        # Synthesize stimulus
        freqs = np.arange(h_low, h_high + 1) * f0
        levels = np.ones(len(freqs)) * level
        phases = np.zeros(len(freqs))
        pt = sg.complex_tone(freqs, levels, phases, dur, fs)
        pt = sg.cosine_ramp(pt, dur_ramp, fs)
        # Raise warnings about arguments
        check_args(kwargs)
        return pt
예제 #5
0
def test_complex_tone_single_component():
    """ Check that complex_tone correctly synthesizes an individual pure tone component """
    assert sg.complex_tone(np.array([1]), np.array([1]), np.array([1]), 1,
                           int(48e3)).shape == (48e3, )