Updated static modes for new pulse cache.

Fixed a few minor bugs in the process.
This commit is contained in:
Jean-Marc Valin 2010-08-25 13:52:27 -04:00
parent 3ad8db49c5
commit 732ea38810
6 changed files with 40 additions and 35 deletions

View file

@ -652,7 +652,7 @@ void get_required_bits(celt_int16 *_bits,int _n,int _maxk,int _frac){
_bits[0]=0;
if (_n==1)
{
for (k=1;k<_maxk;k++)
for (k=1;k<=_maxk;k++)
_bits[k] = 1<<_frac;
}
else {

View file

@ -108,6 +108,19 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
fprintf(file, "#endif\n");
fprintf(file, "\n");
fprintf(file, "#ifndef DEF_PULSE_CACHE%d_%d\n", mode->Fs, mdctSize);
fprintf(file, "#define DEF_PULSE_CACHE%d_%d\n", mode->Fs, mdctSize);
fprintf (file, "static const celt_int16 cache_index%d_%d[%d] = {\n", mode->Fs, mdctSize, (mode->maxLM+2)*mode->nbEBands);
for (j=0;j<mode->nbEBands*(mode->maxLM+2);j++)
fprintf (file, "%d, ", mode->cache.index[j]);
fprintf (file, "};\n");
fprintf (file, "static const unsigned char cache_bits%d_%d[%d] = {\n", mode->Fs, mdctSize, mode->cache.size);
for (j=0;j<mode->cache.size;j++)
fprintf (file, "%d, ", mode->cache.bits[j]);
fprintf (file, "};\n");
fprintf(file, "#endif\n");
fprintf(file, "\n");
fprintf(file, "static const CELTMode mode%d_%d_%d = {\n", mode->Fs, mdctSize, mode->overlap);
fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
fprintf(file, INT32 ",\t/* Fs */\n", mode->Fs);
@ -121,18 +134,6 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
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);
fprintf(file, "NULL,\t/* bits */\n");
fprintf (file, "{ ");
for (k=0;(1<<k>>1)<=mode->nbShortMdcts;k++)
{
int mdctSize2 = mode->shortMdctSize;
if (k>=1)
mdctSize2 <<= k-1;
else
mdctSize2 >>= 1;
fprintf (file, "allocCache%d_%d, ", mode->Fs, mdctSize2);
}
fprintf (file, "}, /* _bits */\n");
fprintf(file, "{%d, 0, 0, 0},\t", 2*mode->shortMdctSize*mode->nbShortMdcts);
fprintf (file, "/* mdct */\n");
@ -143,6 +144,8 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
fprintf(file, "%d,\t/* shortMdctSize */\n", mode->shortMdctSize);
fprintf(file, "0,\t/* prob */\n");
fprintf(file, "logN%d_%d,\t/* logN */\n", mode->Fs, mdctSize);
fprintf(file, "{%d, cache_index%d_%d, cache_bits%d_%d},\t/* cache */\n",
mode->cache.size, mode->Fs, mdctSize, mode->Fs, mdctSize);
fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
fprintf(file, "};\n");
}

View file

