X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=lib%2Flpc.c;h=798f4cf0766418856ad02c77ebdc9e583a8a01e6;hb=a9eb99a5bd6f2d7da02d6cd13a428baf3a1bf48c;hp=4010ca8fec0e6581fbc01e487c280d664d0fe66e;hpb=321b01cbbc49f8f4fb685b16c3f743cfd62944f6;p=platform%2Fupstream%2Flibvorbis.git diff --git a/lib/lpc.c b/lib/lpc.c index 4010ca8..798f4cf 100644 --- a/lib/lpc.c +++ b/lib/lpc.c @@ -1,20 +1,16 @@ /******************************************************************** * * - * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY * - * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. * - * PLEASE READ THESE TERMS DISTRIBUTING. * + * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * * * - * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-1999 * - * by 1999 Monty and The XIPHOPHORUS Company * - * http://www.xiph.org/ * + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * + * by the Xiph.Org Foundation http://www.xiph.org/ * * * ******************************************************************** function: LPC low level routines - author: Monty - modifications by: Monty - last modification date: Aug 22 1999 ********************************************************************/ @@ -47,65 +43,48 @@ Carsten Bormann *********************************************************************/ #include -#include #include #include +#include "os.h" #include "smallft.h" #include "lpc.h" -#include "xlogmap.h" +#include "scales.h" +#include "misc.h" -/* This is pared down for Vorbis where we only use LPC to encode - spectral envelope curves. Thus we only are interested in - generating the coefficients and recovering the curve from the - coefficients. Autocorrelation LPC coeff generation algorithm - invented by N. Levinson in 1947, modified by J. Durbin in 1959. */ +/* Autocorrelation LPC coeff generation algorithm invented by + N. Levinson in 1947, modified by J. Durbin in 1959. */ -/* Input : n element envelope curve +/* Input : n elements of time doamin data Output: m lpc coefficients, excitation energy */ -double vorbis_gen_lpc(double *curve,double *lpc,lpc_lookup *l){ - int n=l->ln; - int m=l->m; - double aut[m+1],work[n+n],error; +float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){ + double *aut=alloca(sizeof(*aut)*(m+1)); + double *lpc=alloca(sizeof(*lpc)*(m)); + double error; + double epsilon; int i,j; - - /* input is a real curve. make it complex-real */ - for(i=0;ifft,work); - /* The autocorrelation will not be circular. Shift, else we lose - most of the power in the edges. */ - - for(i=0,j=n/2;in=n; - l->ln=mapped; - l->m=m; - l->dscale=malloc(n*sizeof(double)); - l->norm=malloc(n*sizeof(double)); + error*=1.-r*r; - for(i=0;inorm[i]=logB-logA; /* this much */ } - /* the scale is encode/decode specific for algebraic simplicity */ - - if(encode_p){ - /* encode */ - l->bscale=malloc(n*sizeof(int)); - l->escale=malloc(n*sizeof(double)); + done: - for(i=0;iescale[i]=LINEAR_X(i/scale,bias); - l->bscale[i]=rint(LOG_X(i,bias)*scale); - } - - drft_init(&l->fft,mapped*2); - } - /* decode; encode may use this too */ - + /* slightly damp the filter */ { - double w=1./oct*M_PI; - for(i=0;idscale[i]=LOG_X(i,bias)*w; + double g = .99; + double damp = g; + for(j=0;jbscale)free(l->bscale); - if(l->escale)free(l->escale); - drft_clear(&l->fft); - free(l->dscale); - free(l->norm); - } -} + for(j=0;jn; - int mapped=n; - double work[mapped]; - int i; + /* in: coeff[0...m-1] LPC coefficients + prime[0...m-1] initial values (allocated size of n+m-1) + out: data[0...n-1] data samples */ - /* fairly correct for low frequencies, naieve for high frequencies - (suffers from undersampling) */ + long i,j,o,p; + float y; + float *work=alloca(sizeof(*work)*(m+n)); - for(i=0;iescale[i]; - int a=floor(lin); - int b=ceil(lin); - double del=lin-floor(lin); + if(!prime) + for(i=0;inorm[a]*(1.-del)+ - curve[b]/l->norm[b]*del); + for(i=0;in;i++) - curve[i]=vorbis_lpc_magnitude(l->dscale[i],lpc,l->m)*amp*l->norm[i]; } - -/* find frequency response of LPC filter only at nonsero residue - points and apply the envelope to the residue */ - -void vorbis_lpc_apply(double *residue,double *lpc,double amp,lpc_lookup *l){ - int i; - for(i=0;in;i++) - if(residue[i]) - residue[i]*=vorbis_lpc_magnitude(l->dscale[i],lpc,l->m)*amp*l->norm[i]; -} - -