From 67690683130faf37dd9d969ced15eba2a1940ade Mon Sep 17 00:00:00 2001 From: Peter Meerwald Date: Sun, 15 Feb 2015 12:21:21 +0100 Subject: [PATCH] g722: Split out g722_qmf_apply() function into g722dsp.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Meerwald Signed-off-by: Martin Storsjö --- libavcodec/Makefile | 4 ++-- libavcodec/g722.c | 22 --------------------- libavcodec/g722.h | 5 +++-- libavcodec/g722dec.c | 6 ++++-- libavcodec/g722dsp.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ libavcodec/g722dsp.h | 32 ++++++++++++++++++++++++++++++ libavcodec/g722enc.c | 4 +++- 7 files changed, 91 insertions(+), 29 deletions(-) create mode 100644 libavcodec/g722dsp.c create mode 100644 libavcodec/g722dsp.h diff --git a/libavcodec/Makefile b/libavcodec/Makefile index a45d75c090..3f93174aa9 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -511,8 +511,8 @@ OBJS-$(CONFIG_ADPCM_EA_R1_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_EA_R2_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_EA_R3_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_EA_XAS_DECODER) += adpcm.o adpcm_data.o -OBJS-$(CONFIG_ADPCM_G722_DECODER) += g722.o g722dec.o -OBJS-$(CONFIG_ADPCM_G722_ENCODER) += g722.o g722enc.o +OBJS-$(CONFIG_ADPCM_G722_DECODER) += g722.o g722dsp.o g722dec.o +OBJS-$(CONFIG_ADPCM_G722_ENCODER) += g722.o g722dsp.o g722enc.o OBJS-$(CONFIG_ADPCM_G726_DECODER) += g726.o OBJS-$(CONFIG_ADPCM_G726_ENCODER) += g726.o OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER) += adpcm.o adpcm_data.o diff --git a/libavcodec/g722.c b/libavcodec/g722.c index a911bc7b37..74c0868028 100644 --- a/libavcodec/g722.c +++ b/libavcodec/g722.c @@ -71,16 +71,6 @@ const int16_t ff_g722_low_inv_quant6[64] = { 211, 170, 130, 91, 54, 17, -54, -17 }; -/** - * quadrature mirror filter (QMF) coefficients - * - * ITU-T G.722 Table 11 - */ -static const int16_t qmf_coeffs[12] = { - 3, -11, 12, 32, -210, 951, 3876, -805, 362, -156, 53, -11, -}; - - /** * adaptive predictor * @@ -157,15 +147,3 @@ void ff_g722_update_high_predictor(struct G722Band *band, const int dhigh, high_log_factor_step[ihigh&1], 0, 22528); band->scale_factor = linear_scale_factor(band->log_factor - (10 << 11)); } - -void ff_g722_apply_qmf(const int16_t *prev_samples, int *xout1, int *xout2) -{ - int i; - - *xout1 = 0; - *xout2 = 0; - for (i = 0; i < 12; i++) { - MAC16(*xout2, prev_samples[2*i ], qmf_coeffs[i ]); - MAC16(*xout1, prev_samples[2*i+1], qmf_coeffs[11-i]); - } -} diff --git a/libavcodec/g722.h b/libavcodec/g722.h index 71d03fc5fa..483017018b 100644 --- a/libavcodec/g722.h +++ b/libavcodec/g722.h @@ -27,6 +27,7 @@ #include #include "avcodec.h" +#include "g722dsp.h" #define PREV_SAMPLES_BUF_SIZE 1024 @@ -61,6 +62,8 @@ typedef struct G722Context { int value; int prev; } *paths[2]; + + G722DSPContext dsp; } G722Context; extern const int16_t ff_g722_high_inv_quant[4]; @@ -72,6 +75,4 @@ void ff_g722_update_low_predictor(struct G722Band *band, const int ilow); void ff_g722_update_high_predictor(struct G722Band *band, const int dhigh, const int ihigh); -void ff_g722_apply_qmf(const int16_t *prev_samples, int *xout1, int *xout2); - #endif /* AVCODEC_G722_H */ diff --git a/libavcodec/g722dec.c b/libavcodec/g722dec.c index 26f288b721..4e1815009b 100644 --- a/libavcodec/g722dec.c +++ b/libavcodec/g722dec.c @@ -67,6 +67,8 @@ static av_cold int g722_decode_init(AVCodecContext * avctx) c->band[1].scale_factor = 2; c->prev_samples_pos = 22; + ff_g722dsp_init(&c->dsp); + return 0; } @@ -122,8 +124,8 @@ static int g722_decode_frame(AVCodecContext *avctx, void *data, c->prev_samples[c->prev_samples_pos++] = rlow + rhigh; c->prev_samples[c->prev_samples_pos++] = rlow - rhigh; - ff_g722_apply_qmf(c->prev_samples + c->prev_samples_pos - 24, - &xout1, &xout2); + c->dsp.apply_qmf(c->prev_samples + c->prev_samples_pos - 24, + &xout1, &xout2); *out_buf++ = av_clip_int16(xout1 >> 11); *out_buf++ = av_clip_int16(xout2 >> 11); if (c->prev_samples_pos >= PREV_SAMPLES_BUF_SIZE) { diff --git a/libavcodec/g722dsp.c b/libavcodec/g722dsp.c new file mode 100644 index 0000000000..1fefc6b3c4 --- /dev/null +++ b/libavcodec/g722dsp.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2015 Peter Meerwald + * + * This file is part of Libav. + * + * Libav 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. + * + * Libav 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 Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "g722dsp.h" +#include "mathops.h" + +/* + * quadrature mirror filter (QMF) coefficients (ITU-T G.722 Table 11) inlined + * in code below: 3, -11, 12, 32, -210, 951, 3876, -805, 362, -156, 53, -11 + */ +static const int16_t qmf_coeffs[12] = { + 3, -11, 12, 32, -210, 951, 3876, -805, 362, -156, 53, -11, +}; + +static void g722_apply_qmf(const int16_t *prev_samples, int *xout1, int *xout2) +{ + int i; + + *xout1 = 0; + *xout2 = 0; + for (i = 0; i < 12; i++) { + MAC16(*xout2, prev_samples[2*i ], qmf_coeffs[i ]); + MAC16(*xout1, prev_samples[2*i+1], qmf_coeffs[11-i]); + } +} + +av_cold void ff_g722dsp_init(G722DSPContext *c) +{ + c->apply_qmf = g722_apply_qmf; +} diff --git a/libavcodec/g722dsp.h b/libavcodec/g722dsp.h new file mode 100644 index 0000000000..c0d33390ea --- /dev/null +++ b/libavcodec/g722dsp.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015 Peter Meerwald + * + * This file is part of Libav. + * + * Libav 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. + * + * Libav 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 Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_G722DSP_H +#define AVCODEC_G722DSP_H + +#include + +typedef struct G722DSPContext { + void (*apply_qmf)(const int16_t *prev_samples, int *xout1, int *xout2); +} G722DSPContext; + +void ff_g722dsp_init(G722DSPContext *c); + +#endif /* AVCODEC_G722DSP_H */ diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c index be437946c6..3a3d7b7c07 100644 --- a/libavcodec/g722enc.c +++ b/libavcodec/g722enc.c @@ -119,6 +119,8 @@ static av_cold int g722_encode_init(AVCodecContext * avctx) } } + ff_g722dsp_init(&c->dsp); + return 0; error: g722_encode_close(avctx); @@ -138,7 +140,7 @@ static inline void filter_samples(G722Context *c, const int16_t *samples, int xout1, xout2; c->prev_samples[c->prev_samples_pos++] = samples[0]; c->prev_samples[c->prev_samples_pos++] = samples[1]; - ff_g722_apply_qmf(c->prev_samples + c->prev_samples_pos - 24, &xout1, &xout2); + c->dsp.apply_qmf(c->prev_samples + c->prev_samples_pos - 24, &xout1, &xout2); *xlow = xout1 + xout2 >> 14; *xhigh = xout1 - xout2 >> 14; if (c->prev_samples_pos >= PREV_SAMPLES_BUF_SIZE) {