ref: 732ea3881039f500ed5e852c1aa2377fd531a50b
parent: 3ad8db49c55111896610c0d1f4ac9c425741b41e
author: Jean-Marc Valin <[email protected]>
date: Wed Aug 25 09:52:27 EDT 2010
Updated static modes for new pulse cache. Fixed a few minor bugs in the process.
--- a/libcelt/cwrs.c
+++ b/libcelt/cwrs.c
@@ -652,7 +652,7 @@
_bits[0]=0;
if (_n==1)
{
- for (k=1;k<_maxk;k++)
+ for (k=1;k<=_maxk;k++)
_bits[k] = 1<<_frac;
}
else {
--- a/libcelt/dump_modes.c
+++ b/libcelt/dump_modes.c
@@ -108,6 +108,19 @@
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 @@
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 @@
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");
}
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -297,7 +297,6 @@
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 @@
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 @@
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);
--- a/libcelt/modes.h
+++ b/libcelt/modes.h
@@ -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)
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -75,32 +75,33 @@
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 @@
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 @@
}
}
}
- 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++)
--- a/libcelt/rate.h
+++ b/libcelt/rate.h
@@ -59,10 +59,10 @@
{
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 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;
}