avfilter/af_aemphasis: add fltp sample format support

This commit is contained in:
Paul B Mahol 2024-05-07 08:57:35 +02:00
parent 543e8f7ef2
commit 29494ac6a4
4 changed files with 223 additions and 171 deletions

View File

@ -0,0 +1,79 @@
/*
* 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
*/
#undef ftype
#undef SAMPLE_FORMAT
#if DEPTH == 32
#define ftype float
#define SAMPLE_FORMAT fltp
#else
#define ftype double
#define SAMPLE_FORMAT dblp
#endif
#define F(x) ((ftype)(x))
#define fn3(a,b) a##_##b
#define fn2(a,b) fn3(a,b)
#define fn(a) fn2(a, SAMPLE_FORMAT)
static void fn(biquad_process)(BiquadCoeffs *bq, ftype *dst, const ftype *src, int nb_samples,
ftype *w, ftype level_in, ftype level_out)
{
const ftype b0 = bq->b0;
const ftype b1 = bq->b1;
const ftype b2 = bq->b2;
const ftype a1 = -bq->a1;
const ftype a2 = -bq->a2;
ftype w1 = w[0];
ftype w2 = w[1];
for (int i = 0; i < nb_samples; i++) {
ftype in = src[i] * level_in;
ftype out = b0 * in + w1;
w1 = b1 * in + w2 + a1 * out;
w2 = b2 * in + a2 * out;
dst[i] = out * level_out;
}
w[0] = isnormal(w1) ? w1 : F(0.0);
w[1] = isnormal(w2) ? w2 : F(0.0);
}
static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
AudioEmphasisContext *s = ctx->priv;
const ftype level_out = s->level_out;
const ftype level_in = s->level_in;
ThreadData *td = arg;
AVFrame *out = td->out;
AVFrame *in = td->in;
const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
for (int ch = start; ch < end; ch++) {
const ftype *src = (const ftype *)in->extended_data[ch];
ftype *w = (ftype *)s->w->extended_data[ch];
ftype *dst = (ftype *)out->extended_data[ch];
fn(biquad_process)(&s->rc.r1, dst, src, in->nb_samples, w, level_in, level_out);
}
return 0;
}

View File

