# create a periodic function at frequency f by adding in contributions
# from sines at freqs f and 2f.
# look at the plot of the waveform and listen to the sound.
library(tuneR) # need to like with the sound library
f = 400 # our base frequency
sr = 16000 # sampling rate
bits = 16 # bit depth
secs = 2. # length of each note
a1 = .4 # experiment with these
a2 = .8
ph1 = 1.5 # and these
ph2 = .85
samples_per_period = round(sr/f) # length of period in samples
pers = 5 # plot this many periods
t = seq(0,secs,1/sr) # the time points we create samples for
y = a1*sin(2*pi*f *t + ph1) +
a2*sin(2*pi*2*f*t + ph2)
plot(y[1:(pers*samples_per_period)],type='l') # plot with line
u = Wave(round(2^(bits-4)*y), samp.rate = sr, bit=16) # make wave struct
play(u,"play") # play it