Commit 5588d52e authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Psychoacoustic decay coefficients can now be included in the static modes

parent 680a9ec5
......@@ -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;j<MAX_PERIOD/2;j++)
fprintf (file, WORD16 ", ", mode->psy.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");
}
......
......@@ -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;i<mode->nbEBands;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
}
......
......@@ -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)
{
......
......@@ -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<frame_size*channels;i++)
out[i] = in[i];
#endif
#if !(defined (FIXED_POINT) && defined(STATIC_MODES))
for (i=0;i<frame_size*channels;i++)
{
rmsd += (in[i]-out[i])*1.0*(in[i]-out[i]);
/*out[i] -= in[i];*/
}
#endif
count++;
fwrite(out, sizeof(short), (frame_size-skip)*channels, fout);
skip = 0;
......@@ -143,6 +147,7 @@ int main(int argc, char *argv[])
celt_decoder_destroy(dec);
fclose(fin);
fclose(fout);
#if !(defined (FIXED_POINT) && defined(STATIC_MODES))
if (rmsd > 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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment