aboutsummaryrefslogtreecommitdiff
path: root/src/lpc.c
diff options
context:
space:
mode:
authordrowe67 <[email protected]>2023-07-14 12:36:50 +0930
committerDavid Rowe <[email protected]>2023-07-14 12:36:50 +0930
commitb86e88413d4c6ec428aaedb147f7675f28882fe4 (patch)
treece360925856e25d4343d59a37e2e6bac142d3752 /src/lpc.c
parent0c2e969cfbe85548801eeb20ad8113969604892a (diff)
clang-format -i applied to src unittest misc
Diffstat (limited to 'src/lpc.c')
-rw-r--r--src/lpc.c219
1 files changed, 95 insertions, 124 deletions
diff --git a/src/lpc.c b/src/lpc.c
index f2d5c00..3117a1a 100644
--- a/src/lpc.c
+++ b/src/lpc.c
@@ -25,16 +25,18 @@
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-#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 <assert.h>
#include <math.h>
+
#include "defines.h"
-#include "lpc.h"
/*---------------------------------------------------------------------------*\
@@ -48,23 +50,19 @@
\*---------------------------------------------------------------------------*/
-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];
- }
+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()
@@ -73,23 +71,19 @@ void pre_emp(
\*---------------------------------------------------------------------------*/
-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];
- }
+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()
@@ -98,16 +92,14 @@ void de_emp(
\*---------------------------------------------------------------------------*/
-void hanning_window(
- float Sn[], /* input frame of speech samples */
- float Wn[], /* output frame of windowed samples */
- int Nsam /* number of samples */
-)
-{
- int i; /* loop variable */
+void hanning_window(float Sn[], /* input frame of speech samples */
+ float Wn[], /* output frame of windowed samples */
+ int Nsam /* number of samples */
+) {
+ int i; /* loop variable */
- for(i=0; i<Nsam; i++)
- Wn[i] = Sn[i]*(0.5 - 0.5*cosf(2*PI*(float)i/(Nsam-1)));
+ for (i = 0; i < Nsam; i++)
+ Wn[i] = Sn[i] * (0.5 - 0.5 * cosf(2 * PI * (float)i / (Nsam - 1)));
}
/*---------------------------------------------------------------------------*\
@@ -119,19 +111,16 @@ void hanning_window(
\*---------------------------------------------------------------------------*/
-void autocorrelate(
- float Sn[], /* frame of Nsam windowed speech samples */
- float Rn[], /* array of P+1 autocorrelation coefficients */
- int Nsam, /* number of windowed samples to use */
- int order /* order of LPC analysis */
-)
-{
- int i,j; /* loop variables */
+void autocorrelate(float Sn[], /* frame of Nsam windowed speech samples */
+ float Rn[], /* array of P+1 autocorrelation coefficients */
+ int Nsam, /* number of windowed samples to use */
+ int order /* order of LPC analysis */
+) {
+ int i, j; /* loop variables */
- for(j=0; j<order+1; j++) {
+ for (j = 0; j < order + 1; j++) {
Rn[j] = 0.0;
- for(i=0; i<Nsam-j; i++)
- Rn[j] += Sn[i]*Sn[i+j];
+ for (i = 0; i < Nsam - j; i++) Rn[j] += Sn[i] * Sn[i + j];
}
}
@@ -150,36 +139,31 @@ void autocorrelate(
\*---------------------------------------------------------------------------*/
-void levinson_durbin(
- float R[], /* order+1 autocorrelation coeff */
- float lpcs[], /* order+1 LPC's */
- int order /* order of the LPC analysis */
-)
-{
- float a[order+1][order+1];
+void levinson_durbin(float R[], /* order+1 autocorrelation coeff */
+ float lpcs[], /* order+1 LPC's */
+ int order /* order of the LPC analysis */
+) {
+ float a[order + 1][order + 1];
float sum, e, k;
- int i,j; /* loop variables */
+ int i, j; /* loop variables */
- e = R[0]; /* Equation 38a, Makhoul */
+ e = R[0]; /* Equation 38a, Makhoul */
- for(i=1; i<=order; i++) {
+ for (i = 1; i <= order; i++) {
sum = 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;
+ 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<Nsam; i++) {
+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 < Nsam; i++) {
res[i] = 0.0;
- for(j=0; j<=order; j++)
- res[i] += Sn[i-j]*a[j];
+ for (j = 0; j <= order; j++) res[i] += Sn[i - j] * a[j];
}
}
@@ -231,21 +212,19 @@ void inverse_filter(
\*---------------------------------------------------------------------------*/
void synthesis_filter(
- float res[], /* Nsam input residual (excitation) samples */
- float a[], /* LPCs for this frame of speech samples */
- int Nsam, /* number of speech samples */
- int order, /* LPC order */
- float Sn_[] /* Nsam output synthesised speech samples */
-)
-{
- int i,j; /* loop variables */
+ float res[], /* Nsam input residual (excitation) samples */
+ float a[], /* LPCs for this frame of speech samples */
+ int Nsam, /* number of speech samples */
+ int order, /* LPC order */
+ float Sn_[] /* Nsam output synthesised speech samples */
+) {
+ int i, j; /* loop variables */
/* Filter Nsam samples */
- for(i=0; i<Nsam; i++) {
- Sn_[i] = res[i]*a[0];
- for(j=1; j<=order; j++)
- Sn_[i] -= Sn_[i-j]*a[j];
+ for (i = 0; i < Nsam; i++) {
+ Sn_[i] = res[i] * a[0];
+ for (j = 1; j <= order; j++) Sn_[i] -= Sn_[i - j] * a[j];
}
}
@@ -258,29 +237,25 @@ void synthesis_filter(
\*---------------------------------------------------------------------------*/
-void find_aks(
- float Sn[], /* Nsam samples with order sample memory */
- float a[], /* order+1 LPCs with first coeff 1.0 */
- int Nsam, /* number of input speech samples */
- int order, /* order of the LPC analysis */
- float *E /* residual energy */
-)
-{
- float Wn[LPC_MAX_N]; /* windowed frame of Nsam speech samples */
- float R[order+1]; /* order+1 autocorrelation values of Sn[] */
+void find_aks(float Sn[], /* Nsam samples with order sample memory */
+ float a[], /* order+1 LPCs with first coeff 1.0 */
+ int Nsam, /* number of input speech samples */
+ int order, /* order of the LPC analysis */
+ float *E /* residual energy */
+) {
+ float Wn[LPC_MAX_N]; /* windowed frame of Nsam speech samples */
+ float R[order + 1]; /* order+1 autocorrelation values of Sn[] */
int i;
assert(Nsam < LPC_MAX_N);
- hanning_window(Sn,Wn,Nsam);
- autocorrelate(Wn,R,Nsam,order);
- levinson_durbin(R,a,order);
+ hanning_window(Sn, Wn, Nsam);
+ autocorrelate(Wn, R, Nsam, order);
+ levinson_durbin(R, a, order);
*E = 0.0;
- for(i=0; i<=order; i++)
- *E += a[i]*R[i];
- if (*E < 0.0)
- *E = 1E-12;
+ for (i = 0; i <= order; i++) *E += a[i] * R[i];
+ if (*E < 0.0) *E = 1E-12;
}
/*---------------------------------------------------------------------------*\
@@ -291,16 +266,12 @@ void find_aks(
\*---------------------------------------------------------------------------*/
-void weight(
- float ak[], /* vector of order+1 LPCs */
- float gamma, /* weighting factor */
- int order, /* num LPCs (excluding leading 1.0) */
- float akw[] /* weighted vector of order+1 LPCs */
-)
-{
+void weight(float ak[], /* vector of order+1 LPCs */
+ float gamma, /* weighting factor */
+ int order, /* num LPCs (excluding leading 1.0) */
+ float akw[] /* weighted vector of order+1 LPCs */
+) {
int i;
- for(i=1; i<=order; i++)
- akw[i] = ak[i]*powf(gamma,(float)i);
+ for (i = 1; i <= order; i++) akw[i] = ak[i] * powf(gamma, (float)i);
}
-