1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 *
9 * by the Xiph.Org Foundation https://xiph.org/ *
11 ********************************************************************
13 function: LPC low level routines
15 ********************************************************************/
17 /* Some of these routines (autocorrelator, LPC coefficient estimator)
18 are derived from code written by Jutta Degener and Carsten Bormann;
19 thus we include their copyright below. The entirety of this file
20 is freely redistributable on the condition that both of these
21 copyright notices are preserved without modification. */
23 /* Preserved Copyright: *********************************************/
25 /* Copyright 1992, 1993, 1994 by Jutta Degener and Carsten Bormann,
26 Technische Universita"t Berlin
28 Any use of this software is permitted provided that this notice is not
29 removed and that neither the authors nor the Technische Universita"t
30 Berlin are deemed to have made any representations as to the
31 suitability of this software for any purpose nor are held responsible
32 for any defects of this software. THERE IS ABSOLUTELY NO WARRANTY FOR
35 As a matter of courtesy, the authors request to be informed about uses
36 this software has found, about bugs in this software, and about any
37 improvements that may be of general interest.
43 *********************************************************************/
54 /* Autocorrelation LPC coeff generation algorithm invented by
55 N. Levinson in 1947, modified by J. Durbin in 1959. */
57 /* Input : n elements of time doamin data
58 Output: m lpc coefficients, excitation energy */
60 float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
61 double *aut=alloca(sizeof(*aut)*(m+1));
62 double *lpc=alloca(sizeof(*lpc)*(m));
67 /* autocorrelation, p+1 lag coefficients */
70 double d=0; /* double needed for accumulator depth */
71 for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
75 /* Generate lpc coefficients from autocorr values */
77 /* set our noise floor to about -100dB */
78 error=aut[0] * (1. + 1e-10);
79 epsilon=1e-9*aut[0]+1e-10;
85 memset(lpc+i,0,(m-i)*sizeof(*lpc));
89 /* Sum up this iteration's reflection coefficient; note that in
90 Vorbis we don't save it. If anyone wants to recycle this code
91 and needs reflection coefficients, save the results of 'r' from
94 for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
97 /* Update LPC coefficients and total error */
103 lpc[j]+=r*lpc[i-1-j];
106 if(i&1)lpc[j]+=lpc[j]*r;
114 /* slightly damp the filter */
124 for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
126 /* we need the error value to know how big an impulse to hit the
132 void vorbis_lpc_predict(float *coeff,float *prime,int m,
135 /* in: coeff[0...m-1] LPC coefficients
136 prime[0...m-1] initial values (allocated size of n+m-1)
137 out: data[0...n-1] data samples */
141 float *work=alloca(sizeof(*work)*(m+n));
155 y-=work[o++]*coeff[--p];