From b76ee706068c1630d11252629772f8b9d7f2691e Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Mon, 10 Mar 2008 15:42:35 +1100 Subject: [PATCH] Allocation cache can now be pre-computed as well. --- libcelt/dump_modes.c | 33 +++++++++++++++++++++++++++------ libcelt/modes.c | 5 +++-- libcelt/rate.c | 4 ++-- libcelt/rate.h | 2 ++ 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/libcelt/dump_modes.c b/libcelt/dump_modes.c index cd4d611d..5a7b8be8 100644 --- a/libcelt/dump_modes.c +++ b/libcelt/dump_modes.c @@ -36,6 +36,7 @@ #include #include "modes.h" #include "celt.h" +#include "rate.h" #define INT16 "%d" #define INT32 "%d" @@ -53,12 +54,13 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) { int i, j; + fprintf(file, "#include \"modes.h\"\n"); + fprintf(file, "#include \"rate.h\"\n"); + + fprintf(file, "\n"); for (i=0;iFs, 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); @@ -112,6 +114,25 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) fprintf(file, "#endif\n"); fprintf(file, "\n"); + fprintf(file, "#ifndef DEF_ALLOC_CACHE%d_%d_%d\n", mode->Fs, mode->mdctSize, mode->nbChannels); + fprintf(file, "#define DEF_ALLOC_CACHE%d_%d_%d\n", mode->Fs, mode->mdctSize, mode->nbChannels); + for (j=0;jnbEBands;j++) + { + int k; + fprintf (file, "const int 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"); + } + fprintf (file, "const int *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); + } + fprintf (file, "};\n"); + fprintf(file, "#endif\n"); + fprintf(file, "\n"); + fprintf(file, "CELTMode mode%d_%d_%d_%d = {\n", mode->Fs, mode->nbChannels, mode->mdctSize, mode->overlap); fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e); @@ -128,7 +149,7 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) fprintf(file, WORD16 ",\t/* ePredCoef */\n", mode->ePredCoef); fprintf(file, "%d,\t/* nbAllocVectors */\n", mode->nbAllocVectors); fprintf(file, "allocVectors%d_%d,\t/* allocVectors */\n", mode->Fs, mode->mdctSize); - fprintf(file, "0,\t/* bits */\n"); + fprintf(file, "allocCache%d_%d_%d,\t/* bits */\n", mode->Fs, mode->mdctSize, mode->nbChannels); fprintf(file, "{%d, 0, 0},\t/* mdct */\n", 2*mode->mdctSize); fprintf(file, "window%d,\t/* window */\n", mode->overlap); fprintf(file, "{psy_decayR_%d},\t/* psy */\n", mode->Fs); @@ -144,10 +165,10 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) CELTMode *mode = modes[i]; fprintf(file, "&mode%d_%d_%d_%d,\n", mode->Fs, mode->nbChannels, mode->mdctSize, mode->overlap); } - fprintf(file, "};\n"); + fprintf(file, "};\n"); } -#if 1 +#if 0 int main() { CELTMode *m[3]; diff --git a/libcelt/modes.c b/libcelt/modes.c index 07ad8cf8..723a8150 100644 --- a/libcelt/modes.c +++ b/libcelt/modes.c @@ -304,13 +304,14 @@ CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int lo #endif mode->window = window; + compute_alloc_cache(mode); + psydecay_init(&mode->psy, MAX_PERIOD/2, mode->Fs); mode->marker_start = MODEVALID; mode->marker_end = MODEVALID; -#endif +#endif /* !STATIC_MODES */ mdct_init(&mode->mdct, 2*mode->mdctSize); - compute_alloc_cache(mode); if (error) *error = CELT_OK; return mode; diff --git a/libcelt/rate.c b/libcelt/rate.c index 8d53696b..0218cfca 100644 --- a/libcelt/rate.c +++ b/libcelt/rate.c @@ -46,8 +46,7 @@ #define BITROUND 8 #define BITOVERFLOW 10000 -#define MAX_PULSES 64 - +#ifndef STATIC_MODES static int log2_frac(ec_uint32 val, int frac) { int i; @@ -151,6 +150,7 @@ void compute_alloc_cache(CELTMode *m) m->bits = (const int * const *)bits; } +#endif /* !STATIC_MODES */ int bits2pulses(const CELTMode *m, int band, int bits) { diff --git a/libcelt/rate.h b/libcelt/rate.h index 414b9a20..d5e8fe71 100644 --- a/libcelt/rate.h +++ b/libcelt/rate.h @@ -32,6 +32,8 @@ #ifndef RATE_H #define RATE_H +#define MAX_PULSES 64 + /** Computes a cache of the pulses->bits mapping in each band */ void compute_alloc_cache(CELTMode *m);