From 5588d52e9468f8e6c97c8471cbf3e6d8304e24e3 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Mon, 10 Mar 2008 15:07:58 +1100 Subject: [PATCH] Psychoacoustic decay coefficients can now be included in the static modes --- libcelt/dump_modes.c | 11 ++++++++++- libcelt/modes.c | 13 ++++++++----- libcelt/psy.c | 3 ++- libcelt/testcelt.c | 6 ++++++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/libcelt/dump_modes.c b/libcelt/dump_modes.c index 42484434..cd4d611d 100644 --- a/libcelt/dump_modes.c +++ b/libcelt/dump_modes.c @@ -88,6 +88,15 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) fprintf(file, "#endif\n"); fprintf(file, "\n"); + fprintf(file, "#ifndef DEF_PSY%d\n", mode->Fs); + fprintf(file, "#define DEF_PSY%d\n", mode->Fs); + fprintf (file, "const celt_word16_t psy_decayR_%d[%d] = {\n", mode->Fs, MAX_PERIOD/2); + for (j=0;jpsy.decayR[j]); + printf ("};\n"); + fprintf(file, "#endif\n"); + fprintf(file, "\n"); + 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); @@ -122,7 +131,7 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes) fprintf(file, "0,\t/* bits */\n"); fprintf(file, "{%d, 0, 0},\t/* mdct */\n", 2*mode->mdctSize); fprintf(file, "window%d,\t/* window */\n", mode->overlap); - fprintf(file, "{0},\t/* psy */\n"); + fprintf(file, "{psy_decayR_%d},\t/* psy */\n", mode->Fs); fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e); fprintf(file, "};\n"); } diff --git a/libcelt/modes.c b/libcelt/modes.c index 49d8fefb..07ad8cf8 100644 --- a/libcelt/modes.c +++ b/libcelt/modes.c @@ -69,6 +69,8 @@ int celt_mode_info(const CELTMode *mode, int request, celt_int32_t *value) return CELT_OK; } +#ifndef STATIC_MODES + #define PBANDS 8 #define MIN_BINS 4 /* Defining 25 critical bands for the full 0-20 kHz audio bandwidth @@ -101,7 +103,7 @@ static const int band_allocation[BARK_BANDS*BITALLOC_SIZE] = }; - static int *compute_ebands(celt_int32_t Fs, int frame_size, int *nbEBands) +static int *compute_ebands(celt_int32_t Fs, int frame_size, int *nbEBands) { int *eBands; int i, res, min_width, lin, low, high; @@ -215,7 +217,7 @@ static void compute_allocation_table(CELTMode *mode, int res) mode->allocVectors = allocVectors; } - +#endif /* STATIC_MODES */ CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int lookahead, int *error) { @@ -302,12 +304,13 @@ CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int lo #endif mode->window = window; + psydecay_init(&mode->psy, MAX_PERIOD/2, mode->Fs); + mode->marker_start = MODEVALID; mode->marker_end = MODEVALID; #endif mdct_init(&mode->mdct, 2*mode->mdctSize); compute_alloc_cache(mode); - psydecay_init(&mode->psy, MAX_PERIOD/2, mode->Fs); if (error) *error = CELT_OK; return mode; @@ -315,6 +318,7 @@ CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int lo void celt_mode_destroy(CELTMode *mode) { +#ifndef STATIC_MODES int i; const int *prevPtr = NULL; for (i=0;inbEBands;i++) @@ -327,8 +331,6 @@ void celt_mode_destroy(CELTMode *mode) } celt_free((int**)mode->bits); mdct_clear(&mode->mdct); - psydecay_clear(&mode->psy); -#ifndef STATIC_MODES if (check_mode(mode) != CELT_OK) return; celt_free((int*)mode->eBands); @@ -340,6 +342,7 @@ void celt_mode_destroy(CELTMode *mode) mode->marker_start = MODEFREED; mode->marker_end = MODEFREED; celt_free((CELTMode *)mode); + psydecay_clear(&mode->psy); #endif } diff --git a/libcelt/psy.c b/libcelt/psy.c index 2ae547f7..1356a13c 100644 --- a/libcelt/psy.c +++ b/libcelt/psy.c @@ -42,7 +42,7 @@ #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n)) #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f) - +#ifndef STATIC_MODES /* Psychoacoustic spreading function. The idea here is compute a first order recursive filter. The filter coefficient is frequency dependent and chosen such that we have a -10dB/Bark slope on the right side and a -25dB/Bark @@ -69,6 +69,7 @@ void psydecay_init(struct PsyDecay *decay, int len, celt_int32_t Fs) /*printf ("%f %f\n", decayL[i], decayR[i]);*/ } } +#endif void psydecay_clear(struct PsyDecay *decay) { diff --git a/libcelt/testcelt.c b/libcelt/testcelt.c index 4add077c..6afadf17 100644 --- a/libcelt/testcelt.c +++ b/libcelt/testcelt.c @@ -54,7 +54,9 @@ int main(int argc, char *argv[]) int bytes_per_packet; unsigned char data[1024]; int rate, overlap; +#if !(defined (FIXED_POINT) && defined(STATIC_MODES)) double rmsd = 0; +#endif int count = 0; int skip; celt_int16_t *in, *out; @@ -129,11 +131,13 @@ int main(int argc, char *argv[]) for (i=0;i 0) { rmsd = sqrt(rmsd/(1.0*frame_size*channels*count)); @@ -152,6 +157,7 @@ int main(int argc, char *argv[]) } else { fprintf (stderr, "Encoder matches decoder!!\n"); } +#endif celt_mode_destroy(mode); celt_free(in); celt_free(out);