Skip to content
Snippets Groups Projects
Commit abe40f02 authored by Gregory Maxwell's avatar Gregory Maxwell
Browse files

Minor pitch handling cleanups.

parent 8256ed4c
No related branches found
No related tags found
No related merge requests found
......@@ -372,6 +372,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si
#endif
int i, c, N, N4;
int has_pitch;
int id;
int pitch_index;
int bits;
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) */
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))
{
int id;
/* Pitch prediction */
compute_pitch_gain(st->mode, X, P, gains);
id = quant_pitch(gains, st->mode->nbPBands, &enc);
if (id != -1)
id = quant_pitch(gains, st->mode->nbPBands);
if (id > -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 */
if (has_pitch)
{
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));
} else if (st->mode->nbShortMdcts > 1) {
ec_enc_bits(&enc, 0, 1); /* Transient off */
has_fold = 1;
}
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)
{
......@@ -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);
pitch_quant_bands(st->mode, P, gains);
/* Residual quantisation */
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_shift = 0;
}
/* Get the pitch gains */
/* Get the pitch index */
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));
st->last_pitch_index = pitch_index;
} else {
/* FIXME: We could be more intelligent here and just not compute the MDCT */
pitch_index = 0;
for (i=0;i<st->mode->nbPBands;i++)
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);
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;
}
/* Apply pitch gains */
pitch_quant_bands(st->mode, P, gains);
/* Decode fixed codebook and merge with pitch */
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;
}
/** Returns the pitch gain vector corresponding to a certain id */
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 quant_pitch(celt_pgain_t *gains, int len)
{
int i, id;
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))
{
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 {
id = 0;
id = -1;
}
/*for (i=0;i<len;i++) printf ("%f ", pgain_table[id*len+i]);printf ("\n");*/
id2gains(id, gains, len);
if (id != 0)
return id;
else
return -1;
return id;
}
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;
id = ec_dec_bits(dec, 7);
id2gains(id, gains, len);
return id!=0;
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)));
}
......@@ -36,10 +36,9 @@
#include "entenc.h"
#include "entdec.h"
/** If this returns 0, the gain is zero (don't encode the pitch index) */
int quant_pitch(celt_pgain_t *gains, int len, ec_enc *enc);
/** If this returns -1, the gain is zero (don't encode the pitch index) */
int quant_pitch(celt_pgain_t *gains, int len);
/** If this returns 0, the gain is zero (don't decode the pitch index) */
int unquant_pitch(celt_pgain_t *gains, int len, ec_dec *dec);
void unquant_pitch(int id, celt_pgain_t *gains, int len);
#endif /* QUANT_PITCH_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment