csteinmetz1/pyloudnorm

divide by zero error

Closed this issue · 5 comments

Hi! Sometimes I get "divide by zero" error.

/Users/tema/pyloudnorm-master/pyloudnorm/loudness.py:173: RuntimeWarning: divide by zero encountered in log10
l = [-0.691 + 10.0 * np.log10(np.sum([G[i] * z[i,j] for i in range(numChannels)])) for j in j_range]

This occurs whenever you encounter a large block of zero samples (silence) in your input. From my understanding the correct output in such a case should be -inf LUFS. I am currently working on a fix for this issue and will update when complete. Thanks.

@schtschenok I've worked on catching these warnings to ensure they are suppressed and handled properly. When measuring inputs of the silence -inf LUFS will be returned.

I think this issue should be reopened, I've got this error again on a file with a lot of silence, for example really_werid_sound_padded.wav from issue #4
Temas-MacBook-Pro:pyloudnorm tema$ python3 run.py really_werid_sound_padded.wav /Users/tema/pyloudnorm/pyloudnorm/loudness.py:204: RuntimeWarning: divide by zero encountered in log10 l = [-0.691 + 10.0 * np.log10(np.sum([G[i] * z[i,j] for i in range(numChannels)])) for j in j_range] -19.145277178165635

From my understanding this warning an occur whenever 0 is an input to np.log10(). I played around with some inputs and had not seen this but I do see where the warning is occuring. I will try to catch these warnings and use your file to test it. Thank you for your investigation.

I added code to catch the warning that was being thrown on line 204 in the previous commit. I tested it with really_werid_sound_padded.wav from issue #4 and the warning was suppressed properly.