[PATCH] Moved the application of the pitch gain to (un)quant_bands(). This doesn't change anything to the codec, but will make the next changes easier.

Jean-Marc Valin jean-marc.valin at usherbrooke.ca
Tue Jan 13 17:48:30 PST 2009


---
 libcelt/bands.c |   43 ++++++++++++++++++++++++-------------------
 libcelt/bands.h |    6 ++----
 libcelt/celt.c  |    6 ++----
 3 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/libcelt/bands.c b/libcelt/bands.c
index d0c3498..315cce8 100644
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -247,23 +247,6 @@ void compute_pitch_gain(const CELTMode *m, const celt_norm_t *X, const celt_norm
    }*/
 }
 
-/* Apply the (quantised) gain to each "pitch band" */
-void pitch_quant_bands(const CELTMode *m, celt_norm_t * restrict P, const celt_pgain_t * restrict gains)
-{
-   int i;
-   const celt_int16_t *pBands = m->pBands;
-   const int C = CHANNELS(m);
-   for (i=0;i<m->nbPBands;i++)
-   {
-      int j;
-      for (j=C*pBands[i];j<C*pBands[i+1];j++)
-         P[j] = MULT16_16_Q15(gains[i], P[j]);
-      /*printf ("%f ", gain);*/
-   }
-   for (i=C*pBands[m->nbPBands];i<C*pBands[m->nbPBands+1];i++)
-      P[i] = 0;
-}
-
 static void intensity_band(celt_norm_t * restrict X, int len)
 {
    int j;
@@ -352,13 +335,15 @@ void stereo_decision(const CELTMode *m, celt_norm_t * restrict X, int *stereo_mo
 
 
 /* Quantisation of the residual */
-void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, celt_mask_t *W, const celt_ener_t *bandE, const int *stereo_mode, int *pulses, int shortBlocks, int fold, int total_bits, ec_enc *enc)
+void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, celt_mask_t *W, int pitch_used, celt_pgain_t *pgains, const celt_ener_t *bandE, const int *stereo_mode, int *pulses, int shortBlocks, int fold, int total_bits, ec_enc *enc)
 {
    int i, j, remaining_bits, balance;
    const celt_int16_t * restrict eBands = m->eBands;
    celt_norm_t * restrict norm;
    VARDECL(celt_norm_t, _norm);
    const int C = CHANNELS(m);
+   const celt_int16_t *pBands = m->pBands;
+   int pband=-1;
    int B;
    SAVE_STACK;
 
@@ -414,6 +399,15 @@ void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, ce
       if ((eBands[i] >= m->pitchEnd && fold) || q<=0)
       {
          intra_fold(m, X+C*eBands[i], eBands[i+1]-eBands[i], q, norm, P+C*eBands[i], eBands[i], B);
+      } else if (pitch_used && eBands[i] < m->pitchEnd)
+      {
+         if (eBands[i] == pBands[pband+1])
+            pband++;
+         for (j=C*eBands[i];j<C*eBands[i+1];j++)
+            P[j] = MULT16_16_Q15(pgains[pband], P[j]);
+      } else {
+         for (j=C*eBands[i];j<C*eBands[i+1];j++)
+            P[j] = 0;
       }
       
       if (q > 0)
@@ -440,13 +434,15 @@ void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, ce
 }
 
 /* Decoding of the residual */
