Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/celt-0.7.0.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jean-marc.valin@usherbrooke.ca>2009-06-11 06:46:27 +0400
committerJean-Marc Valin <jean-marc.valin@usherbrooke.ca>2009-06-11 06:46:27 +0400
commita76a5e8f0c8797e902924a8f186800707038aa2d (patch)
treedcec3d82b0ac643b69c26a7aae4bc3d70bb0c0c4
parenteb5aa094c479bc26f3ff88c8e0f262b977a0652e (diff)
Better ebits rounding and making it possible to add remaining ebits even to
bands that weren't rounded down.
-rw-r--r--libcelt/quant_bands.c52
-rw-r--r--libcelt/rate.c6
2 files changed, 33 insertions, 25 deletions
diff --git a/libcelt/quant_bands.c b/libcelt/quant_bands.c
index 4fe6a1d..323bf4a 100644
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -174,23 +174,26 @@ static void quant_fine_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_
static void quant_energy_finalise_mono(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, celt_word16_t *error, int *fine_quant, int *fine_priority, int bits_left, ec_enc *enc)
{
- int i;
+ int i, prio;
/* Use up the remaining bits */
- for (i=0;i<m->nbEBands && bits_left!=0 ;i++)
+ for (prio=0;prio<2;prio++)
{
- int q2;
- celt_word16_t offset;
- if (fine_quant[i] >= 7 || fine_priority[i]==0)
- continue;
- q2 = error[i]<0 ? 0 : 1;
- ec_enc_bits(enc, q2, 1);
+ for (i=0;i<m->nbEBands && bits_left!=0 ;i++)
+ {
+ int q2;
+ celt_word16_t offset;
+ if (fine_quant[i] >= 7 || fine_priority[i]!=prio)
+ continue;
+ q2 = error[i]<0 ? 0 : 1;
+ ec_enc_bits(enc, q2, 1);
#ifdef FIXED_POINT
- offset = SHR16(SHL16(q2,8)-QCONST16(.5,8),fine_quant[i]+1);
+ offset = SHR16(SHL16(q2,8)-QCONST16(.5,8),fine_quant[i]+1);
#else
- offset = (q2-.5f)*(1<<(14-fine_quant[i]-1))*(1.f/16384);
+ offset = (q2-.5f)*(1<<(14-fine_quant[i]-1))*(1.f/16384);
#endif
- oldEBands[i] += offset;
- bits_left--;
+ oldEBands[i] += offset;
+ bits_left--;
+ }
}
for (i=0;i<m->nbEBands;i++)
{
@@ -260,22 +263,25 @@ static void unquant_fine_energy_mono(const CELTMode *m, celt_ener_t *eBands, cel
static void unquant_energy_finalise_mono(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int *fine_quant, int *fine_priority, int bits_left, ec_dec *dec)
{
- int i;
+ int i, prio;
/* Use up the remaining bits */
- for (i=0;i<m->nbEBands && bits_left!=0 ;i++)
+ for (prio=0;prio<2;prio++)
{
- int q2;
- celt_word16_t offset;
- if (fine_quant[i] >= 7 || fine_priority[i]==0)
- continue;
- q2 = ec_dec_bits(dec, 1);
+ for (i=0;i<m->nbEBands && bits_left!=0 ;i++)
+ {
+ int q2;
+ celt_word16_t offset;
+ if (fine_quant[i] >= 7 || fine_priority[i]!=prio)
+ continue;
+ q2 = ec_dec_bits(dec, 1);
#ifdef FIXED_POINT
- offset = SHR16(SHL16(q2,8)-QCONST16(.5,8),fine_quant[i]+1);
+ offset = SHR16(SHL16(q2,8)-QCONST16(.5,8),fine_quant[i]+1);
#else
- offset = (q2-.5f)*(1<<(14-fine_quant[i]-1))*(1.f/16384);
+ offset = (q2-.5f)*(1<<(14-fine_quant[i]-1))*(1.f/16384);
#endif
- oldEBands[i] += offset;
- bits_left--;
+ oldEBands[i] += offset;
+ bits_left--;
+ }
}
for (i=0;i<m->nbEBands;i++)
{
diff --git a/libcelt/rate.c b/libcelt/rate.c
index 061f3e7..9248396 100644
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -145,8 +145,10 @@ static void interp_bits2pulses(const CELTMode *m, int *bits1, int *bits2, int to
offset = 50 - log2_frac(N, 4);
/* Offset for the number of fine bits compared to their "fair share" of total/N */
offset = bits[j]-offset*N*C;
- ebits[j] = (offset+(d>>1))/d;
- fine_priority[j] = (ebits[j]*d < offset);
+ if (offset < 0)
+ offset = 0;
+ ebits[j] = (2*offset+d)/(2*d);
+ fine_priority[j] = ebits[j]*d >= offset;
/* Make sure not to bust */
if (C*ebits[j] > (bits[j]>>BITRES))