diff --git a/libcelt/dump_modes.c b/libcelt/dump_modes.c index c32be072..6171cae8 100644 --- a/libcelt/dump_modes.c +++ b/libcelt/dump_modes.c @@ -66,16 +66,22 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) { CELTMode *mode = modes[i]; int mdctSize; + int standard; + mdctSize = mode->shortMdctSize*mode->nbShortMdcts; - fprintf(file, "#ifndef DEF_EBANDS%d_%d\n", mode->Fs, mdctSize); - fprintf(file, "#define DEF_EBANDS%d_%d\n", mode->Fs, mdctSize); - fprintf (file, "static const celt_int16 eBands%d_%d[%d] = {\n", mode->Fs, mdctSize, mode->nbEBands+2); - for (j=0;jnbEBands+2;j++) - fprintf (file, "%d, ", mode->eBands[j]); - fprintf (file, "};\n"); - fprintf(file, "#endif\n"); - fprintf(file, "\n"); - + standard = (mode->Fs == 400*(celt_int32)mode->shortMdctSize); + + if (!standard) + { + fprintf(file, "#ifndef DEF_EBANDS%d_%d\n", mode->Fs, mdctSize); + fprintf(file, "#define DEF_EBANDS%d_%d\n", mode->Fs, mdctSize); + fprintf (file, "static const celt_int16 eBands%d_%d[%d] = {\n", mode->Fs, mdctSize, mode->nbEBands+2); + for (j=0;jnbEBands+2;j++) + fprintf (file, "%d, ", mode->eBands[j]); + fprintf (file, "};\n"); + fprintf(file, "#endif\n"); + fprintf(file, "\n"); + } fprintf(file, "#ifndef DEF_WINDOW%d\n", mode->overlap); fprintf(file, "#define DEF_WINDOW%d\n", mode->overlap); @@ -86,18 +92,21 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) fprintf(file, "#endif\n"); fprintf(file, "\n"); - fprintf(file, "#ifndef DEF_ALLOC_VECTORS%d_%d\n", mode->Fs, mdctSize); - fprintf(file, "#define DEF_ALLOC_VECTORS%d_%d\n", mode->Fs, mdctSize); - fprintf (file, "static const unsigned char allocVectors%d_%d[%d] = {\n", mode->Fs, mdctSize, mode->nbEBands*mode->nbAllocVectors); - for (j=0;jnbAllocVectors;j++) + if (!standard) { - for (k=0;knbEBands;k++) - fprintf (file, "%2d, ", mode->allocVectors[j*mode->nbEBands+k]); - fprintf (file, "\n"); + fprintf(file, "#ifndef DEF_ALLOC_VECTORS%d_%d\n", mode->Fs, mdctSize); + fprintf(file, "#define DEF_ALLOC_VECTORS%d_%d\n", mode->Fs, mdctSize); + fprintf (file, "static const unsigned char allocVectors%d_%d[%d] = {\n", mode->Fs, mdctSize, mode->nbEBands*mode->nbAllocVectors); + for (j=0;jnbAllocVectors;j++) + { + for (k=0;knbEBands;k++) + fprintf (file, "%2d, ", mode->allocVectors[j*mode->nbEBands+k]); + fprintf (file, "\n"); + } + fprintf (file, "};\n"); + fprintf(file, "#endif\n"); + fprintf(file, "\n"); } - fprintf (file, "};\n"); - fprintf(file, "#endif\n"); - fprintf(file, "\n"); fprintf(file, "#ifndef DEF_PROB%d\n", mode->nbEBands); fprintf(file, "#define DEF_PROB%d\n", mode->nbEBands); @@ -143,10 +152,10 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) /* FFT Bitrev tables */ for (i=0;i<=mode->mdct.maxshift;i++) { - fprintf(file, "#ifndef FFT_BITREV%d_%d\n", mode->Fs, mdctSize>>i); - fprintf(file, "#define FFT_BITREV%d_%d\n", mode->Fs, mdctSize>>i); - fprintf (file, "static const celt_int16 fft_bitrev%d_%d[%d] = {\n", - mode->Fs, mdctSize>>i, mode->mdct.kfft[i]->nfft); + fprintf(file, "#ifndef FFT_BITREV%d\n", mode->mdct.kfft[i]->nfft); + fprintf(file, "#define FFT_BITREV%d\n", mode->mdct.kfft[i]->nfft); + fprintf (file, "static const celt_int16 fft_bitrev%d[%d] = {\n", + mode->mdct.kfft[i]->nfft, mode->mdct.kfft[i]->nfft); for (j=0;jmdct.kfft[i]->nfft;j++) fprintf (file, "%d, ", mode->mdct.kfft[i]->bitrev[j]); fprintf (file, "};\n"); @@ -171,7 +180,7 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) for (j=0;j<2*MAXFACTORS;j++) fprintf (file, "%d, ", mode->mdct.kfft[i]->factors[j]); fprintf (file, "},\t/* factors */\n"); - fprintf (file, "fft_bitrev%d_%d,\t/* bitrev */\n", mode->Fs, mdctSize>>i); + fprintf (file, "fft_bitrev%d,\t/* bitrev */\n", mode->mdct.kfft[i]->nfft); fprintf (file, "fft_twiddles%d_%d,\t/* bitrev */\n", mode->Fs, mdctSize); fprintf (file, "};\n"); @@ -205,9 +214,15 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) for (j=0;j<4;j++) fprintf(file, WORD16 ", ", mode->preemph[j]); fprintf(file, "},\t/* preemph */\n"); - fprintf(file, "eBands%d_%d,\t/* eBands */\n", mode->Fs, mdctSize); + if (standard) + fprintf(file, "eband5ms,\t/* eBands */\n"); + else + fprintf(file, "eBands%d_%d,\t/* eBands */\n", mode->Fs, mdctSize); fprintf(file, "%d,\t/* nbAllocVectors */\n", mode->nbAllocVectors); - fprintf(file, "allocVectors%d_%d,\t/* allocVectors */\n", mode->Fs, mdctSize); + if (standard) + fprintf(file, "band_allocation,\t/* allocVectors */\n"); + else + fprintf(file, "allocVectors%d_%d,\t/* allocVectors */\n", mode->Fs, mdctSize); fprintf(file, "{%d, %d, {", mode->mdct.n, mode->mdct.maxshift); for (i=0;i<=mode->mdct.maxshift;i++) diff --git a/libcelt/modes.c b/libcelt/modes.c index 367eadda..30d7a3e8 100644 --- a/libcelt/modes.c +++ b/libcelt/modes.c @@ -42,6 +42,25 @@ #include "stack_alloc.h" #include "quant_bands.h" +static const celt_int16 eband5ms[] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 34, 40, 48, 60, 78, 100 +}; + +#define BITALLOC_SIZE 9 +/* Bit allocation table in units of 1/32 bit/sample (0.1875 dB SNR) */ +static const unsigned char band_allocation[] = { +/*0 200 400 600 800 1k 1.2 1.4 1.6 2k 2.4 2.8 3.2 4k 4.8 5.6 6.8 8k 9.6 12k 15.6 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 80, 80, 75, 70, 65, 60, 55, 50, 44, 40, 35, 30, 15, 1, 0, 0, 0, 0, 0, 0, 0, + 90, 85, 85, 85, 85, 82, 78, 74, 70, 65, 60, 54, 45, 35, 25, 15, 1, 0, 0, 0, 0, +120,110,110,110,100, 96, 90, 88, 84, 76, 70, 65, 60, 45, 35, 25, 20, 1, 1, 0, 0, +135,125,125,125,115,112,104,104,100, 96, 83, 78, 70, 55, 46, 36, 32, 28, 20, 8, 0, +175,170,167,155,149,145,143,138,138,138,129,124,108, 96, 88, 83, 72, 56, 44, 28, 2, +224,192,192,192,192,192,192,192,192,192,192,192,156,128,108, 96, 88, 76, 68, 44, 20, +255,224,224,224,224,224,224,224,224,224,224,224,224,188,164,148,124, 96, 80, 64, 40, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,220,188,144,104, 84, 60, +}; + #ifdef STATIC_MODES #include "static_modes.c" #endif @@ -83,29 +102,6 @@ static const celt_int16 bark_freq[BARK_BANDS+1] = { 6400, 7700, 9500, 12000, 15500, 20000}; -/* This allocation table is per critical band. When creating a mode, the bits get added together - into the codec bands, which are sometimes larger than one critical band at low frequency */ - -#define BITALLOC_SIZE 10 - -static const celt_int16 eband5ms[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 34, 40, 48, 60, 78, 100 -}; - -/* Bit allocation table in units of 1/32 bit/sample (0.1875 dB SNR) */ -static const unsigned char band_allocation[] = { -/*0 200 400 600 800 1k 1.2 1.4 1.6 2k 2.4 2.8 3.2 4k 4.8 5.6 6.8 8k 9.6 12k 15.6 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 80, 80, 75, 70, 65, 60, 55, 50, 44, 40, 35, 30, 15, 1, 0, 0, 0, 0, 0, 0, 0, - 90, 85, 85, 85, 85, 82, 78, 74, 70, 65, 60, 54, 45, 35, 25, 15, 1, 0, 0, 0, 0, -120,110,110,110,100, 96, 90, 88, 84, 76, 70, 65, 60, 45, 35, 25, 20, 1, 1, 0, 0, -135,125,125,125,115,112,104,104,100, 96, 83, 78, 70, 55, 46, 36, 32, 28, 20, 8, 0, -175,170,167,155,149,145,143,138,138,138,129,124,108, 96, 88, 83, 72, 56, 44, 28, 2, -224,192,192,192,192,192,192,192,192,192,192,192,156,128,108, 96, 88, 76, 68, 44, 20, -255,224,224,224,224,224,224,224,224,224,224,224,224,188,164,148,124, 96, 80, 64, 40, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,220,188,144,104, 84, 60, -}; - static celt_int16 *compute_ebands(celt_int32 Fs, int frame_size, int res, int *nbEBands) { celt_int16 *eBands;