Commit 32ec58cc authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Dynamically selecting intra energy based on energy variations from the previous

frame
parent 18a3b79d
......@@ -536,6 +536,17 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si
shortBlocks = 0;
}
ALLOC(freq, C*N, celt_sig_t); /**< Interleaved signal MDCTs */
ALLOC(bandE,st->mode->nbEBands*C, celt_ener_t);
/* Compute MDCTs */
compute_mdcts(st->mode, shortBlocks, in, freq);
compute_band_energies(st->mode, freq, bandE);
if (intra_decision(bandE, st->oldBandE, st->mode->nbEBands) || shortBlocks)
intra_ener = 1;
else
intra_ener = 0;
/* 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 */
has_pitch = st->pitch_enabled && (st->pitch_available >= MAX_PERIOD) && (!shortBlocks) && !intra_ener;
......@@ -553,10 +564,6 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si
find_spectral_pitch(st->mode, st->mode->fft, &st->mode->psy, in, st->out_mem, st->mode->window, NULL, 2*N-2*N4, MAX_PERIOD-(2*N-2*N4), &pitch_index);
}
#endif
ALLOC(freq, C*N, celt_sig_t); /**< Interleaved signal MDCTs */
/* Compute MDCTs */
compute_mdcts(st->mode, shortBlocks, in, freq);
#ifdef EXP_PSY
ALLOC(mask, N, celt_sig_t);
......@@ -569,12 +576,10 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si
/* Deferred allocation after find_spectral_pitch() to reduce the peak memory usage */
ALLOC(X, C*N, celt_norm_t); /**< Interleaved normalised MDCTs */
ALLOC(P, C*N, celt_norm_t); /**< Interleaved normalised pitch MDCTs*/
ALLOC(bandE,st->mode->nbEBands*C, celt_ener_t);
ALLOC(gains,st->mode->nbPBands, celt_pgain_t);
/* Band normalisation */
compute_band_energies(st->mode, freq, bandE);
normalise_bands(st->mode, freq, X, bandE);
#ifdef EXP_PSY
......
......@@ -84,6 +84,18 @@ static inline celt_word16_t amp2dB(celt_ener_t amp)
}
#endif
int intra_decision(celt_ener_t *eBands, celt_word16_t *oldEBands, int len)
{
int i;
celt_word32_t dist = 0;
for (i=0;i<len;i++)
{
celt_word16_t d = SUB16(amp2dB(eBands[i]), oldEBands[i]);
dist = MAC16_16(dist, d,d);
}
return SHR32(dist,16) > 64*len;
}
static const celt_word16_t base_resolution = QCONST16(6.f,8);
static const celt_word16_t base_resolution_1 = QCONST16(0.1666667f,15);
......
......@@ -42,6 +42,8 @@ void quant_prob_free(int *freq);
void compute_fine_allocation(const CELTMode *m, int *bits, int budget);
int intra_decision(celt_ener_t *eBands, celt_word16_t *oldEBands, int len);
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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment