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

Changed some of the mode data from int to celt_int16_t to save memory.

parent 6a0d97eb
......@@ -79,7 +79,7 @@ const celt_word16_t sqrtC_1[2] = {QCONST16(1.f, 14), QCONST16(1.414214f, 14)};
void compute_band_energies(const CELTMode *m, const celt_sig_t *X, celt_ener_t *bank)
{
int i, c, B, C;
const int *eBands = m->eBands;
const celt_int16_t *eBands = m->eBands;
B = m->nbMdctBlocks;
C = m->nbChannels;
for (c=0;c<C;c++)
......@@ -112,7 +112,7 @@ void compute_band_energies(const CELTMode *m, const celt_sig_t *X, celt_ener_t *
void normalise_bands(const CELTMode *m, const celt_sig_t *freq, celt_norm_t *X, const celt_ener_t *bank)
{
int i, c, B, C;
const int *eBands = m->eBands;
const celt_int16_t *eBands = m->eBands;
B = m->nbMdctBlocks;
C = m->nbChannels;
for (c=0;c<C;c++)
......@@ -155,7 +155,7 @@ void renormalise_bands(const CELTMode *m, celt_norm_t *X)
void compute_band_energies(const CELTMode *m, const celt_sig_t *X, celt_ener_t *bank)
{
int i, c, B, C;
const int *eBands = m->eBands;
const celt_int16_t *eBands = m->eBands;
B = m->nbMdctBlocks;
C = m->nbChannels;
for (c=0;c<C;c++)
......@@ -177,7 +177,7 @@ void compute_band_energies(const CELTMode *m, const celt_sig_t *X, celt_ener_t *
void normalise_bands(const CELTMode *m, const celt_sig_t *freq, celt_norm_t *X, const celt_ener_t *bank)
{
int i, c, B, C;
const int *eBands = m->eBands;
const celt_int16_t *eBands = m->eBands;
B = m->nbMdctBlocks;
C = m->nbChannels;
for (c=0;c<C;c++)
......@@ -209,7 +209,7 @@ void renormalise_bands(const CELTMode *m, celt_norm_t *X)
void denormalise_bands(const CELTMode *m, const celt_norm_t *X, celt_sig_t *freq, const celt_ener_t *bank)
{
int i, c, B, C;
const int *eBands = m->eBands;
const celt_int16_t *eBands = m->eBands;
B = m->nbMdctBlocks;
C = m->nbChannels;
if (C>2)
......@@ -233,7 +233,7 @@ void denormalise_bands(const CELTMode *m, const celt_norm_t *X, celt_sig_t *freq
void compute_pitch_gain(const CELTMode *m, const celt_norm_t *X, const celt_norm_t *P, celt_pgain_t *gains)
{
int i, B;
const int *pBands = m->pBands;
const celt_int16_t *pBands = m->pBands;
B = m->nbMdctBlocks*m->nbChannels;
for (i=0;i<m->nbPBands;i++)
......@@ -271,7 +271,7 @@ void compute_pitch_gain(const CELTMode *m, const celt_norm_t *X, const celt_norm
void pitch_quant_bands(const CELTMode *m, celt_norm_t *P, const celt_pgain_t *gains)
{
int i, B;
const int *pBands = m->pBands;
const celt_int16_t *pBands = m->pBands;
B = m->nbMdctBlocks*m->nbChannels;
for (i=0;i<m->nbPBands;i++)
{
......@@ -289,7 +289,7 @@ void pitch_quant_bands(const CELTMode *m, celt_norm_t *P, const celt_pgain_t *ga
void quant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, celt_mask_t *W, int total_bits, ec_enc *enc)
{
int i, j, B, bits;
const int *eBands = m->eBands;
const celt_int16_t *eBands = m->eBands;
celt_word16_t alpha;
VARDECL(celt_norm_t *norm);
VARDECL(int *pulses);
......@@ -353,7 +353,7 @@ void quant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, celt_mask_t
void unquant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, int total_bits, ec_dec *dec)
{
int i, j, B, bits;
const int *eBands = m->eBands;
const celt_int16_t *eBands = m->eBands;
celt_word16_t alpha;
VARDECL(celt_norm_t *norm);
VARDECL(int *pulses);
......@@ -410,7 +410,7 @@ void unquant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, int total_
void stereo_mix(const CELTMode *m, celt_norm_t *X, const celt_ener_t *bank, int dir)
{
int i, B, C;
const int *eBands = m->eBands;
const celt_int16_t *eBands = m->eBands;
B = m->nbMdctBlocks;
C = m->nbChannels;
for (i=0;i<m->nbEBands;i++)
......
......@@ -63,7 +63,7 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
CELTMode *mode = modes[i];
fprintf(file, "#ifndef DEF_EBANDS%d_%d\n", mode->Fs, 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);
fprintf (file, "const celt_int16_t eBands%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbEBands+2);
for (j=0;j<mode->nbEBands+2;j++)
fprintf (file, "%d, ", mode->eBands[j]);
fprintf (file, "};\n");
......@@ -73,7 +73,7 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
fprintf(file, "#ifndef DEF_PBANDS%d_%d\n", mode->Fs, mode->mdctSize);
fprintf(file, "#define DEF_PBANDS%d_%d\n", mode->Fs, mode->mdctSize);
fprintf (file, "const int pBands%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbPBands+2);
fprintf (file, "const celt_int16_t pBands%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbPBands+2);
for (j=0;j<mode->nbPBands+2;j++)
fprintf (file, "%d, ", mode->pBands[j]);
printf ("};\n");
......@@ -102,7 +102,7 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
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);
fprintf (file, "const int allocVectors%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbEBands*mode->nbAllocVectors);
fprintf (file, "const celt_int16_t allocVectors%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbEBands*mode->nbAllocVectors);
for (j=0;j<mode->nbAllocVectors;j++)
{
int k;
......@@ -121,7 +121,7 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
int k;
if (j==0 || (mode->bits[j] != mode->bits[j-1]))
{
fprintf (file, "const int allocCache_band%d_%d_%d_%d[MAX_PULSES] = {\n", j, mode->Fs, mode->mdctSize, mode->nbChannels);
fprintf (file, "const celt_int16_t allocCache_band%d_%d_%d_%d[MAX_PULSES] = {\n", j, mode->Fs, mode->mdctSize, mode->nbChannels);
for (k=0;k<MAX_PULSES;k++)
fprintf (file, "%2d, ", mode->bits[j][k]);
fprintf (file, "};\n");
......@@ -129,7 +129,7 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
fprintf (file, "#define allocCache_band%d_%d_%d_%d allocCache_band%d_%d_%d_%d\n", j, mode->Fs, mode->mdctSize, mode->nbChannels, j-1, mode->Fs, mode->mdctSize, mode->nbChannels);
}
}
fprintf (file, "const int *allocCache%d_%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbChannels, mode->nbEBands);
fprintf (file, "const celt_int16_t *allocCache%d_%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbChannels, mode->nbEBands);
for (j=0;j<mode->nbEBands;j++)
{
fprintf (file, "allocCache_band%d_%d_%d_%d, ", j, mode->Fs, mode->mdctSize, mode->nbChannels);
......@@ -173,14 +173,14 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
fprintf(file, "};\n");
}
#if 0
#if 1
int main()
{
CELTMode *m[3];
m[0] = celt_mode_create(44100, 1, 256, 128, NULL);
m[1] = celt_mode_create(48000, 1, 256, 128, NULL);
m[2] = celt_mode_create(51200, 1, 256, 128, NULL);
dump_modes(stdout, m, 3);
dump_modes(stdout, m, 1);
return 0;
}
#endif
......@@ -103,9 +103,9 @@ static const int band_allocation[BARK_BANDS*BITALLOC_SIZE] =
};
static int *compute_ebands(celt_int32_t Fs, int frame_size, int *nbEBands)
static celt_int16_t *compute_ebands(celt_int32_t Fs, int frame_size, int *nbEBands)
{
int *eBands;
celt_int16_t *eBands;
int i, res, min_width, lin, low, high;
res = (Fs+frame_size)/(2*frame_size);
min_width = MIN_BINS*res;
......@@ -120,7 +120,7 @@ static int *compute_ebands(celt_int32_t Fs, int frame_size, int *nbEBands)
low = ((bark_freq[lin]/res)+(MIN_BINS-1))/MIN_BINS;
high = BARK_BANDS-lin;
*nbEBands = low+high;
eBands = celt_alloc(sizeof(int)*(*nbEBands+2));
eBands = celt_alloc(sizeof(celt_int16_t)*(*nbEBands+2));
/* Linear spacing (min_width) */
for (i=0;i<low;i++)
......@@ -147,8 +147,8 @@ static int *compute_ebands(celt_int32_t Fs, int frame_size, int *nbEBands)
static void compute_pbands(CELTMode *mode, int res)
{
int i;
int *pBands;
pBands=celt_alloc(sizeof(int)*(PBANDS+2));
celt_int16_t *pBands;
pBands=celt_alloc(sizeof(celt_int16_t)*(PBANDS+2));
mode->nbPBands = PBANDS;
for (i=0;i<PBANDS+1;i++)
{
......@@ -183,10 +183,10 @@ static void compute_pbands(CELTMode *mode, int res)
static void compute_allocation_table(CELTMode *mode, int res)
{
int i, j, eband;
int *allocVectors;
celt_int16_t *allocVectors;
mode->nbAllocVectors = BITALLOC_SIZE;
allocVectors = celt_alloc(sizeof(int)*(BITALLOC_SIZE*mode->nbEBands));
allocVectors = celt_alloc(sizeof(celt_int16_t)*(BITALLOC_SIZE*mode->nbEBands));
for (i=0;i<BITALLOC_SIZE;i++)
{
eband = 0;
......@@ -321,7 +321,7 @@ void celt_mode_destroy(CELTMode *mode)
{
#ifndef STATIC_MODES
int i;
const int *prevPtr = NULL;
const celt_int16_t *prevPtr = NULL;
for (i=0;i<mode->nbEBands;i++)
{
if (mode->bits[i] != prevPtr)
......
......@@ -55,15 +55,15 @@ struct CELTMode {
int nbPBands;
int pitchEnd;
const int *eBands; /**< Definition for each "pseudo-critical band" */
const int *pBands; /**< Definition of the bands used for the pitch */
const celt_int16_t *eBands; /**< Definition for each "pseudo-critical band" */
const celt_int16_t *pBands; /**< Definition of the bands used for the pitch */
celt_word16_t ePredCoef;/**< Prediction coefficient for the energy encoding */
int nbAllocVectors; /**< Number of lines in the matrix below */
const int *allocVectors; /**< Number of bits in each band for several rates */
const celt_int16_t *allocVectors; /**< Number of bits in each band for several rates */
const int * const *bits; /**< Cache for pulses->bits mapping in each band */
const celt_int16_t * const *bits; /**< Cache for pulses->bits mapping in each band */
/* Stuff that could go in the {en,de}coder, but we save space this way */
mdct_lookup mdct;
......
......@@ -98,10 +98,10 @@ static int log2_frac64(ec_uint64 val, int frac)
void compute_alloc_cache(CELTMode *m)
{
int i, prevN, BC;
int **bits;
const int *eBands = m->eBands;
celt_int16_t **bits;
const celt_int16_t *eBands = m->eBands;
bits = celt_alloc(m->nbEBands*sizeof(int*));
bits = celt_alloc(m->nbEBands*sizeof(celt_int16_t*));
BC = m->nbMdctBlocks*m->nbChannels;
prevN = -1;
......@@ -114,7 +114,7 @@ void compute_alloc_cache(CELTMode *m)
} else {
int j;
/* FIXME: We could save memory here */
bits[i] = celt_alloc(MAX_PULSES*sizeof(int));
bits[i] = celt_alloc(MAX_PULSES*sizeof(celt_int16_t));
for (j=0;j<MAX_PULSES;j++)
{
int done = 0;
......@@ -147,7 +147,7 @@ void compute_alloc_cache(CELTMode *m)
prevN = N;
}
}
m->bits = (const int * const *)bits;
m->bits = (const celt_int16_t * const *)bits;
}
#endif /* !STATIC_MODES */
......
Markdown is supported
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