From 073d0bc9254d9425585b6614fc9e1b01f3764f0f Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Wed, 5 May 2010 21:37:53 -0400 Subject: [PATCH] Yet another step towards variable frame size --- libcelt/bands.c | 6 ++--- libcelt/celt.c | 12 ++++----- libcelt/modes.c | 72 +++++++++++++++++++++++++------------------------ libcelt/modes.h | 17 ++++++++---- 4 files changed, 58 insertions(+), 49 deletions(-) diff --git a/libcelt/bands.c b/libcelt/bands.c index 2be7fe9e..a78fe1ec 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -472,7 +472,7 @@ void quant_bands(const CELTMode *m, int start, celt_norm * restrict X, const cel int curr_balance, curr_bits; N = M*eBands[i+1]-M*eBands[i]; - BPbits = m->bits; + BPbits = m->bits[FULL_FRAME(m)]; if (encode) tell = ec_enc_tell(enc_dec, BITRES); @@ -552,7 +552,7 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_ X = _X+M*eBands[i]; Y = X+M*eBands[m->nbEBands+1]; - BPbits = m->bits; + BPbits = m->bits[FULL_FRAME(m)]; N = M*eBands[i+1]-M*eBands[i]; tell = ec_enc_tell(enc, BITRES); @@ -789,7 +789,7 @@ void unquant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const cel X = _X+M*eBands[i]; Y = X+M*eBands[m->nbEBands+1]; - BPbits = m->bits; + BPbits = m->bits[FULL_FRAME(m)]; N = M*eBands[i+1]-M*eBands[i]; tell = ec_dec_tell(dec, BITRES); diff --git a/libcelt/celt.c b/libcelt/celt.c index 53713a8b..56a4a866 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -328,11 +328,11 @@ static void compute_mdcts(const CELTMode *mode, int shortBlocks, celt_sig * rest const int C = CHANNELS(_C); if (C==1 && !shortBlocks) { - const mdct_lookup *lookup = MDCT(mode); + const mdct_lookup *lookup = &mode->mdct[FULL_FRAME(mode)]; const int overlap = OVERLAP(mode); clt_mdct_forward(lookup, in, out, mode->window, overlap); } else { - const mdct_lookup *lookup = MDCT(mode); + const mdct_lookup *lookup = &mode->mdct[FULL_FRAME(mode)]; const int overlap = OVERLAP(mode); int N = FRAMESIZE(mode); int B = 1; @@ -342,7 +342,7 @@ static void compute_mdcts(const CELTMode *mode, int shortBlocks, celt_sig * rest SAVE_STACK; if (shortBlocks) { - lookup = &mode->shortMdct; + lookup = &mode->mdct[0]; N = mode->shortMdctSize; B = shortBlocks; } @@ -378,7 +378,7 @@ static void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig *X { int j; if (transient_shift==0 && C==1 && !shortBlocks) { - const mdct_lookup *lookup = MDCT(mode); + const mdct_lookup *lookup = &mode->mdct[FULL_FRAME(mode)]; clt_mdct_backward(lookup, X, out_mem+C*(MAX_PERIOD-N-N4), mode->window, overlap); } else { VARDECL(celt_word32, x); @@ -387,7 +387,7 @@ static void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig *X int N2 = N; int B = 1; int n4offset=0; - const mdct_lookup *lookup = MDCT(mode); + const mdct_lookup *lookup = &mode->mdct[FULL_FRAME(mode)]; SAVE_STACK; ALLOC(x, 2*N, celt_word32); @@ -395,7 +395,7 @@ static void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig *X if (shortBlocks) { - lookup = &mode->shortMdct; + lookup = &mode->mdct[0]; N2 = mode->shortMdctSize; B = shortBlocks; n4offset = N4; diff --git a/libcelt/modes.c b/libcelt/modes.c index 6b128f9d..dcab5ba0 100644 --- a/libcelt/modes.c +++ b/libcelt/modes.c @@ -325,27 +325,15 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error) mode->mdctSize = frame_size; mode->ePredCoef = QCONST16(.8f,15); - if (frame_size > 640 && (frame_size%16)==0) + if (frame_size >= 640 && (frame_size%16)==0) { mode->nbShortMdcts = 8; - } else if (frame_size > 384 && (frame_size%8)==0) + } else if (frame_size >= 320 && (frame_size%8)==0) { mode->nbShortMdcts = 4; - } else if (frame_size > 384 && (frame_size%10)==0) - { - mode->nbShortMdcts = 5; - } else if (frame_size > 256 && (frame_size%6)==0) - { - mode->nbShortMdcts = 3; - } else if (frame_size > 256 && (frame_size%8)==0) - { - mode->nbShortMdcts = 4; - } else if (frame_size > 64 && (frame_size%4)==0) + } else if (frame_size >= 120 && (frame_size%4)==0) { mode->nbShortMdcts = 2; - } else if (frame_size > 128 && (frame_size%6)==0) - { - mode->nbShortMdcts = 3; } else { mode->nbShortMdcts = 1; @@ -384,7 +372,12 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error) #endif mode->window = window; - mode->bits = (const celt_int16 **)compute_alloc_cache(mode, 1, mode->nbShortMdcts); + for (i=0;(1<nbShortMdcts;i++) + { + /* FIXME: Do something for i==0 */ + if (i!=0) + mode->bits[i] = (const celt_int16 **)compute_alloc_cache(mode, 1, 1<bits==NULL) goto failure; @@ -397,16 +390,18 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error) mode->logN = logN; #endif /* !STATIC_MODES */ - clt_mdct_init(&mode->mdct, 2*mode->mdctSize); - - clt_mdct_init(&mode->shortMdct, 2*mode->shortMdctSize); - - mode->prob = quant_prob_alloc(mode); - if ((mode->mdct.trig==NULL) || (mode->shortMdct.trig==NULL) + for (i=0;(1<nbShortMdcts;i++) + { + clt_mdct_init(&mode->mdct[i], 2*mode->shortMdctSize<mdct[i].trig==NULL) #ifndef ENABLE_TI_DSPLIB55 - || (mode->mdct.kfft==NULL) || (mode->shortMdct.kfft==NULL) + || (mode->mdct[i].kfft==NULL) #endif - || (mode->prob==NULL)) + ) + goto failure; + } + mode->prob = quant_prob_alloc(mode); + if (mode->prob==NULL) goto failure; mode->marker_start = MODEVALID; @@ -424,7 +419,7 @@ failure: void celt_mode_destroy(CELTMode *mode) { - int i; + int i, m; const celt_int16 *prevPtr = NULL; if (mode == NULL) { @@ -445,18 +440,24 @@ void celt_mode_destroy(CELTMode *mode) } mode->marker_start = MODEFREED; #ifndef STATIC_MODES - if (mode->bits!=NULL) + for (m=0;(1<nbShortMdcts;m++) { - for (i=0;inbEBands;i++) + /* FIXME: Do something for i==0 */ + if (m==0) + continue; + if (mode->bits[m]!=NULL) { - if (mode->bits[i] != prevPtr) + for (i=0;inbEBands;i++) { - prevPtr = mode->bits[i]; - celt_free((int*)mode->bits[i]); - } + if (mode->bits[m][i] != prevPtr) + { + prevPtr = mode->bits[m][i]; + celt_free((int*)mode->bits[m][i]); + } + } } - } - celt_free((celt_int16**)mode->bits); + celt_free((celt_int16**)mode->bits[m]); + } celt_free((celt_int16*)mode->eBands); celt_free((celt_int16*)mode->allocVectors); @@ -464,8 +465,9 @@ void celt_mode_destroy(CELTMode *mode) celt_free((celt_int16*)mode->logN); #endif - clt_mdct_clear(&mode->mdct); - clt_mdct_clear(&mode->shortMdct); + for (i=0;(1<nbShortMdcts;i++) + clt_mdct_clear(&mode->mdct[i]); + quant_prob_free(mode->prob); mode->marker_end = MODEFREED; celt_free((CELTMode *)mode); diff --git a/libcelt/modes.h b/libcelt/modes.h index f47a735a..d58e64c7 100644 --- a/libcelt/modes.h +++ b/libcelt/modes.h @@ -40,6 +40,8 @@ #include "mdct.h" #include "pitch.h" +#define MAX_CONFIG_SIZES 4 + #define CELT_BITSTREAM_VERSION 0x8000000c #ifdef STATIC_MODES @@ -64,8 +66,6 @@ # endif #endif -#define MDCT(mode) (&(mode)->mdct) - #ifndef OVERLAP #define OVERLAP(mode) ((mode)->overlap) #endif @@ -93,22 +93,29 @@ struct CELTMode { int nbAllocVectors; /**< Number of lines in the matrix below */ const celt_int16 *allocVectors; /**< Number of bits in each band for several rates */ - const celt_int16 * const *bits; /**< Cache for pulses->bits mapping in each band */ + const celt_int16 * const *(bits[MAX_CONFIG_SIZES]); /**< Cache for pulses->bits mapping in each band */ /* Stuff that could go in the {en,de}coder, but we save space this way */ - mdct_lookup mdct; + mdct_lookup mdct[MAX_CONFIG_SIZES]; const celt_word16 *window; int nbShortMdcts; int shortMdctSize; - mdct_lookup shortMdct; int *prob; const celt_int16 *logN; celt_uint32 marker_end; }; +static inline int FULL_FRAME(const CELTMode *m) +{ + int i=0; + while (1<nbShortMdcts) + i++; + return i; +} + int check_mode(const CELTMode *mode); #endif