This function computes the frequency of a musical note (Equal temperament)
notefreq(note, ref = 440, octave = 3)
a numerical or a character vector. See Note
.
a numerical vector of length 1 for the reference frequency.
a numerical vector of length for the octave number.
The frequency in Hz is returned.
The frequency is computed according to:
with: ref = reference frequency, octave = octave number, and note = rank of the note along the scale.
# NOT RUN {
# Some notes frequency (use apply-like functions when dealing with character strings)
sapply(c("C", "A", "Gb"), notefreq)
# C major scale plot
n <- 1:12
freq <- notefreq(n)
names <- c("C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B")
plot(n, freq, pch=19, cex=1.5,
xlab = "Note name",
ylab = "Frequency (Hz)",
xaxt="n", las=1, main="Third octave")
axis(side=1, at=n, labels=names)
abline(h=freq, col="lightgrey")
# C major scale sound
f <- 2000 # sampling rate
s <- NULL
for (i in 1:length(freq))
{
tmp <- synth(d=0.5, f=f, cf=freq[i])
s <- pastew(s, tmp, at="start", f)
}
spectro(s, f, ovlp=75)
# }
Run the code above in your browser using DataLab