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

Multichannel audio #41

Open rawrbw opened 2 years ago

rawrbw commented 2 years ago

What is the reason behind the 5 channel limit on multichannel audio?

csteinmetz1 commented 2 years ago

This is due to how things are defined in the original standard, they only specify behavior for 5.1 audio. I believe there has been more recent work to extend the standard to more multichannel formats. This is something we could look into building out in pyloudnorm. @rawrbw, did you have a particular use case in mind?

rawrbw commented 2 years ago

Ok I see. I was under the impression that 5.1 is actually 6 channels as the ".1" specifies the LFE channel? I was trying out multichannel content and noticed it would not accept more than 5 channels.

csteinmetz1 commented 2 years ago

Ah, I see there is an issue.

The standard states:

The block diagram shows inputs for five main channels (left, centre, right, left surround and right surround); this allows monitoring of programmes containing from one to five channels. For a programme that has less than five channels some inputs would not be used. The low frequency effects (LFE) channel is not included in the measurement.

The code needs to be adapted to ignore the LFE channel in this case instead of throwing an error. Let me work on a patch for this. Thanks for raising this issue. I have not done much testing with multichannel content myself.

rawrbw commented 2 years ago

Ok that explains it! Thank you for your excellent work! 👌

csteinmetz1 commented 2 years ago

So after taking a second look I think the current behavior may be the best option, however, there could be more documentation to describe the expected usage. What is important is that the user feed pyloudnorm with the proper channel layout, and that may vary by use case. In other words, pyloudnorm expects that the channel layout as follows: [Left, Right, Center, Left surround, Right surround]. So, I think it is best if we leave it to the user to remove the LFE channel before making an estimate of the loudness, since pyloudnorm will have no way to know which of the 6 channels is the LFE in the input. I am thinking to add some further discussion on this in the README, but it is also noted in the docstring of the Meter class.