Minor pitch handling cleanups.
This commit is contained in:
parent
8256ed4cf7
commit
abe40f02a9
3 changed files with 33 additions and 49 deletions
|
@ -372,6 +372,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si
|
||||||
#endif
|
#endif
|
||||||
int i, c, N, N4;
|
int i, c, N, N4;
|
||||||
int has_pitch;
|
int has_pitch;
|
||||||
|
int id;
|
||||||
int pitch_index;
|
int pitch_index;
|
||||||
int bits;
|
int bits;
|
||||||
int has_fold=1;
|
int has_fold=1;
|
||||||
|
@ -554,27 +555,24 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si
|
||||||
|
|
||||||
/* Check if we can safely use the pitch (i.e. effective gain isn't too high) */
|
/* Check if we can safely use the pitch (i.e. effective gain isn't too high) */
|
||||||
curr_power = bandE[0]+bandE[1]+bandE[2];
|
curr_power = bandE[0]+bandE[1]+bandE[2];
|
||||||
|
has_pitch = 0;
|
||||||
if (st->pitch_enabled && !shortBlocks && (MULT16_32_Q15(QCONST16(.1f, 15),curr_power) + QCONST32(10.f,ENER_SHIFT) < pitch_power))
|
if (st->pitch_enabled && !shortBlocks && (MULT16_32_Q15(QCONST16(.1f, 15),curr_power) + QCONST32(10.f,ENER_SHIFT) < pitch_power))
|
||||||
{
|
{
|
||||||
int id;
|
|
||||||
|
|
||||||
/* Pitch prediction */
|
/* Pitch prediction */
|
||||||
compute_pitch_gain(st->mode, X, P, gains);
|
compute_pitch_gain(st->mode, X, P, gains);
|
||||||
id = quant_pitch(gains, st->mode->nbPBands, &enc);
|
id = quant_pitch(gains, st->mode->nbPBands);
|
||||||
if (id != -1)
|
if (id > -1)
|
||||||
has_pitch = 1;
|
has_pitch = 1;
|
||||||
else
|
}
|
||||||
has_pitch = 0;
|
|
||||||
|
if (has_pitch)
|
||||||
|
{
|
||||||
|
unquant_pitch(id, gains, st->mode->nbPBands);
|
||||||
ec_enc_bits(&enc, has_pitch, 1); /* Pitch flag */
|
ec_enc_bits(&enc, has_pitch, 1); /* Pitch flag */
|
||||||
if (has_pitch)
|
ec_enc_bits(&enc, has_fold, 1); /* Folding flag */
|
||||||
{
|
ec_enc_bits(&enc, id, 7);
|
||||||
ec_enc_bits(&enc, has_fold, 1); /* Folding flag */
|
ec_enc_uint(&enc, pitch_index, MAX_PERIOD-(2*N-2*N4));
|
||||||
ec_enc_bits(&enc, id, 7);
|
pitch_quant_bands(st->mode, P, gains);
|
||||||
ec_enc_uint(&enc, pitch_index, MAX_PERIOD-(2*N-2*N4));
|
|
||||||
} else if (st->mode->nbShortMdcts > 1) {
|
|
||||||
ec_enc_bits(&enc, 0, 1); /* Transient off */
|
|
||||||
has_fold = 1;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!shortBlocks)
|
if (!shortBlocks)
|
||||||
{
|
{
|
||||||
|
@ -624,8 +622,6 @@ 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);
|
quant_fine_energy(st->mode, bandE, st->oldBandE, error, fine_quant, &enc);
|
||||||
|
|
||||||
pitch_quant_bands(st->mode, P, gains);
|
|
||||||
|
|
||||||
/* Residual quantisation */
|
/* 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, bandE, stereo_mode, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc);
|
||||||
|
|
||||||
|
@ -972,16 +968,16 @@ int celt_decode_float(CELTDecoder * restrict st, unsigned char *data, int len, c
|
||||||
transient_time = -1;
|
transient_time = -1;
|
||||||
transient_shift = 0;
|
transient_shift = 0;
|
||||||
}
|
}
|
||||||
/* Get the pitch gains */
|
|
||||||
|
|
||||||
/* Get the pitch index */
|
|
||||||
if (has_pitch)
|
if (has_pitch)
|
||||||
{
|
{
|
||||||
has_pitch = unquant_pitch(gains, st->mode->nbPBands, &dec);
|
int id;
|
||||||
|
/* Get the pitch gains and index */
|
||||||
|
id = ec_dec_bits(&dec, 7);
|
||||||
|
unquant_pitch(id, gains, st->mode->nbPBands);
|
||||||
pitch_index = ec_dec_uint(&dec, MAX_PERIOD-(2*N-2*N4));
|
pitch_index = ec_dec_uint(&dec, MAX_PERIOD-(2*N-2*N4));
|
||||||
st->last_pitch_index = pitch_index;
|
st->last_pitch_index = pitch_index;
|
||||||
} else {
|
} else {
|
||||||
/* FIXME: We could be more intelligent here and just not compute the MDCT */
|
|
||||||
pitch_index = 0;
|
pitch_index = 0;
|
||||||
for (i=0;i<st->mode->nbPBands;i++)
|
for (i=0;i<st->mode->nbPBands;i++)
|
||||||
gains[i] = 0;
|
gains[i] = 0;
|
||||||
|
@ -1016,14 +1012,13 @@ int celt_decode_float(CELTDecoder * restrict st, unsigned char *data, int len, c
|
||||||
ALLOC(bandEp, st->mode->nbEBands*C, celt_ener_t);
|
ALLOC(bandEp, st->mode->nbEBands*C, celt_ener_t);
|
||||||
compute_band_energies(st->mode, freq, bandEp);
|
compute_band_energies(st->mode, freq, bandEp);
|
||||||
normalise_bands(st->mode, freq, P, bandEp);
|
normalise_bands(st->mode, freq, P, bandEp);
|
||||||
|
/* Apply pitch gains */
|
||||||
|
pitch_quant_bands(st->mode, P, gains);
|
||||||
} else {
|
} else {
|
||||||
for (i=0;i<C*N;i++)
|
for (i=0;i<C*N;i++)
|
||||||
P[i] = 0;
|
P[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply pitch gains */
|
|
||||||
pitch_quant_bands(st->mode, P, gains);
|
|
||||||
|
|
||||||
/* Decode fixed codebook and merge with pitch */
|
/* 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, bandE, stereo_mode, pulses, shortBlocks, has_fold, len*8, &dec);
|
||||||
|
|
||||||
|
|
|
@ -84,15 +84,7 @@ int vq_index(const celt_pgain_t *in, const celt_uint16_t *codebook, int len, int
|
||||||
return best_index;
|
return best_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the pitch gain vector corresponding to a certain id */
|
int quant_pitch(celt_pgain_t *gains, int len)
|
||||||
static void id2gains(int id, celt_pgain_t *gains, int len)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i=0;i<len;i++)
|
|
||||||
gains[i] = celt_sqrt(Q1515ONE-MULT16_16(Q15ONE-PGAIN(pgain_table,id*len+i),Q15ONE-PGAIN(pgain_table,id*len+i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
int quant_pitch(celt_pgain_t *gains, int len, ec_enc *enc)
|
|
||||||
{
|
{
|
||||||
int i, id;
|
int i, id;
|
||||||
celt_word32_t gain_sum = 0;
|
celt_word32_t gain_sum = 0;
|
||||||
|
@ -107,21 +99,19 @@ int quant_pitch(celt_pgain_t *gains, int len, ec_enc *enc)
|
||||||
if (gain_sum > QCONST32(.3f,15))
|
if (gain_sum > QCONST32(.3f,15))
|
||||||
{
|
{
|
||||||
id = vq_index(gains, pgain_table, len, 128);
|
id = vq_index(gains, pgain_table, len, 128);
|
||||||
|
/* FIXME: Remove when we're not waisting a transmitted index on 0 gains */
|
||||||
|
if (id==0)
|
||||||
|
id = -1;
|
||||||
} else {
|
} else {
|
||||||
id = 0;
|
id = -1;
|
||||||
}
|
}
|
||||||
/*for (i=0;i<len;i++) printf ("%f ", pgain_table[id*len+i]);printf ("\n");*/
|
return id;
|
||||||
id2gains(id, gains, len);
|
|
||||||
if (id != 0)
|
|
||||||
return id;
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int unquant_pitch(celt_pgain_t *gains, int len, ec_dec *dec)
|
/** Returns the pitch gain vector corresponding to a certain id */
|
||||||
|
void unquant_pitch(int id, celt_pgain_t *gains, int len)
|
||||||
{
|
{
|
||||||
int id;
|
int i;
|
||||||
id = ec_dec_bits(dec, 7);
|
for (i=0;i<len;i++)
|
||||||
id2gains(id, gains, len);
|
gains[i] = celt_sqrt(Q1515ONE-MULT16_16(Q15ONE-PGAIN(pgain_table,id*len+i),Q15ONE-PGAIN(pgain_table,id*len+i)));
|
||||||
return id!=0;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,9 @@
|
||||||
#include "entenc.h"
|
#include "entenc.h"
|
||||||
#include "entdec.h"
|
#include "entdec.h"
|
||||||
|
|
||||||
/** If this returns 0, the gain is zero (don't encode the pitch index) */
|
/** If this returns -1, the gain is zero (don't encode the pitch index) */
|
||||||
int quant_pitch(celt_pgain_t *gains, int len, ec_enc *enc);
|
int quant_pitch(celt_pgain_t *gains, int len);
|
||||||
|
|
||||||
/** If this returns 0, the gain is zero (don't decode the pitch index) */
|
void unquant_pitch(int id, celt_pgain_t *gains, int len);
|
||||||
int unquant_pitch(celt_pgain_t *gains, int len, ec_dec *dec);
|
|
||||||
|
|
||||||
#endif /* QUANT_PITCH_H */
|
#endif /* QUANT_PITCH_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue