soundgen (version 1.5.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 amplitude envelope (Hilbert, peak or root mean square).

Usage

flatEnv(sound, windowLength = 200, samplingRate = 16000,
  method = c("hil", "rms", "peak")[1], windowLength_points = NULL,
  killDC = FALSE, dynamicRange = 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

'hil' for Hilbert envelope, 'rms' for root mean square amplitude, 'peak' for peak amplitude per window

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

dynamicRange

parts of sound quieter than -dynamicRange 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, windowLength_points = 5)    # too short
c = flatEnv(a, plot = TRUE, windowLength_points = 250)  # too long
d = flatEnv(a, plot = TRUE, windowLength_points = 50)   # about right

# }
# NOT RUN {
s = soundgen(sylLen = 1000, ampl = c(0, -40, 0), plot = TRUE, osc = TRUE)
# playme(s)
s_flat1 = flatEnv(s, plot = TRUE, windowLength = 50, method = 'hil')
s_flat2 = flatEnv(s, plot = TRUE, windowLength = 10, method = 'rms')
# playme(s_flat2)

# Remove DC offset
s1 = c(rep(0, 50), runif(1000, -1, 1), rep(0, 50)) +
     seq(.3, 1, length.out = 1100)
s2 = flatEnv(s1, plot = TRUE, windowLength_points = 50, killDC = FALSE)
s3 = flatEnv(s1, plot = TRUE, windowLength_points = 50, killDC = TRUE)
# }

Run the code above in your browser using DataLab