avcodec/iirfilter: Remove iirfilter, psy-preprocessing
The iirfilter is only used in its test tool since 01ecb7172b684f1c4b3e748f95c5a9a494ca36ec which stopped using it in AAC, its only user. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
28c0a189b6
commit
f0e1a315a1
3
configure
vendored
3
configure
vendored
@ -2606,7 +2606,6 @@ CONFIG_EXTRA="
|
||||
iamfdec
|
||||
iamfenc
|
||||
idctdsp
|
||||
iirfilter
|
||||
inflate_wrapper
|
||||
intrax8
|
||||
iso_media
|
||||
@ -2917,7 +2916,7 @@ wmv2dsp_select="qpeldsp"
|
||||
# decoders / encoders
|
||||
aac_decoder_select="adts_header mpeg4audio sinewin"
|
||||
aac_fixed_decoder_select="adts_header mpeg4audio"
|
||||
aac_encoder_select="audio_frame_queue iirfilter lpc sinewin"
|
||||
aac_encoder_select="audio_frame_queue lpc sinewin"
|
||||
aac_latm_decoder_select="aac_decoder aac_latm_parser"
|
||||
ac3_decoder_select="ac3_parser ac3dsp bswapdsp fmtconvert"
|
||||
ac3_fixed_decoder_select="ac3_parser ac3dsp bswapdsp"
|
||||
|
@ -60,6 +60,5 @@ Files that have MIPS copyright notice in them:
|
||||
compute_antialias_float.h
|
||||
lsp_mips.h
|
||||
fmtconvert_mips.c
|
||||
iirfilter_mips.c
|
||||
mpegaudiodsp_mips_fixed.c
|
||||
mpegaudiodsp_mips_float.c
|
||||
|
@ -120,7 +120,6 @@ OBJS-$(CONFIG_HUFFMAN) += huffman.o
|
||||
OBJS-$(CONFIG_HUFFYUVDSP) += huffyuvdsp.o
|
||||
OBJS-$(CONFIG_HUFFYUVENCDSP) += huffyuvencdsp.o
|
||||
OBJS-$(CONFIG_IDCTDSP) += idctdsp.o simple_idct.o jrevdct.o
|
||||
OBJS-$(CONFIG_IIRFILTER) += iirfilter.o
|
||||
OBJS-$(CONFIG_INFLATE_WRAPPER) += zlib_wrapper.o
|
||||
OBJS-$(CONFIG_INTRAX8) += intrax8.o intrax8dsp.o msmpeg4_vc1_data.o
|
||||
OBJS-$(CONFIG_IVIDSP) += ivi_dsp.o
|
||||
@ -1336,7 +1335,6 @@ TESTPROGS-$(CONFIG_CABAC) += cabac
|
||||
TESTPROGS-$(CONFIG_GOLOMB) += golomb
|
||||
TESTPROGS-$(CONFIG_IDCTDSP) += dct
|
||||
TESTPROGS-$(CONFIG_DXV_ENCODER) += hashtable
|
||||
TESTPROGS-$(CONFIG_IIRFILTER) += iirfilter
|
||||
TESTPROGS-$(CONFIG_MJPEG_ENCODER) += mjpegenc_huffman
|
||||
TESTPROGS-$(HAVE_MMX) += motion
|
||||
TESTPROGS-$(CONFIG_MPEGVIDEO) += mpeg12framerate
|
||||
|
@ -845,8 +845,6 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
|
||||
}
|
||||
|
||||
copy_input_samples(s, frame);
|
||||
if (s->psypp)
|
||||
ff_psy_preprocess(s->psypp, s->planar_samples, s->channels);
|
||||
|
||||
if (!avctx->frame_num)
|
||||
return 0;
|
||||
@ -1141,8 +1139,6 @@ static av_cold int aac_encode_end(AVCodecContext *avctx)
|
||||
av_tx_uninit(&s->mdct128);
|
||||
ff_psy_end(&s->psy);
|
||||
ff_lpc_end(&s->lpc);
|
||||
if (s->psypp)
|
||||
ff_psy_preprocess_end(s->psypp);
|
||||
av_freep(&s->buffer.samples);
|
||||
av_freep(&s->cpe);
|
||||
av_freep(&s->fdsp);
|
||||
@ -1294,7 +1290,6 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
|
||||
if ((ret = ff_psy_init(&s->psy, avctx, 2, sizes, lengths,
|
||||
s->chan_map[0], grouping)) < 0)
|
||||
return ret;
|
||||
s->psypp = ff_psy_preprocess_init(avctx);
|
||||
ff_lpc_init(&s->lpc, 2*avctx->frame_size, TNS_MAX_ORDER, FF_LPC_TYPE_LEVINSON);
|
||||
s->random_state = 0x1f2e3d4c;
|
||||
|
||||
|
@ -199,7 +199,6 @@ typedef struct AACEncContext {
|
||||
|
||||
ChannelElement *cpe; ///< channel elements
|
||||
FFPsyContext psy;
|
||||
struct FFPsyPreprocessContext* psypp;
|
||||
const AACCoefficientsEncoder *coder;
|
||||
int cur_channel; ///< current channel for coder context
|
||||
int random_state;
|
||||
|
@ -1,326 +0,0 @@
|
||||
/*
|
||||
* IIR filter
|
||||
* Copyright (c) 2008 Konstantin Shishkov
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* different IIR filters implementation
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "libavutil/attributes.h"
|
||||
#include "libavutil/common.h"
|
||||
#include "libavutil/log.h"
|
||||
#include "libavutil/mem.h"
|
||||
|
||||
#include "iirfilter.h"
|
||||
|
||||
/**
|
||||
* IIR filter global parameters
|
||||
*/
|
||||
typedef struct FFIIRFilterCoeffs {
|
||||
int order;
|
||||
float gain;
|
||||
int *cx;
|
||||
float *cy;
|
||||
} FFIIRFilterCoeffs;
|
||||
|
||||
/**
|
||||
* IIR filter state
|
||||
*/
|
||||
typedef struct FFIIRFilterState {
|
||||
float x[1];
|
||||
} FFIIRFilterState;
|
||||
|
||||
/// maximum supported filter order
|
||||
#define MAXORDER 30
|
||||
|
||||
static av_cold int butterworth_init_coeffs(void *avc,
|
||||
struct FFIIRFilterCoeffs *c,
|
||||
enum IIRFilterMode filt_mode,
|
||||
int order, float cutoff_ratio,
|
||||
float stopband)
|
||||
{
|
||||
int i, j;
|
||||
double wa;
|
||||
double p[MAXORDER + 1][2];
|
||||
|
||||
if (filt_mode != FF_FILTER_MODE_LOWPASS) {
|
||||
av_log(avc, AV_LOG_ERROR, "Butterworth filter currently only supports "
|
||||
"low-pass filter mode\n");
|
||||
return -1;
|
||||
}
|
||||
if (order & 1) {
|
||||
av_log(avc, AV_LOG_ERROR, "Butterworth filter currently only supports "
|
||||
"even filter orders\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
wa = 2 * tan(M_PI * 0.5 * cutoff_ratio);
|
||||
|
||||
c->cx[0] = 1;
|
||||
for (i = 1; i < (order >> 1) + 1; i++)
|
||||
c->cx[i] = c->cx[i - 1] * (order - i + 1LL) / i;
|
||||
|
||||
p[0][0] = 1.0;
|
||||
p[0][1] = 0.0;
|
||||
for (i = 1; i <= order; i++)
|
||||
p[i][0] = p[i][1] = 0.0;
|
||||
for (i = 0; i < order; i++) {
|
||||
double zp[2];
|
||||
double th = (i + (order >> 1) + 0.5) * M_PI / order;
|
||||
double a_re, a_im, c_re, c_im;
|
||||
zp[0] = cos(th) * wa;
|
||||
zp[1] = sin(th) * wa;
|
||||
a_re = zp[0] + 2.0;
|
||||
c_re = zp[0] - 2.0;
|
||||
a_im =
|
||||
c_im = zp[1];
|
||||
zp[0] = (a_re * c_re + a_im * c_im) / (c_re * c_re + c_im * c_im);
|
||||
zp[1] = (a_im * c_re - a_re * c_im) / (c_re * c_re + c_im * c_im);
|
||||
|
||||
for (j = order; j >= 1; j--) {
|
||||
a_re = p[j][0];
|
||||
a_im = p[j][1];
|
||||
p[j][0] = a_re * zp[0] - a_im * zp[1] + p[j - 1][0];
|
||||
p[j][1] = a_re * zp[1] + a_im * zp[0] + p[j - 1][1];
|
||||
}
|
||||
a_re = p[0][0] * zp[0] - p[0][1] * zp[1];
|
||||
p[0][1] = p[0][0] * zp[1] + p[0][1] * zp[0];
|
||||
p[0][0] = a_re;
|
||||
}
|
||||
c->gain = p[order][0];
|
||||
for (i = 0; i < order; i++) {
|
||||
c->gain += p[i][0];
|
||||
c->cy[i] = (-p[i][0] * p[order][0] + -p[i][1] * p[order][1]) /
|
||||
(p[order][0] * p[order][0] + p[order][1] * p[order][1]);
|
||||
}
|
||||
c->gain /= 1 << order;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static av_cold int biquad_init_coeffs(void *avc, struct FFIIRFilterCoeffs *c,
|
||||
enum IIRFilterMode filt_mode, int order,
|
||||
float cutoff_ratio, float stopband)
|
||||
{
|
||||
double cos_w0, sin_w0;
|
||||
double a0, x0, x1;
|
||||
|
||||
if (filt_mode != FF_FILTER_MODE_HIGHPASS &&
|
||||
filt_mode != FF_FILTER_MODE_LOWPASS) {
|
||||
av_log(avc, AV_LOG_ERROR, "Biquad filter currently only supports "
|
||||
"high-pass and low-pass filter modes\n");
|
||||
return -1;
|
||||
}
|
||||
if (order != 2) {
|
||||
av_log(avc, AV_LOG_ERROR, "Biquad filter must have order of 2\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
cos_w0 = cos(M_PI * cutoff_ratio);
|
||||
sin_w0 = sin(M_PI * cutoff_ratio);
|
||||
|
||||
a0 = 1.0 + (sin_w0 / 2.0);
|
||||
|
||||
if (filt_mode == FF_FILTER_MODE_HIGHPASS) {
|
||||
c->gain = ((1.0 + cos_w0) / 2.0) / a0;
|
||||
x0 = ((1.0 + cos_w0) / 2.0) / a0;
|
||||
x1 = (-(1.0 + cos_w0)) / a0;
|
||||
} else { // FF_FILTER_MODE_LOWPASS
|
||||
c->gain = ((1.0 - cos_w0) / 2.0) / a0;
|
||||
x0 = ((1.0 - cos_w0) / 2.0) / a0;
|
||||
x1 = (1.0 - cos_w0) / a0;
|
||||
}
|
||||
c->cy[0] = (-1.0 + (sin_w0 / 2.0)) / a0;
|
||||
c->cy[1] = (2.0 * cos_w0) / a0;
|
||||
|
||||
// divide by gain to make the x coeffs integers.
|
||||
// during filtering, the delay state will include the gain multiplication
|
||||
c->cx[0] = lrintf(x0 / c->gain);
|
||||
c->cx[1] = lrintf(x1 / c->gain);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
av_cold struct FFIIRFilterCoeffs *ff_iir_filter_init_coeffs(void *avc,
|
||||
enum IIRFilterType filt_type,
|
||||
enum IIRFilterMode filt_mode,
|
||||
int order, float cutoff_ratio,
|
||||
float stopband, float ripple)
|
||||
{
|
||||
FFIIRFilterCoeffs *c;
|
||||
int ret = 0;
|
||||
|
||||
if (order <= 0 || order > MAXORDER || cutoff_ratio >= 1.0)
|
||||
return NULL;
|
||||
|
||||
if (!(c = av_mallocz(sizeof(*c))) ||
|
||||
!(c->cx = av_malloc (sizeof(c->cx[0]) * ((order >> 1) + 1))) ||
|
||||
!(c->cy = av_malloc (sizeof(c->cy[0]) * order)))
|
||||
goto free;
|
||||
c->order = order;
|
||||
|
||||
switch (filt_type) {
|
||||
case FF_FILTER_TYPE_BUTTERWORTH:
|
||||
ret = butterworth_init_coeffs(avc, c, filt_mode, order, cutoff_ratio,
|
||||
stopband);
|
||||
break;
|
||||
case FF_FILTER_TYPE_BIQUAD:
|
||||
ret = biquad_init_coeffs(avc, c, filt_mode, order, cutoff_ratio,
|
||||
stopband);
|
||||
break;
|
||||
default:
|
||||
av_log(avc, AV_LOG_ERROR, "filter type is not currently implemented\n");
|
||||
goto free;
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
return c;
|
||||
free:
|
||||
ff_iir_filter_free_coeffsp(&c);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
av_cold struct FFIIRFilterState *ff_iir_filter_init_state(int order)
|
||||
{
|
||||
FFIIRFilterState *s = av_mallocz(sizeof(FFIIRFilterState) + sizeof(s->x[0]) * (order - 1));
|
||||
return s;
|
||||
}
|
||||
|
||||
#define CONV_S16(dest, source) dest = av_clip_int16(lrintf(source));
|
||||
|
||||
#define CONV_FLT(dest, source) dest = source;
|
||||
|
||||
#define FILTER_BW_O4_1(i0, i1, i2, i3, fmt) \
|
||||
in = *src0 * c->gain + \
|
||||
c->cy[0] * s->x[i0] + \
|
||||
c->cy[1] * s->x[i1] + \
|
||||
c->cy[2] * s->x[i2] + \
|
||||
c->cy[3] * s->x[i3]; \
|
||||
res = (s->x[i0] + in) * 1 + \
|
||||
(s->x[i1] + s->x[i3]) * 4 + \
|
||||
s->x[i2] * 6; \
|
||||
CONV_ ## fmt(*dst0, res) \
|
||||
s->x[i0] = in; \
|
||||
src0 += sstep; \
|
||||
dst0 += dstep;
|
||||
|
||||
#define FILTER_BW_O4(type, fmt) { \
|
||||
int i; \
|
||||
const type *src0 = src; \
|
||||
type *dst0 = dst; \
|
||||
for (i = 0; i < size; i += 4) { \
|
||||
float in, res; \
|
||||
FILTER_BW_O4_1(0, 1, 2, 3, fmt); \
|
||||
FILTER_BW_O4_1(1, 2, 3, 0, fmt); \
|
||||
FILTER_BW_O4_1(2, 3, 0, 1, fmt); \
|
||||
FILTER_BW_O4_1(3, 0, 1, 2, fmt); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define FILTER_DIRECT_FORM_II(type, fmt) { \
|
||||
int i; \
|
||||
const type *src0 = src; \
|
||||
type *dst0 = dst; \
|
||||
for (i = 0; i < size; i++) { \
|
||||
int j; \
|
||||
float in, res; \
|
||||
in = *src0 * c->gain; \
|
||||
for (j = 0; j < c->order; j++) \
|
||||
in += c->cy[j] * s->x[j]; \
|
||||
res = s->x[0] + in + s->x[c->order >> 1] * c->cx[c->order >> 1]; \
|
||||
for (j = 1; j < c->order >> 1; j++) \
|
||||
res += (s->x[j] + s->x[c->order - j]) * c->cx[j]; \
|
||||
for (j = 0; j < c->order - 1; j++) \
|
||||
s->x[j] = s->x[j + 1]; \
|
||||
CONV_ ## fmt(*dst0, res) \
|
||||
s->x[c->order - 1] = in; \
|
||||
src0 += sstep; \
|
||||
dst0 += dstep; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define FILTER_O2(type, fmt) { \
|
||||
int i; \
|
||||
const type *src0 = src; \
|
||||
type *dst0 = dst; \
|
||||
for (i = 0; i < size; i++) { \
|
||||
float in = *src0 * c->gain + \
|
||||
s->x[0] * c->cy[0] + \
|
||||
s->x[1] * c->cy[1]; \
|
||||
CONV_ ## fmt(*dst0, s->x[0] + in + s->x[1] * c->cx[1]) \
|
||||
s->x[0] = s->x[1]; \
|
||||
s->x[1] = in; \
|
||||
src0 += sstep; \
|
||||
dst0 += dstep; \
|
||||
} \
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform IIR filtering on floating-point input samples.
|
||||
*
|
||||
* @param coeffs pointer to filter coefficients
|
||||
* @param state pointer to filter state
|
||||
* @param size input length
|
||||
* @param src source samples
|
||||
* @param sstep source stride
|
||||
* @param dst filtered samples (destination may be the same as input)
|
||||
* @param dstep destination stride
|
||||
*/
|
||||
static void iir_filter_flt(const struct FFIIRFilterCoeffs *c,
|
||||
struct FFIIRFilterState *s, int size,
|
||||
const float *src, ptrdiff_t sstep,
|
||||
float *dst, ptrdiff_t dstep)
|
||||
{
|
||||
if (c->order == 2) {
|
||||
FILTER_O2(float, FLT)
|
||||
} else if (c->order == 4) {
|
||||
FILTER_BW_O4(float, FLT)
|
||||
} else {
|
||||
FILTER_DIRECT_FORM_II(float, FLT)
|
||||
}
|
||||
}
|
||||
|
||||
av_cold void ff_iir_filter_free_statep(struct FFIIRFilterState **state)
|
||||
{
|
||||
av_freep(state);
|
||||
}
|
||||
|
||||
av_cold void ff_iir_filter_free_coeffsp(struct FFIIRFilterCoeffs **coeffsp)
|
||||
{
|
||||
struct FFIIRFilterCoeffs *coeffs = *coeffsp;
|
||||
if (coeffs) {
|
||||
av_freep(&coeffs->cx);
|
||||
av_freep(&coeffs->cy);
|
||||
}
|
||||
av_freep(coeffsp);
|
||||
}
|
||||
|
||||
void ff_iir_filter_init(FFIIRFilterContext *f) {
|
||||
f->filter_flt = iir_filter_flt;
|
||||
|
||||
#if HAVE_MIPSFPU
|
||||
ff_iir_filter_init_mips(f);
|
||||
#endif
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
/*
|
||||
* IIR filter
|
||||
* Copyright (c) 2008 Konstantin Shishkov
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* IIR filter interface
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_IIRFILTER_H
|
||||
#define AVCODEC_IIRFILTER_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
struct FFIIRFilterCoeffs;
|
||||
struct FFIIRFilterState;
|
||||
|
||||
enum IIRFilterType{
|
||||
FF_FILTER_TYPE_BESSEL,
|
||||
FF_FILTER_TYPE_BIQUAD,
|
||||
FF_FILTER_TYPE_BUTTERWORTH,
|
||||
FF_FILTER_TYPE_CHEBYSHEV,
|
||||
FF_FILTER_TYPE_ELLIPTIC,
|
||||
};
|
||||
|
||||
enum IIRFilterMode{
|
||||
FF_FILTER_MODE_LOWPASS,
|
||||
FF_FILTER_MODE_HIGHPASS,
|
||||
FF_FILTER_MODE_BANDPASS,
|
||||
FF_FILTER_MODE_BANDSTOP,
|
||||
};
|
||||
|
||||
typedef struct FFIIRFilterContext {
|
||||
/**
|
||||
* Perform IIR filtering on floating-point input samples.
|
||||
*
|
||||
* @param coeffs pointer to filter coefficients
|
||||
* @param state pointer to filter state
|
||||
* @param size input length
|
||||
* @param src source samples
|
||||
* @param sstep source stride
|
||||
* @param dst filtered samples (destination may be the same as input)
|
||||
* @param dstep destination stride
|
||||
*/
|
||||
void (*filter_flt)(const struct FFIIRFilterCoeffs *coeffs,
|
||||
struct FFIIRFilterState *state, int size,
|
||||
const float *src, ptrdiff_t sstep, float *dst, ptrdiff_t dstep);
|
||||
} FFIIRFilterContext;
|
||||
|
||||
/**
|
||||
* Initialize FFIIRFilterContext
|
||||
*/
|
||||
void ff_iir_filter_init(FFIIRFilterContext *f);
|
||||
void ff_iir_filter_init_mips(FFIIRFilterContext *f);
|
||||
|
||||
/**
|
||||
* Initialize filter coefficients.
|
||||
*
|
||||
* @param avc a pointer to an arbitrary struct of which the first
|
||||
* field is a pointer to an AVClass struct
|
||||
* @param filt_type filter type (e.g. Butterworth)
|
||||
* @param filt_mode filter mode (e.g. lowpass)
|
||||
* @param order filter order
|
||||
* @param cutoff_ratio cutoff to input frequency ratio
|
||||
* @param stopband stopband to input frequency ratio (used by bandpass and bandstop filter modes)
|
||||
* @param ripple ripple factor (used only in Chebyshev filters)
|
||||
*
|
||||
* @return pointer to filter coefficients structure or NULL if filter cannot be created
|
||||
*/
|
||||
struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc,
|
||||
enum IIRFilterType filt_type,
|
||||
enum IIRFilterMode filt_mode,
|
||||
int order, float cutoff_ratio,
|
||||
float stopband, float ripple);
|
||||
|
||||
/**
|
||||
* Create new filter state.
|
||||
*
|
||||
* @param order filter order
|
||||
*
|
||||
* @return pointer to new filter state or NULL if state creation fails
|
||||
*/
|
||||
struct FFIIRFilterState* ff_iir_filter_init_state(int order);
|
||||
|
||||
/**
|
||||
* Free filter coefficients.
|
||||
*
|
||||
* @param coeffs pointer allocated with ff_iir_filter_init_coeffs()
|
||||
*/
|
||||
void ff_iir_filter_free_coeffsp(struct FFIIRFilterCoeffs **coeffs);
|
||||
|
||||
/**
|
||||
* Free and zero filter state.
|
||||
*
|
||||
* @param state pointer to pointer allocated with ff_iir_filter_init_state()
|
||||
*/
|
||||
void ff_iir_filter_free_statep(struct FFIIRFilterState **state);
|
||||
|
||||
#endif /* AVCODEC_IIRFILTER_H */
|
@ -14,7 +14,6 @@ MIPSFPU-OBJS-$(CONFIG_MPEGAUDIODSP) += mips/mpegaudiodsp_mips_float.o
|
||||
MIPSDSP-OBJS-$(CONFIG_MPEGAUDIODSP) += mips/mpegaudiodsp_mips_fixed.o
|
||||
MIPSFPU-OBJS-$(CONFIG_FMTCONVERT) += mips/fmtconvert_mips.o
|
||||
OBJS-$(CONFIG_AC3DSP) += mips/ac3dsp_mips.o
|
||||
MIPSFPU-OBJS-$(CONFIG_AAC_ENCODER) += mips/iirfilter_mips.o
|
||||
OBJS-$(CONFIG_HEVC_DECODER) += mips/hevcdsp_init_mips.o \
|
||||
mips/hevcpred_init_mips.o
|
||||
OBJS-$(CONFIG_VP9_DECODER) += mips/vp9dsp_init_mips.o
|
||||
|
@ -1,209 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012
|
||||
* MIPS Technologies, Inc., California.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Author: Bojan Zivkovic (bojan@mips.com)
|
||||
*
|
||||
* IIR filter optimized for MIPS floating-point architecture
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Reference: libavcodec/iirfilter.c
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "libavcodec/iirfilter.h"
|
||||
|
||||
#if HAVE_INLINE_ASM
|
||||
#if !HAVE_MIPS32R6 && !HAVE_MIPS64R6
|
||||
typedef struct FFIIRFilterCoeffs {
|
||||
int order;
|
||||
float gain;
|
||||
int *cx;
|
||||
float *cy;
|
||||
} FFIIRFilterCoeffs;
|
||||
|
||||
typedef struct FFIIRFilterState {
|
||||
float x[1];
|
||||
} FFIIRFilterState;
|
||||
|
||||
static void iir_filter_flt_mips(const struct FFIIRFilterCoeffs *c,
|
||||
struct FFIIRFilterState *s, int size,
|
||||
const float *src, ptrdiff_t sstep, float *dst, ptrdiff_t dstep)
|
||||
{
|
||||
if (c->order == 2) {
|
||||
int i;
|
||||
const float *src0 = src;
|
||||
float *dst0 = dst;
|
||||
for (i = 0; i < size; i++) {
|
||||
float in = *src0 * c->gain + s->x[0] * c->cy[0] + s->x[1] * c->cy[1];
|
||||
*dst0 = s->x[0] + in + s->x[1] * c->cx[1];
|
||||
s->x[0] = s->x[1];
|
||||
s->x[1] = in;
|
||||
src0 += sstep;
|
||||
dst0 += dstep;
|
||||
}
|
||||
} else if (c->order == 4) {
|
||||
int i;
|
||||
const float *src0 = src;
|
||||
float *dst0 = dst;
|
||||
float four = 4.0;
|
||||
float six = 6.0;
|
||||
for (i = 0; i < size; i += 4) {
|
||||
float in1, in2, in3, in4;
|
||||
float res1, res2, res3, res4;
|
||||
float *x = s->x;
|
||||
float *cy = c->cy;
|
||||
float gain = c->gain;
|
||||
float src0_0 = src0[0 ];
|
||||
float src0_1 = src0[sstep ];
|
||||
float src0_2 = src0[2*sstep];
|
||||
float src0_3 = src0[3*sstep];
|
||||
|
||||
__asm__ volatile (
|
||||
"lwc1 $f0, 0(%[cy]) \n\t"
|
||||
"lwc1 $f4, 0(%[x]) \n\t"
|
||||
"lwc1 $f5, 4(%[x]) \n\t"
|
||||
"lwc1 $f6, 8(%[x]) \n\t"
|
||||
"lwc1 $f7, 12(%[x]) \n\t"
|
||||
"mul.s %[in1], %[src0_0], %[gain] \n\t"
|
||||
"mul.s %[in2], %[src0_1], %[gain] \n\t"
|
||||
"mul.s %[in3], %[src0_2], %[gain] \n\t"
|
||||
"mul.s %[in4], %[src0_3], %[gain] \n\t"
|
||||
"lwc1 $f1, 4(%[cy]) \n\t"
|
||||
"madd.s %[in1], %[in1], $f0, $f4 \n\t"
|
||||
"madd.s %[in2], %[in2], $f0, $f5 \n\t"
|
||||
"madd.s %[in3], %[in3], $f0, $f6 \n\t"
|
||||
"madd.s %[in4], %[in4], $f0, $f7 \n\t"
|
||||
"lwc1 $f2, 8(%[cy]) \n\t"
|
||||
"madd.s %[in1], %[in1], $f1, $f5 \n\t"
|
||||
"madd.s %[in2], %[in2], $f1, $f6 \n\t"
|
||||
"madd.s %[in3], %[in3], $f1, $f7 \n\t"
|
||||
"lwc1 $f3, 12(%[cy]) \n\t"
|
||||
"add.s $f8, $f5, $f7 \n\t"
|
||||
"madd.s %[in1], %[in1], $f2, $f6 \n\t"
|
||||
"madd.s %[in2], %[in2], $f2, $f7 \n\t"
|
||||
"mul.s $f9, $f6, %[six] \n\t"
|
||||
"mul.s $f10, $f7, %[six] \n\t"
|
||||
"madd.s %[in1], %[in1], $f3, $f7 \n\t"
|
||||
"madd.s %[in2], %[in2], $f3, %[in1] \n\t"
|
||||
"madd.s %[in3], %[in3], $f2, %[in1] \n\t"
|
||||
"madd.s %[in4], %[in4], $f1, %[in1] \n\t"
|
||||
"add.s %[res1], $f4, %[in1] \n\t"
|
||||
"swc1 %[in1], 0(%[x]) \n\t"
|
||||
"add.s $f0, $f6, %[in1] \n\t"
|
||||
"madd.s %[in3], %[in3], $f3, %[in2] \n\t"
|
||||
"madd.s %[in4], %[in4], $f2, %[in2] \n\t"
|
||||
"add.s %[res2], $f5, %[in2] \n\t"
|
||||
"madd.s %[res1], %[res1], $f8, %[four] \n\t"
|
||||
"add.s $f8, $f7, %[in2] \n\t"
|
||||
"swc1 %[in2], 4(%[x]) \n\t"
|
||||
"madd.s %[in4], %[in4], $f3, %[in3] \n\t"
|
||||
"add.s %[res3], $f6, %[in3] \n\t"
|
||||
"add.s %[res1], %[res1], $f9 \n\t"
|
||||
"madd.s %[res2], %[res2], $f0, %[four] \n\t"
|
||||
"swc1 %[in3], 8(%[x]) \n\t"
|
||||
"add.s %[res4], $f7, %[in4] \n\t"
|
||||
"madd.s %[res3], %[res3], $f8, %[four] \n\t"
|
||||
"swc1 %[in4], 12(%[x]) \n\t"
|
||||
"add.s %[res2], %[res2], $f10 \n\t"
|
||||
"add.s $f8, %[in1], %[in3] \n\t"
|
||||
"madd.s %[res3], %[res3], %[in1], %[six] \n\t"
|
||||
"madd.s %[res4], %[res4], $f8, %[four] \n\t"
|
||||
"madd.s %[res4], %[res4], %[in2], %[six] \n\t"
|
||||
|
||||
: [in1]"=&f"(in1), [in2]"=&f"(in2),
|
||||
[in3]"=&f"(in3), [in4]"=&f"(in4),
|
||||
[res1]"=&f"(res1), [res2]"=&f"(res2),
|
||||
[res3]"=&f"(res3), [res4]"=&f"(res4)
|
||||
: [src0_0]"f"(src0_0), [src0_1]"f"(src0_1),
|
||||
[src0_2]"f"(src0_2), [src0_3]"f"(src0_3),
|
||||
[gain]"f"(gain), [x]"r"(x), [cy]"r"(cy),
|
||||
[four]"f"(four), [six]"f"(six)
|
||||
: "$f0", "$f1", "$f2", "$f3",
|
||||
"$f4", "$f5", "$f6", "$f7",
|
||||
"$f8", "$f9", "$f10",
|
||||
"memory"
|
||||
);
|
||||
|
||||
dst0[0 ] = res1;
|
||||
dst0[sstep ] = res2;
|
||||
dst0[2*sstep] = res3;
|
||||
dst0[3*sstep] = res4;
|
||||
|
||||
src0 += 4*sstep;
|
||||
dst0 += 4*dstep;
|
||||
}
|
||||
} else {
|
||||
int i;
|
||||
const float *src0 = src;
|
||||
float *dst0 = dst;
|
||||
for (i = 0; i < size; i++) {
|
||||
int j;
|
||||
float in, res;
|
||||
in = *src0 * c->gain;
|
||||
for(j = 0; j < c->order; j++)
|
||||
in += c->cy[j] * s->x[j];
|
||||
res = s->x[0] + in + s->x[c->order >> 1] * c->cx[c->order >> 1];
|
||||
for(j = 1; j < c->order >> 1; j++)
|
||||
res += (s->x[j] + s->x[c->order - j]) * c->cx[j];
|
||||
for(j = 0; j < c->order - 1; j++)
|
||||
s->x[j] = s->x[j + 1];
|
||||
*dst0 = res;
|
||||
s->x[c->order - 1] = in;
|
||||
src0 += sstep;
|
||||
dst0 += dstep;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* !HAVE_MIPS32R6 && !HAVE_MIPS64R6 */
|
||||
#endif /* HAVE_INLINE_ASM */
|
||||
|
||||
void ff_iir_filter_init_mips(FFIIRFilterContext *f) {
|
||||
#if HAVE_INLINE_ASM
|
||||
#if !HAVE_MIPS32R6 && !HAVE_MIPS64R6
|
||||
f->filter_flt = iir_filter_flt_mips;
|
||||
#endif /* !HAVE_MIPS32R6 && !HAVE_MIPS64R6 */
|
||||
#endif /* HAVE_INLINE_ASM */
|
||||
}
|
@ -19,11 +19,8 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "avcodec.h"
|
||||
#include "psymodel.h"
|
||||
#include "iirfilter.h"
|
||||
#include "libavutil/mem.h"
|
||||
|
||||
extern const FFPsyModel ff_aac_psy_model;
|
||||
@ -86,73 +83,3 @@ av_cold void ff_psy_end(FFPsyContext *ctx)
|
||||
av_freep(&ctx->group);
|
||||
av_freep(&ctx->ch);
|
||||
}
|
||||
|
||||
typedef struct FFPsyPreprocessContext{
|
||||
AVCodecContext *avctx;
|
||||
float stereo_att;
|
||||
struct FFIIRFilterCoeffs *fcoeffs;
|
||||
struct FFIIRFilterState **fstate;
|
||||
struct FFIIRFilterContext fiir;
|
||||
}FFPsyPreprocessContext;
|
||||
|
||||
#define FILT_ORDER 4
|
||||
|
||||
av_cold struct FFPsyPreprocessContext* ff_psy_preprocess_init(AVCodecContext *avctx)
|
||||
{
|
||||
FFPsyPreprocessContext *ctx;
|
||||
int i;
|
||||
float cutoff_coeff = 0;
|
||||
ctx = av_mallocz(sizeof(FFPsyPreprocessContext));
|
||||
if (!ctx)
|
||||
return NULL;
|
||||
ctx->avctx = avctx;
|
||||
|
||||
/* AAC has its own LP method */
|
||||
if (avctx->codec_id != AV_CODEC_ID_AAC) {
|
||||
if (avctx->cutoff > 0)
|
||||
cutoff_coeff = 2.0 * avctx->cutoff / avctx->sample_rate;
|
||||
|
||||
if (cutoff_coeff && cutoff_coeff < 0.98)
|
||||
ctx->fcoeffs = ff_iir_filter_init_coeffs(avctx, FF_FILTER_TYPE_BUTTERWORTH,
|
||||
FF_FILTER_MODE_LOWPASS, FILT_ORDER,
|
||||
cutoff_coeff, 0.0, 0.0);
|
||||
if (ctx->fcoeffs) {
|
||||
ctx->fstate = av_calloc(avctx->ch_layout.nb_channels, sizeof(ctx->fstate[0]));
|
||||
if (!ctx->fstate) {
|
||||
av_free(ctx->fcoeffs);
|
||||
av_free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < avctx->ch_layout.nb_channels; i++)
|
||||
ctx->fstate[i] = ff_iir_filter_init_state(FILT_ORDER);
|
||||
}
|
||||
}
|
||||
|
||||
ff_iir_filter_init(&ctx->fiir);
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, float **audio, int channels)
|
||||
{
|
||||
int ch;
|
||||
int frame_size = ctx->avctx->frame_size;
|
||||
FFIIRFilterContext *iir = &ctx->fiir;
|
||||
|
||||
if (ctx->fstate) {
|
||||
for (ch = 0; ch < channels; ch++)
|
||||
iir->filter_flt(ctx->fcoeffs, ctx->fstate[ch], frame_size,
|
||||
&audio[ch][frame_size], 1, &audio[ch][frame_size], 1);
|
||||
}
|
||||
}
|
||||
|
||||
av_cold void ff_psy_preprocess_end(struct FFPsyPreprocessContext *ctx)
|
||||
{
|
||||
int i;
|
||||
ff_iir_filter_free_coeffsp(&ctx->fcoeffs);
|
||||
if (ctx->fstate)
|
||||
for (i = 0; i < ctx->avctx->ch_layout.nb_channels; i++)
|
||||
ff_iir_filter_free_statep(&ctx->fstate[i]);
|
||||
av_freep(&ctx->fstate);
|
||||
av_free(ctx);
|
||||
}
|
||||
|
1
libavcodec/tests/.gitignore
vendored
1
libavcodec/tests/.gitignore
vendored
@ -12,7 +12,6 @@
|
||||
/h264_levels
|
||||
/h265_levels
|
||||
/htmlsubtitles
|
||||
/iirfilter
|
||||
/jpeg2000dwt
|
||||
/mathops
|
||||
/mjpegenc_huffman
|
||||
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
* 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 <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libavutil/libm.h"
|
||||
|
||||
#include "libavcodec/iirfilter.h"
|
||||
#include "libavcodec/iirfilter.c"
|
||||
|
||||
#define FILT_ORDER 4
|
||||
#define SIZE 1024
|
||||
|
||||
static void iir_filter_int16(const struct FFIIRFilterCoeffs *c,
|
||||
struct FFIIRFilterState *s, int size,
|
||||
const int16_t *src, ptrdiff_t sstep,
|
||||
int16_t *dst, ptrdiff_t dstep)
|
||||
{
|
||||
if (c->order == 2) {
|
||||
FILTER_O2(int16_t, S16)
|
||||
} else if (c->order == 4) {
|
||||
FILTER_BW_O4(int16_t, S16)
|
||||
} else {
|
||||
FILTER_DIRECT_FORM_II(int16_t, S16)
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct FFIIRFilterCoeffs *fcoeffs = NULL;
|
||||
struct FFIIRFilterState *fstate = NULL;
|
||||
float cutoff_coeff = 0.4;
|
||||
int16_t x[SIZE], y[SIZE];
|
||||
int i;
|
||||
|
||||
fcoeffs = ff_iir_filter_init_coeffs(NULL, FF_FILTER_TYPE_BUTTERWORTH,
|
||||
FF_FILTER_MODE_LOWPASS, FILT_ORDER,
|
||||
cutoff_coeff, 0.0, 0.0);
|
||||
fstate = ff_iir_filter_init_state(FILT_ORDER);
|
||||
|
||||
for (i = 0; i < SIZE; i++)
|
||||
x[i] = lrint(0.75 * INT16_MAX * sin(0.5 * M_PI * i * i / SIZE));
|
||||
|
||||
iir_filter_int16(fcoeffs, fstate, SIZE, x, 1, y, 1);
|
||||
|
||||
for (i = 0; i < SIZE; i++)
|
||||
printf("%6d %6d\n", x[i], y[i]);
|
||||
|
||||
ff_iir_filter_free_coeffsp(&fcoeffs);
|
||||
ff_iir_filter_free_statep(&fstate);
|
||||
return 0;
|
||||
}
|
@ -81,10 +81,6 @@ fate-h265-levels: libavcodec/tests/h265_levels$(EXESUF)
|
||||
fate-h265-levels: CMD = run libavcodec/tests/h265_levels$(EXESUF)
|
||||
fate-h265-levels: REF = /dev/null
|
||||
|
||||
FATE_LIBAVCODEC-$(CONFIG_IIRFILTER) += fate-iirfilter
|
||||
fate-iirfilter: libavcodec/tests/iirfilter$(EXESUF)
|
||||
fate-iirfilter: CMD = run libavcodec/tests/iirfilter$(EXESUF)
|
||||
|
||||
FATE_LIBAVCODEC-$(CONFIG_MPEGVIDEO) += fate-mpeg12framerate
|
||||
fate-mpeg12framerate: libavcodec/tests/mpeg12framerate$(EXESUF)
|
||||
fate-mpeg12framerate: CMD = run libavcodec/tests/mpeg12framerate$(EXESUF)
|
||||
|
Loading…
x
Reference in New Issue
Block a user