Bug in wave normalization.
See original GitHub issueHi, thank you for sharing this awesome work.
I’ve encountered this code below, and I dont’ think this is correct.
crepe/core.py
frames = as_strided(audio, shape=(1024, n_frames),
strides=(audio.itemsize, hop_length * audio.itemsize))
frames = frames.transpose()
# normalize each frame -- this is expected by the model
frames -= np.mean(frames, axis=1)[:, np.newaxis]
frames /= np.std(frames, axis=1)[:, np.newaxis]
This code is meant to normalize wave by each frame, but numpy’s as_strided function does not allocate new memory, but does just create a new view of the array. (for example, the memory of first frame and the memory of second frame is not separated.)
See numpy documentation for more details.
So when do “in-place” calculation on that array, unintented result may raise. Here is an example.
np.random.seed(42)
model_srate,step_size = 16000, 10
audio = np.random.randn(16000) # (16000, )
# below code is from capre/core.py#get_activation
hop_length = int(model_srate * step_size / 1000)
n_frames = 1 + int((len(audio) - 1024) / hop_length)
frames = as_strided(audio, shape=(1024, n_frames),
strides=(audio.itemsize, hop_length * audio.itemsize))
frames = frames.transpose()
# normalize each frame -- this is expected by the model
frames -= np.mean(frames, axis=1)[:, np.newaxis]
frames /= np.std(frames, axis=1)[:, np.newaxis]
print(frames.sum())
146.7856165123937
Since frame is normalized, its sum should be about zero. but it’s not.
To avoid this behavior, target array should be copied or something, to do operation correctly as intended. here is an example. only one line is changed. (.copy())
np.random.seed(42)
model_srate,step_size = 16000, 10
audio = np.random.randn(16000) # (16000, )
# below code is from capre/core.py#get_activation
hop_length = int(model_srate * step_size / 1000)
n_frames = 1 + int((len(audio) - 1024) / hop_length)
frames = as_strided(audio, shape=(1024, n_frames),
strides=(audio.itemsize, hop_length * audio.itemsize))
frames = frames.transpose().copy()
# normalize each frame -- this is expected by the model
frames -= np.mean(frames, axis=1)[:, np.newaxis]
frames /= np.std(frames, axis=1)[:, np.newaxis]
print(frames.sum())
-2.384759056894836e-13
- This code is tested with numpy version 1.17.4
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
0000359: DC offset normalization for wave generator - DefleBugs ...
When clicking the normalize functionality the wave should be centered first before getting amplified so the uncentered waves can be amplified too.
Read more >Normalize bug: levels get maxed - Adobe Support Community
i.e. clip turns white because wave form takes up entire clip. When you then listen to clip it sounds totally distorted. I must...
Read more >torchaudio.backend.sox_io_backend does not normalize #2253
I am experiencing a bug when loading a WAV file using sox_io backend where the loaded file is not normalized (i.e. fit in...
Read more >normalize-audio - adjusts volume levels of WAV or MP3 audio ...
normalize -audio is used to adjust the volume of WAV or MP3 audio files to a standard volume level. This is useful for...
Read more >Integral/Calc issues: normalizing wave function - MathWorks
I'm trying to normalize a harmonic oscillator wave function. I'm getting multiple error codes, mostly involving the integral (see below code).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@adarob @justinsalamon Thanks for the heads up! Just pushed v0.0.11 😃
Btw you can use:
in
requirements.txt
to pull the latest commit from Github, or:for a specific commit.
@angusturner Hi, I‘m looking for the pytorch version of CREPE, but found nothing. Does the “PyTorch port” you mentioned is public available? or would you mind about releasing it? Thank you very much in advance.