Пример #1
0
def test_random_timestretch(n_samples, scale, jam_fixture):

    D = muda.deformers.RandomTimeStretch(n_samples=n_samples, scale=scale, rng=0)

    jam_orig = deepcopy(jam_fixture)

    n_out = 0
    for jam_new in D.transform(jam_orig):
        # Verify that the original jam reference hasn't changed
        assert jam_new is not jam_orig
        __test_time(jam_orig, jam_fixture, 1.0)

        # Verify that the state and history objects are intact
        __test_deformer_history(D, jam_new.sandbox.muda.history[-1])

        d_state = jam_new.sandbox.muda.history[-1]['state']
        d_rate = d_state['rate']

        __test_time(jam_orig, jam_new, d_rate)
        n_out += 1

    assert n_samples == n_out
    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    __test_params(D, D2)
Пример #2
0
def test_timestretch(rate, jam_fixture):

    D = muda.deformers.TimeStretch(rate=rate)

    jam_orig = deepcopy(jam_fixture)

    for jam_new in D.transform(jam_orig):
        # Verify that the original jam reference hasn't changed
        assert jam_new is not jam_fixture
        __test_time(jam_orig, jam_fixture, 1.0)

        # Verify that the state and history objects are intact
        __test_deformer_history(D, jam_new.sandbox.muda.history[-1])

        d_state = jam_new.sandbox.muda.history[-1]['state']
        d_rate = d_state['rate']
        if isinstance(rate, list):
            assert d_rate in rate
        else:
            assert d_rate == rate

        __test_time(jam_orig, jam_new, d_rate)

    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    __test_params(D, D2)
Пример #3
0
def test_log_timestretch(n_samples, lower, upper, jam_fixture):

    D = muda.deformers.LogspaceTimeStretch(n_samples=n_samples,
                                           lower=lower,
                                           upper=upper)

    jam_orig = deepcopy(jam_fixture)

    n_out = 0
    for jam_new in D.transform(jam_orig):
        # Verify that the original jam reference hasn't changed
        assert jam_new is not jam_fixture
        __test_time(jam_orig, jam_fixture, 1.0)

        # Verify that the state and history objects are intact
        __test_deformer_history(D, jam_new.sandbox.muda.history[-1])

        d_state = jam_new.sandbox.muda.history[-1]['state']
        d_rate = d_state['rate']
        assert 2.0**lower <= d_rate <= 2.0**upper

        __test_time(jam_orig, jam_new, d_rate)
        n_out += 1

    assert n_samples == n_out
    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    __test_params(D, D2)
Пример #4
0
def test_linear_clipping(n_samples, lower, upper, jam_fixture):

    D = muda.deformers.LinearClipping(n_samples=n_samples,
                                               lower=lower,
                                               upper=upper)

    jam_orig = deepcopy(jam_fixture)

    n_out = 0    
    for jam_new in D.transform(jam_orig):
        # Verify that the original jam reference hasn't changed
        assert jam_new is not jam_fixture
        __test_time(jam_orig, jam_fixture, 1.0)

        # Verify that the state and history objects are intact
        __test_deformer_history(D, jam_new.sandbox.muda.history[-1])

        d_state = jam_new.sandbox.muda.history[-1]['state']
        d_clip_limit = d_state['clip_limit']
        assert lower <= d_clip_limit <= upper

        # Verify clipping outcome
        __test_clipped_buffer(jam_orig, jam_new, d_clip_limit)
        n_out += 1

    assert n_samples == n_out

    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    __test_params(D, D2)
Пример #5
0
def test_random_clipping(n_samples, a, b, jam_fixture):

    D = muda.deformers.RandomClipping(n_samples=n_samples, a=a, b=b, rng=0)

    jam_orig = deepcopy(jam_fixture)

    n_out = 0
    for jam_new in D.transform(jam_orig):
        # Verify that the original jam reference hasn't changed
        assert jam_new is not jam_orig
       
        # Verify that the state and history objects are intact
        __test_deformer_history(D, jam_new.sandbox.muda.history[-1])

        d_state = jam_new.sandbox.muda.history[-1]['state']
        d_clip_limit = d_state['clip_limit']

        # Verify clipping outcome
        __test_clipped_buffer(jam_orig, jam_new, d_clip_limit)
        n_out += 1

    assert n_samples == n_out
    
    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    __test_params(D, D2)
