Completed the separation of coarse and fine energy quantisation

This commit is contained in:
Jean-Marc Valin 2008-08-01 22:26:49 -04:00
parent 7364e758ed
commit c890b58b69
3 changed files with 81 additions and 35 deletions

View file

@ -361,6 +361,7 @@ int celt_encode(CELTEncoder * restrict st, celt_int16_t * restrict pcm, unsigned
int i, c, N, N4; int i, c, N, N4;
int has_pitch; int has_pitch;
int pitch_index; int pitch_index;
int bits;
celt_word32_t curr_power, pitch_power; celt_word32_t curr_power, pitch_power;
VARDECL(celt_sig_t, in); VARDECL(celt_sig_t, in);
VARDECL(celt_sig_t, freq); VARDECL(celt_sig_t, freq);
@ -369,6 +370,8 @@ int celt_encode(CELTEncoder * restrict st, celt_int16_t * restrict pcm, unsigned
VARDECL(celt_ener_t, bandE); VARDECL(celt_ener_t, bandE);
VARDECL(celt_pgain_t, gains); VARDECL(celt_pgain_t, gains);
VARDECL(int, stereo_mode); VARDECL(int, stereo_mode);
VARDECL(celt_int16_t, fine_quant);
VARDECL(celt_word16_t, error);
#ifdef EXP_PSY #ifdef EXP_PSY
VARDECL(celt_word32_t, mask); VARDECL(celt_word32_t, mask);
#endif #endif
@ -525,7 +528,13 @@ int celt_encode(CELTEncoder * restrict st, celt_int16_t * restrict pcm, unsigned
for (i=0;i<C*N;i++) for (i=0;i<C*N;i++)
P[i] = 0; P[i] = 0;
} }
quant_energy(st->mode, bandE, st->oldBandE, 20*C+nbCompressedBytes*8/5, st->mode->prob, &st->enc);
ALLOC(fine_quant, st->mode->nbEBands, celt_int16_t);
ALLOC(error, C*st->mode->nbEBands, celt_word16_t);
bits = ec_enc_tell(&st->enc, 0);
quant_coarse_energy(st->mode, bandE, st->oldBandE, 20*C+nbCompressedBytes*8, st->mode->prob, error, &st->enc);
compute_fine_allocation(st->mode, fine_quant, (20*C+nbCompressedBytes*8/5-(ec_enc_tell(&st->enc, 0)-bits))/C);
quant_fine_energy(st->mode, bandE, st->oldBandE, error, fine_quant, &st->enc);
ALLOC(stereo_mode, st->mode->nbEBands, int); ALLOC(stereo_mode, st->mode->nbEBands, int);
stereo_decision(st->mode, X, stereo_mode, st->mode->nbEBands); stereo_decision(st->mode, X, stereo_mode, st->mode->nbEBands);
@ -735,6 +744,7 @@ int celt_decode(CELTDecoder * restrict st, unsigned char *data, int len, celt_in
int c, N, N4; int c, N, N4;
int has_pitch; int has_pitch;
int pitch_index; int pitch_index;
int bits;
ec_dec dec; ec_dec dec;
ec_byte_buffer buf; ec_byte_buffer buf;
VARDECL(celt_sig_t, freq); VARDECL(celt_sig_t, freq);
@ -743,6 +753,8 @@ int celt_decode(CELTDecoder * restrict st, unsigned char *data, int len, celt_in
VARDECL(celt_ener_t, bandE); VARDECL(celt_ener_t, bandE);
VARDECL(celt_pgain_t, gains); VARDECL(celt_pgain_t, gains);
VARDECL(int, stereo_mode); VARDECL(int, stereo_mode);
VARDECL(celt_int16_t, fine_quant);
int shortBlocks; int shortBlocks;
int transient_time; int transient_time;
int transient_shift; int transient_shift;
@ -808,8 +820,12 @@ int celt_decode(CELTDecoder * restrict st, unsigned char *data, int len, celt_in
pitch_index = 0; pitch_index = 0;
} }
ALLOC(fine_quant, st->mode->nbEBands, celt_int16_t);
bits = ec_dec_tell(&dec, 0);
/* Get band energies */ /* Get band energies */
unquant_energy(st->mode, bandE, st->oldBandE, 20*C+len*8/5, st->mode->prob, &dec); unquant_coarse_energy(st->mode, bandE, st->oldBandE, 20*C+len*8, st->mode->prob, &dec);
compute_fine_allocation(st->mode, fine_quant, (20*C+len*8/5-(ec_dec_tell(&dec, 0)-bits))/C);
unquant_fine_energy(st->mode, bandE, st->oldBandE, fine_quant, &dec);
/* Pitch MDCT */ /* Pitch MDCT */
compute_mdcts(st->mode, 0, st->out_mem+pitch_index*C, freq); compute_mdcts(st->mode, 0, st->out_mem+pitch_index*C, freq);

View file

@ -50,7 +50,7 @@ const celt_word16_t eMeans[24] = {45.f, -8.f, -12.f, -2.5f, 1.f, 0.f, 0.f, 0.f,
/*const int frac[24] = {4, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};*/ /*const int frac[24] = {4, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};*/
/*const int frac[24] = {8, 6, 5, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};*/ /*const int frac[24] = {8, 6, 5, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};*/
static void compute_fine_allocation(const CELTMode *m, celt_int16_t *bits, int budget) void compute_fine_allocation(const CELTMode *m, celt_int16_t *bits, int budget)
{ {
int i,j; int i,j;
int len; int len;
@ -274,22 +274,38 @@ static void unquant_fine_energy_mono(const CELTMode *m, celt_ener_t *eBands, cel
void quant_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, int *prob, ec_enc *enc) 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)
{ {
int C; int C;
VARDECL(celt_int16_t, fine_quant);
VARDECL(celt_word16_t, error);
SAVE_STACK;
ALLOC(fine_quant, m->nbEBands, celt_int16_t);
ALLOC(error, m->nbEBands, celt_word16_t);
C = m->nbChannels; C = m->nbChannels;
if (C==1) if (C==1)
{ {
int bits = ec_enc_tell(enc, 0);
quant_coarse_energy_mono(m, eBands, oldEBands, budget, prob, error, enc); quant_coarse_energy_mono(m, eBands, oldEBands, budget, prob, error, enc);
compute_fine_allocation(m, fine_quant, budget-(ec_enc_tell(enc, 0)-bits));
} else {
int c;
for (c=0;c<C;c++)
{
int i;
VARDECL(celt_ener_t, E);
SAVE_STACK;
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);
}
RESTORE_STACK;
}
}
void quant_fine_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, celt_word16_t *error, celt_int16_t *fine_quant, ec_enc *enc)
{
int C;
C = m->nbChannels;
if (C==1)
{
quant_fine_energy_mono(m, eBands, oldEBands, error, fine_quant, enc); quant_fine_energy_mono(m, eBands, oldEBands, error, fine_quant, enc);
} else { } else {
@ -298,53 +314,61 @@ void quant_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBan
ALLOC(E, m->nbEBands, celt_ener_t); ALLOC(E, m->nbEBands, celt_ener_t);
for (c=0;c<C;c++) for (c=0;c<C;c++)
{ {
int i, bits; int i;
for (i=0;i<m->nbEBands;i++) SAVE_STACK;
E[i] = eBands[C*i+c]; quant_fine_energy_mono(m, E, oldEBands+c*m->nbEBands, error+c*m->nbEBands, fine_quant, enc);
bits = ec_enc_tell(enc, 0);
quant_coarse_energy_mono(m, E, oldEBands+c*m->nbEBands, budget/C, prob, error, enc);
compute_fine_allocation(m, fine_quant, budget/C-(ec_enc_tell(enc, 0)-bits));
quant_fine_energy_mono(m, E, oldEBands+c*m->nbEBands, error, fine_quant, enc);
for (i=0;i<m->nbEBands;i++) for (i=0;i<m->nbEBands;i++)
eBands[C*i+c] = E[i]; eBands[C*i+c] = E[i];
} }
}
RESTORE_STACK; RESTORE_STACK;
}
} }
void unquant_coarse_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, int *prob, ec_dec *dec)
void unquant_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, int *prob, ec_dec *dec) {
int C;
C = m->nbChannels;
if (C==1)
{
unquant_coarse_energy_mono(m, eBands, oldEBands, budget, prob, dec);
}
else {
int c;
VARDECL(celt_ener_t, E);
SAVE_STACK;
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);
}
RESTORE_STACK;
}
}
void unquant_fine_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, celt_int16_t *fine_quant, ec_dec *dec)
{ {
int C; int C;
VARDECL(celt_int16_t, fine_quant);
SAVE_STACK;
C = m->nbChannels; C = m->nbChannels;
ALLOC(fine_quant, m->nbEBands, celt_int16_t);
if (C==1) if (C==1)
{ {
int bits = ec_dec_tell(dec, 0);
unquant_coarse_energy_mono(m, eBands, oldEBands, budget, prob, dec);
compute_fine_allocation(m, fine_quant, budget-(ec_dec_tell(dec, 0)-bits));
unquant_fine_energy_mono(m, eBands, oldEBands, fine_quant, dec); unquant_fine_energy_mono(m, eBands, oldEBands, fine_quant, dec);
} }
else { else {
int c; int c;
VARDECL(celt_ener_t, E); VARDECL(celt_ener_t, E);
SAVE_STACK;
ALLOC(E, m->nbEBands, celt_ener_t); ALLOC(E, m->nbEBands, celt_ener_t);
for (c=0;c<C;c++) for (c=0;c<C;c++)
{ {
int i; int i;
int bits = ec_dec_tell(dec, 0);
unquant_coarse_energy_mono(m, E, oldEBands+c*m->nbEBands, budget/C, prob, dec);
compute_fine_allocation(m, fine_quant, budget/C-(ec_dec_tell(dec, 0)-bits));
unquant_fine_energy_mono(m, E, oldEBands+c*m->nbEBands, fine_quant, dec); unquant_fine_energy_mono(m, E, oldEBands+c*m->nbEBands, fine_quant, dec);
//unquant_energy_mono(m, E, oldEBands+c*m->nbEBands, budget/C, prob, dec);
for (i=0;i<m->nbEBands;i++) for (i=0;i<m->nbEBands;i++)
eBands[C*i+c] = E[i]; eBands[C*i+c] = E[i];
} }
}
RESTORE_STACK; RESTORE_STACK;
}
} }

View file

@ -40,8 +40,14 @@
int *quant_prob_alloc(const CELTMode *m); int *quant_prob_alloc(const CELTMode *m);
void quant_prob_free(int *freq); void quant_prob_free(int *freq);
void quant_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, int *prob, ec_enc *enc); void compute_fine_allocation(const CELTMode *m, celt_int16_t *bits, int budget);
void unquant_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, int *prob, ec_dec *dec); 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_fine_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, celt_word16_t *error, celt_int16_t *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_fine_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, celt_int16_t *fine_quant, ec_dec *dec);
#endif /* QUANT_BANDS */ #endif /* QUANT_BANDS */