From 30325d24d107dbf133da39f7c96d1510fd1c9449 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Fri, 15 Aug 2025 12:42:40 +0200 Subject: Bump to codec2 version 1.2.0 --- lpc.c | 223 +++++++++++++++++++++++++++++------------------------------------- 1 file changed, 97 insertions(+), 126 deletions(-) (limited to 'lpc.c') diff --git a/lpc.c b/lpc.c index 31442cd..3117a1a 100644 --- a/lpc.c +++ b/lpc.c @@ -25,16 +25,18 @@ along with this program; if not, see . */ -#define LPC_MAX_N 512 /* maximum no. of samples in frame */ -#define PI 3.141592654 /* mathematical constant */ +#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 +#define BETA 0.94 + +#include "lpc.h" #include #include + #include "defines.h" -#include "lpc.h" /*---------------------------------------------------------------------------*\ @@ -42,29 +44,25 @@ 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 hense a better match to low energy formants. + greater weight and hence a 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 1.0) - k = 0.0; + for (j = 1; j <= i - 1; j++) sum += a[i - 1][j] * R[i - j]; + k = -1.0 * (R[i] + sum) / e; /* Equation 38b, Makhoul */ + if (fabsf(k) > 1.0) k = 0.0; a[i][i] = k; - for(j=1; j<=i-1; j++) - a[i][j] = a[i-1][j] + k*a[i-1][i-j]; /* Equation 38c, Makhoul */ + for (j = 1; j <= i - 1; j++) + a[i][j] = a[i - 1][j] + k * a[i - 1][i - j]; /* Equation 38c, Makhoul */ - e *= (1-k*k); /* Equation 38d, Makhoul */ + e *= (1 - k * k); /* Equation 38d, Makhoul */ } - for(i=1; i<=order; i++) - lpcs[i] = a[order][i]; + for (i = 1; i <= order; i++) lpcs[i] = a[order][i]; lpcs[0] = 1.0; } @@ -194,20 +178,17 @@ void levinson_durbin( \*---------------------------------------------------------------------------*/ -void inverse_filter( - float Sn[], /* Nsam input samples */ - float a[], /* LPCs for this frame of samples */ - int Nsam, /* number of samples */ - float res[], /* Nsam residual samples */ - int order /* order of LPC */ -) -{ - int i,j; /* loop variables */ - - for(i=0; i