Пример #6
0
def test_clipping(clip_limit, expectation, jam_fixture):

    with expectation: 
        D = muda.deformers.Clipping(clip_limit=clip_limit)

    jam_orig = deepcopy(jam_fixture)

    for jam_new in D.transform(jam_orig):
        # Verify that the original jam reference hasn't changed
        assert jam_new is not jam_fixture
        __test_time(jam_orig, jam_fixture, 1.0)

        # Verify that the state and history objects are intact
        __test_deformer_history(D, jam_new.sandbox.muda.history[-1])

        d_state = jam_new.sandbox.muda.history[-1]['state']
        d_clip_limit = d_state['clip_limit']
        if isinstance(clip_limit, list):
            assert d_clip_limit in clip_limit
        else:
            assert d_clip_limit == clip_limit

        # Verify clipping outcome
        __test_clipped_buffer(jam_orig, jam_new, d_clip_limit)

    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    __test_params(D, D2)
Пример #7
0
def test_pitchshift(n_semitones, jam_fixture):
    D = muda.deformers.PitchShift(n_semitones=n_semitones)

    jam_orig = deepcopy(jam_fixture)

    for jam_new in D.transform(jam_orig):
        # Verify that the original jam reference hasn't changed
        assert jam_new is not jam_orig
        __test_pitch(jam_orig, jam_fixture, 0.0, 0)

        # Verify that the state and history objects are intact
        __test_deformer_history(D, jam_new.sandbox.muda.history[-1])

        d_state = jam_new.sandbox.muda.history[-1]['state']
        d_tones = d_state['n_semitones']
        tuning = d_state['tuning']
        if isinstance(n_semitones, list):
            assert d_tones in n_semitones
        else:
            assert d_tones == n_semitones

        __test_pitch(jam_orig, jam_new, d_tones, tuning)
    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    __test_params(D, D2)
Пример #8
0
def test_linear_pitchshift(n_samples, lower, upper, jam_fixture):
    D = muda.deformers.LinearPitchShift(n_samples=n_samples,
                                        lower=lower,
                                        upper=upper)

    jam_orig = deepcopy(jam_fixture)

    n_out = 0
    for jam_new in D.transform(jam_orig):
        # Verify that the original jam reference hasn't changed
        assert jam_new is not jam_orig
        __test_pitch(jam_orig, jam_fixture, 0.0, 0.0)

        # Verify that the state and history objects are intact
        __test_deformer_history(D, jam_new.sandbox.muda.history[-1])

        d_state = jam_new.sandbox.muda.history[-1]['state']
        d_tones = d_state['n_semitones']
        tuning = d_state['tuning']
        assert lower <= d_tones <= upper

        __test_pitch(jam_orig, jam_new, d_tones, tuning)
        n_out += 1

    assert n_out == n_samples
    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    __test_params(D, D2)
Пример #9
0
def test_random_pitchshift(n_samples, sigma, jam_fixture):

    D = muda.deformers.RandomPitchShift(n_samples=n_samples, sigma=sigma)

    jam_orig = deepcopy(jam_fixture)

    n_out = 0
    for jam_new in D.transform(jam_orig):
        # Verify that the original jam reference hasn't changed
        assert jam_new is not jam_orig
        __test_pitch(jam_orig, jam_fixture, 0.0, 0.0)

        # Verify that the state and history objects are intact
        __test_deformer_history(D, jam_new.sandbox.muda.history[-1])

        d_state = jam_new.sandbox.muda.history[-1]['state']
        d_tones = d_state['n_semitones']
        tuning = d_state['tuning']
        __test_pitch(jam_orig, jam_new, d_tones, tuning)
        n_out += 1

    assert n_out == n_samples
    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    assert D.get_params() == D2.get_params()
