Coverage Report

Created: 2024-09-06 07:53

/src/vorbis/lib/smallft.c
Line
Count
Source (jump to first uncovered line)
1
/********************************************************************
2
 *                                                                  *
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.       *
7
 *                                                                  *
8
 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
9
 * by the Xiph.Org Foundation https://xiph.org/                     *
10
 *                                                                  *
11
 ********************************************************************
12
13
 function: *unnormalized* fft transform
14
15
 ********************************************************************/
16
17
/* FFT implementation from OggSquish, minus cosine transforms,
18
 * minus all but radix 2/4 case.  In Vorbis we only need this
19
 * cut-down version.
20
 *
21
 * To do more than just power-of-two sized vectors, see the full
22
 * version I wrote for NetLib.
23
 *
24
 * Note that the packing is a little strange; rather than the FFT r/i
25
 * packing following R_0, I_n, R_1, I_1, R_2, I_2 ... R_n-1, I_n-1,
26
 * it follows R_0, R_1, I_1, R_2, I_2 ... R_n-1, I_n-1, I_n like the
27
 * FORTRAN version
28
 */
29
30
#include <stdlib.h>
31
#include <string.h>
32
#include <math.h>
33
#include "smallft.h"
34
#include "os.h"
35
#include "misc.h"
36
37
0
static void drfti1(int n, float *wa, int *ifac){
38
0
  static int ntryh[4] = { 4,2,3,5 };
39
0
  static float tpi = 6.28318530717958648f;
40
0
  float arg,argh,argld,fi;
41
0
  int ntry=0,i,j=-1;
42
0
  int k1, l1, l2, ib;
43
0
  int ld, ii, ip, is, nq, nr;
44
0
  int ido, ipm, nfm1;
45
0
  int nl=n;
46
0
  int nf=0;
47
48
0
 L101:
49
0
  j++;
50
0
  if (j < 4)
51
0
    ntry=ntryh[j];
52
0
  else
53
0
    ntry+=2;
54
55
0
 L104:
56
0
  nq=nl/ntry;
57
0
  nr=nl-ntry*nq;
58
0
  if (nr!=0) goto L101;
59
60
0
  nf++;
61
0
  ifac[nf+1]=ntry;
62
0
  nl=nq;
63
0
  if(ntry!=2)goto L107;
64
0
  if(nf==1)goto L107;
65
66
0
  for (i=1;i<nf;i++){
67
0
    ib=nf-i+1;
68
0
    ifac[ib+1]=ifac[ib];
69
0
  }
70
0
  ifac[2] = 2;
71
72
0
 L107:
73
0
  if(nl!=1)goto L104;
74
0
  ifac[0]=n;
75
0
  ifac[1]=nf;
76
0
  argh=tpi/n;
77
0
  is=0;
78
0
  nfm1=nf-1;
79
0
  l1=1;
80
81
0
  if(nfm1==0)return;
82
83
0
  for (k1=0;k1<nfm1;k1++){
84
0
    ip=ifac[k1+2];
85
0
    ld=0;
86
0
    l2=l1*ip;
87
0
    ido=n/l2;
88
0
    ipm=ip-1;
89
90
0
    for (j=0;j<ipm;j++){
91
0
      ld+=l1;
92
0
      i=is;
93
0
      argld=(float)ld*argh;
94
0
      fi=0.f;
95
0
      for (ii=2;ii<ido;ii+=2){
96
0
        fi+=1.f;
97
0
        arg=fi*argld;
98
0
        wa[i++]=cos(arg);
99
0
        wa[i++]=sin(arg);
100
0
      }
101
0
      is+=ido;
102
0
    }
103
0
    l1=l2;
104
0
  }
105
0
}
106
107
0
static void fdrffti(int n, float *wsave, int *ifac){
108
109
0
  if (n == 1) return;
110
0
  drfti1(n, wsave+n, ifac);
111
0
}
112
113
0
static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
114
0
  int i,k;
115
0
  float ti2,tr2;
116
0
  int t0,t1,t2,t3,t4,t5,t6;
117
118
0
  t1=0;
119
0
  t0=(t2=l1*ido);
120
0
  t3=ido<<1;
121
0
  for(k=0;k<l1;k++){
122
0
    ch[t1<<1]=cc[t1]+cc[t2];
123
0
    ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
124
0
    t1+=ido;
125
0
    t2+=ido;
126
0
  }
127
128
0
  if(ido<2)return;
129
0
  if(ido==2)goto L105;
130
131
0
  t1=0;
132
0
  t2=t0;
133
0
  for(k=0;k<l1;k++){
134
0
    t3=t2;
135
0
    t4=(t1<<1)+(ido<<1);
136
0
    t5=t1;
137
0
    t6=t1+t1;
138
0
    for(i=2;i<ido;i+=2){
139
0
      t3+=2;
140
0
      t4-=2;
141
0
      t5+=2;
142
0
      t6+=2;
143
0
      tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
144
0
      ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
145
0
      ch[t6]=cc[t5]+ti2;
146
0
      ch[t4]=ti2-cc[t5];
147
0
      ch[t6-1]=cc[t5-1]+tr2;
148
0
      ch[t4-1]=cc[t5-1]-tr2;
149
0
    }
150
0
    t1+=ido;
151
0
    t2+=ido;
152
0
  }
153
154
0
  if(ido%2==1)return;
155
156
0
 L105:
157
0
  t3=(t2=(t1=ido)-1);
158
0
  t2+=t0;
