ref: 77c80ce524825686501953602ce13b4e9da96d05
parent: 41d819d36a45fb213ae63a45de22fc0258004b09
author: Jean-Marc Valin <[email protected]>
date: Tue Jan 13 15:48:30 EST 2009
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.
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -247,23 +247,6 @@
}*/
}
-/* 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,7 +335,7 @@
/* 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;
@@ -359,6 +342,8 @@
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 @@
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,7 +434,7 @@
}
/* 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;
@@ -447,6 +441,8 @@
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 @@
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)
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -78,8 +78,6 @@
*/
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 @@
* @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 @@
* @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);
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -575,7 +575,6 @@
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 @@
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,7 +1033,6 @@
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;
@@ -1041,7 +1039,7 @@
}
/* 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)
{