diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-10-31 16:30:03 +0400 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-10-31 16:43:33 +0400 |
commit | 3174616f598665cfbe0c920d6e6c4d027fda9ca5 (patch) | |
tree | e463c628d079a260c5e9e7d5597cf26ef5e2c17a /libavcodec/cngdec.c | |
parent | 976175fbe559527389bff397b3174a27b20ab715 (diff) | |
parent | 6860b4081d046558c44b1b42f22022ea341a2a73 (diff) |
Merge commit '6860b4081d046558c44b1b42f22022ea341a2a73'
* commit '6860b4081d046558c44b1b42f22022ea341a2a73':
x86: include x86inc.asm in x86util.asm
cng: Reindent some incorrectly indented lines
cngdec: Allow flushing the decoder
cngdec: Make the dbov variable have the right unit
cngdec: Fix the memset size to cover the full array
cngdec: Update the LPC coefficients after averaging the reflection coefficients
configure: fix print_config() with broke awks
Conflicts:
libavcodec/x86/ac3dsp.asm
libavcodec/x86/dct32.asm
libavcodec/x86/deinterlace.asm
libavcodec/x86/dsputil.asm
libavcodec/x86/dsputilenc.asm
libavcodec/x86/fft.asm
libavcodec/x86/fmtconvert.asm
libavcodec/x86/h264_chromamc.asm
libavcodec/x86/h264_deblock.asm
libavcodec/x86/h264_deblock_10bit.asm
libavcodec/x86/h264_idct.asm
libavcodec/x86/h264_idct_10bit.asm
libavcodec/x86/h264_intrapred.asm
libavcodec/x86/h264_intrapred_10bit.asm
libavcodec/x86/h264_weight.asm
libavcodec/x86/vc1dsp.asm
libavcodec/x86/vp3dsp.asm
libavcodec/x86/vp56dsp.asm
libavcodec/x86/vp8dsp.asm
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/cngdec.c')
-rw-r--r-- | libavcodec/cngdec.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/libavcodec/cngdec.c b/libavcodec/cngdec.c index 0daeb9b969..9b6dfef08e 100644 --- a/libavcodec/cngdec.c +++ b/libavcodec/cngdec.c @@ -32,6 +32,7 @@ typedef struct CNGContext { float *lpc_coef; int order; int energy, target_energy; + int inited; float *filter_out; float *excitation; AVLFG lfg; @@ -94,8 +95,14 @@ static void make_lpc_coefs(float *lpc, const float *refl, int order) memcpy(lpc, cur, sizeof(*lpc) * order); } +static void cng_decode_flush(AVCodecContext *avctx) +{ + CNGContext *p = avctx->priv_data; + p->inited = 0; +} + static int cng_decode_frame(AVCodecContext *avctx, void *data, - int *got_frame_ptr, AVPacket *avpkt) + int *got_frame_ptr, AVPacket *avpkt) { CNGContext *p = avctx->priv_data; @@ -106,18 +113,24 @@ static int cng_decode_frame(AVCodecContext *avctx, void *data, float scaling; if (avpkt->size) { - float dbov = -avpkt->data[0] / 10.0; - p->target_energy = 1081109975 * pow(10, dbov) * 0.75; - memset(p->target_refl_coef, 0, sizeof(p->refl_coef)); + int dbov = -avpkt->data[0]; + p->target_energy = 1081109975 * pow(10, dbov / 10.0) * 0.75; + memset(p->target_refl_coef, 0, p->order * sizeof(*p->target_refl_coef)); for (i = 0; i < FFMIN(avpkt->size - 1, p->order); i++) { p->target_refl_coef[i] = (avpkt->data[1 + i] - 127) / 128.0; } - make_lpc_coefs(p->lpc_coef, p->refl_coef, p->order); } - p->energy = p->energy / 2 + p->target_energy / 2; - for (i = 0; i < p->order; i++) - p->refl_coef[i] = 0.6 *p->refl_coef[i] + 0.4 * p->target_refl_coef[i]; + if (p->inited) { + p->energy = p->energy / 2 + p->target_energy / 2; + for (i = 0; i < p->order; i++) + p->refl_coef[i] = 0.6 *p->refl_coef[i] + 0.4 * p->target_refl_coef[i]; + } else { + p->energy = p->target_energy; + memcpy(p->refl_coef, p->target_refl_coef, p->order * sizeof(*p->refl_coef)); + p->inited = 1; + } + make_lpc_coefs(p->lpc_coef, p->refl_coef, p->order); for (i = 0; i < p->order; i++) e *= 1.0 - p->refl_coef[i]*p->refl_coef[i]; @@ -154,6 +167,7 @@ AVCodec ff_comfortnoise_decoder = { .priv_data_size = sizeof(CNGContext), .init = cng_decode_init, .decode = cng_decode_frame, + .flush = cng_decode_flush, .close = cng_decode_close, .long_name = NULL_IF_CONFIG_SMALL("RFC 3389 comfort noise generator"), .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, |