# program to demonstrate the phenomenon of beats.
# two sine waves are added whose freqs differ by beats. when
# beats is a number < 10 or so hear the individual "beat" events.
library(tuneR) # need to like with the sound library
f = 440 # our base frequency
sr = 32000 # sampling rate
bits = 16 # bit depth
secs = 4. # length of each note
t = seq(0,secs,1/sr) # the time points we create samples for
beats = 5 # beat rate in Hz
y = sin(2*pi*f*t) + # sum of sines with freqs differing by beats
sin(2*pi*(f+beats)*t)
#z = sin(2*pi*beats*t);
#y = c(z,y)
u = Wave(round(2^(bits-3)*y), samp.rate = sr, bit=bits) # make wave struct
play(u,"play") # play it