dca_core: convert to lavu/tx

Thanks to Martin Storsjö <martin@martin.st> for fixing and testing the
arm32 and aarch64 changes.
This commit is contained in:
Lynne 2022-10-30 11:14:15 +01:00
parent 2689038f08
commit e0661fc805
No known key found for this signature in database
GPG Key ID: A2FEA5F03F034464
13 changed files with 80 additions and 53 deletions

View File

@ -32,11 +32,11 @@
AV_CHECK_OFFSET(FFTContext, imdct_half, IMDCT_HALF);
#endif
void ff_synth_filter_float_neon(FFTContext *imdct,
void ff_synth_filter_float_neon(AVTXContext *imdct,
float *synth_buf_ptr, int *synth_buf_offset,
float synth_buf2[32], const float window[512],
float out[32], const float in[32],
float scale);
float out[32], float in[32],
float scale, av_tx_fn imdct_fn);
av_cold void ff_synth_filter_init_aarch64(SynthFilterContext *s)
{

View File

@ -43,8 +43,8 @@
.endm
function ff_synth_filter_float_neon, export=1
mov x9, x7 // imdct_fn parameter
ldr w7, [x2] // *synth_buf_offset
ldr x9, [x0, #IMDCT_HALF] // imdct_half function pointer
sxtw x7, w7
stp x3, x4, [sp, #-64]!
add x1, x1, x7, lsl #2 // synth_buf
@ -58,6 +58,7 @@ function ff_synth_filter_float_neon, export=1
str s0, [sp, #48]
mov x2, x6 // in
mov x3, #4 // sizeof(float)
blr x9

View File

@ -26,17 +26,17 @@
#include "libavcodec/fft.h"
#include "libavcodec/synth_filter.h"
void ff_synth_filter_float_vfp(FFTContext *imdct,
void ff_synth_filter_float_vfp(AVTXContext *imdct,
float *synth_buf_ptr, int *synth_buf_offset,
float synth_buf2[32], const float window[512],
float out[32], const float in[32],
float scale);
float out[32], float in[32],
float scale, av_tx_fn imdct_fn);
void ff_synth_filter_float_neon(FFTContext *imdct,
void ff_synth_filter_float_neon(AVTXContext *imdct,
float *synth_buf_ptr, int *synth_buf_offset,
float synth_buf2[32], const float window[512],
float out[32], const float in[32],
float scale);
float out[32], float in[32],
float scale, av_tx_fn imdct_fn);
av_cold void ff_synth_filter_init_arm(SynthFilterContext *s)
{

View File

@ -31,10 +31,13 @@ function ff_synth_filter_float_neon, export=1
str r12, [r2]
ldr r2, [sp, #12*4] @ in
VFP ldr r12, [sp, #13*4] @ imdct_fn
NOVFP ldr r12, [sp, #14*4] @ imdct_fn
mov r3, #4 @ sizeof(float)
mov r9, r1 @ synth_buf
VFP vpush {d0}
bl X(ff_imdct_half_neon)
blx r12
VFP vpop {d0}
pop {r3}

View File

@ -131,8 +131,11 @@ function ff_synth_filter_float_vfp, export=1
and lr, lr, #512-32
str lr, [P_SB_OFF] @ rotate offset, modulo buffer size, ready for next call
ldr a3, [sp, #(16+6+2)*4] @ fetch in from stack, to pass to imdct_half
mov a4, #4 @ sizeof(float)
VFP ldr r12, [sp, #(16+6+3)*4] @ fetch imdct_fn from stack
NOVFP ldr r12, [sp, #(16+6+4)*4] @ fetch imdct_fn from stack
VFP vmov s16, SCALE @ imdct_half is free to corrupt s0, but it contains one of our arguments in hardfp case
bl X(ff_imdct_half_vfp)
blx r12
VFP vmov SCALE, s16
fmrx OLDFPSCR, FPSCR

View File

@ -2235,7 +2235,8 @@ static int filter_frame_float(DCACoreDecoder *s, AVFrame *frame)
// Filter bank reconstruction
s->dcadsp->sub_qmf_float[x96_synth](
&s->synth,
&s->imdct[x96_synth],
s->imdct[x96_synth],
s->imdct_fn[x96_synth],
output_samples[spkr],
s->subband_samples[ch],
ch < x96_nchannels ? s->x96_subband_samples[ch] : NULL,
@ -2424,16 +2425,24 @@ av_cold void ff_dca_core_flush(DCACoreDecoder *s)
av_cold int ff_dca_core_init(DCACoreDecoder *s)
{
int ret;
float scale = 1.0f;
if (!(s->float_dsp = avpriv_float_dsp_alloc(0)))
return -1;
if (!(s->fixed_dsp = avpriv_alloc_fixed_dsp(0)))
return -1;
ff_dcadct_init(&s->dcadct);
if (ff_mdct_init(&s->imdct[0], 6, 1, 1.0) < 0)
return -1;
if (ff_mdct_init(&s->imdct[1], 7, 1, 1.0) < 0)
return -1;
if ((ret = av_tx_init(&s->imdct[0], &s->imdct_fn[0], AV_TX_FLOAT_MDCT,
1, 32, &scale, 0)) < 0)
return ret;
if ((ret = av_tx_init(&s->imdct[1], &s->imdct_fn[1], AV_TX_FLOAT_MDCT,
1, 64, &scale, 0)) < 0)
return ret;
ff_synth_filter_init(&s->synth);
s->x96_rand = 1;
@ -2445,8 +2454,8 @@ av_cold void ff_dca_core_close(DCACoreDecoder *s)
av_freep(&s->float_dsp);
av_freep(&s->fixed_dsp);
ff_mdct_end(&s->imdct[0]);
ff_mdct_end(&s->imdct[1]);
av_tx_uninit(&s->imdct[0]);
av_tx_uninit(&s->imdct[1]);
av_freep(&s->subband_buffer);
s->subband_size = 0;

View File

@ -24,6 +24,7 @@
#include "libavutil/float_dsp.h"
#include "libavutil/fixed_dsp.h"
#include "libavutil/mem_internal.h"
#include "libavutil/tx.h"
#include "avcodec.h"
#include "get_bits.h"
@ -33,7 +34,6 @@
#include "dcadct.h"
#include "dcamath.h"
#include "dcahuff.h"
#include "fft.h"
#include "synth_filter.h"
#define DCA_CHANNELS 7
@ -190,7 +190,8 @@ typedef struct DCACoreDecoder {
DCADSPData dcadsp_data[DCA_CHANNELS]; ///< FIR history buffers
DCADSPContext *dcadsp;
DCADCTContext dcadct;
FFTContext imdct[2];
AVTXContext *imdct[2];
av_tx_fn imdct_fn[2];
SynthFilterContext synth;
AVFloatDSPContext *float_dsp;
AVFixedDSPContext *fixed_dsp;

View File

@ -114,7 +114,8 @@ static void lfe_x96_float_c(float *dst, const float *src,
}
static void sub_qmf32_float_c(SynthFilterContext *synth,
FFTContext *imdct,
AVTXContext *imdct,
av_tx_fn imdct_fn,
float *pcm_samples,
int32_t **subband_samples_lo,
int32_t **subband_samples_hi,
@ -137,13 +138,14 @@ static void sub_qmf32_float_c(SynthFilterContext *synth,
// One subband sample generates 32 interpolated ones
synth->synth_filter_float(imdct, hist1, offset,
hist2, filter_coeff,
pcm_samples, input, scale);
pcm_samples, input, scale, imdct_fn);
pcm_samples += 32;
}
}
static void sub_qmf64_float_c(SynthFilterContext *synth,
FFTContext *imdct,
AVTXContext *imdct,
av_tx_fn imdct_fn,
float *pcm_samples,
int32_t **subband_samples_lo,
int32_t **subband_samples_hi,
@ -186,7 +188,7 @@ static void sub_qmf64_float_c(SynthFilterContext *synth,
// One subband sample generates 64 interpolated ones
synth->synth_filter_float_64(imdct, hist1, offset,
hist2, filter_coeff,
pcm_samples, input, scale);
pcm_samples, input, scale, imdct_fn);
pcm_samples += 64;
}
}

View File

@ -22,8 +22,8 @@
#define AVCODEC_DCADSP_H
#include "libavutil/common.h"
#include "libavutil/tx.h"
#include "fft.h"
#include "dcadct.h"
#include "synth_filter.h"
@ -47,7 +47,8 @@ typedef struct DCADSPContext {
float *hist, ptrdiff_t len);
void (*sub_qmf_float[2])(SynthFilterContext *synth,
FFTContext *imdct,
AVTXContext *imdct,
av_tx_fn imdct_fn,
float *pcm_samples,
int32_t **subband_samples_lo,
int32_t **subband_samples_hi,

View File

@ -24,15 +24,16 @@
#include "dcamath.h"
#include "synth_filter.h"
static void synth_filter_float(FFTContext *imdct,
static void synth_filter_float(AVTXContext *imdct,
float *synth_buf_ptr, int *synth_buf_offset,
float synth_buf2[32], const float window[512],
float out[32], const float in[32], float scale)
float out[32], float in[32], float scale,
av_tx_fn imdct_fn)
{
float *synth_buf = synth_buf_ptr + *synth_buf_offset;
int i, j;
imdct->imdct_half(imdct, synth_buf, in);
imdct_fn(imdct, synth_buf, in, sizeof(float));
for (i = 0; i < 16; i++) {
float a = synth_buf2[i ];
@ -60,15 +61,16 @@ static void synth_filter_float(FFTContext *imdct,
*synth_buf_offset = (*synth_buf_offset - 32) & 511;
}
static void synth_filter_float_64(FFTContext *imdct,
static void synth_filter_float_64(AVTXContext *imdct,
float *synth_buf_ptr, int *synth_buf_offset,
float synth_buf2[64], const float window[1024],
float out[64], const float in[64], float scale)
float out[64], float in[64], float scale,
av_tx_fn imdct_fn)
{
float *synth_buf = synth_buf_ptr + *synth_buf_offset;
int i, j;
imdct->imdct_half(imdct, synth_buf, in);
imdct_fn(imdct, synth_buf, in, sizeof(float));
for (i = 0; i < 32; i++) {
float a = synth_buf2[i ];

View File

@ -21,19 +21,20 @@
#ifndef AVCODEC_SYNTH_FILTER_H
#define AVCODEC_SYNTH_FILTER_H
#include "fft.h"
#include "libavutil/tx.h"
#include "dcadct.h"
typedef struct SynthFilterContext {
void (*synth_filter_float)(FFTContext *imdct,
void (*synth_filter_float)(AVTXContext *imdct,
float *synth_buf_ptr, int *synth_buf_offset,
float synth_buf2[32], const float window[512],
float out[32], const float in[32],
float scale);
void (*synth_filter_float_64)(FFTContext *imdct,
float out[32], float in[32],
float scale, av_tx_fn imdct_fn);
void (*synth_filter_float_64)(AVTXContext *imdct,
float *synth_buf_ptr, int *synth_buf_offset,
float synth_buf2[64], const float window[1024],
float out[64], const float in[64], float scale);
float out[64], float in[64], float scale,
av_tx_fn imdct_fn);
void (*synth_filter_fixed)(DCADCTContext *imdct,
int32_t *synth_buf_ptr, int *synth_buf_offset,
int32_t synth_buf2[32], const int32_t window[512],

View File

@ -27,14 +27,15 @@
void ff_synth_filter_inner_##opt(float *synth_buf_ptr, float synth_buf2[32], \
const float window[512], \
float out[32], intptr_t offset, float scale); \
static void synth_filter_##opt(FFTContext *imdct, \
static void synth_filter_##opt(AVTXContext *imdct, \
float *synth_buf_ptr, int *synth_buf_offset, \
float synth_buf2[32], const float window[512], \
float out[32], const float in[32], float scale) \
float out[32], float in[32], float scale, \
av_tx_fn imdct_fn) \
{ \
float *synth_buf= synth_buf_ptr + *synth_buf_offset; \
\
imdct->imdct_half(imdct, synth_buf, in); \
imdct_fn(imdct, synth_buf, in, sizeof(float)); \
\
ff_synth_filter_inner_##opt(synth_buf, synth_buf2, window, \
out, *synth_buf_offset, scale); \

View File

@ -26,6 +26,7 @@
#include "libavutil/internal.h"
#include "libavutil/intfloat.h"
#include "libavutil/mem_internal.h"
#include "libavutil/tx.h"
#include "libavcodec/dcadata.h"
#include "libavcodec/synth_filter.h"
@ -45,10 +46,12 @@
void checkasm_check_synth_filter(void)
{
FFTContext imdct;
float scale = 1.0;
AVTXContext *imdct;
av_tx_fn imdct_fn;
SynthFilterContext synth;
ff_mdct_init(&imdct, 6, 1, 1.0);
av_tx_init(&imdct, &imdct_fn, AV_TX_FLOAT_MDCT, 0, 16, &scale, 0);
ff_synth_filter_init(&synth);
if (check_func(synth.synth_filter_float, "synth_filter_float")) {
@ -65,8 +68,8 @@ void checkasm_check_synth_filter(void)
float scale = 1.0f;
int i, offset0 = 0, offset1 = 0, offset_b = 0;
declare_func(void, FFTContext *, float *, int *, float[32], const float[512],
float[32], float[32], float);
declare_func(void, AVTXContext *, float *, int *,
float[32], const float[512], float[32], float[32], float, av_tx_fn);
memset(buf2_0, 0, sizeof(*buf2_0) * BUF_SIZE);
memset(buf2_1, 0, sizeof(*buf2_1) * BUF_SIZE);
@ -86,10 +89,10 @@ void checkasm_check_synth_filter(void)
randomize_input();
call_ref(&imdct, buf0, &offset0, buf2_0, window,
out0, in, scale);
call_new(&imdct, buf1, &offset1, buf2_1, window,
out1, in, scale);
call_ref(imdct, buf0, &offset0, buf2_0, window,
out0, in, scale, imdct_fn);
call_new(imdct, buf1, &offset1, buf2_1, window,
out1, in, scale, imdct_fn);
if (offset0 != offset1) {
fail();
@ -113,11 +116,11 @@ void checkasm_check_synth_filter(void)
}
}
bench_new(&imdct, buf_b, &offset_b, buf2_b, window,
out_b, in, scale);
bench_new(imdct, buf_b, &offset_b, buf2_b, window,
out_b, in, scale, imdct_fn);
}
}
ff_mdct_end(&imdct);
av_tx_uninit(&imdct);
report("synth_filter");
}