159
0
  for(k=0;k<l1;k++){
160
0
    ch[t1]=-cc[t2];
161
0
    ch[t1-1]=cc[t3];
162
0
    t1+=ido<<1;
163
0
    t2+=ido;
164
0
    t3+=ido;
165
0
  }
166
0
}
167
168
static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
169
0
            float *wa2,float *wa3){
170
0
  static float hsqt2 = .70710678118654752f;
171
0
  int i,k,t0,t1,t2,t3,t4,t5,t6;
172
0
  float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
173
0
  t0=l1*ido;
174
175
0
  t1=t0;
176
0
  t4=t1<<1;
177
0
  t2=t1+(t1<<1);
178
0
  t3=0;
179
180
0
  for(k=0;k<l1;k++){
181
0
    tr1=cc[t1]+cc[t2];
182
0
    tr2=cc[t3]+cc[t4];
183
184
0
    ch[t5=t3<<2]=tr1+tr2;
185
0
    ch[(ido<<2)+t5-1]=tr2-tr1;
186
0
    ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
187
0
    ch[t5]=cc[t2]-cc[t1];
188
189
0
    t1+=ido;
190
0
    t2+=ido;
191
0
    t3+=ido;
192
0
    t4+=ido;
193
0
  }
194
195
0
  if(ido<2)return;
196
0
  if(ido==2)goto L105;
197
198
199
0
  t1=0;
200
0
  for(k=0;k<l1;k++){
201
0
    t2=t1;
202
0
    t4=t1<<2;
203
0
    t5=(t6=ido<<1)+t4;
204
0
    for(i=2;i<ido;i+=2){
205
0
      t3=(t2+=2);
206
0
      t4+=2;
207
0
      t5-=2;
208
209
0
      t3+=t0;
210
0
      cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
211
0
      ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
212
0
      t3+=t0;
213
0
      cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
214
0
      ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
215
0
      t3+=t0;
216
0
      cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
217
0
      ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
218
219
0
      tr1=cr2+cr4;
220
0
      tr4=cr4-cr2;
221
0
      ti1=ci2+ci4;
222
0
      ti4=ci2-ci4;
223
224
0
      ti2=cc[t2]+ci3;
225
0
      ti3=cc[t2]-ci3;
226
0
      tr2=cc[t2-1]+cr3;
227
0
      tr3=cc[t2-1]-cr3;
228
229
0
      ch[t4-1]=tr1+tr2;
230
0
      ch[t4]=ti1+ti2;
231
232
0
      ch[t5-1]=tr3-ti4;
233
0
      ch[t5]=tr4-ti3;
234
235
0
      ch[t4+t6-1]=ti4+tr3;
236
0
      ch[t4+t6]=tr4+ti3;
237
238
0
      ch[t5+t6-1]=tr2-tr1;
239
0
      ch[t5+t6]=ti1-ti2;
240
0
    }
241
0
    t1+=ido;
242
0
  }
243
0
  if(ido&1)return;
244
245
0
 L105:
246
247
0
  t2=(t1=t0+ido-1)+(t0<<1);
248
0
  t3=ido<<2;
249
0
  t4=ido;
250
0
  t5=ido<<1;
251
0
  t6=ido;
252
253
0
  for(k=0;k<l1;k++){
254
0
    ti1=-hsqt2*(cc[t1]+cc[t2]);
255
0
    tr1=hsqt2*(cc[t1]-cc[t2]);
256
257
0
    ch[t4-1]=tr1+cc[t6-1];
258
0
    ch[t4+t5-1]=cc[t6-1]-tr1;
259
260
0
    ch[t4]=ti1-cc[t1+t0];
261
0
    ch[t4+t5]=ti1+cc[t1+t0];
262
263
0
    t1+=ido;
264
0
    t2+=ido;
265
0
    t4+=t3;
266
0
    t6+=ido;
267
0
  }
268
0
}
269
270
static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
271
0
                          float *c2,float *ch,float *ch2,float *wa){
272
273
0
  static float tpi=6.283185307179586f;
274
0
  int idij,ipph,i,j,k,l,ic,ik,is;
275
0
  int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
276
0
  float dc2,ai1,ai2,ar1,ar2,ds2;
277
0
  int nbd;
278
0
  float dcp,arg,dsp,ar1h,ar2h;
279
0
  int idp2,ipp2;
280
281
0
  arg=tpi/(float)ip;
282
0
  dcp=cos(arg);
283
0
  dsp=sin(arg);
284
0
  ipph=(ip+1)>>1;
285
0
  ipp2=ip;
286
0
  idp2=ido;
287
0
  nbd=(ido-1)>>1;
288
0
  t0=l1*ido;
289
0
  t10=ip*ido;
290
291
0
  if(ido==1)goto L119;
292
0
  for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
293
294
0
  t1=0;
295
0
  for(j=1;j<ip;j++){
296
0
    t1+=t0;
297
0
    t2=t1;
298
0
    for(k=0;k<l1;k++){
299
0
      ch[t2]=c1[t2];
300
0
      t2+=ido;
301
0
    }
302
0
  }
303
304
0
  is=-ido;
305
0
  t1=0;
306
0
  if(nbd>l1){
307
0
    for(j=1;j<ip;j++){
308
0
      t1+=t0;
309
0
      is+=ido;
310
0
      t2= -ido+t1;
311
0
      for(k=0;k<l1;k++){
312
0
        idij=is-1;
313
0
        t2+=ido;
314
0
        t3=t2;
315
0
        for(i=2;i<ido;i+=2){
316
0
          idij+=2;
317
0
          t3+=2;
318
0
          ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
319
0
          ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
320
0
        }
321
0
      }
322
0
    }
323
0
  }else{
324
325
0
    for(j=1;j<ip;j++){
326
0
      is+=ido;
327
0
      idij=is-1;
328
0
      t1+=t0;
329
0
      t2=t1;
330
0
      for(i=2;i<ido;i+=2){
331
0
        idij+=2;
332
0
        t2+=2;
333
0
        t3=t2;
334
0
        for(k=0;k<l1;k++){
335
0
          ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
336
0
          ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
337
0
          t3+=ido;
338
0
        }
339
0
      }
340
0
    }
341
0
  }
342
343
0
  t1=0;
344
0
  t2=ipp2*t0;
345
0
  if(nbd<l1){
346
0
    for(j=1;j<ipph;j++){
347
0
      t1+=t0;
348
0
      t2-=t0;
349
0
      t3=t1;
350
0
      t4=t2;
351
0
      for(i=2;i<ido;i+=2){
352
0
        t3+=2;
353
0
        t4+=2;
354
0
        t5=t3-ido;
355
0
        t6=t4-ido;
356
0
        for(k=0;k<l1;k++){
357
0
          t5+=ido;
358
0
          t6+=ido;
359
0
          c1[t5-1]=ch[t5-1]+ch[t6-1];
360
0
          c1[t6-1]=ch[t5]-ch[t6];
361
0
          c1[t5]=ch[t5]+ch[t6];
362
0
          c1[t6]=ch[t6-1]-ch[t5-1];
363
0
        }
364
0
      }
365
0
    }
366
0
  }else{
367
0
    for(j=1;j<ipph;j++){
368
0
      t1+=t0;
369
0
      t2-=t0;
370
0
      t3=t1;
371
0
      t4=t2;
372
0
      for(k=0;k<l1;k++){
373
0
        t5=t3;
374
0
        t6=t4;
375
0
        for(i=2;i<ido;i+=2){
376
0
          t5+=2;
377
0
          t6+=2;
378
0
          c1[t5-1]=ch[t5-1]+ch[t6-1];
379
0
          c1[t6-1]=ch[t5]-ch[t6];
380
0
          c1[t5]=ch[t5]+ch[t6];
381
0
          c1[t6]=ch[t6-1]-ch[t5-1];
382
0
        }
383
0
        t3+=ido;
384
0
        t4+=ido;
385
0
      }
386
0
    }
387
0
  }
388
389
0
L119:
390
0
  for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
391
392
0
  t1=0;
393
0
  t2=ipp2*idl1;
394
0
  for(j=1;j<ipph;j++){
395
0
    t1+=t0;
396
0
    t2-=t0;
397
0
    t3=t1-ido;
398
0
    t4=t2-ido;
399
0
    for(k=0;k<l1;k++){
400
0
      t3+=ido;
401
0
      t4+=ido;
402
0
      c1[t3]=ch[t3]+ch[t4];
403
0
      c1[t4]=ch[t4]-ch[t3];
404
0
    }
405
0
  }
406
407
0
  ar1=1.f;
408
0
  ai1=0.f;
409
0
  t1=0;
410
0
  t2=ipp2*idl1;
411
0
  t3=(ip-1)*idl1;
412
0
  for(l=1;l<ipph;l++){
413
0
    t1+=idl1;
414
0
    t2-=idl1;
415
0
    ar1h=dcp*ar1-dsp*ai1;
416
0
    ai1=dcp*ai1+dsp*ar1;
417
0
    ar1=ar1h;
418
0
    t4=t1;
419
0
    t5=t2;
420
0
    t6=t3;
421
0
    t7=idl1;
422
423
0
    for(ik=0;ik<idl1;ik++){
424
0
      ch2[t4++]=c2[ik]+ar1*c2[t7++];
425
0
      ch2[t5++]=ai1*c2[t6++];
426
0
    }
427
428
0
    dc2=ar1;
429
0
    ds2=ai1;
430
0
    ar2=ar1;
431
0
    ai2=ai1;
432
433
0
    t4=idl1;
434
0
    t5=(ipp2-1)*idl1;
435
0
    for(j=2;j<ipph;j++){
436
0
      t4+=idl1;
437
0
      t5-=idl1;
438
439
0
      ar2h=dc2*ar2-ds2*ai2;
440
0
      ai2=dc2*ai2+ds2*ar2;
441
0
      ar2=ar2h;
442
443
0
      t6=t1;
444
0
      t7=t2;
445
0
      t8=t4;
446
0
      t9=t5;
447
0
      for(ik=0;ik<idl1;ik++){
448
0
        ch2[t6++]+=ar2*c2[t8++];
449
0
        ch2[t7++]+=ai2*c2[t9++];
450
0
      }
451
0
    }
452
0
  }
453
454
0
  t1=0;
455
0
  for(j=1;j<ipph;j++){
456
0
    t1+=idl1;
457
0
    t2=t1;
458
0
    for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
459
0
  }
460
461
0
  if(ido<l1)goto L132;
462
463
0
  t1=0;
464
0
  t2=0;
465
0
  for(k=0;k<l1;k++){
466
0
    t3=t1;
467
0
    t4=t2;
468
0
    for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
469
0
    t1+=ido;
470
0
    t2+=t10;
471
0
  }
472
473
0
  goto L135;
474
475
0
 L132:
476
0
  for(i=0;i<ido;i++){
477
0
    t1=i;
478
0
    t2=i;
479
0
    for(k=0;k<l1;k++){
480
0
      cc[t2]=ch[t1];
481
0
      t1+=ido;
482
0
      t2+=t10;
483
0
    }
484
0
  }
485
486
0
 L135:
487
0
  t1=0;
488
0
  t2=ido<<1;
489
0
  t3=0;
490
0
  t4=ipp2*t0;
491
0
  for(j=1;j<ipph;j++){
492
493
0
    t1+=t2;
494
0
    t3+=t0;
495
0
    t4-=t0;
496
497
0
    t5=t1;
498
0
    t6=t3;
499
0
    t7=t4;
500
501
0
    for(k=0;k<l1;k++){
502
0
      cc[t5-1]=ch[t6];
503
0
      cc[t5]=ch[t7];
504
0
      t5+=t10;
505
0
      t6+=ido;
506
0
      t7+=ido;
507
0
    }
508
0
  }
509
510
0
  if(ido==1)return;
511
0
  if(nbd<l1)goto L141;
512
513
0
  t1=-ido;
514
0
  t3=0;
515
0
  t4=0;
516
0
  t5=ipp2*t0;
517
0
  for(j=1;j<ipph;j++){
518
0
    t1+=t2;
519
0
    t3+=t2;
520
0
    t4+=t0;
521
0
    t5-=t0;
522
0
    t6=t1;
523
0
    t7=t3;
524
0
    t8=t4;
525
0
    t9=t5;
526
0
    for(k=0;k<l1;k++){
527
0
      for(i=2;i<ido;i+=2){
528
0
        ic=idp2-i;
529
0
        cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
530
0
        cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
531
0
        cc[i+t7]=ch[i+t8]+ch[i+t9];
532
0
        cc[ic+t6]=ch[i+t9]-ch[i+t8];
533
0
      }
534
0
      t6+=t10;
535
0
      t7+=t10;
536
0
      t8+=ido;
537
0
      t9+=ido;
538
0
    }
539
0
  }
540
0
  return;
541
542
0
 L141:
543
544
0
  t1=-ido;
545
0
  t3=0;
546
0
  t4=0;
547
0
  t5=ipp2*t0;
548
0
  for(j=1;j<ipph;j++){
549
0
    t1+=t2;
550
0
    t3+=t2;
551
0
    t4+=t0;
552
0
    t5-=t0;
553
0
    for(i=2;i<ido;i+=2){
554
0
      t6=idp2+t1-i;
555
0
      t7=i+t3;
556
0
      t8=i+t4;
557
0
      t9=i+t5;
558
0
      for(k=0;k<l1;k++){
559
0
        cc[t7-1]=ch[t8-1]+ch[t9-1];
560
0
        cc[t6-1]=ch[t8-1]-ch[t9-1];
561
0
        cc[t7]=ch[t8]+ch[t9];
562
0
        cc[t6]=ch[t9]-ch[t8];
563
0
        t6+=t10;
564
0
        t7+=t10;
565
0
        t8+=ido;
566
0
        t9+=ido;
567
0
      }
568
0
    }
569
0
  }
570
0
}
571
572
0
static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
573
0
  int i,k1,l1,l2;
