shithub: opus

Download patch

ref: e901fe35b8368d37bf92b548ab3bd1d9bb516a4b
parent: e046c18acf3307d6c05a703e5485606b83912f54
author: Jean-Marc Valin <[email protected]>
date: Tue Feb 26 09:46:26 EST 2008

fixed-point: added a celt_ener_t type for band energy.

--- a/libcelt/arch.h
+++ b/libcelt/arch.h
@@ -53,6 +53,7 @@
 
 typedef celt_word32_t celt_sig_t;
 typedef celt_word16_t celt_norm_t;
+typedef float celt_ener_t;
 
 #define Q15ONE 32767
 
@@ -102,6 +103,7 @@
 
 typedef float celt_sig_t;
 typedef float celt_norm_t;
+typedef float celt_ener_t;
 
 #define Q15ONE 1.0f
 #define LPC_SCALING  1.f
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -70,7 +70,7 @@
 }
 
 /* Compute the amplitude (sqrt energy) in each of the bands */
-void compute_band_energies(const CELTMode *m, celt_sig_t *X, float *bank)
+void compute_band_energies(const CELTMode *m, celt_sig_t *X, celt_ener_t *bank)
 {
    int i, c, B, C;
    const int *eBands = m->eBands;
@@ -92,7 +92,7 @@
 }
 
 /* Normalise each band such that the energy is one. */