Пример #10
0
def test_ir_convolution(ir_files, jam_fixture, n_fft, rolloff_value):
    D = muda.deformers.IRConvolution(ir_files=ir_files,
                                     n_fft=n_fft,
                                     rolloff_value=rolloff_value)

    jam_orig = deepcopy(jam_fixture)
    orig_duration = librosa.get_duration(**jam_orig.sandbox.muda['_audio'])

    for jam_new in D.transform(jam_orig):
        # Verify that the original jam reference hasn't changed
        assert jam_new is not jam_orig

        #Testing with shifted impulse
        __test_shifted_impulse(jam_orig,
                               jam_new,
                               ir_files,
                               orig_duration,
                               n_fft=n_fft,
                               rolloff_value=rolloff_value)

        #Verify that the state and history objects are intact
        __test_deformer_history(D, jam_new.sandbox.muda.history[-1])

    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    __test_params(D, D2)
Пример #11
0
def test_filtering(btype, cutoff, jam_impulse,attenuation):
   
    D = muda.deformers.Filter(btype=btype, 
                                order=4, 
                                attenuation=attenuation,
                                cutoff=cutoff)

  
    jam_orig = deepcopy(jam_impulse)
  
    
    for jam_new in D.transform(jam_orig):
        # Verify that the original jam reference hasn't changed
        assert jam_new is not jam_orig
        assert not np.allclose(jam_orig.sandbox.muda['_audio']['y'],
                               jam_new.sandbox.muda['_audio']['y'])
    
        d_state = jam_new.sandbox.muda.history[-1]['state']
        nyquist = d_state["nyquist"]
        order = d_state['order']
        atten = d_state['attenuation'] #this is the halfed one for the filter parameter

        
        if btype == "bandpass":
            low,high = d_state['cut_off']
        elif btype == "low": 
            low = 0
            high = d_state['cut_off']
        else:
            low = d_state['cut_off']
            high = nyquist

        
        assert order > 0
        assert isinstance(order,int)
        assert atten > 0

        if btype == "bandpass":
            assert 0 < low < high < nyquist
            
        else:
            assert 0 <= low < high <= nyquist
           

        __test_pitch_filter(jam_orig, jam_new, [low,high])

        #test sound
        __testsound(attenuation, #this is the ultimate one
            d_state['cut_off'],
            jam_new.sandbox.muda['_audio']['y'],
            jam_orig.sandbox.muda['_audio']['y'],
            jam_orig.sandbox.muda['_audio']['sr'],
            btype)

    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    __test_params(D, D2)
Пример #12
0
def test_serialize_deformer():

    D = muda.deformers.LogspaceTimeStretch()
    D_ser = muda.serialize(D)
    D2 = muda.deserialize(D_ser)

    eq_(D.get_params(), D2.get_params())

    assert D is not D2
Пример #13
0
def test_serialize_deformer():

    D = muda.deformers.LogspaceTimeStretch()
    D_ser = muda.serialize(D)
    D2 = muda.deserialize(D_ser)

    eq_(D.get_params(), D2.get_params())

    assert D is not D2
Пример #14
0
def test_randombpfiltering(cutoff, n_samples, jam_impulse,attenuation):
    if type(cutoff) != tuple:
        raise ValueError("cut off frequency for random bandpass filter must be a tuple") 
    else:
         low,high = cutoff
    
    D = muda.deformers.RandomBPFilter(n_samples=n_samples,
                                         order=4, 
                                         attenuation=attenuation, 
                                         cutoff_low=low,
                                         cutoff_high = high,
                                         sigma=1.0,
                                         rng=0)

  
    jam_orig = deepcopy(jam_impulse)
    orig_duration = librosa.get_duration(**jam_orig.sandbox.muda['_audio'])
    
    n_out = 0
    for jam_new in D.transform(jam_orig):
        # Verify that the original jam reference hasn't changed
        assert jam_new is not jam_orig
       

        # Verify that the state and history objects are intact
        __test_deformer_history(D, jam_new.sandbox.muda.history[-1])

        d_state = jam_new.sandbox.muda.history[-1]['state']
        low,high = d_state['cut_off']
        nyquist = d_state["nyquist"]
        order = d_state['order']
        atten = d_state['attenuation']

        assert order > 0
        assert isinstance(order,int)
        assert atten > 0

        assert 0 < low < high < nyquist

        __test_pitch_filter(jam_orig, jam_new, [low,high])
          #test sound
        __testsound(attenuation,
            d_state['cut_off'],
            jam_new.sandbox.muda['_audio']['y'],
            jam_orig.sandbox.muda['_audio']['y'],
            jam_orig.sandbox.muda['_audio']['sr'],
            "bandpass")

        n_out += 1

    assert n_samples == n_out

    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    __test_params(D, D2)
