soundgen (version 1.5.0)

osc_dB: Oscillogram dB

Description

Plots the oscillogram (waveform) of a sound on a logarithmic scale, in dB. Analogous to "Waveform (dB)" view in Audacity.

Usage

osc_dB(x, dynamicRange = 80, maxAmpl = NULL, samplingRate = NULL,
  returnWave = FALSE, plot = TRUE, xlab = NULL, ylab = "dB",
  bty = "n", midline = TRUE, ...)

Arguments

x

path to a .wav file or a vector of amplitudes with specified samplingRate

dynamicRange

dynamic range of the oscillogram, dB

maxAmpl

the maximum theoretically possible value indicating on which scale the sound is coded: 1 if the range is -1 to +1, 2^15 for 16-bit wav files, etc

samplingRate

sampling rate of x (only needed if x is a numeric vector, rather than a .wav file)

returnWave

if TRUE, returns a log-transformed waveform as a numeric vector

plot

if TRUE, plots the oscillogram

xlab, ylab

axis labels

bty

box type (see `?par`)

midline

if TRUE, draws a line at 0 dB

...

Other graphical parameters passed on to `plot()`

Value

Returns the input waveform on a dB scale: a vector with range from `-dynamicRange` to `dynamicRange`.

Details

Algorithm: centers and normalizes the sound, then takes a logarithm of the positive part and a flipped negative part.

Examples

Run this code
# NOT RUN {
sound = sin(1:2000/10) *
        getSmoothContour(anchors = c(1, .01, .5), len = 2000)

# Oscillogram on a linear scale
plot(sound, type = 'l')
# or, for fancy plotting options: seewave::oscillo(sound, f = 1000)

# Oscillogram on a dB scale
osc_dB(sound)

# Time in ms if samplingRate is specified
osc_dB(sound, samplingRate = 5000)

# Assuming that the waveform can range up to 50 instead of 1
osc_dB(sound, maxAmpl = 50)

# Embellish and customize the plot
o = osc_dB(sound, samplingRate = 1000, midline = FALSE,
           main = 'My waveform', col = 'blue')
abline(h = 0, col = 'orange', lty = 3)
# }

Run the code above in your browser using DataLab