-void normalise_bands(const CELTMode *m, celt_sig_t *freq, celt_norm_t *X, float *bank)
+void normalise_bands(const CELTMode *m, celt_sig_t *freq, celt_norm_t *X, celt_ener_t *bank)
 {
    int i, c, B, C;
    const int *eBands = m->eBands;
@@ -114,8 +114,8 @@
 
 void renormalise_bands(const CELTMode *m, celt_norm_t *X)
 {
-   VARDECL(float *tmpE);
-   ALLOC(tmpE, m->nbEBands*m->nbChannels, float);
+   VARDECL(celt_ener_t *tmpE);
+   ALLOC(tmpE, m->nbEBands*m->nbChannels, celt_ener_t);
    compute_band_energies(m, X, tmpE);
    /* FIXME: This isn't right */
    normalise_bands(m, X, X, tmpE);
@@ -122,7 +122,7 @@
 }
 
 /* De-normalise the energy to produce the synthesis from the unit-energy bands */
-void denormalise_bands(const CELTMode *m, celt_norm_t *X, celt_sig_t *freq, float *bank)
+void denormalise_bands(const CELTMode *m, celt_norm_t *X, celt_sig_t *freq, celt_ener_t *bank)
 {
    int i, c, B, C;
    const int *eBands = m->eBands;
@@ -144,7 +144,7 @@
 
 
 /* Compute the best gain for each "pitch band" */
-void compute_pitch_gain(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, float *gains, float *bank)
+void compute_pitch_gain(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, float *gains, celt_ener_t *bank)
 {
    int i, B;
    const int *eBands = m->eBands;
@@ -331,7 +331,7 @@
       X[i] = 0;
 }
 
-void stereo_mix(const CELTMode *m, celt_norm_t *X, float *bank, int dir)
+void stereo_mix(const CELTMode *m, celt_norm_t *X, celt_ener_t *bank, int dir)
 {
    int i, B, C;
    const int *eBands = m->eBands;
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -43,7 +43,7 @@
  * @param X Spectrum
  * @param bands Square root of the energy for each band (returned)
  */
-void compute_band_energies(const CELTMode *m, celt_sig_t *X, float *bands);
+void compute_band_energies(const CELTMode *m, celt_sig_t *X, celt_ener_t *bands);
 
 /** Normalise each band of X such that the energy in each band is 
     equal to 1
@@ -51,7 +51,7 @@
  * @param X Spectrum (returned normalised)
  * @param bands Square root of the energy for each band
  */
-void normalise_bands(const CELTMode *m, celt_sig_t *freq, celt_norm_t *X, float *bands);
+void normalise_bands(const CELTMode *m, celt_sig_t *freq, celt_norm_t *X, celt_ener_t *bands);
 
 void renormalise_bands(const CELTMode *m, celt_norm_t *X);
 
@@ -60,7 +60,7 @@
  * @param X Spectrum (returned de-normalised)
  * @param bands Square root of the energy for each band
  */
-void denormalise_bands(const CELTMode *m, celt_norm_t *X, celt_sig_t *freq, float *bands);
+void denormalise_bands(const CELTMode *m, celt_norm_t *X, celt_sig_t *freq, celt_ener_t *bands);
 
 /** Compute the pitch predictor gain for each pitch band
  * @param m Mode data 
@@ -69,7 +69,7 @@
  * @param gains Gain computed for each pitch band (returned)
  * @param bank Square root of the energy for each band
  */
-void compute_pitch_gain(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, float *gains, float *bank);
+void compute_pitch_gain(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, float *gains, celt_ener_t *bank);
 
 void pitch_quant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, float *gains);
 
@@ -92,6 +92,6 @@
 */
 void unquant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, int total_bits, ec_dec *dec);
 
-void stereo_mix(const CELTMode *m, celt_norm_t *X, float *bank, int dir);
+void stereo_mix(const CELTMode *m, celt_norm_t *X, celt_ener_t *bank, int dir);
 
 #endif /* BANDS_H */
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -230,7 +230,7 @@
    VARDECL(celt_norm_t *X);
    VARDECL(celt_norm_t *P);
    VARDECL(float *mask);
-   VARDECL(float *bandE);
+   VARDECL(celt_ener_t *bandE);
    VARDECL(float *gains);
 
    if (check_mode(st->mode) != CELT_OK)
@@ -244,7 +244,7 @@
    ALLOC(X, B*C*N, celt_norm_t);         /**< Interleaved normalised MDCTs */
    ALLOC(P, B*C*N, celt_norm_t);         /**< Interleaved normalised pitch MDCTs*/
    ALLOC(mask, B*C*N, float);      /**< Masking curve */
-   ALLOC(bandE,st->mode->nbEBands*C, float);
+   ALLOC(bandE,st->mode->nbEBands*C, celt_ener_t);
    ALLOC(gains,st->mode->nbPBands, float);
    
    N4 = (N-st->overlap)/2;
@@ -322,8 +322,8 @@
    if (curr_power + 1e5f < 10.f*pitch_power)
    {
       /* Normalise the pitch vector as well (discard the energies) */
-      VARDECL(float *bandEp);
-      ALLOC(bandEp, st->mode->nbEBands*st->mode->nbChannels, float);
+      VARDECL(celt_ener_t *bandEp);
+      ALLOC(bandEp, st->mode->nbEBands*st->mode->nbChannels, celt_ener_t);
       compute_band_energies(st->mode, freq, bandEp);
       normalise_bands(st->mode, freq, P, bandEp);
 
@@ -578,7 +578,7 @@
    VARDECL(celt_sig_t *freq);
    VARDECL(celt_norm_t *X);
    VARDECL(celt_norm_t *P);
-   VARDECL(float *bandE);
+   VARDECL(celt_ener_t *bandE);
    VARDECL(float *gains);
 
    if (check_mode(st->mode) != CELT_OK)
@@ -591,7 +591,7 @@
    ALLOC(freq, C*B*N, celt_sig_t); /**< Interleaved signal MDCTs */
    ALLOC(X, C*B*N, celt_norm_t);         /**< Interleaved normalised MDCTs */
    ALLOC(P, C*B*N, celt_norm_t);         /**< Interleaved normalised pitch MDCTs*/
-   ALLOC(bandE, st->mode->nbEBands*C, float);
+   ALLOC(bandE, st->mode->nbEBands*C, celt_ener_t);
    ALLOC(gains, st->mode->nbPBands, float);
    
    if (check_mode(st->mode) != CELT_OK)
@@ -625,8 +625,8 @@
    compute_mdcts(&st->mdct_lookup, st->window, st->out_mem+pitch_index*C, freq, N, B, C);
 
    {
-      VARDECL(float *bandEp);
-      ALLOC(bandEp, st->mode->nbEBands*C, float);
+      VARDECL(celt_ener_t *bandEp);
+      ALLOC(bandEp, st->mode->nbEBands*C, celt_ener_t);
       compute_band_energies(st->mode, freq, bandEp);
       normalise_bands(st->mode, freq, P, bandEp);
    }
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -44,7 +44,7 @@
 /*const int frac[24] = {4, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};*/
 const int frac[24] = {8, 6, 5, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
 
-static void quant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands, int budget, ec_enc *enc)
+static void quant_energy_mono(const CELTMode *m, celt_ener_t *eBands, float *oldEBands, int budget, ec_enc *enc)
 {
    int i;
    int bits;
@@ -114,7 +114,7 @@
    /*printf ("\n");*/
 }
 
-static void unquant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands, int budget, ec_dec *dec)
+static void unquant_energy_mono(const CELTMode *m, celt_ener_t *eBands, float *oldEBands, int budget, ec_dec *dec)
 {
    int i;
    int bits;
@@ -163,7 +163,7 @@
 
 
 
-void quant_energy(const CELTMode *m, float *eBands, float *oldEBands, int budget, ec_enc *enc)
+void quant_energy(const CELTMode *m, celt_ener_t *eBands, float *oldEBands, int budget, ec_enc *enc)
 {
    int C;
    
@@ -175,8 +175,8 @@
 #if 1
    {
       int c;
-      VARDECL(float *E);
-      ALLOC(E, m->nbEBands, float);
+      VARDECL(celt_ener_t *E);
+      ALLOC(E, m->nbEBands, celt_ener_t);
       for (c=0;c<C;c++)
       {
          int i;
@@ -225,7 +225,7 @@
 
 
 
-void unquant_energy(const CELTMode *m, float *eBands, float *oldEBands, int budget, ec_dec *dec)
+void unquant_energy(const CELTMode *m, celt_ener_t *eBands, float *oldEBands, int budget, ec_dec *dec)
 {
    int C;   
    C = m->nbChannels;
@@ -234,8 +234,8 @@
       unquant_energy_mono(m, eBands, oldEBands, budget, dec);
    else {
       int c;
-      VARDECL(float *E);
-      ALLOC(E, m->nbEBands, float);
+      VARDECL(celt_ener_t *E);
+      ALLOC(E, m->nbEBands, celt_ener_t);
       for (c=0;c<C;c++)
       {
          int i;
--- a/libcelt/quant_bands.h
+++ b/libcelt/quant_bands.h
@@ -32,12 +32,13 @@
 #ifndef QUANT_BANDS
 #define QUANT_BANDS
 
+#include "arch.h"
 #include "modes.h"
 #include "entenc.h"
 #include "entdec.h"
 
-void quant_energy(const CELTMode *m, float *eBands, float *oldEBands, int budget, ec_enc *enc);
+void quant_energy(const CELTMode *m, celt_ener_t *eBands, float *oldEBands, int budget, ec_enc *enc);
 
-void unquant_energy(const CELTMode *m, float *eBands, float *oldEBands, int budget, ec_dec *dec);
+void unquant_energy(const CELTMode *m, celt_ener_t *eBands, float *oldEBands, int budget, ec_dec *dec);
 
 #endif /* QUANT_BANDS */