Learn R Programming

soundgen (version 1.2.1)

generateNoise: Generate noise

Description

Generates noise of length len and with spectrum defined by linear decay of rolloffNoise dB/kHz above noiseFlatSpec Hz OR by a specified filter filterNoise. 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 fart and beat for similarly simplified functions for voiced non-biological sounds.

Usage

generateNoise(len, rolloffNoise = 0, noiseFlatSpec = 1200,
  filterNoise = NULL, noiseAnchors = NULL, temperature = 0.1,
  attackLen = 10, windowLength_points = 1024, samplingRate = 16000,
  overlap = 75, throwaway = -80)

Arguments

len

length of output

rolloffNoise

linear rolloff of the excitation source for the unvoiced component, dB/kHz (vectorized)

noiseFlatSpec

keeps noise spectrum flat to this frequency, Hz

filterNoise

(optional): as an alternative to using rolloffNoise, we can provide the exact filter - a vector of non-negative numbers specifying the power in each frequency bin on a linear scale (interpolated to length equal to windowLength_points/2). A matrix specifying the filter for each STFT step is also accepted. The easiest way to create this matrix is to call soundgen:::getSpectralEnvelope, but then you might as well just use soundgen()

noiseAnchors

a numeric vector of noise amplitudes (throwaway dB = none, 0 dB = as loud as voiced component) or a dataframe specifying the time (ms) and amplitude (dB) of anchors for generating the noise component such as aspiration, hissing, etc

temperature

hyperparameter for regulating the amount of stochasticity in sound generation

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)

windowLength_points

the length of fft window, points

samplingRate

sampling frequency, Hz

overlap

FFT window overlap, %. For allowed values, see istft

throwaway

discard harmonics and noise that are quieter than this number (in dB, defaults to -80) to save computational resources

Details

Algorithm: paints a spectrum with desired characteristics, sets phase to zero, and generates a time sequence via inverse FFT. Noise can then be used as an additional source to be added to the glottal source AFTER the glottal source has been formant-filtered, or BEFORE formant-filtering for glottal breathing noise.

Examples

Run this code
# NOT RUN {
# .5 s of white noise
samplingRate = 16000
noise1 = generateNoise(len = samplingRate * .5,
  samplingRate = samplingRate)
# playme(noise1, samplingRate)
# seewave::meanspec(noise1, f = samplingRate)

# Percussion (run a few times to notice stochasticity due to temperature = .25)
noise2 = generateNoise(len = samplingRate * .15, noiseAnchors = c(0, -80),
  rolloffNoise = c(4, -6), attackLen = 5, temperature = .25)
noise3 = generateNoise(len = samplingRate * .25, noiseAnchors = c(0, -40),
  rolloffNoise = c(4, -24), attackLen = 5, temperature = .25)
# playme(c(noise2, noise3), samplingRate)

# }
# NOT RUN {
# 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)
# playme(noise, samplingRate = samplingRate)
# spectrogram(noise, samplingRate)

# To create a sibilant [s], specify a single strong, broad formant at ~7 kHz:
windowLength_points = 1024
filterNoise = soundgen:::getSpectralEnvelope(
  nr = windowLength_points / 2, nc = 1, samplingRate = samplingRate,
 formants = list('f1' = data.frame(time = 0, freq = 7000,
                                   amp = 50, width = 2000)))
noise = generateNoise(len = samplingRate,
  samplingRate = samplingRate, filterNoise = as.numeric(filterNoise))
# plot(filterNoise, type = 'l')
# playme(noise, samplingRate = samplingRate)

# Low-frequency, wind-like noise
filterNoise = soundgen:::getSpectralEnvelope(
  nr = windowLength_points / 2, nc = 1, lipRad = 0,
  samplingRate = samplingRate, formants = list('f1' = data.frame(
    time = 0, freq = 150, amp = 30, width = 90)))
noise = generateNoise(len = samplingRate,
  samplingRate = samplingRate, filterNoise = as.numeric(filterNoise))
# playme(noise, samplingRate = samplingRate)

# Manual filter, e.g. for a kettle-like whistle (narrow-band noise)
filterNoise = c(rep(0, 100), 120, rep(0, 100))  # any length is fine
# plot(filterNoise, type = 'b')  # notch filter at Nyquist / 2, here 4 kHz
noise = generateNoise(len = samplingRate,
  samplingRate = samplingRate, filterNoise = filterNoise)
# playme(noise, samplingRate = samplingRate)
# spectrogram(noise, samplingRate)

# Compare to a similar sound created with soundgen()
# (unvoiced only, a single formant at 4 kHz)
noise_s = soundgen(pitchAnchors = NULL,
  noiseAnchors = data.frame(time = c(0, 1000), value = c(0, 0)),
  formants = list(f1 = data.frame(freq = 4000, amp = 80, width = 20)))
# playme(noise_s)
# }

Run the code above in your browser using DataLab