Adding tapset decision logic

Based on spreading_decision()'s logic. We choose tapsets
with less roll-off when we think the HF are tonal.
This commit is contained in:
Jean-Marc Valin 2011-01-17 16:37:51 -05:00
parent dfa847a25d
commit 8d367029a7
3 changed files with 43 additions and 7 deletions

View file

@ -300,13 +300,16 @@ static void stereo_merge(celt_norm *X, celt_norm *Y, celt_word16 mid, int N)
} }
/* Decide whether we should spread the pulses in the current frame */ /* Decide whether we should spread the pulses in the current frame */
int spreading_decision(const CELTMode *m, celt_norm *X, int *average, int last_decision, int end, int _C, int M) int spreading_decision(const CELTMode *m, celt_norm *X, int *average,
int last_decision, int *hf_average, int *tapset_decision, int update_hf,
int end, int _C, int M)
{ {
int i, c, N0; int i, c, N0;
int sum = 0, nbBands=0; int sum = 0, nbBands=0;
const int C = CHANNELS(_C); const int C = CHANNELS(_C);
const celt_int16 * restrict eBands = m->eBands; const celt_int16 * restrict eBands = m->eBands;
int decision; int decision;
int hf_sum=0;
N0 = M*m->shortMdctSize; N0 = M*m->shortMdctSize;
@ -335,11 +338,33 @@ int spreading_decision(const CELTMode *m, celt_norm *X, int *average, int last_d
tcount[2]++; tcount[2]++;
} }
/* Only include four last bands (8 kHz and up) */
if (i>m->nbEBands-4)
hf_sum += 32*(tcount[1]+tcount[0])/N;
tmp = (2*tcount[2] >= N) + (2*tcount[1] >= N) + (2*tcount[0] >= N); tmp = (2*tcount[2] >= N) + (2*tcount[1] >= N) + (2*tcount[0] >= N);
sum += tmp*256; sum += tmp*256;
nbBands++; nbBands++;
} }
} while (++c<C); } while (++c<C);
if (update_hf)
{
if (hf_sum)
hf_sum /= C*(4-m->nbEBands+end);
*hf_average = (*hf_average+hf_sum)>>1;
hf_sum = *hf_average;
if (*tapset_decision==2)
hf_sum += 4;
else if (*tapset_decision==0)
hf_sum -= 4;
if (hf_sum > 22)
*tapset_decision=2;
else if (hf_sum > 18)
*tapset_decision=1;
else
*tapset_decision=0;
}
/*printf("%d %d %d\n", hf_sum, *hf_average, *tapset_decision);*/
sum /= nbBands; sum /= nbBands;
/* Recursive averaging */ /* Recursive averaging */
sum = (sum+*average)>>1; sum = (sum+*average)>>1;

View file

@ -69,7 +69,9 @@ void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig
#define SPREAD_NORMAL (2) #define SPREAD_NORMAL (2)
#define SPREAD_AGGRESSIVE (3) #define SPREAD_AGGRESSIVE (3)
int spreading_decision(const CELTMode *m, celt_norm *X, int *average, int last_decision, int end, int _C, int M); int spreading_decision(const CELTMode *m, celt_norm *X, int *average,
int last_decision, int *hf_average, int *tapset_decision, int update_hf,
int end, int _C, int M);
#ifdef MEASURE_NORM_MSE #ifdef MEASURE_NORM_MSE
void measure_norm_mse(const CELTMode *m, float *X, float *X0, float *bandE, float *bandE0, int M, int N, int C); void measure_norm_mse(const CELTMode *m, float *X, float *X0, float *bandE, float *bandE0, int M, int N, int C);

View file

