import numpy as np
import matplotlib.pyplot as plt
from risset import *
import IPython.display as ipd
tune_length = 12
sr = 44100
ps, times = load_tune("Tunes/birthday.txt", tune_length)
t = np.arange(int(sr*tune_length))/sr
y = np.zeros_like(t) # Start with silence
for p, onset in zip(ps, times):
f = get_note_freq(p)
# Add cos(2pif(t-time))
this_note = np.sign(np.cos(2*np.pi*f*(t-onset)))
# Make everything before 0.1 seconds of the onset
# and after 0.1 seconds of the onset quiet
this_note[(t < onset - 0.1) | (t > onset + 0.1)] = 0
y = y + this_note
ipd.Audio(y, rate=sr)