sound = sin(1:2000/10) *
getSmoothContour(anchors = c(1, .01, .5), len = 2000)
# 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
if (FALSE) {
# Wave object
data(sheep, package = 'seewave')
osc(sheep, dB = TRUE)
# Plot a section
osc(sheep, from = .5, to = 1.2)
# for long files, reduce the resolution to plot quickly (careful: if the
# resolution is too low, antialiasing may cause artifacts)
osc(sheep, dB = TRUE, maxPoints = 2500)
osc(sheep, samplingRate = 5000, maxPoints = 100)
# files several minutes long can be plotted in under a second
osc('~/Downloads/speechEx.wav', maxPoints = 20000)
# saves oscillograms of all audio files in a folder
osc('~/Downloads/temp2', savePlots = '')
}
Run the code above in your browser using DataLab