[xiph-commits] r10147 - trunk/speex/libspeex

jm at svn.xiph.org jm at svn.xiph.org
Mon Oct 10 22:45:48 PDT 2005


Author: jm
Date: 2005-10-10 22:45:44 -0700 (Mon, 10 Oct 2005)
New Revision: 10147

Modified:
   trunk/speex/libspeex/nb_celp.c
   trunk/speex/libspeex/nb_celp.h
   trunk/speex/libspeex/vorbis_psy.c
   trunk/speex/libspeex/vorbis_psy.h
Log:
Hooks are in for using any masking curve.


Modified: trunk/speex/libspeex/nb_celp.c
===================================================================
--- trunk/speex/libspeex/nb_celp.c	2005-10-10 15:10:17 UTC (rev 10146)
+++ trunk/speex/libspeex/nb_celp.c	2005-10-11 05:45:44 UTC (rev 10147)
@@ -48,6 +48,10 @@
 #include "misc.h"
 #include <speex/speex_callbacks.h>
 
+#ifdef VORBIS_PSYCHO
+#include "vorbis_psy.h"
+#endif
+
 #ifndef M_PI
 #define M_PI           3.14159265358979323846  /* pi */
 #endif
@@ -137,6 +141,12 @@
    st->lbr_48k=mode->lbr48k;
 #endif
 
+#ifdef VORBIS_PSYCHO
+   st->psy = vorbis_psy_init(8000, 128);
+   st->curve = speex_alloc(64*sizeof(float));
+   st->old_curve = speex_alloc(64*sizeof(float));
+#endif
+
    /* Allocating input buffer */
    st->inBuf = speex_alloc((st->windowSize)*sizeof(spx_sig_t));
    st->frame = st->inBuf;
@@ -252,6 +262,12 @@
    vbr_destroy(st->vbr);
    speex_free (st->vbr);
 
+#ifdef VORBIS_PSYCHO
+   vorbis_psy_destroy(st->psy);
+   speex_free (st->curve);
+   speex_free (st->old_curve);
+#endif
+
    /*Free state memory... should be last*/
    speex_free(st);
 }
@@ -421,6 +437,13 @@
 #endif
    }
 
+#ifdef VORBIS_PSYCHO
+   compute_curve(st->psy, st->frame+52, st->curve);
+   if (st->first)
+      for (i=0;i<64;i++)
+         st->old_curve[i] = st->curve[i];
+#endif
+
    /*VBR stuff*/
    if (st->vbr && (st->vbr_enabled||st->vad_enabled))
    {
@@ -718,7 +741,15 @@
          st->pi_gain[sub] = pi_g;
       }
 
-
+#ifdef VORBIS_PSYCHO
+      {
+         float curr_curve[64];
+         float fact = ((float)sub+1.0f)/st->nbSubframes;
+         for (i=0;i<64;i++)
+            curr_curve[i] = (1.0f-fact)*st->old_curve[i] + fact*st->curve[i];
+         curve_to_lpc(st->psy, curr_curve, st->bw_lpc1, st->bw_lpc2, 10);
+      }
+#else
       /* Compute bandwidth-expanded (unquantized) LPCs for perceptual weighting */
       bw_lpc(st->gamma1, st->interp_lpc, st->bw_lpc1, st->lpcSize);
       if (st->gamma2>=0)
@@ -729,6 +760,7 @@
          for (i=1;i<=st->lpcSize;i++)
             st->bw_lpc2[i]=0;
       }
+#endif
 
       for (i=0;i<st->subframeSize;i++)
          real_exc[i] = exc[i];

Modified: trunk/speex/libspeex/nb_celp.h
===================================================================
--- trunk/speex/libspeex/nb_celp.h	2005-10-10 15:10:17 UTC (rev 10146)
+++ trunk/speex/libspeex/nb_celp.h	2005-10-11 05:45:44 UTC (rev 10147)
@@ -42,6 +42,10 @@
 #include "vbr.h"
 #include "filters.h"
 