574
0
  int na,kh,nf;
575
0
  int ip,iw,ido,idl1,ix2,ix3;
576
577
0
  nf=ifac[1];
578
0
  na=1;
579
0
  l2=n;
580
0
  iw=n;
581
582
0
  for(k1=0;k1<nf;k1++){
583
0
    kh=nf-k1;
584
0
    ip=ifac[kh+1];
585
0
    l1=l2/ip;
586
0
    ido=n/l2;
587
0
    idl1=ido*l1;
588
0
    iw-=(ip-1)*ido;
589
0
    na=1-na;
590
591
0
    if(ip!=4)goto L102;
592
593
0
    ix2=iw+ido;
594
0
    ix3=ix2+ido;
595
0
    if(na!=0)
596
0
      dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
597
0
    else
598
0
      dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
599
0
    goto L110;
600
601
0
 L102:
602
0
    if(ip!=2)goto L104;
603
0
    if(na!=0)goto L103;
604
605
0
    dradf2(ido,l1,c,ch,wa+iw-1);
606
0
    goto L110;
607
608
0
  L103:
609
0
    dradf2(ido,l1,ch,c,wa+iw-1);
610
0
    goto L110;
611
612
0
  L104:
613
0
    if(ido==1)na=1-na;
614
0
    if(na!=0)goto L109;
615
616
0
    dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
617
0
    na=1;
618
0
    goto L110;
619
620
0
  L109:
621
0
    dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
622
0
    na=0;
623
624
0
  L110:
625
0
    l2=l1;
626
0
  }