@ -297,7 +297,6 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error)
if (mode==NULL)
goto failure;
CELT_COPY(mode, m, 1);
mode->bits = mode->_bits+1;
mode->marker_start = MODEPARTIAL;
#else
int res;
@ -424,7 +423,7 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error)
compute_pulse_cache(mode, mode->maxLM);
#endif /* !STATIC_MODES */
clt_mdct_init(&mode->mdct, 2*mode->shortMdctSize*mode->nbShortMdcts, LM);
clt_mdct_init(&mode->mdct, 2*mode->shortMdctSize*mode->nbShortMdcts, mode->maxLM);
if ((mode->mdct.trig==NULL)
#ifndef ENABLE_TI_DSPLIB55
|| (mode->mdct.kfft==NULL)
@ -476,8 +475,8 @@ void celt_mode_destroy(CELTMode *mode)
celt_free((celt_word16*)mode->window);
celt_free((celt_int16*)mode->logN);
celt_free(mode->cache.index);
celt_free(mode->cache.bits);
celt_free((celt_int16*)mode->cache.index);
celt_free((unsigned char*)mode->cache.bits);
#endif
clt_mdct_clear(&mode->mdct);

View file

@ -68,9 +68,9 @@
#endif
typedef struct {
int nbBands;
celt_int16 *index;
unsigned char *bits;
int size;
const celt_int16 *index;
const unsigned char *bits;
} PulseCache;
/** Mode definition (opaque)

View file

@ -75,32 +75,33 @@ void compute_pulse_cache(CELTMode *m, int LM)
int entryN[100], entryK[100], entryI[100];
const celt_int16 *eBands = m->eBands;
PulseCache *cache = &m->cache;
celt_int16 *cindex;
unsigned char *bits;
cache->nbBands = m->nbEBands;
cache->index = celt_alloc(sizeof(cache->index[0])*cache->nbBands*(LM+2));
cindex = celt_alloc(sizeof(cache->index[0])*m->nbEBands*(LM+2));
cache->index = cindex;
for (i=0;i<=LM+1;i++)
{
int j;
for (j=0;j<cache->nbBands;j++)
for (j=0;j<m->nbEBands;j++)
{
int k;
int N = (eBands[j+1]-eBands[j])<<i>>1;
cache->index[i*cache->nbBands+j] = -1;
cindex[i*m->nbEBands+j] = -1;
for (k=0;k<=i;k++)
{
int n;
for (n=0;n<cache->nbBands && (k!=i || n<j);n++)
for (n=0;n<m->nbEBands && (k!=i || n<j);n++)
{
if (N == (eBands[n+1]-eBands[n])<<k>>1)
{
cache->index[i*cache->nbBands+j] =
cache->index[k*cache->nbBands+n];
cindex[i*m->nbEBands+j] = cindex[k*m->nbEBands+n];
break;
}
}
}
if (cache->index[i*cache->nbBands+j] == -1)
if (cache->index[i*m->nbEBands+j] == -1 && N!=0)
{
int K;
entryN[nbEntries] = N;
@ -108,7 +109,7 @@ void compute_pulse_cache(CELTMode *m, int LM)
while (fits_in32(N,get_pulses(K+1)) && K<MAX_PSEUDO-1)
K++;
entryK[nbEntries] = K;
cache->index[i*cache->nbBands+j] = curr;
cindex[i*m->nbEBands+j] = curr;
entryI[nbEntries] = curr;
curr += K+1;
@ -116,11 +117,13 @@ void compute_pulse_cache(CELTMode *m, int LM)
}
}
}
cache->bits = celt_alloc(sizeof(unsigned char)*curr);
bits = celt_alloc(sizeof(unsigned char)*curr);
cache->bits = bits;
cache->size = curr;
for (i=0;i<nbEntries;i++)
{
int j;
unsigned char *ptr = cache->bits+entryI[i];
unsigned char *ptr = bits+entryI[i];
celt_int16 tmp[MAX_PULSES];
get_required_bits(tmp, entryN[i], get_pulses(entryK[i]), BITRES);
for (j=1;j<=entryK[i];j++)

View file

@ -59,10 +59,10 @@ static inline int bits2pulses(const CELTMode *m, int band, int LM, int bits)
{
int i;
int lo, hi;
unsigned char *cache;
const unsigned char *cache;
LM++;
cache = m->cache.bits + m->cache.index[LM*m->cache.nbBands+band];
cache = m->cache.bits + m->cache.index[LM*m->nbEBands+band];
lo = 0;
hi = cache[0];
@ -84,10 +84,10 @@ static inline int bits2pulses(const CELTMode *m, int band, int LM, int bits)
static inline int pulses2bits(const CELTMode *m, int band, int LM, int pulses)
{
unsigned char *cache;
const unsigned char *cache;
LM++;
cache = m->cache.bits + m->cache.index[LM*m->cache.nbBands+band];
cache = m->cache.bits + m->cache.index[LM*m->nbEBands+band];
return pulses == 0 ? 0 : cache[pulses]+1;
}