@ -83,6 +83,8 @@ struct CELTEncoder {
int delayedIntra; int delayedIntra;
int tonal_average; int tonal_average;
int lastCodedBands; int lastCodedBands;
int hf_average;
int tapset_decision;
int prefilter_period; int prefilter_period;
celt_word16 prefilter_gain; celt_word16 prefilter_gain;
@ -160,6 +162,8 @@ CELTEncoder *celt_encoder_init(CELTEncoder *st, const CELTMode *mode, int channe
st->delayedIntra = 1; st->delayedIntra = 1;
st->tonal_average = 256; st->tonal_average = 256;
st->spread_decision = SPREAD_NORMAL; st->spread_decision = SPREAD_NORMAL;
st->hf_average = 0;
st->tapset_decision = 0;
st->complexity = 5; st->complexity = 5;
if (error) if (error)
@ -809,7 +813,8 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
celt_int32 total_bits; celt_int32 total_bits;
celt_int32 total_boost; celt_int32 total_boost;
celt_int32 tell; celt_int32 tell;
int prefilter_tapset; int prefilter_tapset=0;
int pf_on;
SAVE_STACK; SAVE_STACK;
if (nbCompressedBytes<0 || pcm==NULL) if (nbCompressedBytes<0 || pcm==NULL)
@ -927,7 +932,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
if (pitch_index > COMBFILTER_MAXPERIOD-2) if (pitch_index > COMBFILTER_MAXPERIOD-2)
pitch_index = COMBFILTER_MAXPERIOD-2; pitch_index = COMBFILTER_MAXPERIOD-2;
gain1 = MULT16_16_Q15(QCONST16(.7f,15),gain1); gain1 = MULT16_16_Q15(QCONST16(.7f,15),gain1);
prefilter_tapset = 0; prefilter_tapset = st->tapset_decision;
} else { } else {
gain1 = 0; gain1 = 0;
} }
@ -954,6 +959,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
if(tell+15<=total_bits) if(tell+15<=total_bits)
ec_enc_bit_logp(enc, 0, 1); ec_enc_bit_logp(enc, 0, 1);
gain1 = 0; gain1 = 0;
pf_on = 0;
} else { } else {
int qg; int qg;
int octave; int octave;
@ -979,11 +985,13 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
ec_enc_bits(enc, prefilter_tapset!=0, 1); ec_enc_bits(enc, prefilter_tapset!=0, 1);
if (prefilter_tapset!=0) if (prefilter_tapset!=0)
ec_enc_bits(enc, prefilter_tapset>1, 1); ec_enc_bits(enc, prefilter_tapset>1, 1);
pf_on = 1;
} }
/*printf("%d %f\n", pitch_index, gain1);*/ /*printf("%d %f\n", pitch_index, gain1);*/
#else /* ENABLE_POSTFILTER */ #else /* ENABLE_POSTFILTER */
if(tell+15<=total_bits) if(tell+17<=total_bits)
ec_enc_bit_logp(enc, 0, 1); ec_enc_bit_logp(enc, 0, 1);
pf_on = 0;
#endif /* ENABLE_POSTFILTER */ #endif /* ENABLE_POSTFILTER */
c=0; do { c=0; do {
@ -1068,7 +1076,8 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
st->spread_decision = SPREAD_NONE; st->spread_decision = SPREAD_NONE;
} else { } else {
st->spread_decision = spreading_decision(st->mode, X, st->spread_decision = spreading_decision(st->mode, X,
&st->tonal_average, st->spread_decision, effEnd, C, M); &st->tonal_average, st->spread_decision, &st->hf_average,
&st->tapset_decision, pf_on&&!shortBlocks, effEnd, C, M);
} }
ec_enc_icdf(enc, st->spread_decision, spread_icdf, 5); ec_enc_icdf(enc, st->spread_decision, spread_icdf, 5);
} }
@ -1934,7 +1943,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
postfilter_gain = 0; postfilter_gain = 0;
postfilter_pitch = 0; postfilter_pitch = 0;
postfilter_tapset = 0; postfilter_tapset = 0;
if (tell+15 <= total_bits) if (tell+17 <= total_bits)
{ {
if(ec_dec_bit_logp(dec, 1)) if(ec_dec_bit_logp(dec, 1))
{ {