Commit 3dbc1d0d authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

cleaning up some of the mode stuff

parent 03f9ed30
......@@ -160,7 +160,7 @@ inline celt_int16_t SIG2INT16(celt_sig_t x)
}
/** Apply window and compute the MDCT for all sub-frames and all channels in a frame */
static celt_word32_t compute_mdcts(const mdct_lookup *mdct_lookup, celt_word16_t *window, celt_sig_t *in, celt_sig_t *out, int N, int overlap, int B, int C)
static celt_word32_t compute_mdcts(const mdct_lookup *mdct_lookup, const celt_word16_t *window, celt_sig_t *in, celt_sig_t *out, int N, int overlap, int B, int C)
{
int i, c, N4;
celt_word32_t E = 0;
......@@ -200,7 +200,7 @@ static celt_word32_t compute_mdcts(const mdct_lookup *mdct_lookup, celt_word16_t
}
/** Compute the IMDCT and apply window for all sub-frames and all channels in a frame */
static void compute_inv_mdcts(const mdct_lookup *mdct_lookup, celt_word16_t *window, celt_sig_t *X, celt_sig_t *out_mem, celt_sig_t *mdct_overlap, int N, int overlap, int B, int C)
static void compute_inv_mdcts(const mdct_lookup *mdct_lookup, const celt_word16_t *window, celt_sig_t *X, celt_sig_t *out_mem, celt_sig_t *mdct_overlap, int N, int overlap, int B, int C)
{
int i, c, N4;
VARDECL(celt_word32_t *x);
......
......@@ -37,12 +37,19 @@
#include "modes.h"
#include "celt.h"
#define INT16 "%d"
#define INT32 "%d"
#define FLOAT "%f"
#ifdef FIXED_POINT
#define WORD "%d"
#define WORD16 INT16
#define WORD32 INT32
#else
#define WORD "%f"
#define WORD16 FLOAT
#define WORD32 FLOAT
#endif
void dump_modes(FILE *file, CELTMode *modes, int nb_modes)
{
int i, j;
......@@ -63,7 +70,7 @@ void dump_modes(FILE *file, CELTMode *modes, int nb_modes)
fprintf(file, "\n");
fprintf (file, "const celt_word16_t window%d[%d] = {\n", modes->overlap, modes->overlap);
for (j=0;j<modes->overlap;j++)
fprintf (file, WORD ", ", modes->window[j]);
fprintf (file, WORD16 ", ", modes->window[j]);
printf ("};\n");
fprintf(file, "\n");
fprintf (file, "const int allocVectors%d_%d[%d] = {\n", modes->Fs, modes->mdctSize, modes->nbEBands*modes->nbAllocVectors);
......@@ -78,7 +85,7 @@ void dump_modes(FILE *file, CELTMode *modes, int nb_modes)
fprintf(file, "\n");
fprintf(file, "CELTMode mode%d_%d_%d_%d = {\n", modes->Fs, modes->nbChannels, modes->mdctSize, modes->overlap);
fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
fprintf(file, "%d,\t/* Fs */\n", modes->Fs);
fprintf(file, INT32 ",\t/* Fs */\n", modes->Fs);
fprintf(file, "%d,\t/* overlap */\n", modes->overlap);
fprintf(file, "%d,\t/* mdctSize */\n", modes->mdctSize);
fprintf(file, "%d,\t/* nbMdctBlocks */\n", modes->nbMdctBlocks);
......@@ -88,22 +95,23 @@ void dump_modes(FILE *file, CELTMode *modes, int nb_modes)
fprintf(file, "%d,\t/* pitchEnd */\n", modes->pitchEnd);
fprintf(file, "eBands%d_%d,\t/* eBands */\n", modes->Fs, modes->mdctSize);
fprintf(file, "pBands%d_%d,\t/* pBands */\n", modes->Fs, modes->mdctSize);
fprintf(file, "%d,\t/* ePredCoef */\n", modes->ePredCoef);
fprintf(file, WORD16 ",\t/* ePredCoef */\n", modes->ePredCoef);
fprintf(file, "%d,\t/* nbAllocVectors */\n", modes->nbAllocVectors);
fprintf(file, "allocVectors%d_%d,\t/* allocVectors */\n", modes->Fs, modes->mdctSize);
fprintf(file, "0,\t/* bits */\n");
fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
fprintf(file, "{0, 0, 0},\t/* ,mdct */\n", modes->mdctSize);
fprintf(file, "{%d, 0, 0},\t/* mdct */\n", 2*modes->mdctSize);
fprintf(file, "window%d,\t/* window */\n", modes->overlap);
fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
fprintf(file, "};\n");
modes++;
}
}
#if 0
#if 1
int main()
{
CELTMode *m = celt_mode_create(44100, 2, 256, 128, NULL);
CELTMode *m = celt_mode_create(44100, 1, 256, 128, NULL);
dump_modes(stdout, m, 1);
return 0;
}
#endif
......@@ -218,7 +218,8 @@ CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int lo
int res;
int N, i;
CELTMode *mode;
celt_word16_t *window;
/* The good thing here is that permutation of the arguments will automatically be invalid */
if (Fs < 32000 || Fs > 64000)
......@@ -268,15 +269,16 @@ CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int lo
N = mode->mdctSize;
mdct_init(&mode->mdct, 2*N);
mode->window = (celt_word16_t*)celt_alloc(mode->overlap*sizeof(celt_word16_t));
window = (celt_word16_t*)celt_alloc(mode->overlap*sizeof(celt_word16_t));
#ifndef FIXED_POINT
for (i=0;i<mode->overlap;i++)
mode->window[i] = Q15ONE*sin(.5*M_PI* sin(.5*M_PI*(i+.5)/mode->overlap) * sin(.5*M_PI*(i+.5)/mode->overlap));
window[i] = Q15ONE*sin(.5*M_PI* sin(.5*M_PI*(i+.5)/mode->overlap) * sin(.5*M_PI*(i+.5)/mode->overlap));
#else
for (i=0;i<mode->overlap;i++)
mode->window[i] = MIN32(32767,32768.*sin(.5*M_PI* sin(.5*M_PI*(i+.5)/mode->overlap) * sin(.5*M_PI*(i+.5)/mode->overlap)));
window[i] = MIN32(32767,32768.*sin(.5*M_PI* sin(.5*M_PI*(i+.5)/mode->overlap) * sin(.5*M_PI*(i+.5)/mode->overlap)));
#endif
mode->window = window;
mode->marker_start = MODEVALID;
mode->marker_end = MODEVALID;
......@@ -303,7 +305,7 @@ void celt_mode_destroy(CELTMode *mode)
}
celt_free((int**)mode->bits);
mdct_clear(&mode->mdct);
celt_free(mode->window);
celt_free((celt_word16_t*)mode->window);
mode->marker_start = MODEFREED;
mode->marker_end = MODEFREED;
......
......@@ -61,13 +61,13 @@ struct CELTMode {
const int *allocVectors; /**< Number of bits in each band for several rates */
const int * const *bits; /**< Cache for pulses->bits mapping in each band */
celt_uint32_t marker_end;
/* Stuff that could go in the {en,de}coder, but we save space this way */
mdct_lookup mdct;
celt_word16_t *window;
const celt_word16_t *window;
celt_uint32_t marker_end;
};
int check_mode(const CELTMode *mode);
......
......@@ -99,7 +99,7 @@ int quant_pitch(celt_pgain_t *gains, int len, ec_enc *enc)
int unquant_pitch(celt_pgain_t *gains, int len, ec_dec *dec)
{
int i, id;
int id;
id = ec_dec_uint(dec, 128);
id2gains(id, gains, len);
return id!=0;
......
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