def generate_dataset(n_measures, tempo=Tempo(120), scale=GenericScale('C', [0, 2, 3, 5, 7, 8, 10]), sampling_info=SamplingInfo(44100)): signature = Signature(4, 4) n_notes_per_measure = 4 bass_instrument = make_bass_instrument(sampling_info) lead_instrument = make_lead_instrument(sampling_info) chord_instrument = make_accomp_instrument(sampling_info) chord_track = generate_chord_track(scale, tempo, signature, n_measures) y_chord = chord_instrument.generate_track(chord_track) lead_track = generate_lead_track(scale, tempo, signature, n_measures, n_notes_per_measure) y_lead = lead_instrument.generate_track(lead_track) bass_track = generate_bass_track(scale, tempo, signature, n_measures) y_bass = bass_instrument.generate_track(bass_track) mix = mixdown([y_bass, y_chord, y_lead]) return [bass_track, chord_track, lead_track], [y_bass, y_chord, y_lead], mix
def test_generation(): sampling_info = SamplingInfo(88200) instrument = Instrument(AliasingSquareOscillator(sampling_info)) vj = vader_jacob() y = instrument.generate_track(vj)
def lead(): lead = generate_dataset(n_measures=4, tempo=Tempo(120), scale=GenericScale('C', [0, 2, 3, 5, 7, 8, 10]), sampling_info=SamplingInfo(44100))[1][2] lead = np.concatenate((lead, np.zeros(shape=44100)), axis=0) return lead
def test_blit(): sampling_info = SamplingInfo(44100) x = np.arange(0, 1., 1/44100.) * 440 * 2 * np.pi y = signalproc.blit(sampling_info, x, 440, 0, -1) plt.plot(x, y) # plt.show() pass
def test_bl_square(): sampling_info = SamplingInfo(44100) x = np.arange(0, 1., 1/44100.) * 1440 * 2 * np.pi pos = signalproc.blit(sampling_info, x, 1440, 0, -1) neg = signalproc.blit(sampling_info, x, 1440, np.pi, -1) y = np.cumsum(pos - neg) # y = pos plt.plot(x, y) # plt.show() # play_array(y) pass
def test_apply_filter(): """Testing low- and high-pass filters Note that the hard-coded test values are not exact and are merely checking if the function yield reasonable behaviour. """ amp = 1 sampling_info = SamplingInfo(44100) osc = SineOscillator(sampling_info) data = osc.generate(amplitude=amp, duration=1, frequency=440, phase=0) y = apply_filter(data, sampling_info, 440, 5, 'lowpass') assert np.max(y) <= 0.55 * amp assert np.max(y) >= 0.45 * amp y = apply_filter(data, sampling_info, 220, 5, 'lowpass') assert np.max(y) <= 0.05 * amp y = apply_filter(data, sampling_info, 220, 5, 'highpass') assert np.max(y) >= 0.95 * amp pass
def generate_synthetic_data(batch_size, fragment_length, sampling_rate): sampling_info = SamplingInfo(sampling_rate) all_roots = scales.chromatic_scale('C') # Generate in all keys roots = [n.get_symbol() for n in all_roots.generate(0, 1)] print(roots) with Pool(8) as pool: datasets_train = pool.map( partial(__generate_dataset_for_root, sampling_info=sampling_info), roots) datasets_test = pool.map( partial(__generate_dataset_for_root, sampling_info=sampling_info), roots) x_train, y_train = __process_dataset(datasets_train, batch_size, fragment_length) x_test, y_test = __process_dataset(datasets_test, batch_size, fragment_length) return x_train, y_train, x_test, y_test
def test_additive_osc(): additive = AdditiveOscillator(SamplingInfo(44100), [1, 0.5, 0.25, 0.125]) fx = additive.generate(0.5, 1, 440, 0)
def sampling_info(): return SamplingInfo(44100)