comparison fft/kissfft/FFT.js @ 40:223f770b5341 kissfft-double tip

Try a double-precision kissfft
author Chris Cannam
date Wed, 07 Sep 2016 10:40:32 +0100
parents a47f895d79c0
children
comparison
equal deleted inserted replaced
39:c1ec7564ccac 40:223f770b5341
33 function KissFFT(size) { 33 function KissFFT(size) {
34 34
35 this.size = size; 35 this.size = size;
36 this.fcfg = kiss_fft_alloc(size, false); 36 this.fcfg = kiss_fft_alloc(size, false);
37 this.icfg = kiss_fft_alloc(size, true); 37 this.icfg = kiss_fft_alloc(size, true);
38
39 var samplesize = 8;
40 this.inptr = kissFFTModule._malloc(size*samplesize*2 + size*samplesize*2);
41 this.outptr = this.inptr + size*samplesize*2;
38 42
39 this.inptr = kissFFTModule._malloc(size*8 + size*8); 43 this.cin = new Float64Array(kissFFTModule.HEAPU8.buffer, this.inptr, size*2);
40 this.outptr = this.inptr + size*8; 44 this.cout = new Float64Array(kissFFTModule.HEAPU8.buffer, this.outptr, size*2);
41
42 this.cin = new Float32Array(kissFFTModule.HEAPU8.buffer, this.inptr, size*2);
43 this.cout = new Float32Array(kissFFTModule.HEAPU8.buffer, this.outptr, size*2);
44 45
45 this.forward = function(cin) { 46 this.forward = function(cin) {
46 this.cin.set(cin); 47 this.cin.set(cin);
47 kiss_fft(this.fcfg, this.inptr, this.outptr); 48 kiss_fft(this.fcfg, this.inptr, this.outptr);
48 return new Float32Array(kissFFTModule.HEAPU8.buffer, 49 return new Float64Array(kissFFTModule.HEAPU8.buffer,
49 this.outptr, this.size * 2); 50 this.outptr, this.size * 2);
50 } 51 }
51 52
52 this.inverse = function(cin) { 53 this.inverse = function(cin) {
53 this.cin.set(cpx); 54 this.cin.set(cpx);
54 kiss_fft(this.icfg, this.inptr, this.outptr); 55 kiss_fft(this.icfg, this.inptr, this.outptr);
55 return new Float32Array(kissFFTModule.HEAPU8.buffer, 56 return new Float64Array(kissFFTModule.HEAPU8.buffer,
56 this.outptr, this.size * 2); 57 this.outptr, this.size * 2);
57 } 58 }
58 59
59 this.dispose = function() { 60 this.dispose = function() {
60 kissFFTModule._free(this.inptr); 61 kissFFTModule._free(this.inptr);
67 68
68 this.size = size; 69 this.size = size;
69 this.fcfg = kiss_fftr_alloc(size, false); 70 this.fcfg = kiss_fftr_alloc(size, false);
70 this.icfg = kiss_fftr_alloc(size, true); 71 this.icfg = kiss_fftr_alloc(size, true);
71 72
72 this.rptr = kissFFTModule._malloc(size*4 + (size+2)*4); 73 var samplesize = 8;
73 this.cptr = this.rptr + size*4; 74 this.rptr = kissFFTModule._malloc(size*samplesize + (size+2)*samplesize);
75 this.cptr = this.rptr + size*samplesize;
74 76
75 this.ri = new Float32Array(kissFFTModule.HEAPU8.buffer, this.rptr, size); 77 this.ri = new Float64Array(kissFFTModule.HEAPU8.buffer, this.rptr, size);
76 this.ci = new Float32Array(kissFFTModule.HEAPU8.buffer, this.cptr, size+2); 78 this.ci = new Float64Array(kissFFTModule.HEAPU8.buffer, this.cptr, size+2);
77 79
78 this.forward = function(real) { 80 this.forward = function(real) {
79 this.ri.set(real); 81 this.ri.set(real);
80 kiss_fftr(this.fcfg, this.rptr, this.cptr); 82 kiss_fftr(this.fcfg, this.rptr, this.cptr);
81 return new Float32Array(kissFFTModule.HEAPU8.buffer, 83 return new Float64Array(kissFFTModule.HEAPU8.buffer,
82 this.cptr, this.size + 2); 84 this.cptr, this.size + 2);
83 } 85 }
84 86
85 this.inverse = function(cpx) { 87 this.inverse = function(cpx) {
86 this.ci.set(cpx); 88 this.ci.set(cpx);
87 kiss_fftri(this.icfg, this.cptr, this.rptr); 89 kiss_fftri(this.icfg, this.cptr, this.rptr);
88 return new Float32Array(kissFFTModule.HEAPU8.buffer, 90 return new Float64Array(kissFFTModule.HEAPU8.buffer,
89 this.rptr, this.size); 91 this.rptr, this.size);
90 } 92 }
91 93
92 this.dispose = function() { 94 this.dispose = function() {
93 kissFFTModule._free(this.rptr); 95 kissFFTModule._free(this.rptr);