Learn R Programming

soundgen (version 1.1.0)

flatEnv: Flat envelope

Description

Flattens the amplitude envelope of a waveform. This is achieved by dividing the waveform by some function of its smoothed rolling amplitude (peak or root mean square).

Usage

flatEnv(sound, windowLength = 200, samplingRate = 16000, method = c("rms",
  "peak")[1], windowLength_points = NULL, killDC = FALSE, throwaway = -80,
  plot = FALSE)

Arguments

sound

input vector oscillating about zero

windowLength

the length of smoothing window, ms

samplingRate

the sampling rate, Hz. Only needed if the length of smoothing window is specified in ms rather than points

method

'peak' for peak amplitude per window, 'rms' for root mean square amplitude

windowLength_points

the length of smoothing window, points. If specified, overrides both windowLength and samplingRate

killDC

if TRUE, dynamically removes DC offset or similar deviations of average waveform from zero

throwaway

parts of sound quieter than throwaway dB will not be amplified

plot

if TRUE, plots the original sound, smoothed envelope, and flattened sound

Examples

Run this code
# NOT RUN {
a = rnorm(500) * seq(1, 0, length.out = 500)
b = flatEnv(a, plot = TRUE, killDC = TRUE, method = 'peak',
            windowLength_points = 5)         # too short
c = flatEnv(a, plot = TRUE, killDC = TRUE,
            windowLength_points = 250)       # too long
d = flatEnv(a, plot = TRUE, killDC = TRUE,
            windowLength_points = 50)        # about right
# }

Run the code above in your browser using DataLab