From 32ec58cc3e80d63b26ff139fc8c4f4a27cd75d69 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Fri, 1 May 2009 21:28:58 -0400 Subject: [PATCH] Dynamically selecting intra energy based on energy variations from the previous frame --- libcelt/celt.c | 17 +++++++++++------ libcelt/quant_bands.c | 12 ++++++++++++ libcelt/quant_bands.h | 2 ++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/libcelt/celt.c b/libcelt/celt.c index 95484bad..13cb2ff5 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -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 diff --git a/libcelt/quant_bands.c b/libcelt/quant_bands.c index 58f7ea52..0e39d37b 100644 --- a/libcelt/quant_bands.c +++ b/libcelt/quant_bands.c @@ -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 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); diff --git a/libcelt/quant_bands.h b/libcelt/quant_bands.h index 138bb1cf..bc1603e3 100644 --- a/libcelt/quant_bands.h +++ b/libcelt/quant_bands.h @@ -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);