-void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, const celt_ener_t *bandE, const int *stereo_mode, int *pulses, int shortBlocks, int fold, int total_bits, ec_dec *dec)
+void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, int pitch_used, celt_pgain_t *pgains, const celt_ener_t *bandE, const int *stereo_mode, int *pulses, int shortBlocks, int fold, int total_bits, ec_dec *dec)
 {
    int i, j, remaining_bits, balance;
    const celt_int16_t * restrict eBands = m->eBands;
    celt_norm_t * restrict norm;
    VARDECL(celt_norm_t, _norm);
    const int C = CHANNELS(m);
+   const celt_int16_t *pBands = m->pBands;
+   int pband=-1;
    int B;
    SAVE_STACK;
 
@@ -497,6 +493,15 @@ void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P,
       if ((eBands[i] >= m->pitchEnd && fold) || q<=0)
       {
          intra_fold(m, X+C*eBands[i], eBands[i+1]-eBands[i], q, norm, P+C*eBands[i], eBands[i], B);
+      } else if (pitch_used && eBands[i] < m->pitchEnd)
+      {
+         if (eBands[i] == pBands[pband+1])
+            pband++;
+         for (j=C*eBands[i];j<C*eBands[i+1];j++)
+            P[j] = MULT16_16_Q15(pgains[pband], P[j]);
+      } else {
+         for (j=C*eBands[i];j<C*eBands[i+1];j++)
+            P[j] = 0;
       }
       
       if (q > 0)
diff --git a/libcelt/bands.h b/libcelt/bands.h
index dc9b471..3e4a37c 100644
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -78,8 +78,6 @@ void denormalise_bands(const CELTMode *m, const celt_norm_t * restrict X, celt_s
  */
 void compute_pitch_gain(const CELTMode *m, const celt_norm_t *X, const celt_norm_t *P, celt_pgain_t *gains);
 
-void pitch_quant_bands(const CELTMode *m, celt_norm_t * restrict P, const celt_pgain_t * restrict gains);
-
 /** Quantisation/encoding of the residual spectrum
  * @param m Mode data 
  * @param X Residual (normalised)
@@ -88,7 +86,7 @@ void pitch_quant_bands(const CELTMode *m, celt_norm_t * restrict P, const celt_p
  * @param total_bits Total number of bits that can be used for the frame (including the ones already spent)
  * @param enc Entropy encoder
  */
-void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, celt_mask_t *W, const celt_ener_t *bandE, const int *stereo_mode, int *pulses, int time_domain, int fold, int total_bits, ec_enc *enc);
+void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, celt_mask_t *W, int pitch_used, celt_pgain_t *pgains, const celt_ener_t *bandE, const int *stereo_mode, int *pulses, int time_domain, int fold, int total_bits, ec_enc *enc);
 
 /** Decoding of the residual spectrum
  * @param m Mode data 
@@ -97,7 +95,7 @@ void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, ce
  * @param total_bits Total number of bits that can be used for the frame (including the ones already spent)
  * @param dec Entropy decoder
 */
-void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, const celt_ener_t *bandE, const int *stereo_mode, int *pulses, int time_domain, int fold, int total_bits, ec_dec *dec);
+void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, int pitch_used, celt_pgain_t *pgains, const celt_ener_t *bandE, const int *stereo_mode, int *pulses, int time_domain, int fold, int total_bits, ec_dec *dec);
 
 void stereo_decision(const CELTMode *m, celt_norm_t * restrict X, int *stereo_mode, int len);
 
diff --git a/libcelt/celt.c b/libcelt/celt.c
index 9ebd8df..61aa1fb 100644
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -575,7 +575,6 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si
       ec_enc_bits(&enc, has_fold, 1); /* Folding flag */
       ec_enc_bits(&enc, id, 7);
       ec_enc_uint(&enc, pitch_index, MAX_PERIOD-(2*N-2*N4));
-      pitch_quant_bands(st->mode, P, gains);
    } else {
       if (!shortBlocks)
       {
@@ -626,7 +625,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si
    quant_fine_energy(st->mode, bandE, st->oldBandE, error, fine_quant, &enc);
 
    /* Residual quantisation */
-   quant_bands(st->mode, X, P, NULL, bandE, stereo_mode, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc);
+   quant_bands(st->mode, X, P, NULL, has_pitch, gains, bandE, stereo_mode, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc);
 
    /* Re-synthesis of the coded audio if required */
    if (st->pitch_available>0 || optional_synthesis!=NULL)
@@ -1034,14 +1033,13 @@ int celt_decode_float(CELTDecoder * restrict st, unsigned char *data, int len, c
       compute_band_energies(st->mode, freq, bandEp);
       normalise_bands(st->mode, freq, P, bandEp);
       /* Apply pitch gains */
-      pitch_quant_bands(st->mode, P, gains);
    } else {
       for (i=0;i<C*N;i++)
          P[i] = 0;
    }
 
    /* Decode fixed codebook and merge with pitch */
-   unquant_bands(st->mode, X, P, bandE, stereo_mode, pulses, shortBlocks, has_fold, len*8, &dec);
+   unquant_bands(st->mode, X, P, has_pitch, gains, bandE, stereo_mode, pulses, shortBlocks, has_fold, len*8, &dec);
 
    if (C==2)
    {
-- 
1.6.0.1


--Boundary_(ID_jgXhjYjopgINfHT8h8W/XQ)
Content-type: text/x-patch; CHARSET=US-ASCII;
 name=0002-Pitch-now-quantised-at-the-band-level-got-rid-of-al.patch
Content-transfer-encoding: 7BIT
Content-disposition: inline;
 filename=0002-Pitch-now-quantised-at-the-band-level-got-rid-of-al.patch;
 filename*0=0002-Pitch-now-quantised-at-the-band-level-got-rid-of-al.pat;
 filename*1=ch



More information about the celt-dev mailing list