1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00
FFmpeg/libavcodec/opusdsp.c
Lynne 6b22e28f4c opusdsp: adjust and optimize C function to match assembly
The C and asm versions behaved differently _outside_ of the codec.

The C version returned pre-multiplied 'state' for the next execution
to use right away, while the assembly version outputted non-multiplied
'state' for the next execution to multiply to save instructions.
Since the initial state when initialized or seeking is always 0,
and since C and asm versions were never mixed, there was no issue.

However, comparing outputs directly in checkasm doesn't work without
dividing the initial state by CELT_EMPH_COEFF and multiplying the
returned state by CELT_EMPH_COEFF for the assembly function.

Since its actually faster to do this in C as well, copy the behavior the
asm versions use. As a reminder, the initial state 0 is divided by
CELT_EMPH_COEFF on seek and init (just in case in the future this is
changed, its technically more correct to init with CELT_EMPH_COEFF than 0,
however when seeking this will result in more audiable pops, unlike with 0
where the output gets in sync over a few samples).
2019-09-11 03:28:22 +01:00

63 lines
1.7 KiB
C

/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "opusdsp.h"
static void postfilter_c(float *data, int period, float *gains, int len)
{
const float g0 = gains[0];
const float g1 = gains[1];
const float g2 = gains[2];
float x4 = data[-period - 2];
float x3 = data[-period - 1];
float x2 = data[-period + 0];
float x1 = data[-period + 1];
for (int i = 0; i < len; i++) {
float x0 = data[i - period + 2];
data[i] += g0 * x2 +
g1 * (x1 + x3) +
g2 * (x0 + x4);
x4 = x3;
x3 = x2;
x2 = x1;
x1 = x0;
}
}
static float deemphasis_c(float *y, float *x, float coeff, int len)
{
for (int i = 0; i < len; i++)
coeff = y[i] = x[i] + coeff*CELT_EMPH_COEFF;
return coeff;
}
av_cold void ff_opus_dsp_init(OpusDSP *ctx)
{
ctx->postfilter = postfilter_c;
ctx->deemphasis = deemphasis_c;
if (ARCH_X86)
ff_opus_dsp_init_x86(ctx);
if (ARCH_AARCH64)
ff_opus_dsp_init_aarch64(ctx);
}