# simple program to demonstrate sine waves. try varying freq f and amplitude amp
library(tuneR) # need to link with the sound library
f = 880 # our base frequency in Hz (cycles per sec.)
amp = 1 # the amplitude
sr = 16000 # sampling rate
bits = 16 # bit depth
secs = 2. # length of each note in seconds
t = seq(0,secs,by=1/sr) # the time points at which we sample sound
y = amp*sin(2*pi*f*t) # the sine wave
s = floor(2^(bits-2)*y) # the sample values are signed integers so they must be
# within -2^(bits-1) ... 2^(bits-1). To be a little more
# safe we spread it over +- 2^(bits-2) here.
u = Wave(s, samp.rate = sr, bit=bits) # make wave struct.
play(u) # play it