| mixAtSNR | R Documentation |
Adds two partly overlapping vectors, such as two waveforms or "signal" and
"noise", at specific RMS or loudness levels. The location at which vector 2
("noise") is pasted is defined by insertionPoint. Algorithm: both
vectors are padded with zeros to match in length, rescaled, added, and
re-normalized. All NA's are converted to 0. addVectors is the former
name from soundgen 2.x, preserved for back-compatibility.
mixAtSNR(
signal,
noise,
insertionPoint = 1L,
normalize = TRUE,
SNR = NULL,
type = c("rms", "RMS", "peak", "loudness"),
loudness_pars = list()
)
addVectors(
signal,
noise,
insertionPoint = 1L,
normalize = TRUE,
SNR = NULL,
type = c("rms", "RMS", "peak", "loudness"),
loudness_pars = list()
)
signal, noise |
numeric vectors |
insertionPoint |
the index of element in vector 1 at which vector 2 will be inserted (any integer, can also be negative) |
normalize |
if TRUE, the output is normalized to range from -1 to +1 |
SNR |
signal-to-noise ratio, dB |
type |
rescale |
loudness_pars |
a list of parameters passed to |
A numeric vector.
v1 = 1:6
v2 = rep(100, 3)
addVectors(v1, v2, insertionPoint = 5, normalize = FALSE)
addVectors(v1, v2, insertionPoint = -4, normalize = FALSE)
addVectors(v1, rep(100, 15), insertionPoint = -4, normalize = FALSE)
# note the asymmetry: insertionPoint refers to the first arg
addVectors(v1, v2, insertionPoint = -4, normalize = FALSE)
v3 = rep(100, 15)
addVectors(v1, v3, insertionPoint = -4, normalize = FALSE)
addVectors(v2, v3, insertionPoint = 7, normalize = FALSE)
addVectors(1:6, 3:6, insertionPoint = 3, normalize = FALSE)
# add noise to a sound at a particular SNR
signal = rep(c(rep(0, 500), cospi(2 * 440 * (1:1000) / 16000)), 2)
noise = rnorm(length(signal))
osc(mixAtSNR(signal, noise, SNR = 6), samplingRate = 16000)
osc(mixAtSNR(signal, noise, SNR = 6, type = 'peak'), samplingRate = 16000)
osc(mixAtSNR(signal, noise, SNR = 6, type = 'loudness',
loudness_pars = list(samplingRate = 16000, SPL = 80)), samplingRate = 16000)
osc(mixAtSNR(signal, noise, SNR = 12), samplingRate = 16000)
osc(mixAtSNR(signal, noise, SNR = 0), samplingRate = 16000)
# no rescaling (SNR = NULL)
osc(mixAtSNR(signal, noise, SNR = NULL), samplingRate = 16000)
osc(mixAtSNR(signal, noise/4, SNR = NULL), samplingRate = 16000)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.