| normalizeFolder | R Documentation |
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. If preserveRelativeDif is set to TRUE, all recordings
in the target folder get a boost in amplitude, so the loudest one reaches
maxAmp, but the relative differences between the recordings are
preserved (i.e., all files are boosted by the same amount - as much as
possible to avoid clipping the loudest one).
normalizeFolder(
myfolder,
type = c("peak", "rms", "loudness"),
maxAmp = 0,
summaryFun = "mean",
preserveRelativeDif = FALSE,
windowLength = 50,
step = NULL,
overlap = 70,
killDC = FALSE,
windowDC = 200,
cores = 1,
savePath = NULL,
reportEvery = NULL
)
myfolder |
full path to folder containing input audio files |
type |
normalize so the output files have the same peak amplitude ('peak'), root mean square amplitude ('rms'), or subjective loudness in sone ('loudness') |
maxAmp |
maximum amplitude in dB (0 = max possible, -10 = 10 dB below max possible, etc.) |
summaryFun |
should the output files have the same mean / median / max etc RMS amplitude or loudness? (summaryFun has no effect if type = 'peak') |
preserveRelativeDif |
(only for |
windowLength |
length of analysis window, ms (longer windows = more smoothing) |
step |
step between successive windows, ms; if provided, overrides
|
overlap |
overlap between successive windows, % |
killDC |
if TRUE, removes DC offset (see also |
windowDC |
the window for calculating DC offset, ms |
cores |
number of cores for parallel processing |
savePath |
full path to where the normalized files should be saved; defaults to NULL = 'myfolder/normalized'; NA = do not save the processed files |
reportEvery |
when processing multiple inputs, report estimated time
left every |
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'. NB:
because loudness is not a simple linear function of SPL, loudness
normalization is only approximate; reiterate the process several times to
improve the precision of loudness normalization.
Does not return anything, only saves the normalized audio files.
getRMS analyze getLoudness
## Not run:
# put a few short audio files in a folder, eg '~/Downloads/temp'
target = '~/Downloads/temp'
save_in_folder = paste0(target, '/normalized')
getRMS(target, summaryFun = 'mean')$summary # different
normalizeFolder(target, type = 'rms', summaryFun = 'mean',
savePath = save_in_folder)
getRMS(save_in_folder, 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.