normalizeFolder {soundgen} | R Documentation |
Normalize folder
Description
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.
Usage
normalizeFolder(
myfolder,
type = c("peak", "rms", "loudness")[1],
maxAmp = 0,
summaryFun = "mean",
windowLength = 50,
step = NULL,
overlap = 70,
killDC = FALSE,
windowDC = 200,
saveAudio = NULL,
reportEvery = NULL
)
Arguments
myfolder |
full path to folder containing input audio files |
type |
normalize so the output files has 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') |
windowLength |
length of FFT window, ms |
step |
you can override |
overlap |
overlap between successive FFT frames, % |
killDC |
if TRUE, removed DC offset (see also |
windowDC |
the window for calculating DC offset, ms |
saveAudio |
full path to where the normalized files should be saved (defaults to 'myfolder/normalized') |
reportEvery |
when processing multiple inputs, report estimated time left every ... iterations (NULL = default, NA = don't report) |
Details
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
Examples
## 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)