Chris@32: "use strict"; Chris@32: Chris@32: var nayukiCModule = NayukiCModule({}); Chris@32: Chris@32: var nc_precalc = nayukiCModule.cwrap( Chris@32: 'precalc', 'number', ['number'] Chris@32: ); Chris@32: Chris@32: var nc_dispose = nayukiCModule.cwrap( Chris@32: 'dispose', 'void', ['number'] Chris@32: ); Chris@32: Chris@32: var nc_transform_radix2_precalc = nayukiCModule.cwrap( Chris@32: 'transform_radix2_precalc', 'void', ['number', 'number', 'number', 'number'] Chris@32: ); Chris@32: Chris@33: var nc_precalc_f = nayukiCModule.cwrap( Chris@33: 'precalc_f', 'number', ['number'] Chris@33: ); Chris@33: Chris@33: var nc_dispose_f = nayukiCModule.cwrap( Chris@33: 'dispose_f', 'void', ['number'] Chris@33: ); Chris@33: Chris@33: var nc_transform_radix2_precalc_f = nayukiCModule.cwrap( Chris@33: 'transform_radix2_precalc_f', 'void', ['number', 'number', 'number', 'number'] Chris@33: ); Chris@33: Chris@32: function FFTNayukiC(n) { Chris@32: Chris@32: this.n = n; Chris@32: this.rptr = nayukiCModule._malloc(n*8 + n*8); Chris@32: this.iptr = this.rptr + n*8; Chris@32: this.rarr = new Float64Array(nayukiCModule.HEAPU8.buffer, this.rptr, n); Chris@32: this.iarr = new Float64Array(nayukiCModule.HEAPU8.buffer, this.iptr, n); Chris@32: this.tables = nc_precalc(n); Chris@32: Chris@32: this.forward = function(real, imag) { Chris@32: this.rarr.set(real); Chris@32: this.iarr.set(imag); Chris@32: nc_transform_radix2_precalc(this.rptr, this.iptr, this.n, this.tables); Chris@32: real.set(this.rarr); Chris@32: imag.set(this.iarr); Chris@32: }; Chris@32: Chris@32: this.dispose = function() { Chris@32: nayukiCModule._free(this.rptr); Chris@32: nc_dispose(this.tables); Chris@32: } Chris@32: } Chris@32: Chris@33: function FFTNayukiCFloat(n) { Chris@33: Chris@33: this.n = n; Chris@33: this.rptr = nayukiCModule._malloc(n*4 + n*4); Chris@33: this.iptr = this.rptr + n*4; Chris@33: this.rarr = new Float32Array(nayukiCModule.HEAPU8.buffer, this.rptr, n); Chris@33: this.iarr = new Float32Array(nayukiCModule.HEAPU8.buffer, this.iptr, n); Chris@33: this.tables = nc_precalc_f(n); Chris@33: Chris@33: this.forward = function(real, imag) { Chris@33: this.rarr.set(real); Chris@33: this.iarr.set(imag); Chris@33: nc_transform_radix2_precalc_f(this.rptr, this.iptr, this.n, this.tables); Chris@33: real.set(this.rarr); Chris@33: imag.set(this.iarr); Chris@33: }; Chris@33: Chris@33: this.dispose = function() { Chris@33: nayukiCModule._free(this.rptr); Chris@33: nc_dispose_f(this.tables); Chris@33: } Chris@33: } Chris@33: