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)
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)) assert D.get_params() == D2.get_params()
def test_pitchshift(n_semitones, jam_fixture): np.random.seed(0) 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)) assert D.get_params() == D2.get_params()
def test_random_timestretch(n_samples, scale, jam_fixture): np.random.seed(0) D = muda.deformers.RandomTimeStretch(n_samples=n_samples, scale=scale) 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)) assert D.get_params() == D2.get_params()
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)) assert D.get_params() == D2.get_params()
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)
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
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)
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()
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()
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)
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)
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)
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)
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)
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()