From 82595311602a327dc52aef96e0ed151b4ae5046b Mon Sep 17 00:00:00 2001 From: Gregory Maxwell Date: Tue, 30 Sep 2008 18:20:14 -0400 Subject: [PATCH] API: Change celt_encode and celt_encode_float so that they take an optional synthesis parameter after the PCM input. If optional_synthesis is null the encoder will be able to save some computation. If optional_synthesis is non-null if will be used to write the encoder's expectation of the decoder's output. Synthesis may alias the input pcm, so calling the encoder with the same buffer twice will achieve the old behavior. Remove 'restrict' from the CTL prototype. --- libcelt/celt.c | 53 +++++++++++++++++++++++++--------------------- libcelt/celt.h | 6 +++--- libcelt/testcelt.c | 2 +- tools/celtclient.c | 4 ++-- tools/celtenc.c | 2 +- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/libcelt/celt.c b/libcelt/celt.c index d582438c..002fd083 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -371,10 +371,10 @@ static void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig_t } #ifdef FIXED_POINT -int celt_encode(CELTEncoder * restrict st, celt_int16_t * restrict pcm, unsigned char *compressed, int nbCompressedBytes) +int celt_encode(CELTEncoder * restrict st, const celt_int16_t * pcm, celt_int16_t * optional_synthesis, unsigned char *compressed, int nbCompressedBytes) { #else -int celt_encode_float(CELTEncoder * restrict st, celt_sig_t * restrict pcm, unsigned char *compressed, int nbCompressedBytes) +int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_sig_t * optional_synthesis, unsigned char *compressed, int nbCompressedBytes) { #endif int i, c, N, N4; @@ -602,7 +602,7 @@ int celt_encode_float(CELTEncoder * restrict st, celt_sig_t * restrict pcm, unsi /* Residual quantisation */ quant_bands(st->mode, X, P, NULL, bandE, stereo_mode, pulses, shortBlocks, nbCompressedBytes*8, &st->enc); - if (st->pitch_enabled) + if (st->pitch_enabled || optional_synthesis!=NULL) { if (C==2) renormalise_bands(st->mode, X); @@ -614,19 +614,19 @@ int celt_encode_float(CELTEncoder * restrict st, celt_sig_t * restrict pcm, unsi compute_inv_mdcts(st->mode, shortBlocks, freq, transient_time, transient_shift, st->out_mem); /* De-emphasis and put everything back at the right place in the synthesis history */ -#ifndef SHORTCUTS - for (c=0;cout_mem[C*(MAX_PERIOD-N)+C*j+c], + int j; + for (j=0;jout_mem[C*(MAX_PERIOD-N)+C*j+c], preemph,st->preemph_memD[c]); - st->preemph_memD[c] = tmp; - pcm[C*j+c] = SCALEOUT(SIG2WORD16(tmp)); + st->preemph_memD[c] = tmp; + optional_synthesis[C*j+c] = SCALEOUT(SIG2WORD16(tmp)); + } } } -#endif } /*fprintf (stderr, "remaining bits after encode = %d\n", nbCompressedBytes*8-ec_enc_tell(&st->enc, 0));*/ /*if (ec_enc_tell(&st->enc, 0) < nbCompressedBytes*8 - 7) @@ -668,7 +668,7 @@ int celt_encode_float(CELTEncoder * restrict st, celt_sig_t * restrict pcm, unsi #ifdef FIXED_POINT #ifndef DISABLE_FLOAT_API -int celt_encode_float(CELTEncoder * restrict st, float * restrict pcm, unsigned char *compressed, int nbCompressedBytes) +int celt_encode_float(CELTEncoder * restrict st, const float * pcm, float * optional_synthesis, unsigned char *compressed, int nbCompressedBytes) { int j, ret; const int C = CHANNELS(st->mode); @@ -679,18 +679,20 @@ int celt_encode_float(CELTEncoder * restrict st, float * restrict pcm, unsigned for (j=0;j