Add support for intra-coding of the coarse energy.
This commit is contained in:
parent
a8be38a376
commit
18a3b79d24
3 changed files with 35 additions and 17 deletions
|
@ -457,6 +457,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si
|
||||||
VARDECL(celt_word32_t, bandM);
|
VARDECL(celt_word32_t, bandM);
|
||||||
VARDECL(celt_ener_t, bandN);
|
VARDECL(celt_ener_t, bandN);
|
||||||
#endif
|
#endif
|
||||||
|
int intra_ener = 0;
|
||||||
int shortBlocks=0;
|
int shortBlocks=0;
|
||||||
int transient_time;
|
int transient_time;
|
||||||
int transient_shift;
|
int transient_shift;
|
||||||
|
@ -537,7 +538,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si
|
||||||
|
|
||||||
/* Pitch analysis: we do it early to save on the peak stack space */
|
/* 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 */
|
/* 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
|
#ifdef EXP_PSY
|
||||||
ALLOC(tonality, MAX_PERIOD/4, celt_word16_t);
|
ALLOC(tonality, MAX_PERIOD/4, celt_word16_t);
|
||||||
{
|
{
|
||||||
|
@ -624,7 +625,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
encode_flags(&enc, 0, has_pitch, shortBlocks, has_fold);
|
encode_flags(&enc, intra_ener, has_pitch, shortBlocks, has_fold);
|
||||||
if (has_pitch)
|
if (has_pitch)
|
||||||
{
|
{
|
||||||
ec_enc_uint(&enc, pitch_index, MAX_PERIOD-(2*N-2*N4));
|
ec_enc_uint(&enc, pitch_index, MAX_PERIOD-(2*N-2*N4));
|
||||||
|
@ -660,7 +661,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si
|
||||||
|
|
||||||
/* Bit allocation */
|
/* Bit allocation */
|
||||||
ALLOC(error, C*st->mode->nbEBands, celt_word16_t);
|
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(offsets, st->mode->nbEBands, int);
|
||||||
ALLOC(stereo_mode, st->mode->nbEBands, int);
|
ALLOC(stereo_mode, st->mode->nbEBands, int);
|
||||||
|
@ -1060,7 +1061,7 @@ int celt_decode_float(CELTDecoder * restrict st, const unsigned char *data, int
|
||||||
|
|
||||||
ALLOC(fine_quant, st->mode->nbEBands, int);
|
ALLOC(fine_quant, st->mode->nbEBands, int);
|
||||||
/* Get band energies */
|
/* 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(pulses, st->mode->nbEBands, int);
|
||||||
ALLOC(offsets, st->mode->nbEBands, int);
|
ALLOC(offsets, st->mode->nbEBands, int);
|
||||||
|
|
|
@ -91,12 +91,17 @@ int *quant_prob_alloc(const CELTMode *m)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int *prob;
|
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++)
|
for (i=0;i<m->nbEBands;i++)
|
||||||
{
|
{
|
||||||
prob[2*i] = 6000-i*200;
|
prob[2*i] = 6000-i*200;
|
||||||
prob[2*i+1] = ec_laplace_get_start_freq(prob[2*i]);
|
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;
|
return prob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,13 +110,19 @@ void quant_prob_free(int *freq)
|
||||||
celt_free(freq);
|
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;
|
int i;
|
||||||
unsigned bits;
|
unsigned bits;
|
||||||
celt_word16_t prev = 0;
|
celt_word16_t prev = 0;
|
||||||
celt_word16_t coef = m->ePredCoef;
|
celt_word16_t coef = m->ePredCoef;
|
||||||
celt_word16_t beta;
|
celt_word16_t beta;
|
||||||
|
|
||||||
|
if (intra)
|
||||||
|
{
|
||||||
|
coef = 0;
|
||||||
|
prob += 2*m->nbEBands;
|
||||||
|
}
|
||||||
/* The .8 is a heuristic */
|
/* The .8 is a heuristic */
|
||||||
beta = MULT16_16_Q15(QCONST16(.8f,15),coef);
|
beta = MULT16_16_Q15(QCONST16(.8f,15),coef);
|
||||||
|
|
||||||
|
@ -190,14 +201,21 @@ static void quant_fine_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_
|
||||||
/*printf ("\n");*/
|
/*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;
|
int i;
|
||||||
unsigned bits;
|
unsigned bits;
|
||||||
celt_word16_t prev = 0;
|
celt_word16_t prev = 0;
|
||||||
celt_word16_t coef = m->ePredCoef;
|
celt_word16_t coef = m->ePredCoef;
|
||||||
|
celt_word16_t beta;
|
||||||
|
|
||||||
|
if (intra)
|
||||||
|
{
|
||||||
|
coef = 0;
|
||||||
|
prob += 2*m->nbEBands;
|
||||||
|
}
|
||||||
/* The .8 is a heuristic */
|
/* 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);
|
bits = ec_dec_tell(dec, 0);
|
||||||
/* Decode at a fixed coarse resolution */
|
/* Decode at a fixed coarse resolution */
|
||||||
|
@ -249,15 +267,14 @@ static void unquant_fine_energy_mono(const CELTMode *m, celt_ener_t *eBands, cel
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
int C;
|
||||||
C = m->nbChannels;
|
C = m->nbChannels;
|
||||||
|
|
||||||
if (C==1)
|
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 {
|
} else {
|
||||||
int c;
|
int c;
|
||||||
for (c=0;c<C;c++)
|
for (c=0;c<C;c++)
|
||||||
|
@ -268,7 +285,7 @@ void quant_coarse_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *
|
||||||
ALLOC(E, m->nbEBands, celt_ener_t);
|
ALLOC(E, m->nbEBands, celt_ener_t);
|
||||||
for (i=0;i<m->nbEBands;i++)
|
for (i=0;i<m->nbEBands;i++)
|
||||||
E[i] = eBands[C*i+c];
|
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;
|
RESTORE_STACK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -300,14 +317,14 @@ void quant_fine_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *ol
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
int C;
|
||||||
|
|
||||||
C = m->nbChannels;
|
C = m->nbChannels;
|
||||||
if (C==1)
|
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 {
|
else {
|
||||||
int c;
|
int c;
|
||||||
|
@ -316,7 +333,7 @@ void unquant_coarse_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t
|
||||||
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++)
|
||||||
{
|
{
|
||||||
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;
|
RESTORE_STACK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,11 @@ void quant_prob_free(int *freq);
|
||||||
|
|
||||||
void compute_fine_allocation(const CELTMode *m, int *bits, int budget);
|
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 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);
|
void unquant_fine_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int *fine_quant, ec_dec *dec);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue