From a6631746659a7d54bc342b1d7e56bbce1b6305a1 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Wed, 16 Jan 2008 17:16:04 +1100 Subject: [PATCH] more bit allocation wip --- libcelt/rate.c | 130 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 112 insertions(+), 18 deletions(-) diff --git a/libcelt/rate.c b/libcelt/rate.c index 06a08e14..6d98dd8e 100644 --- a/libcelt/rate.c +++ b/libcelt/rate.c @@ -33,9 +33,13 @@ #include "modes.h" #include "cwrs.h" #include "arch.h" +#include "os_support.h" #include "entcode.h" +#define BITRES 4 +#define BITOVERFLOW 1000 + int log2_frac(ec_uint32 val, int frac) { int i; @@ -84,6 +88,87 @@ int log2_frac64(ec_uint64 val, int frac) return L; } +int bits2pulses(int bits, int N) +{ + int i, b, prev; + /* FIXME: This is terribly inefficient. Do a bisection instead + but be careful about overflows */ + prev = 0; + i=1; + b = log2_frac64(ncwrs64(N, i),0); + while (beBands; + alloc->bits = celt_alloc(m->nbEBands*sizeof(int*)); + alloc->rev_bits = celt_alloc(m->nbEBands*sizeof(int*)); + alloc->len = m->nbEBands; + BC = m->nbMdctBlocks*m->nbChannels; + prevN = -1; + for (i=0;ilen;i++) + { + int N = BC*(eBands[i+1]-eBands[i]); + if (N == prevN) + { + alloc->bits[i] = alloc->bits[i-1]; + alloc->rev_bits[i] = alloc->rev_bits[i-1]; + } else { + int j; + /* FIXME: We could save memory here */ + alloc->bits[i] = celt_alloc(64*sizeof(int)); + alloc->rev_bits[i] = celt_alloc(64*sizeof(int)); + for (j=0;j<64;j++) + { + alloc->bits[i][j] = log2_frac64(ncwrs64(N, j),BITRES); + /* We could just update rev_bits here */ + if (alloc->bits[i][j] > (60>>BITRES)) + break; + } + for (;j<64;j++) + alloc->bits[i][j] = BITOVERFLOW; + for (j=0;j<32;j++) + alloc->rev_bits[i][j] = bits2pulses(j, N); + prevN = N; + } + } +} + +void alloc_clear(struct alloc_data *alloc) +{ + int i; + int *prevPtr = NULL; + for (i=0;ilen;i++) + { + if (alloc->bits[i] != prevPtr) + { + prevPtr = alloc->bits[i]; + celt_free(alloc->bits[i]); + celt_free(alloc->rev_bits[i]); + } + } + celt_free(alloc->bits); + celt_free(alloc->rev_bits); +} + + int compute_allocation(const CELTMode *m, int *pulses) { int i, N, BC, bits; @@ -106,24 +191,6 @@ int compute_allocation(const CELTMode *m, int *pulses) return (bits+255)>>8; } -int bits2pulses(int bits, int N) -{ - int i, b, prev; - /* FIXME: This is terribly inefficient. Do a bisection instead - but be careful about overflows */ - prev = 0; - i=1; - b = log2_frac64(ncwrs(N, i),0); - while (b