[xiph-commits] r13227 - trunk/ghost/libghost

jm at svn.xiph.org jm at svn.xiph.org
Wed Jul 4 21:00:17 PDT 2007


Author: jm
Date: 2007-07-04 21:00:17 -0700 (Wed, 04 Jul 2007)
New Revision: 13227

Modified:
   trunk/ghost/libghost/ghost.c
   trunk/ghost/libghost/ghost.h
   trunk/ghost/libghost/vorbis_psy.c
   trunk/ghost/libghost/vorbis_psy.h
Log:
Very basic scalar quantization of the noise component using the vorbis
psy model and a short LPC weighting filter.


Modified: trunk/ghost/libghost/ghost.c
===================================================================
--- trunk/ghost/libghost/ghost.c	2007-07-04 18:52:40 UTC (rev 13226)
+++ trunk/ghost/libghost/ghost.c	2007-07-05 04:00:17 UTC (rev 13227)
@@ -33,6 +33,7 @@
 #define PCM_BUF_SIZE 2048
 
 #define SINUSOIDS 30
+#define MASK_LPC_ORDER 12
 
 void fir_mem2(const spx_sig_t *x, const spx_coef_t *num, spx_sig_t *y, int N, int ord, spx_mem_t *mem)
 {
@@ -79,7 +80,7 @@
    st->advance = 192;
    st->overlap = 64;
    st->lpc_length = 384;
-   st->lpc_order = 40;
+   st->lpc_order = MASK_LPC_ORDER;
    st->pcm_buf = calloc(PCM_BUF_SIZE,sizeof(float));
 #if 0
    /* pre-analysis window centered around the current frame */
@@ -93,6 +94,8 @@
    st->noise_buf = calloc(PCM_BUF_SIZE,sizeof(float));
    st->new_noise = st->noise_buf + PCM_BUF_SIZE/2 - st->length/2;
    
+   st->psy = vorbis_psy_init(44100, PCM_BUF_SIZE);
+   
    st->analysis_window = calloc(st->length,sizeof(float));
    st->synthesis_window = calloc(st->length,sizeof(float));
    st->big_window = calloc(PCM_BUF_SIZE,sizeof(float));
@@ -138,10 +141,18 @@
    float gain;
    float pitch;
    float w;
+   float curve[PCM_BUF_SIZE>>1];
+   float awk1[MASK_LPC_ORDER], awk2[MASK_LPC_ORDER];
+   float mask_gain;
+   
    for (i=0;i<PCM_BUF_SIZE-st->advance;i++)
       st->pcm_buf[i] = st->pcm_buf[i+st->advance];
    for (i=0;i<st->advance;i++)
       st->new_pcm[i]=pcm[i];
+   
+   compute_curve(st->psy, st->pcm_buf, curve);
+   mask_gain = curve_to_lpc(st->psy, curve, awk1, awk2, MASK_LPC_ORDER);
+   
    /*for (i=0;i<st->advance;i++)
       st->new_pcm[i]=pcm[i]+10*3.4641f*.001f*(rand()%1000-500);*/
    {
@@ -213,7 +224,8 @@
       noise_psd[st->lpc_length-1] *= noise_psd[st->lpc_length-1];
       spx_ifft_float(st->lpc_fft, noise_psd, noise_ac);
       */
-      for (i=0;i<st->lpc_order+1;i++)
+      
+      /*for (i=0;i<st->lpc_order+1;i++)
       {
          int j;
          double tmp = 0;
@@ -227,7 +239,8 @@
       noise_ac[0] += 1;
       
       float lpc[st->lpc_order];
-      _spx_lpc(lpc, noise_ac, st->lpc_order);
+      _spx_lpc(lpc, noise_ac, st->lpc_order);*/
+      
       /*for (i=0;i<st->lpc_order;i++)
       lpc[i] *= pow(.9,i+1);*/
       /*for (i=0;i<st->lpc_order;i++)
@@ -239,8 +252,8 @@
          for (i=0;i<st->lpc_order+1;i++)
             printf ("%f ", noise_ac[i]);
          printf ("\n");
-         for (i=0;i<st->lpc_order;i++)
-         printf ("%f ", lpc[i]);
+         //for (i=0;i<st->lpc_order;i++)
+         //printf ("%f ", lpc[i]);
          printf ("\n");
          /*for (i=0;i<st->lpc_length;i++)
          printf ("%f ", noise_window[i]);
@@ -254,10 +267,14 @@
          exit(1);
       }
       float noise[st->advance];
-      fir_mem2(st->new_noise, lpc, noise, st->advance, st->lpc_order, st->noise_mem);
+      //for (i=0;i<MASK_LPC_ORDER;i++)
+      //   awk1[i] = 0;
+      fir_mem2(st->new_noise, awk1, noise, st->advance, MASK_LPC_ORDER, st->noise_mem);
+      for (i=0;i<st->advance;i++)
+         noise[i] /= mask_gain;
       
       //Replace whitened residual by white noise
-      if (1) {
+      if (0) {
          float ener = 0;
          for (i=0;i<st->advance;i++)
             ener += noise[i]*noise[i];
@@ -266,7 +283,14 @@
             noise[i] = ener*sqrt(12.)*((((float)(rand()))/RAND_MAX)-.5);
       }
       
-      iir_mem2(noise, lpc, noise, st->advance, st->lpc_order, st->noise_mem2);
+      for (i=0;i<st->advance;i++)
+         printf ("%f\n", noise[i]);
+      printf ("\n");
+      for (i=0;i<st->advance;i++)
+         noise[i] = 16*floor(.5+.0625*noise[i]);
+      for (i=0;i<st->advance;i++)
+         noise[i] *= mask_gain;
+      iir_mem2(noise, awk1, noise, st->advance, MASK_LPC_ORDER, st->noise_mem2);
       
       /*for (i=0;i<st->advance;i++)
       pcm[i] = st->current_frame[i]-st->new_noise[i];*/

Modified: trunk/ghost/libghost/ghost.h
===================================================================
--- trunk/ghost/libghost/ghost.h	2007-07-04 18:52:40 UTC (rev 13226)
+++ trunk/ghost/libghost/ghost.h	2007-07-05 04:00:17 UTC (rev 13227)
@@ -23,6 +23,8 @@
 #ifndef _GHOST_H
 #define _GHOST_H
 
+#include "vorbis_psy.h"
+
 typedef struct {
    float *pcm_buf;
    float *new_pcm;
@@ -37,6 +39,8 @@
    float *noise_mem;
    float *noise_mem2;
    
+   VorbisPsy *psy;
+   
    float *noise_buf;
    float *new_noise;
    //float *current_noise;

Modified: trunk/ghost/libghost/vorbis_psy.c
===================================================================
--- trunk/ghost/libghost/vorbis_psy.c	2007-07-04 18:52:40 UTC (rev 13226)
+++ trunk/ghost/libghost/vorbis_psy.c	2007-07-05 04:00:17 UTC (rev 13227)
@@ -450,11 +450,12 @@
 }
 
 /* Transform a masking curve (power spectrum) into a pole-zero filter */
-void curve_to_lpc(VorbisPsy *psy, float *curve, float *awk1, float *awk2, int ord)
+float curve_to_lpc(VorbisPsy *psy, float *curve, float *awk1, float *awk2, int ord)
 {
    int i;
    float ac[psy->n];
    float tmp;
+   float mean_ratio=0;
    int len = psy->n >> 1;
    for (i=0;i<2*len;i++)
       ac[i] = 0;
@@ -489,8 +490,11 @@
    ac[len] = ac[2*len-1]*ac[2*len-1];
    /* Compute correction required */
    for (i=0;i<len;i++)
+   {
+      mean_ratio += curve[i]*ac[i];
       curve[i] = 1. / (1e-6f+curve[i]*ac[i]);
-
+   }
+   mean_ratio /= len;
    for (i=0;i<2*len;i++)
       ac[i] = 0;
    for (i=1;i<len;i++)
@@ -506,6 +510,7 @@
       tmp *= .99;
       awk2[i] *= tmp;
    }
+   return sqrt(mean_ratio);
 #endif
 }
 

Modified: trunk/ghost/libghost/vorbis_psy.h
===================================================================
--- trunk/ghost/libghost/vorbis_psy.h	2007-07-04 18:52:40 UTC (rev 13226)
+++ trunk/ghost/libghost/vorbis_psy.h	2007-07-05 04:00:17 UTC (rev 13227)
@@ -89,6 +89,6 @@
 VorbisPsy *vorbis_psy_init(int rate, int size);
 void vorbis_psy_destroy(VorbisPsy *psy);
 void compute_curve(VorbisPsy *psy, float *audio, float *curve);
-void curve_to_lpc(VorbisPsy *psy, float *curve, float *awk1, float *awk2, int ord);
+float curve_to_lpc(VorbisPsy *psy, float *curve, float *awk1, float *awk2, int ord);
 
 #endif



More information about the commits mailing list