@ -50,6 +50,8 @@ typedef struct AudioEmphasisContext {
RIAACurve rc;
AVFrame *w;
int (*filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
} AudioEmphasisContext;
#define OFFSET(x) offsetof(AudioEmphasisContext, x)
@ -74,60 +76,22 @@ static const AVOption aemphasis_options[] = {
AVFILTER_DEFINE_CLASS(aemphasis);
static inline void biquad_process(BiquadCoeffs *bq, double *dst, const double *src, int nb_samples,
double *w, double level_in, double level_out)
{
const double b0 = bq->b0;
const double b1 = bq->b1;
const double b2 = bq->b2;
const double a1 = -bq->a1;
const double a2 = -bq->a2;
double w1 = w[0];
double w2 = w[1];
for (int i = 0; i < nb_samples; i++) {
double in = src[i] * level_in;
double out = b0 * in + w1;
w1 = b1 * in + w2 + a1 * out;
w2 = b2 * in + a2 * out;
dst[i] = out * level_out;
}
w[0] = isnormal(w1) ? w1 : 0.0;
w[1] = isnormal(w2) ? w2 : 0.0;
}
typedef struct ThreadData {
AVFrame *in, *out;
} ThreadData;
static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
AudioEmphasisContext *s = ctx->priv;
const double level_out = s->level_out;
const double level_in = s->level_in;
ThreadData *td = arg;
AVFrame *out = td->out;
AVFrame *in = td->in;
const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
#define DEPTH 32
#include "aemphasis_template.c"
for (int ch = start; ch < end; ch++) {
const double *src = (const double *)in->extended_data[ch];
double *w = (double *)s->w->extended_data[ch];
double *dst = (double *)out->extended_data[ch];
biquad_process(&s->rc.r1, dst, src, in->nb_samples, w, level_in, level_out);
}
return 0;
}
#undef DEPTH
#define DEPTH 64
#include "aemphasis_template.c"
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
{
AVFilterContext *ctx = inlink->dst;
AVFilterLink *outlink = ctx->outputs[0];
AudioEmphasisContext *s = ctx->priv;
ThreadData td;
AVFrame *out;
@ -143,7 +107,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
}
td.in = in; td.out = out;
ff_filter_execute(ctx, filter_channels, &td, NULL,
ff_filter_execute(ctx, s->filter_channels, &td, NULL,
FFMIN(inlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
if (in != out)
@ -174,6 +138,15 @@ static int config_input(AVFilterLink *inlink)
AudioEmphasisContext *s = ctx->priv;
BiquadCoeffs coeffs;
switch (inlink->format) {
case AV_SAMPLE_FMT_DBLP:
s->filter_channels = filter_channels_dblp;
break;
case AV_SAMPLE_FMT_FLTP:
s->filter_channels = filter_channels_fltp;
break;
}
if (!s->w)
s->w = ff_get_audio_buffer(inlink, 2);
if (!s->w)
@ -291,7 +264,7 @@ const AVFilter ff_af_aemphasis = {
.uninit = uninit,
FILTER_INPUTS(aemphasis_inputs),
FILTER_OUTPUTS(ff_audio_default_filterpad),
FILTER_SINGLE_SAMPLEFMT(AV_SAMPLE_FMT_DBLP),
FILTER_SAMPLEFMTS(AV_SAMPLE_FMT_DBLP, AV_SAMPLE_FMT_FLTP),
.process_command = process_command,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |
AVFILTER_FLAG_SLICE_THREADS,

View File

@ -3,68 +3,68 @@
#codec_id 0: pcm_s16le
#sample_rate 0: 44100
#channel_layout_name 0: stereo
0, 0, 0, 4096, 16384, 0x990adba7
0, 4096, 4096, 4096, 16384, 0xe8fbef2b
0, 8192, 8192, 4096, 16384, 0x1f11da2f
0, 12288, 12288, 4096, 16384, 0x5844e52d
0, 16384, 16384, 4096, 16384, 0x7739ef7b
0, 20480, 20480, 4096, 16384, 0xf6bef2b3
0, 24576, 24576, 4096, 16384, 0x1a34e98b
0, 28672, 28672, 4096, 16384, 0x46ede893
0, 32768, 32768, 4096, 16384, 0x9353de13
0, 36864, 36864, 4096, 16384, 0xe8fbef2b
0, 40960, 40960, 4096, 16384, 0x3206e5e1
0, 45056, 45056, 4096, 16384, 0x1162bfdd
0, 49152, 49152, 4096, 16384, 0xef9c0744
0, 53248, 53248, 4096, 16384, 0x72dff7bb
0, 57344, 57344, 4096, 16384, 0x8a3ba387
0, 61440, 61440, 4096, 16384, 0x41b29a55
0, 65536, 65536, 4096, 16384, 0x564ae7e9
0, 69632, 69632, 4096, 16384, 0x46632596
0, 73728, 73728, 4096, 16384, 0xe4d003f6
0, 77824, 77824, 4096, 16384, 0x0f8fd5bd
0, 81920, 81920, 4096, 16384, 0x57a6d1ff
0, 86016, 86016, 4096, 16384, 0x97050b2c
0, 90112, 90112, 4096, 16384, 0x5df3831d
0, 94208, 94208, 4096, 16384, 0xd74cc599
0, 98304, 98304, 4096, 16384, 0x691e1c4a
0, 102400, 102400, 4096, 16384, 0xc9829a91
0, 106496, 106496, 4096, 16384, 0xd723c44b
0, 110592, 110592, 4096, 16384, 0xf2f61906
0, 114688, 114688, 4096, 16384, 0x09452c84
0, 0, 0, 4096, 16384, 0xef0cdbad
0, 4096, 4096, 4096, 16384, 0xdfebef2b
0, 8192, 8192, 4096, 16384, 0x7b17da31
0, 12288, 12288, 4096, 16384, 0x918ce52d
0, 16384, 16384, 4096, 16384, 0x4d83ef79
0, 20480, 20480, 4096, 16384, 0x3b30f2b1
0, 24576, 24576, 4096, 16384, 0xdb85e98b
0, 28672, 28672, 4096, 16384, 0xbe83e895
0, 32768, 32768, 4096, 16384, 0xe955de19
0, 36864, 36864, 4096, 16384, 0xdfebef2b
0, 40960, 40960, 4096, 16384, 0x8e0ce5e3
0, 45056, 45056, 4096, 16384, 0xf837bde7
0, 49152, 49152, 4096, 16384, 0xff280748
0, 53248, 53248, 4096, 16384, 0x6ef8f7b3
0, 57344, 57344, 4096, 16384, 0x1f80a389
0, 61440, 61440, 4096, 16384, 0xc8579a5f
0, 65536, 65536, 4096, 16384, 0x2a33e7e1
0, 69632, 69632, 4096, 16384, 0xd8142596
0, 73728, 73728, 4096, 16384, 0xf3b203f4
0, 77824, 77824, 4096, 16384, 0x2b90d5b5
0, 81920, 81920, 4096, 16384, 0xadced1ff
0, 86016, 86016, 4096, 16384, 0x47690b28
0, 90112, 90112, 4096, 16384, 0x228d831b
0, 94208, 94208, 4096, 16384, 0x9446c597
0, 98304, 98304, 4096, 16384, 0x887b1c46
0, 102400, 102400, 4096, 16384, 0x09699a91
0, 106496, 106496, 4096, 16384, 0x1dbac44b
0, 110592, 110592, 4096, 16384, 0x99581904
0, 114688, 114688, 4096, 16384, 0x3b8d2c84
0, 118784, 118784, 4096, 16384, 0x07330e2a
0, 122880, 122880, 4096, 16384, 0xb36f6f5c
0, 126976, 126976, 4096, 16384, 0x183d7150
0, 131072, 131072, 4096, 16384, 0xe201aee0
0, 135168, 135168, 4096, 16384, 0xa26fe7e9
0, 139264, 139264, 4096, 16384, 0xb18b0d75
0, 143360, 143360, 4096, 16384, 0x3ac0d9e6
0, 147456, 147456, 4096, 16384, 0x861407c9
0, 151552, 151552, 4096, 16384, 0x541bdc46
0, 155648, 155648, 4096, 16384, 0xa2ffba75
0, 159744, 159744, 4096, 16384, 0x8926bd30
0, 163840, 163840, 4096, 16384, 0xd57de0dc
0, 167936, 167936, 4096, 16384, 0x0351d5d4
0, 172032, 172032, 4096, 16384, 0x80e1e079
0, 176128, 176128, 4096, 16384, 0x8eaff53a
0, 180224, 180224, 4096, 16384, 0x6818a593
0, 184320, 184320, 4096, 16384, 0x172a9e58
0, 188416, 188416, 4096, 16384, 0x3d0af7a0
0, 192512, 192512, 4096, 16384, 0xa1cfee35
0, 196608, 196608, 4096, 16384, 0xcb6a24f3
0, 200704, 200704, 4096, 16384, 0x97369bae
0, 204800, 204800, 4096, 16384, 0x3457c4b4
0, 208896, 208896, 4096, 16384, 0xab0504d6
0, 212992, 212992, 4096, 16384, 0x6818a593
0, 217088, 217088, 4096, 16384, 0x172a9e58
0, 221184, 221184, 4096, 16384, 0x3d0af7a0
0, 225280, 225280, 4096, 16384, 0xa1cfee35
0, 229376, 229376, 4096, 16384, 0xcb6a24f3
0, 233472, 233472, 4096, 16384, 0x97369bae
0, 237568, 237568, 4096, 16384, 0x3457c4b4
0, 241664, 241664, 4096, 16384, 0xab0504d6
0, 245760, 245760, 4096, 16384, 0x6818a593
0, 249856, 249856, 4096, 16384, 0x172a9e58
0, 253952, 253952, 4096, 16384, 0x3d0af7a0
0, 258048, 258048, 4096, 16384, 0xa1cfee35
0, 262144, 262144, 2456, 9824, 0xc3555abe
0, 122880, 122880, 4096, 16384, 0x81116f5a
0, 126976, 126976, 4096, 16384, 0x174f714e
0, 131072, 131072, 4096, 16384, 0x6ae6aee3
0, 135168, 135168, 4096, 16384, 0xea6de7ec
0, 139264, 139264, 4096, 16384, 0x34b70d71
0, 143360, 143360, 4096, 16384, 0xdeead9ec
0, 147456, 147456, 4096, 16384, 0x00c607c7
0, 151552, 151552, 4096, 16384, 0x6c5fdc46
0, 155648, 155648, 4096, 16384, 0x5de1ba74
0, 159744, 159744, 4096, 16384, 0x2e42bd2e
0, 163840, 163840, 4096, 16384, 0xde27e0dd
0, 167936, 167936, 4096, 16384, 0x8ea9d5d7
0, 172032, 172032, 4096, 16384, 0x4611e079
0, 176128, 176128, 4096, 16384, 0x24b7f536
0, 180224, 180224, 4096, 16384, 0x30aca58f
0, 184320, 184320, 4096, 16384, 0x0e1e9e56
0, 188416, 188416, 4096, 16384, 0x02ccf7a0
0, 192512, 192512, 4096, 16384, 0xefa1ee37
0, 196608, 196608, 4096, 16384, 0xa5cc24f3
0, 200704, 200704, 4096, 16384, 0x82329bac
0, 204800, 204800, 4096, 16384, 0xf100c4b1
0, 208896, 208896, 4096, 16384, 0x410d04d2
0, 212992, 212992, 4096, 16384, 0x30aca58f
0, 217088, 217088, 4096, 16384, 0x0e1e9e56
0, 221184, 221184, 4096, 16384, 0x02ccf7a0
0, 225280, 225280, 4096, 16384, 0xefa1ee37
0, 229376, 229376, 4096, 16384, 0xa5cc24f3
0, 233472, 233472, 4096, 16384, 0x82329bac
0, 237568, 237568, 4096, 16384, 0xf100c4b1
0, 241664, 241664, 4096, 16384, 0x410d04d2
0, 245760, 245760, 4096, 16384, 0x30aca58f
0, 249856, 249856, 4096, 16384, 0x0e1e9e56
0, 253952, 253952, 4096, 16384, 0x02ccf7a0
0, 258048, 258048, 4096, 16384, 0xefa1ee37
0, 262144, 262144, 2456, 9824, 0xa8bd5abd

View File

@ -3,68 +3,68 @@
#codec_id 0: pcm_s16le
#sample_rate 0: 44100
#channel_layout_name 0: stereo
0, 0, 0, 4096, 16384, 0xd3bcd82f
0, 4096, 4096, 4096, 16384, 0x267de021
0, 8192, 8192, 4096, 16384, 0x49b1ede1
0, 12288, 12288, 4096, 16384, 0x89c9e5c7
0, 16384, 16384, 4096, 16384, 0x09a7ef11
0, 0, 0, 4096, 16384, 0x1149d831
0, 4096, 4096, 4096, 16384, 0xdd07e027
0, 8192, 8192, 4096, 16384, 0x1b89ede1
0, 12288, 12288, 4096, 16384, 0x2a54e5cb
0, 16384, 16384, 4096, 16384, 0xf9a2ef0f
0, 20480, 20480, 4096, 16384, 0xd0bbe7cb
0, 24576, 24576, 4096, 16384, 0x3f45d98f
0, 28672, 28672, 4096, 16384, 0xc2cee3a7
0, 32768, 32768, 4096, 16384, 0xcab9d86b
0, 36864, 36864, 4096, 16384, 0x267de021
0, 40960, 40960, 4096, 16384, 0x5014f593
0, 45056, 45056, 4096, 16384, 0x6670be6f
0, 24576, 24576, 4096, 16384, 0xce39d993
0, 28672, 28672, 4096, 16384, 0x1e79e3ab
0, 32768, 32768, 4096, 16384, 0x0846d86d
0, 36864, 36864, 4096, 16384, 0xdd07e027
0, 40960, 40960, 4096, 16384, 0x0bf6f591
0, 45056, 45056, 4096, 16384, 0x3d12be6d
0, 49152, 49152, 4096, 16384, 0xdd6ef309
0, 53248, 53248, 4096, 16384, 0x23edd875
0, 57344, 57344, 4096, 16384, 0x57201482
0, 61440, 61440, 4096, 16384, 0xa345dc5f
0, 65536, 65536, 4096, 16384, 0x9129d101
0, 69632, 69632, 4096, 16384, 0x067bb785
0, 73728, 73728, 4096, 16384, 0xc020e627
0, 53248, 53248, 4096, 16384, 0x6081d879
0, 57344, 57344, 4096, 16384, 0x57011488
0, 61440, 61440, 4096, 16384, 0xbb75dc5f
0, 65536, 65536, 4096, 16384, 0xa850d0fb
0, 69632, 69632, 4096, 16384, 0x99ffb789
0, 73728, 73728, 4096, 16384, 0xc27fe621
0, 77824, 77824, 4096, 16384, 0xc90ae24b
0, 81920, 81920, 4096, 16384, 0x7a0b8b41
0, 86016, 86016, 4096, 16384, 0xee43839f
0, 90112, 90112, 4096, 16384, 0x7ebc540a
0, 94208, 94208, 4096, 16384, 0xa4ed7161
0, 98304, 98304, 4096, 16384, 0xa646c553
0, 102400, 102400, 4096, 16384, 0x8e053dee
0, 106496, 106496, 4096, 16384, 0xbcd1b9e1
0, 110592, 110592, 4096, 16384, 0xec941980
0, 114688, 114688, 4096, 16384, 0x3bfb8a94
0, 118784, 118784, 4096, 16384, 0x641c03e6
0, 122880, 122880, 4096, 16384, 0x1053f4fc
0, 126976, 126976, 4096, 16384, 0x06ac5032
0, 131072, 131072, 4096, 16384, 0x1ac29d2a
0, 135168, 135168, 4096, 16384, 0xf7f7d7b5
0, 139264, 139264, 4096, 16384, 0xc402febf
0, 143360, 143360, 4096, 16384, 0xd0ced176
0, 147456, 147456, 4096, 16384, 0xeb33f547
0, 151552, 151552, 4096, 16384, 0x6356e6d8
0, 155648, 155648, 4096, 16384, 0x1aebf4e6
0, 159744, 159744, 4096, 16384, 0x2ce1e48c
0, 163840, 163840, 4096, 16384, 0x0d21de12
0, 81920, 81920, 4096, 16384, 0x6ac38b41
0, 86016, 86016, 4096, 16384, 0xb073839f
0, 90112, 90112, 4096, 16384, 0x44d05406
0, 94208, 94208, 4096, 16384, 0xe3257161
0, 98304, 98304, 4096, 16384, 0xf5edc54d
0, 102400, 102400, 4096, 16384, 0x0b613dea
0, 106496, 106496, 4096, 16384, 0xb1abb9df
0, 110592, 110592, 4096, 16384, 0x22a41986
0, 114688, 114688, 4096, 16384, 0x79c98a96
0, 118784, 118784, 4096, 16384, 0x450c03e6
0, 122880, 122880, 4096, 16384, 0x4bf1f4fe
0, 126976, 126976, 4096, 16384, 0x32745032
0, 131072, 131072, 4096, 16384, 0xab689d2d
0, 135168, 135168, 4096, 16384, 0x2708d7b6
0, 139264, 139264, 4096, 16384, 0x01b3fec0
0, 143360, 143360, 4096, 16384, 0xe1aad176
0, 147456, 147456, 4096, 16384, 0xce33f547
0, 151552, 151552, 4096, 16384, 0xf13be6d5
0, 155648, 155648, 4096, 16384, 0x3eddf4e7
0, 159744, 159744, 4096, 16384, 0x3475e48c
0, 163840, 163840, 4096, 16384, 0xd25ede11
0, 167936, 167936, 4096, 16384, 0x4f30eb6a
0, 172032, 172032, 4096, 16384, 0x9b07ed9b
0, 176128, 176128, 4096, 16384, 0xf4650f0f
0, 180224, 180224, 4096, 16384, 0xc049f76e
0, 184320, 184320, 4096, 16384, 0x54928d24
0, 188416, 188416, 4096, 16384, 0x1e88eb77
0, 192512, 192512, 4096, 16384, 0x2a8edfed
0, 196608, 196608, 4096, 16384, 0x6ccad68a
0, 200704, 200704, 4096, 16384, 0x44e3bc16
0, 204800, 204800, 4096, 16384, 0xd576d791
0, 208896, 208896, 4096, 16384, 0x9e9e13ca
0, 212992, 212992, 4096, 16384, 0xc049f76e
0, 217088, 217088, 4096, 16384, 0x54928d24
0, 221184, 221184, 4096, 16384, 0x1e88eb77
0, 225280, 225280, 4096, 16384, 0x2a8edfed
0, 229376, 229376, 4096, 16384, 0x6ccad68a
0, 233472, 233472, 4096, 16384, 0x44e3bc16
0, 237568, 237568, 4096, 16384, 0xd576d791
0, 241664, 241664, 4096, 16384, 0x9e9e13ca
0, 245760, 245760, 4096, 16384, 0xc049f76e
0, 249856, 249856, 4096, 16384, 0x54928d24
0, 253952, 253952, 4096, 16384, 0x1e88eb77
0, 258048, 258048, 4096, 16384, 0x2a8edfed
0, 262144, 262144, 2456, 9824, 0x41840883
0, 172032, 172032, 4096, 16384, 0xcf69ed9c
0, 176128, 176128, 4096, 16384, 0x0f160f10
0, 180224, 180224, 4096, 16384, 0xa2fbf76f
0, 184320, 184320, 4096, 16384, 0x27de8d22
0, 188416, 188416, 4096, 16384, 0x2f84eb76
0, 192512, 192512, 4096, 16384, 0x4974dfef
0, 196608, 196608, 4096, 16384, 0xb339d686
0, 200704, 200704, 4096, 16384, 0x7e65bc18
0, 204800, 204800, 4096, 16384, 0x329fd793
0, 208896, 208896, 4096, 16384, 0xb94013cb
0, 212992, 212992, 4096, 16384, 0xa2fbf76f
0, 217088, 217088, 4096, 16384, 0x27de8d22
0, 221184, 221184, 4096, 16384, 0x2f84eb76
0, 225280, 225280, 4096, 16384, 0x4974dfef
0, 229376, 229376, 4096, 16384, 0xb339d686
0, 233472, 233472, 4096, 16384, 0x7e65bc18
0, 237568, 237568, 4096, 16384, 0x329fd793
0, 241664, 241664, 4096, 16384, 0xb94013cb
0, 245760, 245760, 4096, 16384, 0xa2fbf76f
0, 249856, 249856, 4096, 16384, 0x27de8d22
0, 253952, 253952, 4096, 16384, 0x2f84eb76
0, 258048, 258048, 4096, 16384, 0x4974dfef
0, 262144, 262144, 2456, 9824, 0xf047087f