normalizeFolder: Normalize folder

View source: R/amplitude.R

normalizeFolderR Documentation

Normalize folder


Normalizes the amplitude of all wav/mp3 files in a folder based on their peak or RMS amplitude or subjective loudness. This is good for playback experiments, which require that all sounds should have similar intensity or loudness.


  type = c("peak", "rms", "loudness")[1],
  maxAmp = 0,
  summaryFun = "mean",
  windowLength = 50,
  step = NULL,
  overlap = 70,
  killDC = FALSE,
  windowDC = 200,
  saveAudio = NULL,
  reportEvery = NULL



full path to folder containing input audio files


normalize so the output files has the same peak amplitude ('peak'), root mean square amplitude ('rms'), or subjective loudness in sone ('loudness')


maximum amplitude in dB (0 = max possible, -10 = 10 dB below max possible, etc.)


should the output files have the same mean / median / max etc rms amplitude or loudness? (summaryFun has no effect if type = 'peak')


length of FFT window, ms


you can override overlap by specifying FFT step, ms (NB: because digital audio is sampled at discrete time intervals of 1/samplingRate, the actual step and thus the time stamps of STFT frames may be slightly different, eg 24.98866 instead of 25.0 ms)


overlap between successive FFT frames, %


if TRUE, removed DC offset (see also flatEnv)


the window for calculating DC offset, ms


full path to where the normalized files should be saved (defaults to 'myfolder/normalized')


when processing multiple inputs, report estimated time left every ... iterations (NULL = default, NA = don't report)


Algorithm: first all files are rescaled to have the same peak amplitude of maxAmp dB. If type = 'peak', the process ends here. If type = 'rms', there are two additional steps. First the original RMS amplitude of all files is calculated per frame by getRMS. The "quietest" sound with the lowest summary RMS value is not modified, so its peak amplitude remains maxAmp dB. All the remaining sounds are rescaled linearly, so that their summary RMS values becomes the same as that of the "quietest" sound, and their peak amplitudes become smaller, <maxAmp. Finally, if type = 'loudness', the subjective loudness of each sound is estimated by getLoudness, which assumes frequency sensitivity typical of human hearing. The following normalization procedure is similar to that for type = 'rms'.

See Also

getRMS analyze getLoudness


## Not run: 
# put a few short audio files in a folder, eg '~/Downloads/temp'
getRMS('~/Downloads/temp2', summaryFun = 'mean')$summary  # different
normalizeFolder('~/Downloads/temp2', type = 'rms', summaryFun = 'mean',
  saveAudio = '~/Downloads/temp2/normalized')
getRMS('~/Downloads/temp2/normalized', summaryFun = 'mean')$summary  # same
# If the saved audio files are treated as stereo with one channel missing,
# try reconverting with ffmpeg (saving is handled by tuneR::writeWave)

## End(Not run)

soundgen documentation built on Aug. 14, 2022, 5:05 p.m.