From patchwork Tue Sep 8 21:18:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22192 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 52AA144BE02 for ; Wed, 9 Sep 2020 00:20:46 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 238D868B76C; Wed, 9 Sep 2020 00:19:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8BD4E68B737 for ; Wed, 9 Sep 2020 00:19:37 +0300 (EEST) Received: by mail-wm1-f50.google.com with SMTP id e11so452229wme.0 for ; Tue, 08 Sep 2020 14:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9DKNNQQIfZtwEjMgMK0r4a7lKrq8S8/26k2jYHAXF4g=; b=ggmiwXyE15Jb+axL/IBkRx3znzz+b7AxE5Q1OxjnuuUeFXuDxd2llw3Aw/m4Y/aNuU QmifMZgUskLxiz16C4gA2w3So3NYNFOUsPSyTi7qYrj8vhq6NoLuvd8Kwnd3EyzQDwW2 jV4P1UcPlJkPnZoc2Lo1ryLWVQuUxiMbIS22GIiNBD6Vx6DaQ4iEq2T065bMge6DHXIn egQKcgMBQ/o7I0C3jibSk9dxAwjB/NIje47LSpuLzLEgaqsHFZJHQLEjdOGeHbut+mxG 0aCcty148SURXQhX6Z9lYNah8r/JrAGToSZyet2nZaCTBYZ4SvGAkDDlQjmYOzsaRmYR X4GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9DKNNQQIfZtwEjMgMK0r4a7lKrq8S8/26k2jYHAXF4g=; b=fRXI/oXIwpClJ+KJjH9kzut8Rm1EJaQYKKH9nmVUQqE461HkITO5bercy/jWMZzlid 4sQVChyosAyGQWMa5p4ulNrKkeq0eqZy2ERMDCmJ3zrKBj5amKGtErPrQwGasxljjYFv GOJndrnyZkJX5K7nHUnaskWZfDINDlabEOE8FqnLyxdM2ox0poqwAPTr+xQS6S9zuba5 WnzYEg45gZ/aeW7G8ou85xqtPWG3vPttM/zPjJmOuCI4j+ECPg4TWoVmVgLLa+Cl2G1c S2id3vrhw1DFDhEoDse7+KNbygZ7IJnLt26yS5pTyhPbCgsCkBU3a4ZH6xgUH7O+SBM/ 9KhA== X-Gm-Message-State: AOAM5338/TLJ0Wh2C55OOivCyRakxCVGYsiHFYuR3hsrYt7r5DPMDKDS smXP0cvQEpB1sZtK/9fUoXNcGYn+ci8= X-Google-Smtp-Source: ABdhPJy3h00MFwBquCB6p54Z8N8vaCU5tkPkrgwczHaKwMiyQAt/RzwViFLW0EyDpTnwOsdiEiAHnw== X-Received: by 2002:a7b:c397:: with SMTP id s23mr342859wmj.174.1599599976567; Tue, 08 Sep 2020 14:19:36 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id a15sm1074304wrn.3.2020.09.08.14.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:35 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:47 +0200 Message-Id: <20200908211856.16290-16-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200908211856.16290-1-andreas.rheinhardt@gmail.com> References: <20200908211856.16290-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/25] avfilter/af_headphone: Fix channel assignment X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The documentation of the map argument of the headphone filter states: "Set mapping of input streams for convolution. The argument is a ’|’-separated list of channel names in order as they are given as additional stream inputs for filter." Yet this has not been honoured at all. Instead for the kth given HRIR channel pair it was checked whether there was a kth mapping and if the channel position so given was present in the channel layout of the main input; if so, then the given HRIR channel pair was matched to the kth channel of the main input. It should actually have been matched to the channel given by the kth mapping. A consequence of the current algorithm is that if N additional HRIR channel pairs are given, a permutation of the first N entries of the mapping does not affect the output at all. The old code might even set arrays belonging to streams that don't exist (i.e. whose index is >= the number of channels of the main input stream); these parts were not read lateron at all. The new code doesn't do this any longer and therefore the number of elements of some of the allocated arrays has been reduced (in case the number of mappings was bigger than the number of channels of the first input stream). Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index fb6af7a966..d6647ff80b 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -117,8 +117,6 @@ static void parse_map(AVFilterContext *ctx) continue; } used_channels |= out_channel; - if (out_channel == AV_CH_LOW_FREQUENCY) - s->lfe_channel = s->nb_irs; s->mapping[s->nb_irs] = out_channel; s->nb_irs++; } @@ -368,7 +366,6 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) { struct HeadphoneContext *s = ctx->priv; const int ir_len = s->ir_len; - int nb_irs = s->nb_irs; int nb_input_channels = ctx->inputs[0]->channels; float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10); FFTComplex *fft_in_l = NULL; @@ -430,15 +427,15 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) s->temp_src[0] = av_calloc(s->air_len, sizeof(float)); s->temp_src[1] = av_calloc(s->air_len, sizeof(float)); - s->data_ir[0] = av_calloc(nb_irs * s->air_len, sizeof(*s->data_ir[0])); - s->data_ir[1] = av_calloc(nb_irs * s->air_len, sizeof(*s->data_ir[1])); + s->data_ir[0] = av_calloc(nb_input_channels * s->air_len, sizeof(*s->data_ir[0])); + s->data_ir[1] = av_calloc(nb_input_channels * s->air_len, sizeof(*s->data_ir[1])); if (!s->data_ir[0] || !s->data_ir[1] || !s->temp_src[0] || !s->temp_src[1]) { ret = AVERROR(ENOMEM); goto fail; } } else { - s->data_hrtf[0] = av_calloc(n_fft, sizeof(*s->data_hrtf[0]) * nb_irs); - s->data_hrtf[1] = av_calloc(n_fft, sizeof(*s->data_hrtf[1]) * nb_irs); + s->data_hrtf[0] = av_calloc(n_fft, sizeof(*s->data_hrtf[0]) * nb_input_channels); + s->data_hrtf[1] = av_calloc(n_fft, sizeof(*s->data_hrtf[1]) * nb_input_channels); if (!s->data_hrtf[0] || !s->data_hrtf[1]) { ret = AVERROR(ENOMEM); goto fail; @@ -459,7 +456,9 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) for (j = 0; j < inlink->channels; j++) { if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[i]) { - idx = i; + idx = j; + if (s->mapping[i] == AV_CH_LOW_FREQUENCY) + s->lfe_channel = j; break; } } @@ -499,14 +498,16 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) for (j = 0; j < inlink->channels; j++) { if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[k]) { - idx = k; + idx = j; + if (s->mapping[k] == AV_CH_LOW_FREQUENCY) + s->lfe_channel = j; break; } } if (idx == -1) continue; - I = idx * 2; + I = k * 2; if (s->type == TIME_DOMAIN) { float *data_ir_l = s->data_ir[0] + idx * s->air_len; float *data_ir_r = s->data_ir[1] + idx * s->air_len;