pre-emph and de-emp functions, used to test LPC modelling improvements
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 15 Oct 2012 20:15:55 +0000 (20:15 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 15 Oct 2012 20:15:55 +0000 (20:15 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@753 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/lpc.c
codec2-dev/src/lpc.h

index e38bbd547f4f14176923d32e6dfa06958127786d..a253289a4631024844da7eb3719dbbb0a27981c7 100644 (file)
@@ -2,14 +2,14 @@
                                                                            
   FILE........: lpc.c                                                              
   AUTHOR......: David Rowe                                                      
-  DATE CREATED: 30/9/90                                                   
+  DATE CREATED: 30 Sep 1990 (!)                                                 
                                                                           
   Linear Prediction functions written in C.                                
                                                                           
 \*---------------------------------------------------------------------------*/
 
 /*
-  Copyright (C) 2009 David Rowe
+  Copyright (C) 2009-2012 David Rowe
 
   All rights reserved.
 
 #define LPC_MAX_N 512          /* maximum no. of samples in frame */
 #define PI 3.141592654         /* mathematical constant */
 
+#define ALPHA 1.0
+#define BETA  0.94
+
 #include <assert.h>
 #include <math.h>
 #include "defines.h"
 #include "lpc.h"
 
+/*---------------------------------------------------------------------------*\
+                                                                         
+  pre_emp()                                                        
+                                                                         
+  Pre-emphasise (high pass filter with zero close to 0 Hz) a frame of
+  speech samples.  Helps reduce dynamic range of LPC spectrum, giving
+  greater weight and hensea better match to low energy formants.  
+
+  Should be balanced by de-emphasis of the output speech.
+                                                                           
+\*---------------------------------------------------------------------------*/
+
+void pre_emp(
+  float  Sn_pre[], /* output frame of speech samples                     */
+  float  Sn[],    /* input frame of speech samples                      */
+  float *mem,      /* Sn[-1]single sample memory                         */
+  int   Nsam      /* number of speech samples to use                    */
+)
+{
+    int   i;
+
+    for(i=0; i<Nsam; i++) {
+       Sn_pre[i] = Sn[i] - ALPHA * mem[0];
+       mem[0] = Sn[i];
+    }
+
+}
+
+
+/*---------------------------------------------------------------------------*\
+                                                                         
+  de_emp()                                                        
+                                                                         
+  De-emphasis filter (low pass filter with polse close to 0 Hz).
+                                                                           
+\*---------------------------------------------------------------------------*/
+
+void de_emp(
+  float  Sn_de[],  /* output frame of speech samples                     */
+  float  Sn[],    /* input frame of speech samples                      */
+  float *mem,      /* Sn[-1]single sample memory                         */
+  int    Nsam     /* number of speech samples to use                    */
+)
+{
+    int   i;
+
+    for(i=0; i<Nsam; i++) {
+       Sn_de[i] = Sn[i] + BETA * mem[0];
+       mem[0] = Sn_de[i];
+    }
+
+}
+
+
 /*---------------------------------------------------------------------------*\
                                                                          
   hanning_window()                                                        
index dc0cc40d6b3eb644b27dd36c3a996ee024c0f325..d5385bdf5877ea92f7345525b186ce4043cb91d5 100644 (file)
@@ -9,7 +9,7 @@
 \*---------------------------------------------------------------------------*/
 
 /*
-  Copyright (C) 2009 David Rowe
+  Copyright (C) 2009-2012 David Rowe
 
   All rights reserved.
 
@@ -30,6 +30,8 @@
 
 #define LPC_MAX_ORDER 20
 
+void pre_emp(float Sn_pre[], float Sn[], float *mem, int Nsam);
+void de_emp(float Sn_se[], float Sn[], float *mem, int Nsam);
 void hanning_window(float Sn[],        float Wn[], int Nsam);
 void autocorrelate(float Sn[], float Rn[], int Nsam, int order);
 void levinson_durbin(float R[],        float lpcs[], int order);