65 float amp,
float ampoffset){
71 for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
79 float w=vorbis_coslook(wdel*k);
102 q=vorbis_fromdBlook(amp*
104 vorbis_invsq2explook(qexp+m)-
121 static int MLOOP_1[64]={
122 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
123 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
124 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
125 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
128 static int MLOOP_2[64]={
129 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
130 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
131 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
132 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
135 static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
140 float amp,
float ampoffset){
146 int ampoffseti=rint(ampoffset*4096.
f);
147 int ampi=rint(amp*16.
f);
148 long *ilsp=alloca(m*
sizeof(*ilsp));
149 for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/
M_PI*65536.
f+.5
f);
154 unsigned long pi=46341;
155 unsigned long qi=46341;
157 long wi=vorbis_coslook_i(k*65536/ln);
159 qi*=labs(ilsp[0]-wi);
160 pi*=labs(ilsp[1]-wi);
163 if(!(shift=MLOOP_1[(pi|qi)>>25]))
164 if(!(shift=MLOOP_2[(pi|qi)>>19]))
165 shift=MLOOP_3[(pi|qi)>>16];
166 qi=(qi>>shift)*labs(ilsp[j-1]-wi);
167 pi=(pi>>shift)*labs(ilsp[j]-wi);
170 if(!(shift=MLOOP_1[(pi|qi)>>25]))
171 if(!(shift=MLOOP_2[(pi|qi)>>19]))
172 shift=MLOOP_3[(pi|qi)>>16];
179 qi=(qi>>shift)*labs(ilsp[j-1]-wi);
183 if(!(shift=MLOOP_1[(pi|qi)>>25]))
184 if(!(shift=MLOOP_2[(pi|qi)>>19]))
185 shift=MLOOP_3[(pi|qi)>>16];
189 qexp+=shift-14*((m+1)>>1);
195 pi*=(1<<14)-((wi*wi)>>14);
226 while(qi && !(qi&0x8000)){
230 amp=vorbis_fromdBlook_i(ampi*
231 vorbis_invsqlook_i(qi,qexp)-
236 while(map[++i]==k)curve[
i]*=amp;
248 float amp,
float ampoffset){
251 for(i=0;i<m;i++)lsp[i]=2.
f*cos(lsp[i]);
258 float w=2.f*cos(wdel*k);
275 q=
fromdB(amp/sqrt(p+q)-ampoffset);
278 while(map[++i]==k)curve[
i]*=
q;
285 static void cheby(
float *
g,
int ord) {
289 for(i=2; i<= ord; i++) {
290 for(j=ord; j >=
i; j--) {
297 static int comp(
const void *
a,
const void *
b){
298 return (*(
float *)a<*(
float *)b)-(*(
float *)a>*(
float *)
b);
308 #define EPSILON 10e-7
309 static int Laguerre_With_Deflation(
float *a,
int ord,
float *
r){
311 double lastdelta=0.f;
312 double *defl=alloca(
sizeof(*defl)*(ord+1));
313 for(i=0;i<=ord;i++)defl[i]=a[i];
316 double new=0.f,delta;
320 double p=defl[m],pp=0.f,ppp=0.f,denom;
326 p =
new*p + defl[i-1];
330 denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
335 denom = pp + sqrt(denom);
338 denom = pp - sqrt(denom);
345 if(delta<0.
f)delta*=-1;
347 if(fabs(delta/
new)<10e-12)
break;
356 defl[i-1]+=
new*defl[i];
365 static int Newton_Raphson(
float *a,
int ord,
float *
r){
368 double *root=alloca(ord*
sizeof(*root));
370 for(i=0; i<ord;i++) root[i] = r[i];
375 for(i=0; i<ord; i++) {
377 double rooti=root[
i];
379 for(k=ord-1; k>= 0; k--) {
382 p = p * rooti + a[k];
390 if(count>40)
return(-1);
398 for(i=0; i<ord;i++) r[i] = root[i];
406 int g1_order,g2_order;
407 float *g1=alloca(
sizeof(*g1)*(order2+1));
408 float *g2=alloca(
sizeof(*g2)*(order2+1));
409 float *g1r=alloca(
sizeof(*g1r)*(order2+1));
410 float *g2r=alloca(
sizeof(*g2r)*(order2+1));
423 for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
425 for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
427 if(g1_order>g2_order){
428 for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
430 for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
431 for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
439 if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
440 Laguerre_With_Deflation(g2,g2_order,g2r))
443 Newton_Raphson(g1,g1_order,g1r);
444 Newton_Raphson(g2,g2_order,g2r);
446 qsort(g1r,g1_order,
sizeof(*g1r),comp);
447 qsort(g2r,g2_order,
sizeof(*g2r),comp);
449 for(i=0;i<g1_order;i++)
450 lsp[i*2] = acos(g1r[i]);
452 for(i=0;i<g2_order;i++)
453 lsp[i*2+1] = acos(g2r[i]);
GLdouble GLdouble GLdouble GLdouble q
#define vorbis_fpu_setround(vorbis_fpu_control)
GLuint GLuint GLsizei count
int vorbis_lpc_to_lsp(float *lpc, float *lsp, int m)
void vorbis_lsp_to_curve(float *curve, int *map, int n, int ln, float *lsp, int m, float amp, float ampoffset)
GLubyte GLubyte GLubyte GLubyte w
GLubyte GLubyte GLubyte a
GLdouble GLdouble GLdouble r
#define vorbis_fpu_restore(vorbis_fpu_control)