Normalize waveforms
I have added the argument normalize_wav
to the following classes and functions (which all handle loading of audio from wav files),
- Waveform.from_wav
- MagSpectrogram.from_wav, PowerSpectrogram.from_wav, MelSpectrogram.from_wav, CQTSpectrogram.from_wav
- AudioLoader, AudioFrameLoader, AudioSelectionLoader
- create_database
If normalize_wav=True
, the waveform will be normalized so it has zero (0) mean and unity (1) standard deviation. The default value is normalize_wav=False
(ensures backward compatibility).
I have also expanded the audio representation parser to handle this new argument.
Unit tests have been created and are all passing.
Should be ready to merge. Please have a look, thanks
added 1 commit
- 25b36594 - normalize_wav passed on as part of audio representation
added 1 commit
- 0478e1d4 - parse_audio_representation can also handle normalize_wav argument
The Waveform and Spectrogram classes have this method 'normalize()', which they inherit from BaseAudio. But that puts the data into a 0-1 range.
So maybe it be would worth changing the implementation so that you can choose how to 'normalize'? I guess technically 'normalize' would mean 'put the data in a normal distribution with a given mean and a given std', but do you think it could be useful to keep the transformation that adjusts the range to. And, in both cases, would it be useful to have some parameters like the mean and std you want, or the range?
Good catch! I had forgotten about the
normalize()
method.We could alter the implementation of the
normalize()
as you suggest, i.e.,def normalize(self, mean=0, std=1): """ Normalize the data array to specified mean and standard deviation """ self.data = (self.data - np.mean(self.data)) / np.std(self.data)
And then have a separate method for adjusting the range,
def set_range(self, range=(0,1)): """ Applies a linear transformation to the data array that puts the values within the specified range. """ x_min = self.min() x_max = self.max() self.data = (range[1] - range[0]) * (self.data - x_min) / (x_max - x_min) + range[0]
The latter method could also be named
adjust_range
instead ofset_range
...@fsfrazao , what do you think?
Edited by Oliver Kirsebomadded 1 commit
- be6f78ce - re-implemented normalize method and added adjust_range method in base_audio
added 106 commits
-
be6f78ce...b48e2d16 - 105 commits from branch
development
- 06d7e8e0 - Merge branch 'development' into 'norm_audio'
-
be6f78ce...b48e2d16 - 105 commits from branch
mentioned in commit ea8d5b23