627
628
0
  if(na==1)return;
629
630
0
  for(i=0;i<n;i++)c[i]=ch[i];
631
0
}
632
633
0
static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
634
0
  int i,k,t0,t1,t2,t3,t4,t5,t6;
635
0
  float ti2,tr2;
636
637
0
  t0=l1*ido;
638
639
0
  t1=0;
640
0
  t2=0;
641
0
  t3=(ido<<1)-1;
642
0
  for(k=0;k<l1;k++){
643
0
    ch[t1]=cc[t2]+cc[t3+t2];
644
0
    ch[t1+t0]=cc[t2]-cc[t3+t2];
645
0
    t2=(t1+=ido)<<1;
646
0
  }
647
648
0
  if(ido<2)return;
649
0
  if(ido==2)goto L105;
650
651
0
  t1=0;
652
0
  t2=0;
653
0
  for(k=0;k<l1;k++){
654
0
    t3=t1;
655
0
    t5=(t4=t2)+(ido<<1);
656
0
    t6=t0+t1;
657
0
    for(i=2;i<ido;i+=2){
658
0
      t3+=2;
659
0
      t4+=2;
660
0
      t5-=2;
661
0
      t6+=2;
662
0
      ch[t3-1]=cc[t4-1]+cc[t5-1];
663
0
      tr2=cc[t4-1]-cc[t5-1];
664
0
      ch[t3]=cc[t4]-cc[t5];
665
0
      ti2=cc[t4]+cc[t5];
666
0
      ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
667
0
      ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
668
0
    }
669
0
    t2=(t1+=ido)<<1;
670
0
  }
