plt.bar(y_pos, quantities, align='center') 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)
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()
import numpy import sys import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import waveIO sr = 44100. wave_data = waveIO.read_wav_file('vocalscales.wav') wave_data = waveIO.unpack(wave_data) data, freqs, bins, im = plt.specgram(wave_data, NFFT=1024, Fs=sr, noverlap=900) plt.ylim(0,2000) plt.title("Spectrogram of vocalscales.wav") plt.xlabel("Time (s)") plt.ylabel("amplitude") plt.show() time = len(wave_data) / sr time = numpy.linspace(0,time,len(wave_data)) plt.plot(time,wave_data) plt.title("Time domain of vocalscales.wav") plt.xlabel("Time (s)") plt.ylabel("Amplitude") plt.show()
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
import numpy import sys import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import waveIO sr = 44100. wave_data = waveIO.read_wav_file('vocalscales.wav') wave_data = waveIO.unpack(wave_data) data, freqs, bins, im = plt.specgram(wave_data, NFFT=1024, Fs=sr, noverlap=900) plt.ylim(0, 2000) plt.title("Spectrogram of vocalscales.wav") plt.xlabel("Time (s)") plt.ylabel("amplitude") plt.show() time = len(wave_data) / sr time = numpy.linspace(0, time, len(wave_data)) plt.plot(time, wave_data) plt.title("Time domain of vocalscales.wav") plt.xlabel("Time (s)") plt.ylabel("Amplitude") plt.show()