From db0141e76600b1f337a39b5345afc48474151c1a Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Mon, 10 Mar 2008 16:37:37 +1100 Subject: [PATCH] Changed some of the mode data from int to celt_int16_t to save memory. --- libcelt/bands.c | 20 ++++++++++---------- libcelt/dump_modes.c | 14 +++++++------- libcelt/modes.c | 16 ++++++++-------- libcelt/modes.h | 8 ++++---- libcelt/rate.c | 10 +++++----- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/libcelt/bands.c b/libcelt/bands.c index 0244b87f..06d93d2a 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -79,7 +79,7 @@ const celt_word16_t sqrtC_1[2] = {QCONST16(1.f, 14), QCONST16(1.414214f, 14)}; void compute_band_energies(const CELTMode *m, const celt_sig_t *X, celt_ener_t *bank) { int i, c, B, C; - const int *eBands = m->eBands; + const celt_int16_t *eBands = m->eBands; B = m->nbMdctBlocks; C = m->nbChannels; for (c=0;ceBands; + const celt_int16_t *eBands = m->eBands; B = m->nbMdctBlocks; C = m->nbChannels; for (c=0;ceBands; + const celt_int16_t *eBands = m->eBands; B = m->nbMdctBlocks; C = m->nbChannels; for (c=0;ceBands; + const celt_int16_t *eBands = m->eBands; B = m->nbMdctBlocks; C = m->nbChannels; for (c=0;ceBands; + const celt_int16_t *eBands = m->eBands; B = m->nbMdctBlocks; C = m->nbChannels; if (C>2) @@ -233,7 +233,7 @@ void denormalise_bands(const CELTMode *m, const celt_norm_t *X, celt_sig_t *freq void compute_pitch_gain(const CELTMode *m, const celt_norm_t *X, const celt_norm_t *P, celt_pgain_t *gains) { int i, B; - const int *pBands = m->pBands; + const celt_int16_t *pBands = m->pBands; B = m->nbMdctBlocks*m->nbChannels; for (i=0;inbPBands;i++) @@ -271,7 +271,7 @@ void compute_pitch_gain(const CELTMode *m, const celt_norm_t *X, const celt_norm void pitch_quant_bands(const CELTMode *m, celt_norm_t *P, const celt_pgain_t *gains) { int i, B; - const int *pBands = m->pBands; + const celt_int16_t *pBands = m->pBands; B = m->nbMdctBlocks*m->nbChannels; for (i=0;inbPBands;i++) { @@ -289,7 +289,7 @@ void pitch_quant_bands(const CELTMode *m, celt_norm_t *P, const celt_pgain_t *ga void quant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, celt_mask_t *W, int total_bits, ec_enc *enc) { int i, j, B, bits; - const int *eBands = m->eBands; + const celt_int16_t *eBands = m->eBands; celt_word16_t alpha; VARDECL(celt_norm_t *norm); VARDECL(int *pulses); @@ -353,7 +353,7 @@ void quant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, celt_mask_t void unquant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, int total_bits, ec_dec *dec) { int i, j, B, bits; - const int *eBands = m->eBands; + const celt_int16_t *eBands = m->eBands; celt_word16_t alpha; VARDECL(celt_norm_t *norm); VARDECL(int *pulses); @@ -410,7 +410,7 @@ void unquant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, int total_ void stereo_mix(const CELTMode *m, celt_norm_t *X, const celt_ener_t *bank, int dir) { int i, B, C; - const int *eBands = m->eBands; + const celt_int16_t *eBands = m->eBands; B = m->nbMdctBlocks; C = m->nbChannels; for (i=0;inbEBands;i++) diff --git a/libcelt/dump_modes.c b/libcelt/dump_modes.c index 972289e9..8bd364b6 100644 --- a/libcelt/dump_modes.c +++ b/libcelt/dump_modes.c @@ -63,7 +63,7 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) CELTMode *mode = modes[i]; fprintf(file, "#ifndef DEF_EBANDS%d_%d\n", mode->Fs, mode->mdctSize); fprintf(file, "#define DEF_EBANDS%d_%d\n", mode->Fs, mode->mdctSize); - fprintf (file, "const int eBands%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbEBands+2); + fprintf (file, "const celt_int16_t eBands%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbEBands+2); for (j=0;jnbEBands+2;j++) fprintf (file, "%d, ", mode->eBands[j]); fprintf (file, "};\n"); @@ -73,7 +73,7 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) fprintf(file, "#ifndef DEF_PBANDS%d_%d\n", mode->Fs, mode->mdctSize); fprintf(file, "#define DEF_PBANDS%d_%d\n", mode->Fs, mode->mdctSize); - fprintf (file, "const int pBands%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbPBands+2); + fprintf (file, "const celt_int16_t pBands%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbPBands+2); for (j=0;jnbPBands+2;j++) fprintf (file, "%d, ", mode->pBands[j]); printf ("};\n"); @@ -102,7 +102,7 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) fprintf(file, "#ifndef DEF_ALLOC_VECTORS%d_%d\n", mode->Fs, mode->mdctSize); fprintf(file, "#define DEF_ALLOC_VECTORS%d_%d\n", mode->Fs, mode->mdctSize); - fprintf (file, "const int allocVectors%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbEBands*mode->nbAllocVectors); + fprintf (file, "const celt_int16_t allocVectors%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbEBands*mode->nbAllocVectors); for (j=0;jnbAllocVectors;j++) { int k; @@ -121,7 +121,7 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) int k; if (j==0 || (mode->bits[j] != mode->bits[j-1])) { - fprintf (file, "const int allocCache_band%d_%d_%d_%d[MAX_PULSES] = {\n", j, mode->Fs, mode->mdctSize, mode->nbChannels); + fprintf (file, "const celt_int16_t allocCache_band%d_%d_%d_%d[MAX_PULSES] = {\n", j, mode->Fs, mode->mdctSize, mode->nbChannels); for (k=0;kbits[j][k]); fprintf (file, "};\n"); @@ -129,7 +129,7 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) fprintf (file, "#define allocCache_band%d_%d_%d_%d allocCache_band%d_%d_%d_%d\n", j, mode->Fs, mode->mdctSize, mode->nbChannels, j-1, mode->Fs, mode->mdctSize, mode->nbChannels); } } - fprintf (file, "const int *allocCache%d_%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbChannels, mode->nbEBands); + fprintf (file, "const celt_int16_t *allocCache%d_%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbChannels, mode->nbEBands); for (j=0;jnbEBands;j++) { fprintf (file, "allocCache_band%d_%d_%d_%d, ", j, mode->Fs, mode->mdctSize, mode->nbChannels); @@ -173,14 +173,14 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) fprintf(file, "};\n"); } -#if 0 +#if 1 int main() { CELTMode *m[3]; m[0] = celt_mode_create(44100, 1, 256, 128, NULL); m[1] = celt_mode_create(48000, 1, 256, 128, NULL); m[2] = celt_mode_create(51200, 1, 256, 128, NULL); - dump_modes(stdout, m, 3); + dump_modes(stdout, m, 1); return 0; } #endif diff --git a/libcelt/modes.c b/libcelt/modes.c index 723a8150..3f06be89 100644 --- a/libcelt/modes.c +++ b/libcelt/modes.c @@ -103,9 +103,9 @@ static const int band_allocation[BARK_BANDS*BITALLOC_SIZE] = }; -static int *compute_ebands(celt_int32_t Fs, int frame_size, int *nbEBands) +static celt_int16_t *compute_ebands(celt_int32_t Fs, int frame_size, int *nbEBands) { - int *eBands; + celt_int16_t *eBands; int i, res, min_width, lin, low, high; res = (Fs+frame_size)/(2*frame_size); min_width = MIN_BINS*res; @@ -120,7 +120,7 @@ static int *compute_ebands(celt_int32_t Fs, int frame_size, int *nbEBands) low = ((bark_freq[lin]/res)+(MIN_BINS-1))/MIN_BINS; high = BARK_BANDS-lin; *nbEBands = low+high; - eBands = celt_alloc(sizeof(int)*(*nbEBands+2)); + eBands = celt_alloc(sizeof(celt_int16_t)*(*nbEBands+2)); /* Linear spacing (min_width) */ for (i=0;inbPBands = PBANDS; for (i=0;inbAllocVectors = BITALLOC_SIZE; - allocVectors = celt_alloc(sizeof(int)*(BITALLOC_SIZE*mode->nbEBands)); + allocVectors = celt_alloc(sizeof(celt_int16_t)*(BITALLOC_SIZE*mode->nbEBands)); for (i=0;inbEBands;i++) { if (mode->bits[i] != prevPtr) diff --git a/libcelt/modes.h b/libcelt/modes.h index fdb48507..90421ec5 100644 --- a/libcelt/modes.h +++ b/libcelt/modes.h @@ -55,15 +55,15 @@ struct CELTMode { int nbPBands; int pitchEnd; - const int *eBands; /**< Definition for each "pseudo-critical band" */ - const int *pBands; /**< Definition of the bands used for the pitch */ + const celt_int16_t *eBands; /**< Definition for each "pseudo-critical band" */ + const celt_int16_t *pBands; /**< Definition of the bands used for the pitch */ celt_word16_t ePredCoef;/**< Prediction coefficient for the energy encoding */ int nbAllocVectors; /**< Number of lines in the matrix below */ - const int *allocVectors; /**< Number of bits in each band for several rates */ + const celt_int16_t *allocVectors; /**< Number of bits in each band for several rates */ - const int * const *bits; /**< Cache for pulses->bits mapping in each band */ + const celt_int16_t * const *bits; /**< 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; diff --git a/libcelt/rate.c b/libcelt/rate.c index 0218cfca..4f376eba 100644 --- a/libcelt/rate.c +++ b/libcelt/rate.c @@ -98,10 +98,10 @@ static int log2_frac64(ec_uint64 val, int frac) void compute_alloc_cache(CELTMode *m) { int i, prevN, BC; - int **bits; - const int *eBands = m->eBands; + celt_int16_t **bits; + const celt_int16_t *eBands = m->eBands; - bits = celt_alloc(m->nbEBands*sizeof(int*)); + bits = celt_alloc(m->nbEBands*sizeof(celt_int16_t*)); BC = m->nbMdctBlocks*m->nbChannels; prevN = -1; @@ -114,7 +114,7 @@ void compute_alloc_cache(CELTMode *m) } else { int j; /* FIXME: We could save memory here */ - bits[i] = celt_alloc(MAX_PULSES*sizeof(int)); + bits[i] = celt_alloc(MAX_PULSES*sizeof(celt_int16_t)); for (j=0;jbits = (const int * const *)bits; + m->bits = (const celt_int16_t * const *)bits; } #endif /* !STATIC_MODES */