Open
Description
Scaper clips sometimes.
I suggest we add some logic to the Scaper.generate
and Scaper._generate_audio
functions. Namely two parameters:
Parameters
------------
fix_clipping : bool
Checks the soundscape audio for clipping (abs(sample) > 1). If so, then the soundscape is
peak_normalized and the audio for each event is scaled accordingly. Defaults to ???
peak_normalize : bool
Always peak normalize the soundscape regardless of clipping. Note that if this is turned
on, then the loudness of the soundscape will be off of what `ref_db` is set to. Defaults to
False.
If the soundscape is clipping, then the peak_normalize
functionality is used if fix_clipping
is
True.
I think a good home for this logic would be in scaper.audio.peak_normalize
. The signature might
look like this:
def peak_normalize(soundscape_audio, event_audio_list):
# figure out scaling factor to peak normalize the soundscape_audio.
eps = 1e-10
scale = np.max(np.abs(soundscape_audio))
# scale the event audio and the soundscape audio:
soundscape_audio = soundscape_audio / (scale + eps)
for i, event_audio in enumerate(event_audio_list):
event_audio_list[i] = event_audio / (scale + eps)
return soundscape_audio, event_audio_list
We would call this function from core.py
.
Metadata
Assignees
Labels
No labels
Activity