ref: 18a3b79d24cf322b0ec7eec4867a1bc99d3fd1d7
parent: a8be38a3769e9f0f1766be5891db46051a1c961a
author: Jean-Marc Valin <[email protected]>
date: Fri May 1 15:58:55 EDT 2009
Add support for intra-coding of the coarse energy.
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -457,6 +457,7 @@
VARDECL(celt_word32_t, bandM);
VARDECL(celt_ener_t, bandN);
#endif
+ int intra_ener = 0;
int shortBlocks=0;
int transient_time;
int transient_shift;
@@ -537,7 +538,7 @@
/* Pitch analysis: we do it early to save on the peak stack space */
/* Don't use pitch if there isn't enough data available yet, or if we're using shortBlocks */
- has_pitch = st->pitch_enabled && (st->pitch_available >= MAX_PERIOD) && (!shortBlocks);
+ has_pitch = st->pitch_enabled && (st->pitch_available >= MAX_PERIOD) && (!shortBlocks) && !intra_ener;
#ifdef EXP_PSY
ALLOC(tonality, MAX_PERIOD/4, celt_word16_t);
{
@@ -624,7 +625,7 @@
}
}
- encode_flags(&enc, 0, has_pitch, shortBlocks, has_fold);
+ encode_flags(&enc, intra_ener, has_pitch, shortBlocks, has_fold);
if (has_pitch)
{
ec_enc_uint(&enc, pitch_index, MAX_PERIOD-(2*N-2*N4));
@@ -660,7 +661,7 @@
/* Bit allocation */
ALLOC(error, C*st->mode->nbEBands, celt_word16_t);
- quant_coarse_energy(st->mode, bandE, st->oldBandE, nbCompressedBytes*8/3, st->mode->prob, error, &enc);
+ quant_coarse_energy(st->mode, bandE, st->oldBandE, nbCompressedBytes*8/3, intra_ener, st->mode->prob, error, &enc);
ALLOC(offsets, st->mode->nbEBands, int);
ALLOC(stereo_mode, st->mode->nbEBands, int);
@@ -1060,7 +1061,7 @@
ALLOC(fine_quant, st->mode->nbEBands, int);
/* Get band energies */
- unquant_coarse_energy(st->mode, bandE, st->oldBandE, len*8/3, st->mode->prob, &dec);
+ unquant_coarse_energy(st->mode, bandE, st->oldBandE, len*8/3, intra_ener, st->mode->prob, &dec);
ALLOC(pulses, st->mode->nbEBands, int);
ALLOC(offsets, st->mode->nbEBands, int);
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -91,12 +91,17 @@
{
int i;
int *prob;
- prob = celt_alloc(2*m->nbEBands*sizeof(int));
+ prob = celt_alloc(4*m->nbEBands*sizeof(int));
for (i=0;i<m->nbEBands;i++)
{
prob[2*i] = 6000-i*200;
prob[2*i+1] = ec_laplace_get_start_freq(prob[2*i]);
}
+ for (i=0;i<m->nbEBands;i++)
+ {
+ prob[2*m->nbEBands+2*i] = 9000-i*240;
+ prob[2*m->nbEBands+2*i+1] = ec_laplace_get_start_freq(prob[2*m->nbEBands+2*i]);
+ }
return prob;
}
@@ -105,7 +110,7 @@
celt_free(freq);
}
-static void quant_coarse_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, unsigned budget, int *prob, celt_word16_t *error, ec_enc *enc)
+static void quant_coarse_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, unsigned budget, int intra, int *prob, celt_word16_t *error, ec_enc *enc)
{
int i;
unsigned bits;
@@ -112,6 +117,12 @@
celt_word16_t prev = 0;
celt_word16_t coef = m->ePredCoef;
celt_word16_t beta;
+
+ if (intra)
+ {
+ coef = 0;
+ prob += 2*m->nbEBands;
+ }
/* The .8 is a heuristic */
beta = MULT16_16_Q15(QCONST16(.8f,15),coef);
@@ -190,14 +201,21 @@
/*printf ("\n");*/
}
-static void unquant_coarse_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, unsigned budget, int *prob, ec_dec *dec)
+static void unquant_coarse_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, unsigned budget, int intra, int *prob, ec_dec *dec)
{
int i;
unsigned bits;
celt_word16_t prev = 0;
celt_word16_t coef = m->ePredCoef;
+ celt_word16_t beta;
+
+ if (intra)
+ {
+ coef = 0;
+ prob += 2*m->nbEBands;
+ }
/* The .8 is a heuristic */
- celt_word16_t beta = MULT16_16_Q15(QCONST16(.8f,15),coef);
+ beta = MULT16_16_Q15(QCONST16(.8f,15),coef);
bits = ec_dec_tell(dec, 0);
/* Decode at a fixed coarse resolution */
@@ -249,7 +267,7 @@
-void quant_coarse_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, int *prob, celt_word16_t *error, ec_enc *enc)
+void quant_coarse_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, int intra, int *prob, celt_word16_t *error, ec_enc *enc)
{
int C;
C = m->nbChannels;
@@ -256,8 +274,7 @@
if (C==1)
{
- quant_coarse_energy_mono(m, eBands, oldEBands, budget, prob, error, enc);
-
+ quant_coarse_energy_mono(m, eBands, oldEBands, budget, intra, prob, error, enc);
} else {
int c;
for (c=0;c<C;c++)
@@ -268,7 +285,7 @@
ALLOC(E, m->nbEBands, celt_ener_t);
for (i=0;i<m->nbEBands;i++)
E[i] = eBands[C*i+c];
- quant_coarse_energy_mono(m, E, oldEBands+c*m->nbEBands, budget/C, prob, error+c*m->nbEBands, enc);
+ quant_coarse_energy_mono(m, E, oldEBands+c*m->nbEBands, budget/C, intra, prob, error+c*m->nbEBands, enc);
RESTORE_STACK;
}
}
@@ -300,7 +317,7 @@
}
-void unquant_coarse_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, int *prob, ec_dec *dec)
+void unquant_coarse_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, int intra, int *prob, ec_dec *dec)
{
int C;
@@ -307,7 +324,7 @@
C = m->nbChannels;
if (C==1)
{
- unquant_coarse_energy_mono(m, eBands, oldEBands, budget, prob, dec);
+ unquant_coarse_energy_mono(m, eBands, oldEBands, budget, intra, prob, dec);
}
else {
int c;
@@ -316,7 +333,7 @@
ALLOC(E, m->nbEBands, celt_ener_t);
for (c=0;c<C;c++)
{
- unquant_coarse_energy_mono(m, E, oldEBands+c*m->nbEBands, budget/C, prob, dec);
+ unquant_coarse_energy_mono(m, E, oldEBands+c*m->nbEBands, budget/C, intra, prob, dec);
}
RESTORE_STACK;
}
--- a/libcelt/quant_bands.h
+++ b/libcelt/quant_bands.h
@@ -42,11 +42,11 @@
void compute_fine_allocation(const CELTMode *m, int *bits, int budget);
-void quant_coarse_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, int *prob, celt_word16_t *error, ec_enc *enc);
+void quant_coarse_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, int intra, int *prob, celt_word16_t *error, ec_enc *enc);
void quant_fine_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, celt_word16_t *error, int *fine_quant, ec_enc *enc);
-void unquant_coarse_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, int *prob, ec_dec *dec);
+void unquant_coarse_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, int intra, int *prob, ec_dec *dec);
void unquant_fine_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int *fine_quant, ec_dec *dec);