import numpy import sys import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import waveIO musicwave = waveIO.read_wav_file(sys.argv[1]) musicwave = waveIO.unpack(musicwave) data, freqs, bins, im = plt.specgram(musicwave, NFFT=2048, Fs=44100, noverlap=900) plt.ylim(0,800) plt.title("Spectrogram of {!s}".format(sys.argv[1])) plt.show()
plt.title("notes pulled from wave by quantity, naive") plt.xlabel("Note names and octaves") plt.ylabel("quantity") plt.xticks(y_pos, objects) plt.show() if __name__ == '__main__': global dt # figure out the correct dt length based on the tempo of the output wave you want dt = compute_dt(bpm) # read and parse each sample wave for i in range(1, len(sys.argv) - 2): #read in the wave file and unpack its data wave_data = waveIO.read_wav_file(sys.argv[i]) wave_data = waveIO.unpack(wave_data) wave_time = len(wave_data) / sr note_length = dt * sr wave_chunks = split_wave(wave_data, int(note_length)) #test_sample_wave(wave_chunks) for i in range(len(wave_chunks)): chunk = wave_chunks[i] if len(chunk) != int(note_length): continue store_note(chunk) print_notes()
plt.bar(y_pos, quantities, align='center', width=0.75) plt.title("notes pulled from wave by quantity, stft") plt.xlabel("Note names and octaves") plt.ylabel("quantity") plt.xticks(y_pos, objects, fontsize=10) plt.show() if __name__ == '__main__': WINDOW_FUNC = window_hanning # read and parse each input wave for i in range(1, len(sys.argv) - 2): #read in the wave file and unpack its data wave_data = waveIO.read_wav_file(sys.argv[i]) wave_data = waveIO.unpack(wave_data) wave_time = len(wave_data)/sr wave_chunks = [] #Instead of multiplying the entire wave by the windowing function, we can simply examine window-sized pieces of the wave at a time #counting by WINDOW_LENGTH*(1-OVERLAP_PERCENT) allows adjustment of what percent of each window overlaps with the next #Example: OVERLAP_PERCENT = 0 means the next window will start where the previous window ended #Example: OVERLAP_PERCENT = 0.5 means the next window will start at the halfway mark of the previous window #This is necessary when using nonrectangular window functions, to prevent loss of data for i in range(0, len(wave_data), int(WINDOW_LENGTH*(1-OVERLAP_PERCENT))): window = [] window.extend(wave_data[i:i+WINDOW_LENGTH]) #multiply by the window function window = WINDOW_FUNC(window)