"unified" narrowband and wideband post-filters
authorjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Mon, 3 Jun 2002 00:51:38 +0000 (00:51 +0000)
committerjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Mon, 3 Jun 2002 00:51:38 +0000 (00:51 +0000)
git-svn-id: http://svn.xiph.org/trunk/speex@3338 0101bb08-14d6-0310-b084-bc0e0c8e3800

libspeex/ltp.c
libspeex/modes.c
libspeex/modes.h
libspeex/nb_celp.c
libspeex/nb_celp.h
libspeex/post_filter.c
libspeex/post_filter.h

index 560ed70..6a15539 100644 (file)
@@ -574,7 +574,10 @@ int lost)
    }
 
    *pitch_val = pitch;
-   *gain_val = gain[0]+gain[1]+gain[2];
+   /**gain_val = gain[0]+gain[1]+gain[2];*/
+   gain_val[0]=gain[0];
+   gain_val[1]=gain[1];
+   gain_val[2]=gain[2];
 
 #ifdef DEBUG
    printf ("unquantized pitch: %d %f %f %f\n", pitch, gain[0], gain[1], gain[2]);
index 3d77e8a..0b7fc06 100644 (file)
@@ -26,7 +26,7 @@
 #include "cb_search.h"
 #include "sb_celp.h"
 #include "nb_celp.h"
-
+#include "post_filter.h"
 
 /* Extern declarations for all codebooks we use here */
 extern float gain_cdbk_nb[];
@@ -34,8 +34,20 @@ extern float hexc_table[];
 extern float exc_5_256_table[];
 extern float exc_5_64_table[];
 
+/* Post-filter parameters for narrowband */
+pf_params pf_params_nb = {
+   0.1,      /* formant enhancement factor */
+   0.6       /* pitch enhancement factor */
+};
+
+/* Post-filter parameters for wideband */
+pf_params pf_params_sb = {
+   0.04,     /* formant enhancement factor */
+   0.4       /* pitch enhancement factor */
+};
+
 /* Parameters for Long-Term Prediction (LTP)*/
