mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-06-04 05:57:49 +02:00
lavfi/ebur128: fix channel weights
Correct the recognition of channel layouts for good channel weight in the loudness computation. This suggested patch is 2 of 3 for Ticket #2144 "libavfilter ebur128 loudness inaccuracy, irregular time interval, LFE interference". Signed-off-by: David A. Sedacca <sedacca at comcast.net>
This commit is contained in:
parent
f98598942f
commit
de21e6736e
@ -314,12 +314,15 @@ static int config_video_output(AVFilterLink *outlink)
|
|||||||
static int config_audio_output(AVFilterLink *outlink)
|
static int config_audio_output(AVFilterLink *outlink)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
int idx_bitposn = 0;
|
||||||
AVFilterContext *ctx = outlink->src;
|
AVFilterContext *ctx = outlink->src;
|
||||||
EBUR128Context *ebur128 = ctx->priv;
|
EBUR128Context *ebur128 = ctx->priv;
|
||||||
const int nb_channels = av_get_channel_layout_nb_channels(outlink->channel_layout);
|
const int nb_channels = av_get_channel_layout_nb_channels(outlink->channel_layout);
|
||||||
|
|
||||||
#define BACK_MASK (AV_CH_BACK_LEFT |AV_CH_BACK_CENTER |AV_CH_BACK_RIGHT| \
|
#define BACK_MASK (AV_CH_BACK_LEFT |AV_CH_BACK_CENTER |AV_CH_BACK_RIGHT| \
|
||||||
AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_CENTER|AV_CH_TOP_BACK_RIGHT)
|
AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_CENTER|AV_CH_TOP_BACK_RIGHT| \
|
||||||
|
AV_CH_SIDE_LEFT |AV_CH_SIDE_RIGHT| \
|
||||||
|
AV_CH_SURROUND_DIRECT_LEFT |AV_CH_SURROUND_DIRECT_RIGHT)
|
||||||
|
|
||||||
ebur128->nb_channels = nb_channels;
|
ebur128->nb_channels = nb_channels;
|
||||||
ebur128->ch_weighting = av_calloc(nb_channels, sizeof(*ebur128->ch_weighting));
|
ebur128->ch_weighting = av_calloc(nb_channels, sizeof(*ebur128->ch_weighting));
|
||||||
@ -328,13 +331,24 @@ static int config_audio_output(AVFilterLink *outlink)
|
|||||||
|
|
||||||
for (i = 0; i < nb_channels; i++) {
|
for (i = 0; i < nb_channels; i++) {
|
||||||
|
|
||||||
|
/* find the next bit that is set starting from the right */
|
||||||
|
while ((outlink->channel_layout & 1ULL<<idx_bitposn) == 0 && idx_bitposn < 63)
|
||||||
|
idx_bitposn++;
|
||||||
|
|
||||||
/* channel weighting */
|
/* channel weighting */
|
||||||
if ((outlink->channel_layout & 1ULL<<i) == AV_CH_LOW_FREQUENCY)
|
if ((1ULL<<idx_bitposn & AV_CH_LOW_FREQUENCY) ||
|
||||||
continue;
|
(1ULL<<idx_bitposn & AV_CH_LOW_FREQUENCY_2)) {
|
||||||
if (outlink->channel_layout & 1ULL<<i & BACK_MASK)
|
ebur128->ch_weighting[i] = 0;
|
||||||
|
} else if (1ULL<<idx_bitposn & BACK_MASK) {
|
||||||
ebur128->ch_weighting[i] = 1.41;
|
ebur128->ch_weighting[i] = 1.41;
|
||||||
else
|
} else {
|
||||||
ebur128->ch_weighting[i] = 1.0;
|
ebur128->ch_weighting[i] = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
idx_bitposn++;
|
||||||
|
|
||||||
|
if (!ebur128->ch_weighting[i])
|
||||||
|
continue;
|
||||||
|
|
||||||
/* bins buffer for the two integration window (400ms and 3s) */
|
/* bins buffer for the two integration window (400ms and 3s) */
|
||||||
ebur128->i400.cache[i] = av_calloc(I400_BINS, sizeof(*ebur128->i400.cache[0]));
|
ebur128->i400.cache[i] = av_calloc(I400_BINS, sizeof(*ebur128->i400.cache[0]));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user