import matplotlib.pyplot as plt import numpy as np from scipy.io import wavfile from tones import sin_tone, exp_decay if __name__ == '__main__': RATE = 48000 MAX_VOL = 15000 FREQ = 440 # * 2**(1/4) MOD = int(RATE / (2 * FREQ)) signal = np.array([ sin_tone(FREQ, RATE, i) * MAX_VOL * exp_decay(RATE, i) for i in range(RATE) ]) FREQ = 440 * 2**(1/3) MOD = RATE / FREQ # signal += np.array([ # (-1)**(i//int(MOD)) * MAX_VOL * np.exp(-i/(RATE/5)) # for i in range(RATE) # ]) # signal = np.concatenate((signal, signal2)) plt.plot(signal)
)) RATE = 8000 MAX_VOL = 15000 TONE = sin_tone empty_song = make_space(notes, RATE) pointer = 0 # keeps current position in song for note, duration in notes: duration = int(RATE * notelen(duration)) freq = NOTES[note] if freq != 0: for i in range(duration): empty_song[pointer + i] = \ MAX_VOL *\ TONE(freq, RATE, i) *\ exp_decay(RATE, i) else: for i in range(duration): empty_song[pointer + i] = 0 pointer += duration plt.plot(empty_song) plt.show() wavfile.write('melody.wav', RATE, np.array(empty_song, dtype=np.int16))
filter(lambda x: not x.startswith('#'), sheet_music))) RATE = 8000 MAX_VOL = 15000 TONE = sin_tone empty_song = make_space(notes, RATE) pointer = 0 # keeps current position in song for note, duration in notes: duration = int(RATE * notelen(duration)) freq = NOTES[note] if freq != 0: for i in range(duration): empty_song[pointer + i] = \ MAX_VOL *\ TONE(freq, RATE, i) *\ exp_decay(RATE, i) else: for i in range(duration): empty_song[pointer + i] = 0 pointer += duration plt.plot(empty_song) plt.show() wavfile.write('melody.wav', RATE, np.array(empty_song, dtype=np.int16))
import matplotlib.pyplot as plt import numpy as np from scipy.io import wavfile from tones import sin_tone, exp_decay if __name__ == '__main__': RATE = 48000 MAX_VOL = 15000 FREQ = 440 # * 2**(1/4) MOD = int(RATE / (2 * FREQ)) signal = np.array([ sin_tone(FREQ, RATE, i) * MAX_VOL * exp_decay(RATE, i) for i in range(RATE) ]) FREQ = 440 * 2**(1 / 3) MOD = RATE / FREQ # signal += np.array([ # (-1)**(i//int(MOD)) * MAX_VOL * np.exp(-i/(RATE/5)) # for i in range(RATE) # ]) # signal = np.concatenate((signal, signal2)) plt.plot(signal)