diff --git a/libcelt/modes.c b/libcelt/modes.c index 72ae8836..2f1db65e 100644 --- a/libcelt/modes.c +++ b/libcelt/modes.c @@ -124,19 +124,24 @@ static const int band_allocation[BARK_BANDS*BITALLOC_SIZE] = static celt_int16_t *compute_ebands(celt_int32_t Fs, int frame_size, int *nbEBands) { celt_int16_t *eBands; - int i, res, min_width, lin, low, high; + int i, res, min_width, lin, low, high, nBark; res = (Fs+frame_size)/(2*frame_size); min_width = MIN_BINS*res; /*printf ("min_width = %d\n", min_width);*/ + /* Find the number of critical bands supported by our sampling rate */ + for (nBark=1;nBark= Fs) + break; + /* Find where the linear part ends (i.e. where the spacing is more than min_width */ - for (lin=0;lin= min_width) break; /*printf ("lin = %d (%d Hz)\n", lin, bark_freq[lin]);*/ low = ((bark_freq[lin]/res)+(MIN_BINS-1))/MIN_BINS; - high = BARK_BANDS-lin; + high = nBark-lin; *nbEBands = low+high; eBands = celt_alloc(sizeof(celt_int16_t)*(*nbEBands+2)); @@ -150,7 +155,7 @@ static celt_int16_t *compute_ebands(celt_int32_t Fs, int frame_size, int *nbEBan for (i=0;i<*nbEBands;i++) if (eBands[i] < MIN_BINS*i) eBands[i] = MIN_BINS*i; - eBands[*nbEBands] = (bark_freq[BARK_BANDS]+res/2)/res; + eBands[*nbEBands] = (bark_freq[nBark]+res/2)/res; eBands[*nbEBands+1] = frame_size; if (eBands[*nbEBands] > eBands[*nbEBands+1]) eBands[*nbEBands] = eBands[*nbEBands+1]; @@ -201,10 +206,15 @@ static void compute_pbands(CELTMode *mode, int res) static void compute_allocation_table(CELTMode *mode, int res) { - int i, j, eband; + int i, j, eband, nBark; celt_int16_t *allocVectors, *allocEnergy; const int C = CHANNELS(mode); + /* Find the number of critical bands supported by our sampling rate */ + for (nBark=1;nBark= mode->Fs) + break; + mode->nbAllocVectors = BITALLOC_SIZE; allocVectors = celt_alloc(sizeof(celt_int16_t)*(BITALLOC_SIZE*mode->nbEBands)); allocEnergy = celt_alloc(sizeof(celt_int16_t)*(mode->nbAllocVectors*(mode->nbEBands+1))); @@ -212,7 +222,7 @@ static void compute_allocation_table(CELTMode *mode, int res) for (i=0;i 512 || frame_size%2!=0) { - celt_warning("Only even frame sizes between 64 and 512 are supported"); + celt_warning("Only even frame sizes from 64 to 512 are supported"); if (error) *error = CELT_BAD_ARG; return NULL;