shithub: opus

Download patch

ref: 32ec58cc3e80d63b26ff139fc8c4f4a27cd75d69
parent: 18a3b79d24cf322b0ec7eec4867a1bc99d3fd1d7
author: Jean-Marc Valin <[email protected]>
date: Fri May 1 17:28:58 EDT 2009

Dynamically selecting intra energy based on energy variations from the previous
frame

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -536,6 +536,17 @@
       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 @@
       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 @@
    /* 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
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -84,6 +84,18 @@
 }
 #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);
 
--- a/libcelt/quant_bands.h
+++ b/libcelt/quant_bands.h
@@ -42,6 +42,8 @@
 
 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);