shithub: opus

Download patch

ref: a2012d8dc5af8e0db693eb42992f510d61288447
parent: 3b34e188ede286d7a4ecc9fdf66831397a352cb3
author: Jean-Marc Valin <[email protected]>
date: Wed Nov 5 16:54:37 EST 2008

experimental code for choosing whether to apply folding for the high bands

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -128,6 +128,28 @@
    /*printf ("\n");*/
 }
 
+#ifdef EXP_PSY
+void compute_noise_energies(const CELTMode *m, const celt_sig_t *X, const celt_word16_t *tonality, celt_ener_t *bank)
+{
+   int i, c;
+   const celt_int16_t *eBands = m->eBands;
+   const int C = CHANNELS(m);
+   for (c=0;c<C;c++)
+   {
+      for (i=0;i<m->nbEBands;i++)
+      {
+         int j;
+         celt_word32_t sum = 1e-10;
+         for (j=eBands[i];j<eBands[i+1];j++)
+            sum += X[j*C+c]*X[j*C+c]*tonality[j];
+         bank[i*C+c] = sqrt(sum);
+         /*printf ("%f ", bank[i*C+c]);*/
+      }
+   }
+   /*printf ("\n");*/
+}
+#endif
+
 /* Normalise each band such that the energy is one. */
 void normalise_bands(const CELTMode *m, const celt_sig_t * restrict freq, celt_norm_t * restrict X, const celt_ener_t *bank)
 {
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -50,6 +50,8 @@
  */
 void compute_band_energies(const CELTMode *m, const celt_sig_t *X, celt_ener_t *bands);
 
+void compute_noise_energies(const CELTMode *m, const celt_sig_t *X, const celt_word16_t *tonality, celt_ener_t *bank);
+
 /** Normalise each band of X such that the energy in each band is 
     equal to 1
  * @param m Mode data 
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -374,6 +374,7 @@
    int has_pitch;
    int pitch_index;
    int bits;
+   int has_fold;
    ec_byte_buffer buf;
    ec_enc         enc;
    celt_word32_t curr_power, pitch_power=0;
@@ -391,6 +392,8 @@
 #ifdef EXP_PSY
    VARDECL(celt_word32_t, mask);
    VARDECL(celt_word32_t, tonality);
+   VARDECL(celt_word32_t, bandM);
+   VARDECL(celt_ener_t, bandN);
 #endif
    int shortBlocks=0;
    int transient_time;
@@ -529,8 +532,22 @@
    /* Band normalisation */
    compute_band_energies(st->mode, freq, bandE);
 #ifdef EXP_PSY
-   VARDECL(celt_word32_t, bandM);
+   ALLOC(bandN,C*st->mode->nbEBands, celt_ener_t);
    ALLOC(bandM,st->mode->nbEBands, celt_ener_t);
+   compute_noise_energies(st->mode, freq, tonality, bandN);
+
+   /*for (i=0;i<st->mode->nbEBands;i++)
+      printf ("%f ", (.1+bandN[i])/(.1+bandE[i]));
+   printf ("\n");*/
+   has_fold = 0;
+   for (i=st->mode->nbPBands;i<st->mode->nbEBands;i++)
+      if (bandN[i] < .4*bandE[i])
+         has_fold++;
+   /*printf ("%d\n", has_fold);*/
+   if (has_fold>=2)
+      has_fold = 1;
+   else
+      has_fold = 0;
    for (i=0;i<N;i++)
       mask[i] = sqrt(mask[i]);
    compute_band_energies(st->mode, mask, bandM);