chords = [ m21.chord.Chord((soprano[i], alto[i], tenor[i], bass[i])) for i in range(len(soprano)) ] # row = chord, column = melody chord_freqs = np.array([[pitch.frequency for pitch in chord.pitches] for chord in chords]) note_sigs = [[ sts.ClarinetApproxSignal(freq=freq, duration=note_duration, samp_rate=samp_rate) for freq in chord_freqs.T[i] ] for i in range(len(chord_freqs))] melody_data = np.array([nst.NonStationarySignal(ns).data for ns in note_sigs]) left_signal = np.sum((left_intensities * melody_data.T).T, axis=0) right_signal = np.sum(((1 - left_intensities) * melody_data.T).T, axis=0) src = np.array((left_signal, right_signal)) _, left_recons, right_recons, extra = adress.adress( left_signal=left_signal, right_signal=right_signal, samp_rate=samp_rate, left_ds=left_ds, left_Hs=left_Hs, right_ds=right_ds, right_Hs=right_Hs, beta=beta, window=window,
durations = [1] * n_signals # durations = [max(1 - i * 0.25, 0.25) for i in range(n_signals)] window = "blackmanharris" # # Generate data # freqs = np.arange(n_signals) * freq_inc + base_freq signals = [ ss.SineSignal(freq=freqs[i], duration=durations[i], samp_rate=samp_rate) for i in range(len(freqs)) ] nst = nsts.NonStationarySignal(signals) # Compute FFT # Compute STFT # f: Array of sample frequencies, len 129 real numbers. [0. , 172.265625 , 344.53125...] # t: Array of segment times, len 1380 real numbers. [0. , 0.00290249 , 0.00580499...] # Zxx: STFT of x f, t, Zxx = signal.stft(x=nst.data, fs=nst.samp_rate, window=window, nperseg=100) print(t.shape, f.shape, Zxx.shape) # print(f.shape, f[:10]) # print(t.shape, t[:10]) # print(Zxx.shape, Zxx[:10])
# # Generate signals # freqs = anotes.major_chord(scale_name=scale_name, n_notes=n_notes, output="freq") note_names = " ".join([n.nameWithOctave for n in anotes.major_chord(scale_name=scale_name, n_notes=n_notes, output="note")]) underline_note_names = note_names.replace(" ", "_") duration = sum(durations) signals = [ss.SineSignal(freq=freqs[i], duration=durations[i], samp_rate=samp_rate) for i in range(len(freqs))] melody = nsts.NonStationarySignal(signals) chord = sts.StationarySignal(sin_freqs=freqs, sin_coeffs=[1] * n_notes, duration=duration, samp_rate=samp_rate) # Only consider positive frequencies (since the spectrum is symmetric) melody_fft_x = fftfreq(melody.samp_nums.shape[0], 1 / melody.samp_rate) chord_fft_x = fftfreq(chord.samp_nums.shape[0], 1 / chord.samp_rate) slice_num = np.where(melody_fft_x > freqs[-1] * 2)[0][0] # FFT of both melody_fft = fft(melody.data)[:slice_num] / (melody.duration * samp_rate) chord_fft = fft(chord.data)[:slice_num] / (chord.duration * samp_rate) #