From 5c0d486fe13d4767f0df747b51fd14df8fd0cdac Mon Sep 17 00:00:00 2001
From: Jean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Date: Thu, 24 Jul 2008 08:49:34 -0400
Subject: [PATCH] Better bit allocation for all frame sizes that are not equal
 to 256.

---
 README          |  2 +-
 TODO            | 11 ++++-------
 libcelt/modes.c |  7 +++++--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/README b/README
index 33ee0d5f1..87278175c 100644
--- a/README
+++ b/README
@@ -8,7 +8,7 @@ To compile:
 % make
 
 To test the encoder:
-% testcelt <rate> <channels> <frame size> <overlap> <bytes per packet> input.sw output.sw
+% testcelt <rate> <channels> <frame size> <bytes per packet> input.sw output.sw
 
 where input.sw is a 16-bit (machine endian) audio file sampled at 
 44.1 kHz or 48 kHz. The output file is already decompressed. 
diff --git a/TODO b/TODO
index 54411e77a..05826ed27 100644
--- a/TODO
+++ b/TODO
@@ -1,16 +1,13 @@
 - Check minimum width of bands
-- Adjust the energy resolution based on the bit-rate
+- Revisit energy resolution based on the bit-rate
+- Revisit static bit allocation (as a function of frame size and channels)
 - Dynamic adjustment of energy quantisation
 - Psychacoustics
   * Error shaping within each band
-  * Desisions on the rate
-- Intensity stereo option (e.g. threshold)
+  * Decisions on the rate
+- Intensity stereo decisions
 - Dynamic (intra-frame) bit allocation 
 - Joint encoding of stereo energy
-- Disable intra-frame prediction for more than X pulses
-- Remove contraction?
-- Simplify search?
-- Remove pulse spreading?
 
 - Encode band shape (or just tilt)?
 - Make energy encoding more robust to losses?
diff --git a/libcelt/modes.c b/libcelt/modes.c
index e41d2a6fa..3fc4a875f 100644
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -208,11 +208,14 @@ static void compute_allocation_table(CELTMode *mode, int res)
       eband = 0;
       for (j=0;j<BARK_BANDS;j++)
       {
-         int edge, low, alloc;
+         int edge, low;
+         celt_int32_t alloc;
          edge = mode->eBands[eband+1]*res;
          alloc = band_allocation[i*BARK_BANDS+j];
          if (mode->nbChannels == 2)
-            alloc += alloc/2;
+            alloc = alloc*3*mode->mdctSize/512;
+         else
+            alloc = alloc*mode->mdctSize/256;
          if (edge < bark_freq[j+1])
          {
             int num, den;
-- 
GitLab