shithub: opus

Download patch

ref: 4213a7254c6192788199da84aed67e2d36d1a02a
parent: d5e5436e075312bd3f281fc6556c4e1767c22ced
author: Jean-Marc Valin <[email protected]>
date: Thu Oct 1 15:42:18 EDT 2009

Demoved the divisions from the inner pitch prediction loops, bumped the version
and bit-stream version

--- a/configure.ac
+++ b/configure.ac
@@ -5,8 +5,8 @@
 AM_CONFIG_HEADER([config.h])
 
 CELT_MAJOR_VERSION=0
-CELT_MINOR_VERSION=6
-CELT_MICRO_VERSION=1
+CELT_MINOR_VERSION=7
+CELT_MICRO_VERSION=0
 CELT_EXTRA_VERSION=
 CELT_VERSION=$CELT_MAJOR_VERSION.$CELT_MINOR_VERSION.$CELT_MICRO_VERSION$CELT_EXTRA_VERSION
 
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -216,13 +216,14 @@
    }
 }
 
-int compute_new_pitch(const CELTMode *m, const celt_sig_t *X, const celt_sig_t *P, int norm_rate, int *gain_id)
+int compute_pitch_gain(const CELTMode *m, const celt_sig_t *X, const celt_sig_t *P, int norm_rate, int *gain_id)
 {
-   int j ;
+   int j, c;
    celt_word16_t g;
+   celt_word16_t delta;
    const int C = CHANNELS(m);
    celt_word32_t Sxy=0, Sxx=0, Syy=0;
-   int len = m->pitchEnd*C;
+   int len = m->pitchEnd;
 #ifdef FIXED_POINT
    int shift = 0;
    celt_word32_t maxabs=0;
@@ -235,15 +236,20 @@
    if (shift<0)
       shift = 0;
 #endif
-   for (j=0;j<len;j++)
+   delta = PDIV32_16(Q15ONE, len);
+   for (c=0;c<C;c++)
    {
-      celt_word16_t gg = Q15ONE-DIV32_16(MULT16_16(Q15ONE,j),len);
-      celt_word16_t Xj, Pj;
-      Xj = EXTRACT16(SHR32(X[j], shift));
-      Pj = MULT16_16_P15(gg,EXTRACT16(SHR32(P[j], shift)));
-      Sxy = MAC16_16(Sxy, Xj, Pj);
-      Sxx = MAC16_16(Sxx, Pj, Pj);
-      Syy = MAC16_16(Syy, Xj, Xj);
+      celt_word16_t gg = Q15ONE;
+      for (j=0;j<len;j++)
+      {
+         celt_word16_t Xj, Pj;
+         Xj = EXTRACT16(SHR32(X[C*j+c], shift));
+         Pj = MULT16_16_P15(gg,EXTRACT16(SHR32(P[C*j+c], shift)));
+         Sxy = MAC16_16(Sxy, Xj, Pj);
+         Sxx = MAC16_16(Sxx, Pj, Pj);
+         Syy = MAC16_16(Syy, Xj, Xj);
+         gg = SUB16(gg, delta);
+      }
    }
 #ifdef FIXED_POINT
    {
@@ -286,19 +292,28 @@
    }
 }
 
-void apply_new_pitch(const CELTMode *m, celt_sig_t *X, const celt_sig_t *P, int gain_id, int pred)
+void apply_pitch(const CELTMode *m, celt_sig_t *X, const celt_sig_t *P, int gain_id, int pred)
 {
-   int j;
+   int j, c;
    celt_word16_t gain;
+   celt_word16_t delta;
    const int C = CHANNELS(m);
-   int len = m->pitchEnd*C;
+   int len = m->pitchEnd;
+   
    gain = ADD16(QCONST16(.5,14), MULT16_16_16(QCONST16(.05,14),gain_id));
+   delta = PDIV32_16(gain, len);
    if (pred)
       gain = -gain;
-   for (j=0;j<len;j++)
+   else
+      delta = -delta;
+   for (c=0;c<C;c++)
    {
-      celt_word16_t gg = SUB16(gain, DIV32_16(MULT16_16(gain,j),len));
-      X[j] += SHL(MULT16_32_Q15(gg,P[j]),1);
+      celt_word16_t gg = gain;
+      for (j=0;j<len;j++)
+      {
+         X[C*j+c] += SHL(MULT16_32_Q15(gg,P[C*j+c]),1);
+         gg = ADD16(gg, delta);
+      }
    }
 }
 
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -64,10 +64,6 @@
  */
 void denormalise_bands(const CELTMode *m, const celt_norm_t * restrict X, celt_sig_t * restrict freq, const celt_ener_t *bands);
 