671
672
0
  if(ido%2==1)return;
673
674
0
L105:
675
0
  t1=ido-1;
676
0
  t2=ido-1;
677
0
  for(k=0;k<l1;k++){
678
0
    ch[t1]=cc[t2]+cc[t2];
679
0
    ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
680
0
    t1+=ido;
681
0
    t2+=ido<<1;
682
0
  }
683
0
}
684
685
static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
686
0
                          float *wa2){
687
0
  static float taur = -.5f;
688
0
  static float taui = .8660254037844386f;
689
0
  int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
690
0
  float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
691
0
  t0=l1*ido;
692
693
0
  t1=0;
694
0
  t2=t0<<1;
695
0
  t3=ido<<1;
696
0
  t4=ido+(ido<<1);
697
0
  t5=0;
698
0
  for(k=0;k<l1;k++){
699
0
    tr2=cc[t3-1]+cc[t3-1];
700
0
    cr2=cc[t5]+(taur*tr2);
701
0
    ch[t1]=cc[t5]+tr2;
702
0
    ci3=taui*(cc[t3]+cc[t3]);
703
0
    ch[t1+t0]=cr2-ci3;
704
0
    ch[t1+t2]=cr2+ci3;
705
0
    t1+=ido;
706
0
    t3+=t4;
707
0
    t5+=t4;
708
0
  }
709
710
0
  if(ido==1)return;
711
712
0
  t1=0;
713
0
  t3=ido<<1;
714
0
  for(k=0;k<l1;k++){
715
0
    t7=t1+(t1<<1);
716
0
    t6=(t5=t7+t3);
717
0
    t8=t1;
718
0
    t10=(t9=t1+t0)+t0;
719
720
0
    for(i=2;i<ido;i+=2){
721
0
      t5+=2;
722
0
      t6-=2;
723
0
      t7+=2;
724
0
      t8+=2;
725
0
      t9+=2;
726
0
      t10+=2;
727
0
      tr2=cc[t5-1]+cc[t6-1];
728
0
      cr2=cc[t7-1]+(taur*tr2);
729
0
      ch[t8-1]=cc[t7-1]+tr2;
730
0
      ti2=cc[t5]-cc[t6];
731
0
      ci2=cc[t7]+(taur*ti2);
732
0
      ch[t8]=cc[t7]+ti2;
733
0
      cr3=taui*(cc[t5-1]-cc[t6-1]);
734
0
      ci3=taui*(cc[t5]+cc[t6]);
735
0
      dr2=cr2-ci3;
736
0
      dr3=cr2+ci3;
737
0
      di2=ci2+cr3;
738
0
      di3=ci2-cr3;
739
0
      ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
740
0
      ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
741
0
      ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
742
0
      ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
743
0
    }
744
0
    t1+=ido;
745
0
  }
746
0
}
747
748
static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
749
0
                          float *wa2,float *wa3){
750
0
  static float sqrt2=1.414213562373095f;
751
0
  int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
752
0
  float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
753
0
  t0=l1*ido;
754
755
0
  t1=0;
756
0
  t2=ido<<2;
757
0
  t3=0;
758
0
  t6=ido<<1;
759
0
  for(k=0;k<l1;k++){
760
0
    t4=t3+t6;
761
0
    t5=t1;
762
0
    tr3=cc[t4-1]+cc[t4-1];
763
0
    tr4=cc[t4]+cc[t4];
764
0
    tr1=cc[t3]-cc[(t4+=t6)-1];
765
0
    tr2=cc[t3]+cc[t4-1];
766
0
    ch[t5]=tr2+tr3;
767
0
    ch[t5+=t0]=tr1-tr4;
768
0
    ch[t5+=t0]=tr2-tr3;
769
0
    ch[t5+=t0]=tr1+tr4;
770
0
    t1+=ido;
771
0
    t3+=t2;
772
0
  }
773
774
0
  if(ido<2)return;
775
0
  if(ido==2)goto L105;
776
777
0
  t1=0;
778
0
  for(k=0;k<l1;k++){
779
0
    t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
780
0
    t7=t1;
781
0
    for(i=2;i<ido;i+=2){
782
0
      t2+=2;
783
0
      t3+=2;
784
0
      t4-=2;
785
0
      t5-=2;
786
0
      t7+=2;
787
0
      ti1=cc[t2]+cc[t5];
788
0
      ti2=cc[t2]-cc[t5];
789
0
      ti3=cc[t3]-cc[t4];
790
0
      tr4=cc[t3]+cc[t4];
791
0
      tr1=cc[t2-1]-cc[t5-1];
792
0
      tr2=cc[t2-1]+cc[t5-1];
793
0
      ti4=cc[t3-1]-cc[t4-1];
794
0
      tr3=cc[t3-1]+cc[t4-1];
795
0
      ch[t7-1]=tr2+tr3;
796
0
      cr3=tr2-tr3;
797
0
      ch[t7]=ti2+ti3;
798
0
      ci3=ti2-ti3;
799
0
      cr2=tr1-tr4;
800
0
      cr4=tr1+tr4;
801
0
      ci2=ti1+ti4;
802
0
      ci4=ti1-ti4;
803
804
0
      ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
805
0
      ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
806
0
      ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
807
0
      ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
808
0
      ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
809
0
      ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
810
0
    }
811
0
    t1+=ido;
812
0
  }
813
814
0
  if(ido%2 == 1)return;
815
816
0
 L105:
817
818
0
  t1=ido;
819
0
  t2=ido<<2;
820
0
  t3=ido-1;
821
0
  t4=ido+(ido<<1);
822
0
  for(k=0;k<l1;k++){
823
0
    t5=t3;
824
0
    ti1=cc[t1]+cc[t4];
825
0
    ti2=cc[t4]-cc[t1];
826
0
    tr1=cc[t1-1]-cc[t4-1];
827
0
    tr2=cc[t1-1]+cc[t4-1];
828
0
    ch[t5]=tr2+tr2;
829
0
    ch[t5+=t0]=sqrt2*(tr1-ti1);
830
0
    ch[t5+=t0]=ti2+ti2;
831
0
    ch[t5+=t0]=-sqrt2*(tr1+ti1);
832
833
0
    t3+=ido;
834
0
    t1+=t2;
835
0
    t4+=t2;
836
0
  }
837
0
}
838
839
static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
840
0
            float *c2,float *ch,float *ch2,float *wa){
841
0
  static float tpi=6.283185307179586f;
842
0
  int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
843
0
      t11,t12;
844
0
  float dc2,ai1,ai2,ar1,ar2,ds2;
845
0
  int nbd;
846
0
  float dcp,arg,dsp,ar1h,ar2h;
847
0
  int ipp2;
848
849
0
  t10=ip*ido;
850
0
  t0=l1*ido;
851
0
  arg=tpi/(float)ip;
852
0
  dcp=cos(arg);
853
0
  dsp=sin(arg);
854
0
  nbd=(ido-1)>>1;
855
0
  ipp2=ip;
856
0
  ipph=(ip+1)>>1;
857
0
  if(ido<l1)goto L103;
858
859
0
  t1=0;
860
0
  t2=0;
861
0
  for(k=0;k<l1;k++){
862
0
    t3=t1;
863
0
    t4=t2;
864
0
    for(i=0;i<ido;i++){
865
0
      ch[t3]=cc[t4];
866
0
      t3++;
867
0
      t4++;
868
0
    }
869
0
    t1+=ido;
870
0
    t2+=t10;
871
0
  }
872
0
  goto L106;
873
874
0
 L103:
875
0
  t1=0;
876
0
  for(i=0;i<ido;i++){
877
0
    t2=t1;
878
0
    t3=t1;
879
0
    for(k=0;k<l1;k++){
880
0
      ch[t2]=cc[t3];
881
0
      t2+=ido;
882
0
      t3+=t10;
883
0
    }
884
0
    t1++;
885
0
  }
886
887
0
 L106:
888
0
  t1=0;
889
0
  t2=ipp2*t0;
890
0
  t7=(t5=ido<<1);
891
0
  for(j=1;j<ipph;j++){
892
0
    t1+=t0;
893
0
    t2-=t0;
894
0
    t3=t1;
895
0
    t4=t2;
896
0
    t6=t5;
897
0
    for(k=0;k<l1;k++){
898
0
      ch[t3]=cc[t6-1]+cc[t6-1];
899
0
      ch[t4]=cc[t6]+cc[t6];
900
0
      t3+=ido;
901
0
      t4+=ido;
902
0
      t6+=t10;
903
0
    }
904
0
    t5+=t7;
905
0
  }
906
907
0
  if (ido == 1)goto L116;
908
0
  if(nbd<l1)goto L112;
909
910
0
  t1=0;
911
0
  t2=ipp2*t0;
912
0
  t7=0;
913
0
  for(j=1;j<ipph;j++){
914
0
    t1+=t0;
915
0
    t2-=t0;
916
0
    t3=t1;
917
0
    t4=t2;
918
919
0
    t7+=(ido<<1);
920
0
    t8=t7;
921
0
    for(k=0;k<l1;k++){
922
0
      t5=t3;
923
0
      t6=t4;
924
0
      t9=t8;
925
0
      t11=t8;
926
0
      for(i=2;i<ido;i+=2){
927
0
        t5+=2;
928
0
        t6+=2;
929
0
        t9+=2;
930
0
        t11-=2;
931
0
        ch[t5-1]=cc[t9-1]+cc[t11-1];
932
0
        ch[t6-1]=cc[t9-1]-cc[t11-1];
933
0
        ch[t5]=cc[t9]-cc[t11];
934
0
        ch[t6]=cc[t9]+cc[t11];
935
0
      }
936
0
      t3+=ido;
937
0
      t4+=ido;
938
0
      t8+=t10;
939
0
    }
940
0
  }
941
0
  goto L116;
942
943
0
 L112:
944
0
  t1=0;
945
0
  t2=ipp2*t0;
946
0
  t7=0;
947
0
  for(j=1;j<ipph;j++){
948
0
    t1+=t0;
949
0
    t2-=t0;
950
0
    t3=t1;
951
0
    t4=t2;
952
0
    t7+=(ido<<1);
953
0
    t8=t7;
954
0
    t9=t7;
955
0
    for(i=2;i<ido;i+=2){
956
0
      t3+=2;
957
0
      t4+=2;
958
0
      t8+=2;
959
0
      t9-=2;
960
0
      t5=t3;
961
0
      t6=t4;
962
0
      t11=t8;
963
0
      t12=t9;
964
0
      for(k=0;k<l1;k++){
965
0
        ch[t5-1]=cc[t11-1]+cc[t12-1];
966
0
        ch[t6-1]=cc[t11-1]-cc[t12-1];
967
0
        ch[t5]=cc[t11]-cc[t12];
968
0
        ch[t6]=cc[t11]+cc[t12];
969
0
        t5+=ido;
970
0
        t6+=ido;
971
0
        t11+=t10;
972
0
        t12+=t10;
973
0
      }
974
0
    }
975
0
  }
976
977
0
L116:
978
0
  ar1=1.f;
979
0
  ai1=0.f;
980
0
  t1=0;
981
0
  t9=(t2=ipp2*idl1);
982
0
  t3=(ip-1)*idl1;
983
0
  for(l=1;l<ipph;l++){
984
0
    t1+=idl1;
985
0
    t2-=idl1;
986
987
0
    ar1h=dcp*ar1-dsp*ai1;
988
0
    ai1=dcp*ai1+dsp*ar1;
989
0
    ar1=ar1h;
990
0
    t4=t1;
991
0
    t5=t2;
992
0
    t6=0;
993
0
    t7=idl1;
994
0
    t8=t3;
995
0
    for(ik=0;ik<idl1;ik++){
996
0
      c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
997
0
      c2[t5++]=ai1*ch2[t8++];
998
0
    }
999
0
    dc2=ar1;
1000
0
    ds2=ai1;
1001
0
    ar2=ar1;
1002
0
    ai2=ai1;
1003
1004
0
    t6=idl1;
1005
0
    t7=t9-idl1;
1006
0
    for(j=2;j<ipph;j++){
1007
0
      t6+=idl1;
1008
0
      t7-=idl1;
1009
0
      ar2h=dc2*ar2-ds2*ai2;
1010
0
      ai2=dc2*ai2+ds2*ar2;
1011
0
      ar2=ar2h;
1012
0
      t4=t1;
1013
0
      t5=t2;
1014
0
      t11=t6;
1015
0
      t12=t7;
1016
0
      for(ik=0;ik<idl1;ik++){
1017
0
        c2[t4++]+=ar2*ch2[t11++];
1018
0
        c2[t5++]+=ai2*ch2[t12++];
1019
0
      }
1020
0
    }
1021
0
  }
1022
1023
0
  t1=0;
1024
0
  for(j=1;j<ipph;j++){
1025
0
    t1+=idl1;
1026
0
    t2=t1;
1027
0
    for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
1028
0
  }
1029
1030
0
  t1=0;
1031
0
  t2=ipp2*t0;
1032
0
  for(j=1;j<ipph;j++){
1033
0
    t1+=t0;
1034
0
    t2-=t0;
1035
0
    t3=t1;
1036
0
    t4=t2;
1037
0
    for(k=0;k<l1;k++){
1038
0
      ch[t3]=c1[t3]-c1[t4];
1039
0
      ch[t4]=c1[t3]+c1[t4];
1040
0
      t3+=ido;
1041
0
      t4+=ido;
1042
0
    }
1043
0
  }
1044
1045
0
  if(ido==1)goto L132;
1046
0
  if(nbd<l1)goto L128;
1047
1048
0
  t1=0;
1049
0
  t2=ipp2*t0;
1050
0
  for(j=1;j<ipph;j++){
1051
0
    t1+=t0;
1052
0
    t2-=t0;
1053
0
    t3=t1;
1054
0
    t4=t2;
1055
0
    for(k=0;k<l1;k++){
1056
0
      t5=t3;
1057
0
      t6=t4;
1058
0
      for(i=2;i<ido;i+=2){
1059
0
        t5+=2;
1060
0
        t6+=2;
1061
0
        ch[t5-1]=c1[t5-1]-c1[t6];
1062
0
        ch[t6-1]=c1[t5-1]+c1[t6];
1063
0
        ch[t5]=c1[t5]+c1[t6-1];
1064
0
        ch[t6]=c1[t5]-c1[t6-1];
1065
0
      }
1066
0
      t3+=ido;
1067
0
      t4+=ido;
1068
0
    }
1069
0
  }
1070
0
  goto L132;
1071
1072
0
 L128:
1073
0
  t1=0;
1074
0
  t2=ipp2*t0;
1075
0
  for(j=1;j<ipph;j++){
1076
0
    t1+=t0;
1077
0
    t2-=t0;
1078
0
    t3=t1;
1079
0
    t4=t2;
1080
0
    for(i=2;i<ido;i+=2){
1081
0
      t3+=2;
1082
0
      t4+=2;
1083
0
      t5=t3;
1084
0
      t6=t4;
1085
0
      for(k=0;k<l1;k++){
1086
0
        ch[t5-1]=c1[t5-1]-c1[t6];
1087
0
        ch[t6-1]=c1[t5-1]+c1[t6];
1088
0
        ch[t5]=c1[t5]+c1[t6-1];
1089
0
        ch[t6]=c1[t5]-c1[t6-1];
1090
0
        t5+=ido;
1091
0
        t6+=ido;
1092
0
      }
1093
0
    }
1094
0
  }
1095
1096
0
L132:
1097
0
  if(ido==1)return;
1098
1099
0
  for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
1100
1101
0
  t1=0;
1102
0
  for(j=1;j<ip;j++){
1103
0
    t2=(t1+=t0);
1104
0
    for(k=0;k<l1;k++){
1105
0
      c1[t2]=ch[t2];
1106
0
      t2+=ido;
1107
0
    }
1108
0
  }
1109
1110
0
  if(nbd>l1)goto L139;
1111
1112
0
  is= -ido-1;
1113
0
  t1=0;
1114
0
  for(j=1;j<ip;j++){
1115
0
    is+=ido;
1116
0
    t1+=t0;
1117
0
    idij=is;
1118
0
    t2=t1;
1119
0
    for(i=2;i<ido;i+=2){
1120
0
      t2+=2;
1121
0
      idij+=2;
1122
0
      t3=t2;
1123
0
      for(k=0;k<l1;k++){
1124
0
        c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
1125
0
        c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
1126
0
        t3+=ido;
1127
0
      }
1128
0
    }
1129
0
  }
1130
0
  return;
1131
1132
0
 L139:
1133
0
  is= -ido-1;
1134
0
  t1=0;
1135
0
  for(j=1;j<ip;j++){
1136
0
    is+=ido;
1137
0
    t1+=t0;
1138
0
    t2=t1;
1139
0
    for(k=0;k<l1;k++){
1140
0
      idij=is;
1141
0
      t3=t2;
1142
0
      for(i=2;i<ido;i+=2){
1143
0
        idij+=2;
1144
0
        t3+=2;
1145
0
        c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
1146
0
        c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
1147
0
      }
1148
0
      t2+=ido;
1149
0
    }
1150
0
  }
1151
0
}
1152
1153
0
static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
1154
0
  int i,k1,l1,l2;