Пример #15
0
def test_serialize_pipeline():

    D1 = muda.deformers.LogspaceTimeStretch()
    D2 = muda.deformers.LogspaceTimeStretch()
    P_orig = muda.Pipeline([('stretch_1', D1), ('stretch_2', D2)])
    P_ser = muda.serialize(P_orig)

    P_new = muda.deserialize(P_ser)

    assert P_orig is not P_new
    assert P_orig.get_params() == P_new.get_params()
Пример #16
0
def test_serialize_union():

    D1 = muda.deformers.LogspaceTimeStretch()
    D2 = muda.deformers.LogspaceTimeStretch()
    U_orig = muda.Union([('stretch_1', D1), ('stretch_2', D2)])
    U_ser = muda.serialize(U_orig)

    U_new = muda.deserialize(U_ser)

    assert U_orig is not U_new
    assert U_orig.get_params() == U_new.get_params()
Пример #17
0
def test_serialize_pipeline():

    D1 = muda.deformers.LogspaceTimeStretch()
    D2 = muda.deformers.LogspaceTimeStretch()
    P_orig = muda.Pipeline([('stretch_1', D1),
                            ('stretch_2', D2)])
    P_ser = muda.serialize(P_orig)

    P_new = muda.deserialize(P_ser)

    assert P_orig is not P_new
    assert P_orig.get_params() == P_new.get_params()
Пример #18
0
def test_randomhpfiltering(cutoff, n_samples,jam_impulse,attenuation):
    
    D = muda.deformers.RandomHPFilter(n_samples=n_samples,
                                         order=4, 
                                         attenuation=attenuation, 
                                         cutoff=cutoff,
                                         sigma=1.0,
                                         rng=0)

  
    jam_orig = deepcopy(jam_impulse)
    orig_duration = librosa.get_duration(**jam_orig.sandbox.muda['_audio'])
    
    n_out = 0 
    for jam_new in D.transform(jam_orig):
        # Verify that the original jam reference hasn't changed
        assert jam_new is not jam_orig


        # Verify that the state and history objects are intact
        __test_deformer_history(D, jam_new.sandbox.muda.history[-1])

        d_state = jam_new.sandbox.muda.history[-1]['state']
        nyquist = d_state["nyquist"]
        low = d_state['cut_off']
        high = nyquist
       
        order = d_state['order']
        atten = d_state['attenuation']

        assert order > 0
        assert isinstance(order,int)
        assert atten > 0

       
        assert 0 < low < nyquist

        __test_pitch_filter(jam_orig, jam_new, [low,high])
        #test sound
        __testsound(attenuation,
            d_state['cut_off'],
            jam_new.sandbox.muda['_audio']['y'],
            jam_orig.sandbox.muda['_audio']['y'],
            jam_orig.sandbox.muda['_audio']['sr'],
            "high")

        n_out += 1

    assert n_samples == n_out

    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    __test_params(D, D2)
Пример #19
0
def test_serialize_union():

    D1 = muda.deformers.LogspaceTimeStretch()
    D2 = muda.deformers.LogspaceTimeStretch()
    U_orig = muda.Union([('stretch_1', D1),
                         ('stretch_2', D2)])
    U_ser = muda.serialize(U_orig)

    U_new = muda.deserialize(U_ser)

    assert U_orig is not U_new
    assert U_orig.get_params() == U_new.get_params()