-static ltp_params ltp_params_nb = {
+ltp_params ltp_params_nb = {
    gain_cdbk_nb,
    7,
    7
@@ -87,7 +99,9 @@ SpeexNBMode nb_mode = {
    /*Innovation quantization*/
    split_cb_search_nogain2,
    split_cb_nogain_unquant,
-   &split_cb_nb
+   &split_cb_nb,
+   nb_post_filter,
+   &pf_params_nb
 };
 
 /* Narrowband mode used for split-band wideband CELP*/
@@ -114,7 +128,9 @@ static SpeexNBMode low_sb_mode = {
    /*Innovation quantization*/
    split_cb_search_nogain2,
    split_cb_nogain_unquant,
-   &split_cb_sb
+   &split_cb_sb,
+   nb_post_filter,
+   &pf_params_nb
 };
 
 SpeexMode low_wb_mode = {
index 0bdbc61..cf35fb6 100644 (file)
@@ -46,6 +46,9 @@ typedef void (*innovation_quant_func)(float *, float *, float *, float *, void *
 
 typedef void (*innovation_unquant_func)(float *, void *, int, SpeexBits*, float *);
 
+typedef void (*nb_post_filter_func)(float *, float *, float *, int, int, int, 
+                               float *, void *, float *);
+
 /*Struct defining the encoding/decoding mode*/
 typedef struct SpeexNBMode {
    int     frameSize;
@@ -60,6 +63,7 @@ typedef struct SpeexNBMode {
    float   lag_factor;
    float   lpc_floor;
    float   preemph;
+
    /*LSP functions*/
    lsp_quant_func    lsp_quant;
    lsp_unquant_func  lsp_unquant;
@@ -68,11 +72,15 @@ typedef struct SpeexNBMode {
    ltp_quant_func    ltp_quant;
    ltp_unquant_func  ltp_unquant;
    void             *ltp_params;
-   /*Quantization of innovation */
+
+   /*Quantization of innovation*/
    innovation_quant_func innovation_quant;
    innovation_unquant_func innovation_unquant;
    void             *innovation_params;
 
+   /*Post-filter*/
+   nb_post_filter_func post_filter_func;
+   void             *post_filter_params;
 } SpeexNBMode;
 
 
index 871f15f..72c769a 100644 (file)
@@ -36,6 +36,7 @@
 #define M_PI           3.14159265358979323846  /* pi */
 #endif
 
+
 #define sqr(x) ((x)*(x))
 #define min(a,b) ((a) < (b) ? (a) : (b))
 
@@ -582,6 +583,9 @@ void *nb_decoder_init(SpeexMode *m)
    st->innovation_unquant = mode->innovation_unquant;
    st->innovation_params = mode->innovation_params;
 
+   st->post_filter_func = mode->post_filter_func;
+   st->post_filter_params = mode->post_filter_params;
+
    st->stack = calloc(10000, sizeof(float));
 
    st->inBuf = malloc(st->bufSize*sizeof(float));
@@ -631,7 +635,7 @@ void nb_decode(void *state, SpeexBits *bits, float *out, int lost)
    DecState *st;
    int i, sub;
    int pitch;
-   float pitch_gain;
+   float pitch_gain[3];
 
    st=state;
 
@@ -685,7 +689,7 @@ void nb_decode(void *state, SpeexBits *bits, float *out, int lost)
          exc[i]=0;
 
       /*Adaptive codebook contribution*/
-      st->ltp_unquant(exc, st->min_pitch, st->max_pitch, st->ltp_params, st->subframeSize, &pitch, &pitch_gain, bits, st->stack, lost);
+      st->ltp_unquant(exc, st->min_pitch, st->max_pitch, st->ltp_params, st->subframeSize, &pitch, &pitch_gain[0], bits, st->stack, lost);
       
 
       {
@@ -712,8 +716,10 @@ void nb_decode(void *state, SpeexBits *bits, float *out, int lost)
 
       for (i=0;i<st->subframeSize;i++)
          exc2[i]=exc[i];
-      /*nb_post_filter(exc, exc2, st->interp_qlpc, st->lpcSize, st->subframeSize,
-        pitch, pitch_gain, st->stack);*/
+
+      if (1)
+         st->post_filter_func(exc, exc2, st->interp_qlpc, st->lpcSize, st->subframeSize,
+                              pitch, pitch_gain, st->post_filter_params, st->stack);
 
       /*Compute decoded signal*/
       syn_filt_mem(exc2, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, st->mem_sp);
index bb2af28..8a96a23 100644 (file)
@@ -120,6 +120,9 @@ typedef struct DecState {
    void             *ltp_params;
    innovation_unquant_func innovation_unquant;
    void             *innovation_params;
+   nb_post_filter_func post_filter_func;
+   void             *post_filter_params;
+
 } DecState;
 
 /**Initializes encoder state*/
index cacb3bc..d9738bc 100644 (file)
@@ -20,6 +20,7 @@
 #include <math.h>
 #include "filters.h"
 #include "stack_alloc.h"
+#include "post_filter.h"
 
 /* Perceptual post-filter for narrowband */
 void nb_post_filter(
@@ -29,24 +30,32 @@ float *ak,
 int p, 
 int nsf,
 int pitch,
-float pitch_gain,
+float *pitch_gain,
+void *par,
 float *stack)
 {
    int i;
    float exc_energy=0, new_exc_energy=0;
    float *awk;
    float gain;
+   pf_params *params;
+   
+   params = (pf_params*) par;
 
    awk = PUSH(stack, p);
    
-   bw_lpc (0.1, ak, awk, p);
+   bw_lpc (params->formant_enh, ak, awk, p);
 
    for (i=0;i<nsf;i++)
       exc_energy+=exc[i]*exc[i];
 
    for (i=0;i<nsf;i++)
    {
-      new_exc[i] = exc[i] + .4*pitch_gain*exc[i-pitch];
+      new_exc[i] = exc[i] + params->pitch_enh*(
+                                               pitch_gain[0]*exc[i-pitch+1] +
+                                               pitch_gain[1]*exc[i-pitch] +
+                                               pitch_gain[2]*exc[i-pitch-1]
+                                               );
    }
    
    syn_filt(new_exc, awk, new_exc, nsf, p);
index d16c4bc..c3b12a9 100644 (file)
 #ifndef POST_FILTER_H
 #define POST_FILTER_H
 
-/* Perceptual post-filter for narrowband */
+/** Post-filter parameters*/
+typedef struct pf_params {
+   float formant_enh;
+   float pitch_enh;
+} pf_params;
+
+/** Perceptual post-filter for narrowband */
 void nb_post_filter(
 float *exc, 
 float *new_exc, 
@@ -28,7 +34,8 @@ float *ak,
 int p, 
 int nsf,
 int pitch,
-float pitch_gain,
+float *pitch_gain,
+void *params,
 float *stack);