1155
0
  int na;
1156
0
  int nf,ip,iw,ix2,ix3,ido,idl1;
1157
1158
0
  nf=ifac[1];
1159
0
  na=0;
1160
0
  l1=1;
1161
0
  iw=1;
1162
1163
0
  for(k1=0;k1<nf;k1++){
1164
0
    ip=ifac[k1 + 2];
1165
0
    l2=ip*l1;
1166
0
    ido=n/l2;
1167
0
    idl1=ido*l1;
1168
0
    if(ip!=4)goto L103;
1169
0
    ix2=iw+ido;
1170
0
    ix3=ix2+ido;
1171
1172
0
    if(na!=0)
1173
0
      dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
1174
0
    else
1175
0
      dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
1176
0
    na=1-na;
1177
0
    goto L115;
1178
1179
0
  L103:
1180
0
    if(ip!=2)goto L106;
1181
1182
0
    if(na!=0)
1183
0
      dradb2(ido,l1,ch,c,wa+iw-1);
1184
0
    else
1185
0
      dradb2(ido,l1,c,ch,wa+iw-1);
1186
0
    na=1-na;
1187
0
    goto L115;
1188
1189
0
  L106:
1190
0
    if(ip!=3)goto L109;
1191
1192
0
    ix2=iw+ido;
1193
0
    if(na!=0)
1194
0
      dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
1195
0
    else
1196
0
      dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
1197
0
    na=1-na;
1198
0
    goto L115;
1199
1200
0
  L109:
1201
/*    The radix five case can be translated later..... */
1202
/*    if(ip!=5)goto L112;
1203
1204
    ix2=iw+ido;
1205
    ix3=ix2+ido;
1206
    ix4=ix3+ido;
1207
    if(na!=0)
1208
      dradb5(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1,wa+ix4-1);
1209
    else
1210
      dradb5(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1,wa+ix4-1);
1211
    na=1-na;
1212
    goto L115;
1213
1214
  L112:*/
1215
0
    if(na!=0)
1216
0
      dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
1217
0
    else
1218
0
      dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
1219
0
    if(ido==1)na=1-na;
1220
1221
0
  L115:
1222
0
    l1=l2;
1223
0
    iw+=(ip-1)*ido;
1224
0
  }
1225
1226
0
  if(na==0)return;
1227
1228
0
  for(i=0;i<n;i++)c[i]=ch[i];
1229
0
}
1230
1231
0
void drft_forward(drft_lookup *l,float *data){
1232
0
  if(l->n==1)return;
1233
0
  drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
1234
0
}
1235
1236
0
void drft_backward(drft_lookup *l,float *data){
1237
0
  if (l->n==1)return;
1238
0
  drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
1239
0
}
1240
1241
0
void drft_init(drft_lookup *l,int n){
1242
0
  l->n=n;
1243
0
  l->trigcache=_ogg_calloc(3*n,sizeof(*l->trigcache));
1244
0
  l->splitcache=_ogg_calloc(32,sizeof(*l->splitcache));
1245
0
  fdrffti(n, l->trigcache, l->splitcache);
1246
0
}
1247
1248
0
void drft_clear(drft_lookup *l){
1249
0
  if(l){
1250
0
    if(l->trigcache)_ogg_free(l->trigcache);
1251
0
    if(l->splitcache)_ogg_free(l->splitcache);
1252
0
    memset(l,0,sizeof(*l));
1253
0
  }
1254
0
}