Пример #20
0
def test_drc(preset, jam_fixture):

    D = muda.deformers.DynamicRangeCompression(preset=preset)

    jam_orig = deepcopy(jam_fixture)

    for jam_new in D.transform(jam_orig):

        assert jam_new is not jam_fixture
        __test_effect(jam_orig, jam_fixture)

        assert not np.allclose(jam_orig.sandbox.muda['_audio']['y'],
                               jam_new.sandbox.muda['_audio']['y'])

        __test_effect(jam_orig, jam_new)
    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    __test_params(D, D2)
Пример #21
0
def test_bypass(D_simple, jam_fixture):

    D = muda.deformers.Bypass(transformer=D_simple)

    jam_orig = deepcopy(jam_fixture)

    generator = D.transform(jam_orig)
    jam_new = six.next(generator)
    assert jam_new is jam_orig
    __test_time(jam_orig, jam_fixture, 1.0)

    for jam_new in generator:
        # Verify that the original jam reference hasn't changed
        assert jam_new is not jam_orig

        # Verify that the state and history objects are intact
        __test_deformer_history(D_simple, jam_new.sandbox.muda.history[-1])
    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    __test_params(D, D2)
Пример #22
0
def test_background(noise, n_samples, weight_min, weight_max, jam_fixture):

    D = muda.deformers.BackgroundNoise(files=noise,
                                       n_samples=n_samples,
                                       weight_min=weight_min,
                                       weight_max=weight_max)

    jam_orig = deepcopy(jam_fixture)
    orig_duration = librosa.get_duration(**jam_orig.sandbox.muda['_audio'])

    n_out = 0
    for jam_new in D.transform(jam_orig):

        assert jam_new is not jam_fixture
        __test_effect(jam_orig, jam_fixture)

        assert not np.allclose(jam_orig.sandbox.muda['_audio']['y'],
                               jam_new.sandbox.muda['_audio']['y'])

        d_state = jam_new.sandbox.muda.history[-1]['state']
        filename = d_state['filename']
        start = d_state['start']
        stop = d_state['stop']

        with psf.SoundFile(str(filename), mode='r') as soundf:
            max_index = len(soundf)
            noise_sr = soundf.samplerate

        assert 0 <= start < stop
        assert start < stop <= max_index
        assert ((stop - start) / float(noise_sr)) == orig_duration

        __test_effect(jam_orig, jam_new)
        n_out += 1

    assert n_out == n_samples
    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    __test_params(D, D2)
Пример #23
0
def test_colorednoise(n_samples, color, weight_min, weight_max, jam_test_silence):

    D = muda.deformers.ColoredNoise(n_samples = n_samples,
                                       color = color,
                                       weight_min = weight_min,
                                       weight_max = weight_max,
                                       seed = True)
    jam_orig = deepcopy(jam_test_silence)

    orig_duration = librosa.get_duration(**jam_orig.sandbox.muda['_audio'])

    n_out = 0
    for jam_new in D.transform(jam_orig):
        print('===================================')
        print(jam_orig.sandbox.muda['_audio']['sr'])
        print(jam_new.sandbox.muda['_audio']['sr'])
        print('===================================')
        assert jam_new is not jam_test_silence
        __test_effect(jam_orig, jam_test_silence)

        assert not np.allclose(jam_orig.sandbox.muda['_audio']['y'],
                                   jam_new.sandbox.muda['_audio']['y'])
        #verify that duration hasn't changed
        assert librosa.get_duration(**jam_new.sandbox.muda['_audio']) == orig_duration

        # Verify that the state and history objects are intact
        __test_deformer_history(D, jam_new.sandbox.muda.history[-1])

        __test_effect(jam_orig, jam_new)

        #Verify the colored noise has desired slope for its log-log scale power spectrum
        color = jam_new.sandbox.muda.history[-1]['state']['colortype']
        __test_color_slope(jam_orig, jam_new, color)

        n_out += 1
    assert n_out == n_samples
    # Serialization test
    D2 = muda.deserialize(muda.serialize(D))
    assert D.get_params() == D2.get_params()