-int compute_new_pitch(const CELTMode *m, const celt_sig_t *X, const celt_sig_t *P, int norm_rate, int *gain_id);
-
-void apply_new_pitch(const CELTMode *m, celt_sig_t *X, const celt_sig_t *P, int gain_id, int pred);
-
 /** Compute the pitch predictor gain for each pitch band
  * @param m Mode data 
  * @param X Spectrum to predict
@@ -75,15 +71,15 @@
  * @param gains Gain computed for each pitch band (returned)
  * @param bank Square root of the energy for each band
  */
-int compute_pitch_gain(const CELTMode *m, const celt_norm_t *X, const celt_norm_t *P, celt_pgain_t *gains);
+int compute_pitch_gain(const CELTMode *m, const celt_sig_t *X, const celt_sig_t *P, int norm_rate, int *gain_id);
 
+void apply_pitch(const CELTMode *m, celt_sig_t *X, const celt_sig_t *P, int gain_id, int pred);
+
 int folding_decision(const CELTMode *m, celt_norm_t *X, celt_word16_t *average, int *last_decision);
 
 /** Quantisation/encoding of the residual spectrum
  * @param m Mode data 
  * @param X Residual (normalised)
- * @param P Pitch vector (normalised)
- * @param W Perceptual weighting
  * @param total_bits Total number of bits that can be used for the frame (including the ones already spent)
  * @param enc Entropy encoder
  */
@@ -94,7 +90,6 @@
 /** Decoding of the residual spectrum
  * @param m Mode data 
  * @param X Residual (normalised)
- * @param P Pitch vector (normalised)
  * @param total_bits Total number of bits that can be used for the frame (including the ones already spent)
  * @param dec Entropy decoder
 */
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -679,11 +679,11 @@
    {
       
       compute_mdcts(st->mode, 0, st->out_mem+pitch_index*C, pitch_freq);
-      has_pitch = compute_new_pitch(st->mode, freq, pitch_freq, norm_rate, &gain_id);
+      has_pitch = compute_pitch_gain(st->mode, freq, pitch_freq, norm_rate, &gain_id);
    }
    
    if (has_pitch)
-      apply_new_pitch(st->mode, freq, pitch_freq, gain_id, 1);
+      apply_pitch(st->mode, freq, pitch_freq, gain_id, 1);
 
    compute_band_energies(st->mode, freq, bandE);
    for (i=0;i<st->mode->nbEBands*C;i++)
@@ -797,7 +797,7 @@
 #endif
       }
       if (has_pitch)
-         apply_new_pitch(st->mode, freq, pitch_freq, gain_id, 0);
+         apply_pitch(st->mode, freq, pitch_freq, gain_id, 0);
       
       compute_inv_mdcts(st->mode, shortBlocks, freq, transient_time, transient_shift, st->out_mem);
       /* De-emphasis and put everything back at the right place 
@@ -1328,7 +1328,7 @@
    }
    
    if (has_pitch)
-      apply_new_pitch(st->mode, freq, pitch_freq, gain_id, 0);
+      apply_pitch(st->mode, freq, pitch_freq, gain_id, 0);
 
    /* Compute inverse MDCTs */
    compute_inv_mdcts(st->mode, shortBlocks, freq, transient_time, transient_shift, st->out_mem);
--- a/libcelt/modes.h
+++ b/libcelt/modes.h
@@ -39,7 +39,7 @@
 #include "psy.h"
 #include "pitch.h"
 
-#define CELT_BITSTREAM_VERSION 0x80000009
+#define CELT_BITSTREAM_VERSION 0x8000000a
 
 #ifdef STATIC_MODES
 #include "static_modes.h"