I'm trying to use R to make music. I've found:
Package musicmakeR, which is broken.
Package audio, which is more for manipulating/playing existing audio files.
Package tuneR.
I THINK tuneR can do everything I want to do, and I found this post (Is it possible to code music in R and play it back? (Mac OS X)). The first response in that post (from 'rakshith1124') seems to answer my question, but either I'm coding something incorrectly or there's an issue with my OS or .wav player. Here is the code I'm using:
library(tuneR)
sr <- 8000
bits <- 16
secs <- 1
amp <- 1
t <- seq(0, secs, 1/sr)
C0 <- 16.35
G3 <- 196
A5 <- 880
C0 <- floor(2^(bits-2)*(amp*sin(2*pi*C0*t)))
G3 <- floor(2^(bits-2)*(amp*sin(2*pi*G3*t)))
A5 <- floor(2^(bits-2)*(amp*sin(2*pi*A5*t)))
u <- Wave(c(C0,G3,A5), samp.rate=sr, bit=bits)
play(u)
This should play three notes (C0, G3, A5) for one second each. I got the frequencies of the notes from https://pages.mtu.edu/~suits/notefreqs.html. The .wav played by the script [play (you)] seems to be truncating the first note or something else I don't understand. Does anyone know what's going on, and relatedly, is there a better package to be using for music creation?