sound = sin(1:2000/10) * approx(c(1, .01, .5), n = 2000)$y
# Oscillogram on a linear scale without bells and whistles, just base R
plot(sound, type = 'l')
# Oscillogram options with soundgen
osc(sound) # linear
osc(sound, dB = TRUE) # dB
# For numeric vectors, indicate samplingRate and scale (max amplitude)
osc(sound, samplingRate = 1000, scale = 100, dB = TRUE)
# Embellish and customize the plot
o = osc(sound, samplingRate = 1000, dB = TRUE, midline = FALSE,
main = 'My waveform', col = 'blue', returnWave = TRUE)
abline(h = -80, col = 'orange', lty = 3)
o[1:10] # the waveform in dB
# Wave object
data(speechEx, package = 'soundgen')
osc(speechEx, from = 2, to = 2.5, dB = TRUE)
# for long files, reduce the resolution to plot quickly (careful: if the
# resolution is too low, antialiasing may cause artifacts)
osc(speechEx, dB = TRUE, maxPoints = 2500)
if (FALSE) {
# saves oscillograms of all audio files in a folder
osc('~/Downloads/temp', savePlots = TRUE)
}
Run the code above in your browser using DataLab