Learn R Programming

soundgen (version 3.0.0)

transplantEnv: Transplant envelope

Description

Extracts a smoothed amplitude envelope of the donor sound and applies it to the recipient sound. The sounds can differ in length and sampling rate. Note that the result depends on the amount of smoothing (controlled by windowLength) and the chosen method of calculating the envelope. This is similar to "setenv" from the seewave package, but with a different smoothing algorithm and with a choice of several types of envelope: rms, hil, peak, etc. - see flatEnv.

Usage

transplantEnv(
  donor,
  recipient,
  samplingRateR = NULL,
  samplingRateD = samplingRateR,
  windowLength = 30,
  method = c("rms", "hil", "peak", "mean"),
  killDC = FALSE,
  dynamicRange = 30,
  plot = FALSE
)

Value

The recipient sound with the donor's amplitude envelope - a numeric vector with the same sampling rate and length as the recipient.

Arguments

donor

the sound that "donates" the amplitude envelope

recipient

the sound that needs to have its amplitude envelope adjusted

samplingRateD, samplingRateR

sampling rate of the donor and recipient, respectively (only needed for vectors, not files); they don't hav to match

windowLength

the length of smoothing window, ms

method

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

killDC

if TRUE, dynamically removes DC offset or similar deviations of average waveform from zero (see examples)

dynamicRange

parts of sound quieter than -dynamicRange dB will not be amplified

plot

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

See Also

flatEnv

Examples

Run this code
donor = c(rep(0, 50), rnorm(500)) * seq(1, 0, length.out = 550)
data('speechEx', package = 'soundgen')
recipient = speechEx@left[1000:4000]
transplantEnv(donor, samplingRateD = 200,
               recipient, samplingRateR = 16000,
               windowLength = 50, method = 'hil', plot = TRUE)
transplantEnv(donor, samplingRateD = 200,
               recipient, samplingRateR = 16000,
               windowLength = 10, method = 'peak', plot = TRUE)

Run the code above in your browser using DataLab