Constrain the pitch gain to prevent potential instabilities.
This commit is contained in:
parent
163b02eb8e
commit
d35d677543
3 changed files with 14 additions and 3 deletions
|
@ -211,7 +211,7 @@ void denormalise_bands(const CELTMode *m, const celt_norm_t * restrict X, celt_s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int compute_pitch_gain(const CELTMode *m, const celt_sig_t *X, const celt_sig_t *P, int norm_rate, int *gain_id, int _C)
|
int compute_pitch_gain(const CELTMode *m, const celt_sig_t *X, const celt_sig_t *P, int norm_rate, int *gain_id, int _C, celt_word16_t *gain_prod)
|
||||||
{
|
{
|
||||||
int j, c;
|
int j, c;
|
||||||
celt_word16_t g;
|
celt_word16_t g;
|
||||||
|
@ -281,6 +281,16 @@ int compute_pitch_gain(const CELTMode *m, const celt_sig_t *X, const celt_sig_t
|
||||||
*gain_id = floor(20*(g-.5));
|
*gain_id = floor(20*(g-.5));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
/* This prevents the pitch gain from being above 1.0 for too long by bounding the
|
||||||
|
maximum error amplification factor to 2.0 */
|
||||||
|
g = ADD16(QCONST16(.5,14), MULT16_16_16(QCONST16(.05,14),*gain_id));
|
||||||
|
*gain_prod = MAX16(QCONST32(1., 13), MULT16_16_Q14(*gain_prod,g));
|
||||||
|
if (*gain_prod>QCONST32(2., 13))
|
||||||
|
{
|
||||||
|
*gain_id=9;
|
||||||
|
*gain_prod = QCONST32(2., 13);
|
||||||
|
}
|
||||||
|
|
||||||
if (*gain_id < 0)
|
if (*gain_id < 0)
|
||||||
{
|
{
|
||||||
*gain_id = 0;
|
*gain_id = 0;
|
||||||
|
|
|
@ -71,7 +71,7 @@ void denormalise_bands(const CELTMode *m, const celt_norm_t * restrict X, celt_s
|
||||||
* @param gains Gain computed for each pitch band (returned)
|
* @param gains Gain computed for each pitch band (returned)
|
||||||
* @param bank Square root of the energy for each band
|
* @param bank Square root of the energy for each band
|
||||||
*/
|
*/
|
||||||
int compute_pitch_gain(const CELTMode *m, const celt_sig_t *X, const celt_sig_t *P, int norm_rate, int *gain_id, int _C);
|
int compute_pitch_gain(const CELTMode *m, const celt_sig_t *X, const celt_sig_t *P, int norm_rate, int *gain_id, int _C, celt_word16_t *gain_prod);
|
||||||
|
|
||||||
void apply_pitch(const CELTMode *m, celt_sig_t *X, const celt_sig_t *P, int gain_id, int pred, int _C);
|
void apply_pitch(const CELTMode *m, celt_sig_t *X, const celt_sig_t *P, int gain_id, int pred, int _C);
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,7 @@ struct CELTEncoder {
|
||||||
int delayedIntra;
|
int delayedIntra;
|
||||||
celt_word16_t tonal_average;
|
celt_word16_t tonal_average;
|
||||||
int fold_decision;
|
int fold_decision;
|
||||||
|
celt_word16_t gain_prod;
|
||||||
|
|
||||||
int VBR_rate; /* Target number of 16th bits per frame */
|
int VBR_rate; /* Target number of 16th bits per frame */
|
||||||
celt_word16_t * restrict preemph_memE;
|
celt_word16_t * restrict preemph_memE;
|
||||||
|
@ -650,7 +651,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si
|
||||||
{
|
{
|
||||||
|
|
||||||
compute_mdcts(st->mode, 0, st->out_mem+pitch_index*C, pitch_freq, C);
|
compute_mdcts(st->mode, 0, st->out_mem+pitch_index*C, pitch_freq, C);
|
||||||
has_pitch = compute_pitch_gain(st->mode, freq, pitch_freq, norm_rate, &gain_id, C);
|
has_pitch = compute_pitch_gain(st->mode, freq, pitch_freq, norm_rate, &gain_id, C, &st->gain_prod);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_pitch)
|
if (has_pitch)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue