| generateNoise | R Documentation |
Generates noise of length len and with spectrum defined by rolloff
parameters OR by a specified filter formantFilter. This function is
called internally by soundgen, but it may be more convenient to
call it directly when synthesizing non-biological noises defined by specific
spectral and amplitude envelopes rather than formants: the wind, whistles,
impact noises, etc. See beat for similarly simplified functions
for tonal non-biological sounds.
generateNoise(
len,
rolloffNoise = -4,
noiseFlatSpec = 1200,
rolloffNoiseExp = 0,
formantFilter = NULL,
noise = NULL,
attackLen = 10,
samplingRate = 16000,
windowLength = 50,
step = NULL,
overlap = 75,
wn = "gaussian",
smoothing = list(),
play = FALSE
)
len |
length of output, samples |
rolloffNoise, rolloffNoiseExp, noiseFlatSpec |
linear (rolloffNoise,
dB/kHz, anchor format) or exponential (rolloffNoiseExp, dB/oct, anchor
format) rolloff of the excitation source for the noise component (anchor
format) applied above |
formantFilter |
(optional): as an alternative to using rolloffNoise, we can provide the exact filter - a vector of non-negative numbers specifying the desired spectrum on a linear scale up to Nyquist frequency. The length doesn't matter as it can be interpolated internally. A matrix specifying time-varying filter for each STFT step is also accepted: frequencies in rows, STFT frames in columns. The easiest way to obtain formantFilter is to call getFormantFilter or to use (smoothed) spectrum / spectrogram of an existing sound |
noise |
intensity of turbulent noise (0 dB = same RMS as that of the periodic (voiced) component, negative values = less intense; anchor format). In soundgen 3.0, the noise component is always calibrated relative to the filtered harmonic component. When noise is present, the harmonic and noise components are filtered separately, their RMS amplitudes are normalized after filtering, and they are then mixed. Because noise can begin before the voiced part and continue after it, the time of noise anchors MUST be in ms, not [0, 1]; this is different from all other soundgen arguments that accept the anchor format with time either in ms or [0, 1] |
attackLen |
duration of fade-in / fade-out at each end of syllables and noise (ms): a vector of length 1 (symmetric) or 2 (separately for fade-in and fade-out) |
samplingRate |
sampling rate of the output (Hz) |
windowLength |
length of the FFT window (ms) |
step |
step between successive windows (ms); if provided, overrides
|
overlap |
overlap between successive windows (0–100%) |
wn |
wn window type accepted by |
smoothing |
a list of parameters passed to |
play |
if TRUE, plays the synthesized sound using the default player on
your system. If character, passed to |
Algorithm: paints a spectrogram with desired characteristics, sets phase to zero, and generates a time sequence via inverse FFT.
The generated waveform as a numeric vector.
soundgen beat
# .5 s of white noise
samplingRate = 16000
noise1 = soundgen:::generateNoise(len = samplingRate * .5,
samplingRate = samplingRate)
meanSpectrum(noise1, samplingRate)
# playme(noise1, samplingRate)
# Percussion (run a few times to notice stochasticity due to temperature = .25)
noise2 = soundgen:::generateNoise(len = samplingRate * .15, noise = c(0, -80),
rolloffNoise = c(4, -6), attackLen = 5)
noise3 = soundgen:::generateNoise(len = samplingRate * .25, noise = c(0, -40),
rolloffNoise = c(4, -20), attackLen = 5)
# playme(c(noise2, noise3), samplingRate)
## Not run:
playback = list(TRUE, FALSE, 'aplay', 'vlc')[[1]]
# 1.2 s of noise with rolloff changing from 0 to -12 dB above 2 kHz
noise = generateNoise(len = samplingRate * 1.2,
rolloffNoise = c(0, -12), noiseFlatSpec = 2000,
samplingRate = samplingRate, play = playback)
# spectrogram(noise, samplingRate)
# Similar, but using the dataframe format to specify a more complicated
# contour for rolloffNoise:
noise = generateNoise(len = samplingRate * 1.2,
rolloffNoise = data.frame(time = c(0, .3, 1), value = c(-12, 0, -12)),
noiseFlatSpec = 2000, samplingRate = samplingRate, play = playback)
# spectrogram(noise, samplingRate)
# To create a sibilant [s], specify a single strong, broad formant at ~7 kHz:
wl = 1024
formantFilter = getFormantFilter(
nr = wl %/% 2 + 1, nc = 1, samplingRate = samplingRate,
formants = list('f1' = data.frame(time = 0, freq = 7000,
amp = 50, width = 2000)))
noise = fade(generateNoise(len = samplingRate,
samplingRate = samplingRate, formantFilter = as.numeric(formantFilter),
play = playback), samplingRate = samplingRate)
# plot(formantFilter, type = 'l')
meanSpectrum(noise, samplingRate)
# Low-frequency, wind-like noise
formantFilter = getFormantFilter(
nr = 50, nc = 1, lipRad = 0,
samplingRate = samplingRate, formants = list('f1' = list(
freq = 250, amp = 30, width = 150)),
formantDepStoch = 0, plot = TRUE)
noise = fade(generateNoise(len = samplingRate,
samplingRate = samplingRate, formantFilter = as.numeric(formantFilter),
play = playback))
spectrogram(noise, samplingRate, ylim = c(0, 2))
# Manual filter, e.g. for a kettle-like whistle (narrow-band noise)
formantFilter = c(rep(0, 100), 120, rep(0, 100)) # any length is fine
# plot(formantFilter, type = 'b') # narrow-band filter at Nyquist / 2, here 4 kHz
noise = fade(generateNoise(len = samplingRate, formantFilter = formantFilter,
samplingRate = samplingRate, play = playback))
spectrogram(noise, samplingRate)
# Compare to a similar sound created with soundgen()
# (aperiodic noise only, a single formant at 4 kHz)
noise_s = soundgen(pitch = NULL,
noise = data.frame(time = c(0, 1000), value = c(0, 0)),
formants = list(f1 = data.frame(freq = 4000, amp = 80, width = 20)),
play = playback)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.