csteinmetz1 / pyloudnorm

Flexible audio loudness meter in Python with implementation of ITU-R BS.1770-4 loudness algorithm
https://www.christiansteinmetz.com/projects-blog/pyloudnorm
MIT License
639 stars 56 forks source link

-Inf #52

Open isolin opened 1 year ago

isolin commented 1 year ago

Hi, I found pyloudnorm just yesterday while searching for a way to get loudness readings from orchestral samples recorded with different velocities, so that I can smoothly interpolate them. For most of them it works just great, so I'm very happy with it. Great job!

There is one issue I found so far: for quite a few samples of timpani it returns -Inf. This is the case for all filter types offered. The rate is 44100 and block_size stays at the default 0.4.

import soundfile as sf
import pyloudnorm as pyln

data, rate = sf.read('path_to_the_wav_sample')
meter = pyln.Meter(rate)
print(meter.integrated_loudness(data))

No idea if that is due to the low base frequency or relatively weak sound. It would be really great to have it fixed. My sample should be ok, it contains no NaN or infinite numbers. I assume the -inf comes from a division by zero, maybe some normalization or similar?

Here an example file that returns -Inf: Timpani_S36_A0_V80_R1.zip

Update: I think the issue is that meter.py:Ln90 produces an empty array since all blocks are between -80 and -70.

harimohanraj commented 1 year ago

I'm also encountering this issue with popular music where many samples within a short amount of time have the maximum or minimum amplitude value.

csteinmetz1 commented 1 year ago

Thanks @isolin and @harimohanraj for raising this.

I took a look at the timpani example. I see that it has very low level. If I use the loudness meter implementation in Adobe Audition it actually will not report any value and instead says: "Selection too short". This is likely because it did not find any blocks in the input signal above -70 dB in energy.

I think it is a detailed question of what pyloudnorm should return in these cases. I think -inf is in fact one valid option as it indicates the we cannot accurate measure the loudness because the input was essentially silent. However, we could potentially adapt the behavior to clamp the minimum value to -80 dB for example, however, I think this is slightly deceiving.

@harimohanraj are you able to share the audio of any example where you found this issue?