From 0de9d8abec2fe2a2477c88b0974ca5f4abcb64ff Mon Sep 17 00:00:00 2001
From: Jean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Date: Mon, 24 Mar 2008 17:06:08 +1100
Subject: [PATCH] Making bits2pulses() use a fixed number of iterations to
 allow further optimisations.

---
 libcelt/rate.c | 6 +++++-
 libcelt/rate.h | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libcelt/rate.c b/libcelt/rate.c
index bd37d660..1a90034a 100644
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -154,11 +154,15 @@ void compute_alloc_cache(CELTMode *m)
 
 static int bits2pulses(const CELTMode *m, int band, int bits)
 {
+   int i;
    int lo, hi;
    lo = 0;
    hi = MAX_PULSES-1;
    
-   while (hi-lo != 1)
+   /* Instead of using the "bisection confition" we use a fixed number of 
+      iterations because it should be faster */
+   /*while (hi-lo != 1)*/
+   for (i=0;i<LOG_MAX_PULSES;i++)
    {
       int mid = (lo+hi)>>1;
       if (m->bits[band][mid] >= bits)
diff --git a/libcelt/rate.h b/libcelt/rate.h
index d5e8fe71..968b8fdc 100644
--- a/libcelt/rate.h
+++ b/libcelt/rate.h
@@ -33,6 +33,7 @@
 #define RATE_H
 
 #define MAX_PULSES 64
+#define LOG_MAX_PULSES 6
 
 /** Computes a cache of the pulses->bits mapping in each band */
 void compute_alloc_cache(CELTMode *m);