ref: 45a7ab523881fd36c3924be54bba76579ee9b032
parent: e28f25f0d14959d521fda0cdb8f1220995bc50e8
author: Jean-Marc Valin <[email protected]>
date: Thu Mar 27 11:41:38 EDT 2008
Optimisation: got rid of about 10% of the 32-bit divisions by using ec_enc_uint in energy quantisation when possible.
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -82,6 +82,51 @@
}
#endif
+/* We could use ec_enc_uint directly, but this saves some divisions */
+static inline void enc_frac(ec_enc *enc, int val, int ft)
+{
+ switch(ft)
+ {
+ case 1:
+ break;
+ case 2:
+ ec_enc_bits(enc, val, 1);
+ break;
+ case 4:
+ ec_enc_bits(enc, val, 2);
+ break;
+ case 8:
+ ec_enc_bits(enc, val, 3);
+ break;
+ default:
+ ec_enc_uint(enc, val, ft);
+ break;
+ }
+}
+
+/* We could use ec_enc_uint directly, but this saves some divisions */
+static inline int dec_frac(ec_dec *dec, int ft)
+{
+ switch(ft)
+ {
+ case 1:
+ return 0;
+ break;
+ case 2:
+ return ec_dec_bits(dec, 1);
+ break;
+ case 4:
+ return ec_dec_bits(dec, 2);
+ break;
+ case 8:
+ return ec_dec_bits(dec, 3);
+ break;
+ default:
+ return ec_dec_uint(dec, ft);
+ break;
+ }
+}
+
static const celt_word16_t base_resolution = QCONST16(6.f,8);
static void quant_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, unsigned budget, ec_enc *enc)
@@ -148,7 +193,7 @@
#endif
if (q2 > frac[i]-1)
q2 = frac[i]-1;
- ec_enc_uint(enc, q2, frac[i]);
+ enc_frac(enc, q2, frac[i]);
offset = EXTRACT16(celt_div(SHL16(q2,8)+QCONST16(.5,8),frac[i])-QCONST16(.5f,8));
oldEBands[i] += PSHR32(MULT16_16(DB_SCALING*6,offset),8);
/*printf ("%f ", error[i] - offset);*/
@@ -198,7 +243,7 @@
celt_word16_t offset;
if (ec_dec_tell(dec, 0) - bits + celt_ilog2(frac[i]) >= budget)
break;
- q2 = ec_dec_uint(dec, frac[i]);
+ q2 = dec_frac(dec, frac[i]);
offset = EXTRACT16(celt_div(SHL16(q2,8)+QCONST16(.5,8),frac[i])-QCONST16(.5f,8));
oldEBands[i] += PSHR32(MULT16_16(DB_SCALING*6,offset),8);
}
--- a/libcelt/quant_pitch.c
+++ b/libcelt/quant_pitch.c
@@ -96,7 +96,7 @@
for (i=0;i<len;i++)
gains[i] = Q15ONE-celt_sqrt(Q1515ONE-MULT16_16(gains[i],gains[i]));
id = vq_index(gains, pgain_table, len, 128);
- ec_enc_uint(enc, id, 128);
+ ec_enc_bits(enc, id, 7);
/*for (i=0;i<len;i++) printf ("%f ", pgain_table[id*len+i]);printf ("\n");*/
id2gains(id, gains, len);
return id!=0;
@@ -105,7 +105,7 @@
int unquant_pitch(celt_pgain_t *gains, int len, ec_dec *dec)
{
int id;
- id = ec_dec_uint(dec, 128);
+ id = ec_dec_bits(dec, 7);
id2gains(id, gains, len);
return id!=0;
}