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()
\*---------------------------------------------------------------------------*/
/*
- Copyright (C) 2009 David Rowe
+ Copyright (C) 2009-2012 David Rowe
All rights reserved.
#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);