Chris@8
|
1 "use strict";
|
Chris@8
|
2
|
Chris@8
|
3 var kissFFTModule = KissFFTModule({});
|
Chris@8
|
4
|
Chris@8
|
5 var kiss_fftr_alloc = kissFFTModule.cwrap(
|
Chris@8
|
6 'kiss_fftr_alloc', 'number', ['number', 'number', 'number', 'number' ]
|
Chris@8
|
7 );
|
Chris@8
|
8
|
Chris@8
|
9 var kiss_fftr = kissFFTModule.cwrap(
|
Chris@8
|
10 'kiss_fftr', 'void', ['number', 'number', 'number' ]
|
Chris@8
|
11 );
|
Chris@8
|
12
|
Chris@8
|
13 var kiss_fftri = kissFFTModule.cwrap(
|
Chris@8
|
14 'kiss_fftri', 'void', ['number', 'number', 'number' ]
|
Chris@8
|
15 );
|
Chris@8
|
16
|
Chris@8
|
17 var kiss_fftr_free = kissFFTModule.cwrap(
|
Chris@8
|
18 'kiss_fftr_free', 'void', ['number']
|
Chris@8
|
19 );
|
Chris@8
|
20
|
Chris@37
|
21 var kiss_fft_alloc = kissFFTModule.cwrap(
|
Chris@37
|
22 'kiss_fft_alloc', 'number', ['number', 'number', 'number', 'number' ]
|
Chris@37
|
23 );
|
Chris@37
|
24
|
Chris@37
|
25 var kiss_fft = kissFFTModule.cwrap(
|
Chris@37
|
26 'kiss_fft', 'void', ['number', 'number', 'number' ]
|
Chris@37
|
27 );
|
Chris@37
|
28
|
Chris@37
|
29 var kiss_fft_free = kissFFTModule.cwrap(
|
Chris@37
|
30 'kiss_fft_free', 'void', ['number']
|
Chris@37
|
31 );
|
Chris@37
|
32
|
Chris@8
|
33 function KissFFT(size) {
|
Chris@19
|
34
|
Chris@8
|
35 this.size = size;
|
Chris@37
|
36 this.fcfg = kiss_fft_alloc(size, false);
|
Chris@37
|
37 this.icfg = kiss_fft_alloc(size, true);
|
Chris@37
|
38
|
Chris@37
|
39 this.inptr = kissFFTModule._malloc(size*8 + size*8);
|
Chris@37
|
40 this.outptr = this.inptr + size*8;
|
Chris@37
|
41
|
Chris@37
|
42 this.cin = new Float32Array(kissFFTModule.HEAPU8.buffer, this.inptr, size*2);
|
Chris@37
|
43 this.cout = new Float32Array(kissFFTModule.HEAPU8.buffer, this.outptr, size*2);
|
Chris@37
|
44
|
Chris@37
|
45 this.forward = function(cin) {
|
Chris@37
|
46 this.cin.set(cin);
|
Chris@37
|
47 kiss_fft(this.fcfg, this.inptr, this.outptr);
|
Chris@37
|
48 return new Float32Array(kissFFTModule.HEAPU8.buffer,
|
Chris@37
|
49 this.outptr, this.size * 2);
|
Chris@37
|
50 }
|
Chris@37
|
51
|
Chris@37
|
52 this.inverse = function(cin) {
|
Chris@37
|
53 this.cin.set(cpx);
|
Chris@37
|
54 kiss_fft(this.icfg, this.inptr, this.outptr);
|
Chris@37
|
55 return new Float32Array(kissFFTModule.HEAPU8.buffer,
|
Chris@37
|
56 this.outptr, this.size * 2);
|
Chris@37
|
57 }
|
Chris@37
|
58
|
Chris@37
|
59 this.dispose = function() {
|
Chris@37
|
60 kissFFTModule._free(this.inptr);
|
Chris@37
|
61 kiss_fft_free(this.fcfg);
|
Chris@37
|
62 kiss_fft_free(this.icfg);
|
Chris@37
|
63 }
|
Chris@37
|
64 }
|
Chris@37
|
65
|
Chris@37
|
66 function KissFFTR(size) {
|
Chris@37
|
67
|
Chris@37
|
68 this.size = size;
|
Chris@8
|
69 this.fcfg = kiss_fftr_alloc(size, false);
|
Chris@8
|
70 this.icfg = kiss_fftr_alloc(size, true);
|
Chris@19
|
71
|
Chris@19
|
72 this.rptr = kissFFTModule._malloc(size*4 + (size+2)*4);
|
Chris@19
|
73 this.cptr = this.rptr + size*4;
|
Chris@19
|
74
|
Chris@19
|
75 this.ri = new Float32Array(kissFFTModule.HEAPU8.buffer, this.rptr, size);
|
Chris@19
|
76 this.ci = new Float32Array(kissFFTModule.HEAPU8.buffer, this.cptr, size+2);
|
Chris@19
|
77
|
Chris@8
|
78 this.forward = function(real) {
|
Chris@19
|
79 this.ri.set(real);
|
Chris@19
|
80 kiss_fftr(this.fcfg, this.rptr, this.cptr);
|
Chris@21
|
81 return new Float32Array(kissFFTModule.HEAPU8.buffer,
|
Chris@21
|
82 this.cptr, this.size + 2);
|
Chris@8
|
83 }
|
Chris@19
|
84
|
Chris@8
|
85 this.inverse = function(cpx) {
|
Chris@19
|
86 this.ci.set(cpx);
|
Chris@19
|
87 kiss_fftri(this.icfg, this.cptr, this.rptr);
|
Chris@21
|
88 return new Float32Array(kissFFTModule.HEAPU8.buffer,
|
Chris@21
|
89 this.rptr, this.size);
|
Chris@8
|
90 }
|
Chris@19
|
91
|
Chris@19
|
92 this.dispose = function() {
|
Chris@19
|
93 kissFFTModule._free(this.rptr);
|
Chris@8
|
94 kiss_fftr_free(this.fcfg);
|
Chris@8
|
95 kiss_fftr_free(this.icfg);
|
Chris@8
|
96 }
|
Chris@8
|
97 }
|
Chris@8
|
98
|