ref: 7e8a487ed2e31e24d679d437b569740d825009c2
parent: cb7a2a3d52f562792c2efe81b204048ef9a5065c
author: Jean-Marc Valin <[email protected]>
date: Mon Feb 11 11:55:34 EST 2008
No longer encoding the pitch index if the gain is zero anyway.
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -201,6 +201,7 @@
int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, int nbCompressedBytes)
{
int i, c, N, B, C, N4;
+ int has_pitch;
N = st->block_size;
B = st->nb_blocks;
C = st->mode->nbChannels;
@@ -296,9 +297,10 @@
/* Pitch prediction */
compute_pitch_gain(st->mode, X, P, gains, bandE);
- quant_pitch(gains, st->mode->nbPBands, &st->enc);
+ has_pitch = quant_pitch(gains, st->mode->nbPBands, &st->enc);
- ec_enc_uint(&st->enc, pitch_index, MAX_PERIOD-(B+1)*N);
+ if (has_pitch)
+ ec_enc_uint(&st->enc, pitch_index, MAX_PERIOD-(B+1)*N);
pitch_quant_bands(st->mode, X, P, gains);
@@ -514,6 +516,7 @@
int celt_decode(CELTDecoder *st, unsigned char *data, int len, celt_int16_t *pcm)
{
int i, c, N, B, C;
+ int has_pitch;
N = st->block_size;
B = st->nb_blocks;
C = st->mode->nbChannels;
@@ -539,11 +542,17 @@
unquant_energy(st->mode, bandE, st->oldBandE, &dec);
/* Get the pitch gains */
- unquant_pitch(gains, st->mode->nbPBands, &dec);
+ has_pitch = unquant_pitch(gains, st->mode->nbPBands, &dec);
/* Get the pitch index */
- pitch_index = ec_dec_uint(&dec, MAX_PERIOD-(B+1)*N);
- st->last_pitch_index = pitch_index;
+ if (has_pitch)
+ {
+ pitch_index = ec_dec_uint(&dec, MAX_PERIOD-(B+1)*N);
+ st->last_pitch_index = pitch_index;
+ } else {
+ /* FIXME: We could be more intelligent here and just not compute the MDCT */
+ pitch_index = 0;
+ }
/* Pitch MDCT */
compute_mdcts(&st->mdct_lookup, st->window, st->out_mem+pitch_index*C, P, N, B, C);
--- a/libcelt/quant_pitch.c
+++ b/libcelt/quant_pitch.c
@@ -33,40 +33,6 @@
#include <math.h>
#include "pgain_table.h"
-static const float cdbk_pitch[]={ 0.00826816, 0.00646836, 0.00520978, 0.00632398, 0.0108199 ,
- 0.723347, 0.0985132, 0.630212, 0.0546661, 0.0246779 ,
- 0.802152, 0.759963, 0.453441, 0.384415, 0.0625198 ,
- 0.461809, 0.313537, 0.0465707, 0.0484357, 0.0196977 ,
- 0.704463, 0.117481, 0.0612584, 0.576791, 0.0273508 ,
- 0.798109, 0.743359, 0.706289, 0.0697711, 0.0386172 ,
- 0.228351, 0.0379557, 0.0285191, 0.0236265, 0.0248726 ,
- 0.114495, 0.279541, 0.038657, 0.0342054, 0.0319817 ,
- 0.609812, 0.0397131, 0.0266344, 0.0239864, 0.0212439 ,
- 0.781349, 0.493848, 0.0353301, 0.0267205, 0.0196015 ,
- 0.0819145, 0.0543806, 0.301274, 0.0507369, 0.0456495 ,
- 0.785118, 0.7315, 0.213724, 0.675786, 0.117822 ,
- 0.791656, 0.0322449, 0.0200075, 0.0203656, 0.0191236 ,
- 0.768495, 0.416117, 0.386172, 0.0510886, 0.022891 ,
- 0.802694, 0.790402, 0.755665, 0.71349, 0.401332 ,
- 0.142781, 0.122736, 0.195102, 0.587634, 0.0490036 ,
- 0.104903, 0.611318, 0.0587345, 0.0822444, 0.028738 ,
- 0.182943, 0.541788, 0.518271, 0.0920779, 0.0338024 ,
- 0.76004, 0.0553314, 0.293129, 0.0392962, 0.0191814 ,
- 0.776575, 0.257797, 0.0323301, 0.0290356, 0.0185467 ,
- 0.798177, 0.759494, 0.368838, 0.0497087, 0.0262797 ,
- 0.724, 0.0643148, 0.0435992, 0.275742, 0.0232963 ,
- 0.803454, 0.783768, 0.741939, 0.711135, 0.0950338 ,
- 0.138766, 0.0770751, 0.649913, 0.129772, 0.0342524 ,
- 0.795955, 0.754889, 0.044966, 0.0279729, 0.0199437 ,
- 0.784278, 0.659435, 0.0713927, 0.339058, 0.0384502 ,
- 0.145974, 0.049395, 0.0403857, 0.302676, 0.04925 ,
- 0.428821, 0.0640999, 0.368384, 0.0519584, 0.0224072 ,
- 0.425792, 0.0341016, 0.0290549, 0.0390711, 0.0227266 ,
- 0.453561, 0.623889, 0.0443806, 0.0432896, 0.0173471 ,
- 0.754851, 0.236843, 0.570091, 0.48421, 0.0622915 ,
- 0.804932, 0.782549, 0.752207, 0.390957, 0.102058
-};
-
/* Taken from Speex.
Finds the index of the entry in a codebook that best matches the input*/
int vq_index(float *in, const float *codebook, int len, int entries)
@@ -91,18 +57,10 @@
return best_index;
}
-void quant_pitch(float *gains, int len, ec_enc *enc)
+int quant_pitch(float *gains, int len, ec_enc *enc)
{
int i, id;
float g2[len];
-#if 0
- for (i=0;i<len;i++)
- g2[i] = gains[i]*gains[i];
- id = vq_index(g2, cdbk_pitch, len, 32);
- ec_enc_uint(enc, id, 32);
- for (i=0;i<len;i++)
- gains[i] = sqrt(cdbk_pitch[id*len+i]);
-#else
//for (i=0;i<len;i++) printf ("%f ", gains[i]);printf ("\n");
for (i=0;i<len;i++)
g2[i] = 1-sqrt(1-gains[i]*gains[i]);
@@ -111,22 +69,14 @@
//for (i=0;i<len;i++) printf ("%f ", pgain_table[id*len+i]);printf ("\n");
for (i=0;i<len;i++)
gains[i] = (sqrt(1-(1-pgain_table[id*len+i])*(1-pgain_table[id*len+i])));
- //for (i=0;i<len;i++) printf ("%f ", g2[i]);printf ("\n");
- //for (i=0;i<len;i++) printf ("%f ", gains[i]);printf ("\n");
- //printf ("\n");
-#endif
+ return id!=0;
}
-void unquant_pitch(float *gains, int len, ec_dec *dec)
+int unquant_pitch(float *gains, int len, ec_dec *dec)
{
int i, id;
-#if 0
- id = ec_dec_uint(dec, 32);
- for (i=0;i<len;i++)
- gains[i] = sqrt(cdbk_pitch[id*len+i]);
-#else
id = ec_dec_uint(dec, 128);
for (i=0;i<len;i++)
gains[i] = (sqrt(1-(1-pgain_table[id*len+i])*(1-pgain_table[id*len+i])));
-#endif
+ return id!=0;
}
--- a/libcelt/quant_pitch.h
+++ b/libcelt/quant_pitch.h
@@ -35,9 +35,10 @@
#include "entenc.h"
#include "entdec.h"
-void quant_pitch(float *gains, int len, ec_enc *enc);
+/* If this returns 0, the gain is zero (don't encode the pitch index) */
+int quant_pitch(float *gains, int len, ec_enc *enc);
-
-void unquant_pitch(float *gains, int len, ec_dec *dec);
+/* If this returns 0, the gain is zero (don't decode the pitch index) */
+int unquant_pitch(float *gains, int len, ec_dec *dec);
#endif /* QUANT_PITCH_H */