+#ifdef VORBIS_PSYCHO
+#include "vorbis_psy.h"
+#endif
+
 /**Structure representing the full state of the narrowband encoder*/
 typedef struct EncState {
    const SpeexMode *mode;       /**< Mode corresponding to the state */
@@ -64,6 +68,12 @@
    int    lbr_48k;
 #endif
 
+#ifdef VORBIS_PSYCHO
+   VorbisPsy *psy;
+   float *curve;
+   float *old_curve;
+#endif
+
    spx_word16_t  gamma1;         /**< Perceptual filter: A(z/gamma1) */
    spx_word16_t  gamma2;         /**< Perceptual filter: A(z/gamma2) */
    float  lag_factor;     /**< Lag windowing Gaussian width */

Modified: trunk/speex/libspeex/vorbis_psy.c
===================================================================
--- trunk/speex/libspeex/vorbis_psy.c	2005-10-10 15:10:17 UTC (rev 10146)
+++ trunk/speex/libspeex/vorbis_psy.c	2005-10-11 05:45:44 UTC (rev 10147)
@@ -33,40 +33,39 @@
 
 #ifdef VORBIS_PSYCHO
 
-
+#include "misc.h"
 #include "smallft.h"
 #include "lpc.h"
 #include "vorbis_psy.h"
 
-struct drft_lookup lookup;
-
-/* FIXME: This is an horrible kludge */
-static void fft_init(int size)
+VorbisPsy *vorbis_psy_init(int rate, int size)
 {
-   static int initialized = -1;
-   if (size != initialized)
-   {
-      if (initialized != -1)
-         spx_drft_clear(&lookup);
-      spx_drft_init(&lookup, size);
-      initialized = size;
-   }
+   VorbisPsy *psy = speex_alloc(sizeof(VorbisPsy));
+   psy->size = size;
+   spx_drft_init(&psy->lookup, size);
+   return psy;
 }
 
-VorbisPsy *vorbis_psy_init(int rate, int size)
+void vorbis_psy_destroy(VorbisPsy *psy)
 {
+   spx_drft_clear(&psy->lookup);
+   speex_free(psy);
 }
 
-void compute_curve(VorbisPsy *psy, float *audio, int len, float *curve)
+void compute_curve(VorbisPsy *psy, float *audio, float *curve)
 {
-   
+   int len = psy->size >> 1;
+   int i;
+   for (i=0;i<len;i++)
+      curve[i] = 1.;
 }
 
 /* Transform a masking curve (power spectrum) into a pole-zero filter */
-void curve_to_lpc(float *curve, int len, float *awk1, float *awk2, int ord)
+void curve_to_lpc(VorbisPsy *psy, float *curve, float *awk1, float *awk2, int ord)
 {
    int i;
-   float ac[len*2];
+   float ac[psy->size];
+   int len = psy->size >> 1;
    for (i=0;i<2*len;i++)
       ac[i] = 0;
    for (i=1;i<len;i++)
@@ -74,8 +73,7 @@
    ac[0] = curve[0];
    ac[2*len-1] = curve[len-1];
    
-   fft_init(2*len);
-   spx_drft_backward(&lookup, ac);
+   spx_drft_backward(&psy->lookup, ac);
    _spx_lpc(awk1, ac, ord);
 #if 0
    for (i=0;i<ord;i++)
@@ -87,7 +85,7 @@
    for (i=0;i<ord;i++)
       ac[i+1] = awk1[i];
    ac[0] = 1;
-   spx_drft_forward(&lookup, ac);
+   spx_drft_forward(&psy->lookup, ac);
    /* Compute (power) response of awk1 (all zero) */
    ac[0] *= ac[0];
    for (i=1;i<len;i++)
@@ -104,14 +102,13 @@
    ac[0] = curve[0];
    ac[2*len-1] = curve[len-1];
    
-   fft_init(2*len);
-   spx_drft_backward(&lookup, ac);
+   spx_drft_backward(&psy->lookup, ac);
    _spx_lpc(awk2, ac, ord);
    
 #endif
 }
 
-#if 1
+#if 0
 #include <stdio.h>
 #include <math.h>
 

Modified: trunk/speex/libspeex/vorbis_psy.h
===================================================================
--- trunk/speex/libspeex/vorbis_psy.h	2005-10-10 15:10:17 UTC (rev 10146)
+++ trunk/speex/libspeex/vorbis_psy.h	2005-10-11 05:45:44 UTC (rev 10147)
@@ -30,22 +30,21 @@
 */
 
 #ifndef VORBIS_PSY_H
-#define VORBIS_PHY_H
+#define VORBIS_PSY_H
 
 #ifdef VORBIS_PSYCHO
 
 #include "smallft.h"
 
 typedef struct {
-   struct drft_lookup analysis_lookup;
-   struct drft_lookup curve_lookup;
-   
+   int size;
+   struct drft_lookup lookup;
 } VorbisPsy;
 
 VorbisPsy *vorbis_psy_init(int rate, int size);
 void vorbis_psy_destroy(VorbisPsy *psy);
-void compute_curve(VorbisPsy *psy, float *audio, int len, float *curve);
-void curve_to_lpc(float *curve, int len, float *awk1, float *awk2, int ord);
+void compute_curve(VorbisPsy *psy, float *audio, float *curve);
+void curve_to_lpc(VorbisPsy *psy, float *curve, float *awk1, float *awk2, int ord);
 
 #endif
 #endif



More information about the commits mailing list