@thi.ng/dsp 4.2.21 → 4.2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -66
- package/package.json +12 -12
- package/dev/fftjs.js +0 -512
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-
|
|
3
|
+
- **Last updated**: 2022-11-23T22:46:54Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -54,20 +54,14 @@ and/or version bumps of transitive dependencies.
|
|
|
54
54
|
|
|
55
55
|
#### ♻️ Refactoring
|
|
56
56
|
|
|
57
|
-
- update imports in all tests/pkgs ([effd591](https://github.com/thi-ng/umbrella/commit/effd591))
|
|
58
57
|
- update imports in all pkgs ([5fa2b6f](https://github.com/thi-ng/umbrella/commit/5fa2b6f))
|
|
59
58
|
- add .js suffix for all relative imports
|
|
59
|
+
- update imports in all tests/pkgs ([effd591](https://github.com/thi-ng/umbrella/commit/effd591))
|
|
60
60
|
|
|
61
61
|
# [4.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dsp@4.0.0) (2021-10-12)
|
|
62
62
|
|
|
63
63
|
#### 🛑 Breaking changes
|
|
64
64
|
|
|
65
|
-
- restructure/flatten /src folder, add ops ([c001e6f](https://github.com/thi-ng/umbrella/commit/c001e6f))
|
|
66
|
-
- BREAKING CHANGE: restructure pkg, add/rename ops
|
|
67
|
-
- dissolve all subfolders
|
|
68
|
-
- add bounce()
|
|
69
|
-
- rename `compP()` => `serial()`
|
|
70
|
-
- add docs
|
|
71
65
|
- major update of ALL pkgs (export maps, ESM only) ([0d1d6ea](https://github.com/thi-ng/umbrella/commit/0d1d6ea))
|
|
72
66
|
- BREAKING CHANGE: discontinue CommonJS & UMD versions
|
|
73
67
|
- only ESM modules will be published from now on
|
|
@@ -80,25 +74,25 @@ and/or version bumps of transitive dependencies.
|
|
|
80
74
|
- normalize/restructure/reorg all package.json files
|
|
81
75
|
- cleanup all build scripts, remove obsolete
|
|
82
76
|
- switch from mocha to [@thi.ng/testament](https://github.com/thi-ng/umbrella/tree/main/packages/testament) for all tests
|
|
77
|
+
- restructure/flatten /src folder, add ops ([c001e6f](https://github.com/thi-ng/umbrella/commit/c001e6f))
|
|
78
|
+
- BREAKING CHANGE: restructure pkg, add/rename ops
|
|
79
|
+
- dissolve all subfolders
|
|
80
|
+
- add bounce()
|
|
81
|
+
- rename `compP()` => `serial()`
|
|
82
|
+
- add docs
|
|
83
83
|
|
|
84
84
|
#### ♻️ Refactoring
|
|
85
85
|
|
|
86
|
-
- dedupe IGen.take() impls ([55ba0f9](https://github.com/thi-ng/umbrella/commit/55ba0f9))
|
|
87
|
-
- update imports (transducers) ([6e7bf71](https://github.com/thi-ng/umbrella/commit/6e7bf71))
|
|
88
|
-
- update imports ([02f1cf7](https://github.com/thi-ng/umbrella/commit/02f1cf7))
|
|
89
86
|
- update all tests in _all_ pkgs ([8b582bc](https://github.com/thi-ng/umbrella/commit/8b582bc))
|
|
90
87
|
- update all to use [@thi.ng/testament](https://github.com/thi-ng/umbrella/tree/main/packages/testament)
|
|
88
|
+
- update imports ([02f1cf7](https://github.com/thi-ng/umbrella/commit/02f1cf7))
|
|
89
|
+
- update imports (transducers) ([6e7bf71](https://github.com/thi-ng/umbrella/commit/6e7bf71))
|
|
90
|
+
- dedupe IGen.take() impls ([55ba0f9](https://github.com/thi-ng/umbrella/commit/55ba0f9))
|
|
91
91
|
|
|
92
92
|
# [3.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dsp@3.0.0) (2020-12-22)
|
|
93
93
|
|
|
94
94
|
#### 🛑 Breaking changes
|
|
95
95
|
|
|
96
|
-
- fix [#256](https://github.com/thi-ng/umbrella/issues/256) replace enums w/ type aliases ([b9cfacb](https://github.com/thi-ng/umbrella/commit/b9cfacb))
|
|
97
|
-
- BREAKING CHANGE: replace filter type enums w/ type aliases
|
|
98
|
-
- FilterType
|
|
99
|
-
- BiquadType
|
|
100
|
-
- SVFType
|
|
101
|
-
- OnepoleType
|
|
102
96
|
- add/update various FFT & spectrum fns (fix [#258](https://github.com/thi-ng/umbrella/issues/258)) ([e351acb](https://github.com/thi-ng/umbrella/commit/e351acb))
|
|
103
97
|
- BREAKING CHANGE: new args for normalizeFFT(),denormalizeFFT(), spectrumPow()
|
|
104
98
|
- add support for windowing adjustments in above functions
|
|
@@ -106,13 +100,15 @@ and/or version bumps of transitive dependencies.
|
|
|
106
100
|
- add copyComplex()
|
|
107
101
|
- update various real/complex checks using isComplex()
|
|
108
102
|
- update docs, add references
|
|
103
|
+
- fix [#256](https://github.com/thi-ng/umbrella/issues/256) replace enums w/ type aliases ([b9cfacb](https://github.com/thi-ng/umbrella/commit/b9cfacb))
|
|
104
|
+
- BREAKING CHANGE: replace filter type enums w/ type aliases
|
|
105
|
+
- FilterType
|
|
106
|
+
- BiquadType
|
|
107
|
+
- SVFType
|
|
108
|
+
- OnepoleType
|
|
109
109
|
|
|
110
110
|
#### 🚀 Features
|
|
111
111
|
|
|
112
|
-
- add windowWelch(), add docs ([84cd476](https://github.com/thi-ng/umbrella/commit/84cd476))
|
|
113
|
-
- add/update power & integral fns ([f455fad](https://github.com/thi-ng/umbrella/commit/f455fad))
|
|
114
|
-
- add applyWindow(), windowBartlett() ([d51a17c](https://github.com/thi-ng/umbrella/commit/d51a17c))
|
|
115
|
-
- add cos() stateless oscillator ([276c6b7](https://github.com/thi-ng/umbrella/commit/276c6b7))
|
|
116
112
|
- add power & integral fns ([88edaac](https://github.com/thi-ng/umbrella/commit/88edaac))
|
|
117
113
|
- add power functions:
|
|
118
114
|
- powerSumSquared()
|
|
@@ -120,6 +116,10 @@ and/or version bumps of transitive dependencies.
|
|
|
120
116
|
- powerTimeIntegral()
|
|
121
117
|
- add integralF/T()
|
|
122
118
|
- add isComplex() check
|
|
119
|
+
- add cos() stateless oscillator ([276c6b7](https://github.com/thi-ng/umbrella/commit/276c6b7))
|
|
120
|
+
- add applyWindow(), windowBartlett() ([d51a17c](https://github.com/thi-ng/umbrella/commit/d51a17c))
|
|
121
|
+
- add/update power & integral fns ([f455fad](https://github.com/thi-ng/umbrella/commit/f455fad))
|
|
122
|
+
- add windowWelch(), add docs ([84cd476](https://github.com/thi-ng/umbrella/commit/84cd476))
|
|
123
123
|
|
|
124
124
|
#### ♻️ Refactoring
|
|
125
125
|
|
|
@@ -130,15 +130,15 @@ and/or version bumps of transitive dependencies.
|
|
|
130
130
|
|
|
131
131
|
#### ♻️ Refactoring
|
|
132
132
|
|
|
133
|
-
- update type-only imports in remaining pkgs ([b22aa30](https://github.com/thi-ng/umbrella/commit/b22aa30))
|
|
134
133
|
- update type-only imports in various tests/pkgs ([3fd9c24](https://github.com/thi-ng/umbrella/commit/3fd9c24))
|
|
134
|
+
- update type-only imports in remaining pkgs ([b22aa30](https://github.com/thi-ng/umbrella/commit/b22aa30))
|
|
135
135
|
|
|
136
136
|
### [2.1.1](https://github.com/thi-ng/umbrella/tree/@thi.ng/dsp@2.1.1) (2020-09-13)
|
|
137
137
|
|
|
138
138
|
#### ♻️ Refactoring
|
|
139
139
|
|
|
140
|
-
- update imports ([28bfb3c](https://github.com/thi-ng/umbrella/commit/28bfb3c))
|
|
141
140
|
- update deps, imports, use new Fn types ([683b4e9](https://github.com/thi-ng/umbrella/commit/683b4e9))
|
|
141
|
+
- update imports ([28bfb3c](https://github.com/thi-ng/umbrella/commit/28bfb3c))
|
|
142
142
|
|
|
143
143
|
## [2.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dsp@2.1.0) (2020-08-28)
|
|
144
144
|
|
|
@@ -168,29 +168,23 @@ and/or version bumps of transitive dependencies.
|
|
|
168
168
|
|
|
169
169
|
#### 🚀 Features
|
|
170
170
|
|
|
171
|
-
-
|
|
172
|
-
- update
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
-
|
|
176
|
-
-
|
|
177
|
-
|
|
178
|
-
- add
|
|
179
|
-
- add
|
|
180
|
-
-
|
|
181
|
-
-
|
|
182
|
-
- add/
|
|
183
|
-
- add
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
- rename
|
|
188
|
-
- update all gens/procs, housekeeping, docs ([e483245](https://github.com/thi-ng/umbrella/commit/e483245))
|
|
189
|
-
- add param accessors for all ops
|
|
190
|
-
- add IReset & impls for most gens/procs
|
|
191
|
-
- add Delay.multiTap()
|
|
192
|
-
- replace exp() w/ curve(), add curvature ctrl
|
|
193
|
-
- remove lfo(), wrapAround, ATwoPole/AllPass2
|
|
171
|
+
- add fft, spectrum and window fns, add tests ([f918af4](https://github.com/thi-ng/umbrella/commit/f918af4))
|
|
172
|
+
- add/update FFT fns, test, update docs ([1ac9508](https://github.com/thi-ng/umbrella/commit/1ac9508))
|
|
173
|
+
- add LFO sin/cos iterator/osc, minor refactor window fns ([dc89204](https://github.com/thi-ng/umbrella/commit/dc89204))
|
|
174
|
+
- add DelayLine ([bd25cd7](https://github.com/thi-ng/umbrella/commit/bd25cd7))
|
|
175
|
+
- update DelayLine ctor, freqBin, update pkg ([228a81e](https://github.com/thi-ng/umbrella/commit/228a81e))
|
|
176
|
+
- import gen & proc nodes, general pkg restructure ([a85c3cf](https://github.com/thi-ng/umbrella/commit/a85c3cf))
|
|
177
|
+
- add filters, refactor, update pkg/docs/readme ([7758609](https://github.com/thi-ng/umbrella/commit/7758609))
|
|
178
|
+
- add AllPass1/2 filters
|
|
179
|
+
- add abstract ATwoPole class
|
|
180
|
+
- fix OnePole HPF impl
|
|
181
|
+
- update protected field names
|
|
182
|
+
- add/update filters, filter resp, delay ([2854b09](https://github.com/thi-ng/umbrella/commit/2854b09))
|
|
183
|
+
- add/optimize Biquad & SVF impls
|
|
184
|
+
- add DCBlocker
|
|
185
|
+
- add FeedbackDelay
|
|
186
|
+
- add filter response types & utils
|
|
187
|
+
- add/rename conversion fns
|
|
194
188
|
- add new operators ([68a88e4](https://github.com/thi-ng/umbrella/commit/68a88e4))
|
|
195
189
|
Generators:
|
|
196
190
|
- ADSR
|
|
@@ -203,32 +197,38 @@ and/or version bumps of transitive dependencies.
|
|
|
203
197
|
- WaveShaper
|
|
204
198
|
Oscillators:
|
|
205
199
|
- Discrete Summation (DSF, stateless)
|
|
206
|
-
-
|
|
207
|
-
- add
|
|
208
|
-
- add
|
|
209
|
-
- add
|
|
210
|
-
-
|
|
211
|
-
-
|
|
212
|
-
- add
|
|
213
|
-
- add
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
-
|
|
218
|
-
-
|
|
219
|
-
- add
|
|
220
|
-
-
|
|
221
|
-
- add
|
|
222
|
-
- add
|
|
200
|
+
- update all gens/procs, housekeeping, docs ([e483245](https://github.com/thi-ng/umbrella/commit/e483245))
|
|
201
|
+
- add param accessors for all ops
|
|
202
|
+
- add IReset & impls for most gens/procs
|
|
203
|
+
- add Delay.multiTap()
|
|
204
|
+
- replace exp() w/ curve(), add curvature ctrl
|
|
205
|
+
- remove lfo(), wrapAround, ATwoPole/AllPass2
|
|
206
|
+
- add/rename oscillators ([8a826bf](https://github.com/thi-ng/umbrella/commit/8a826bf))
|
|
207
|
+
- add HOF versions for:
|
|
208
|
+
- dsfHOF
|
|
209
|
+
- mixOscHOF
|
|
210
|
+
- rectHOF
|
|
211
|
+
- rename comb => parabolic
|
|
212
|
+
- add missing factory fns, update docstrings ([3ede5af](https://github.com/thi-ng/umbrella/commit/3ede5af))
|
|
213
|
+
- add gen/proc composition ops, restructure ([8be2a5f](https://github.com/thi-ng/umbrella/commit/8be2a5f))
|
|
214
|
+
- move all composition ops to own subdir
|
|
215
|
+
- add `compP`, `multiplex`, `pipe` IProc composition
|
|
216
|
+
- add `IXform` impl for `AProc` to allow for direct use as transducer
|
|
217
|
+
- add/update `IReset` impls (re-use type from [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/main/packages/api))
|
|
218
|
+
- add sweep(), move curve(), minor refactor ([0b24d80](https://github.com/thi-ng/umbrella/commit/0b24d80))
|
|
219
|
+
- update gens to support clamping ([fe8f6f3](https://github.com/thi-ng/umbrella/commit/fe8f6f3))
|
|
220
|
+
- add opt clamping for add, mul, madd
|
|
221
|
+
- update curve, line and sweep
|
|
222
|
+
- update ADSR, add ADSROpts, auto-release ([16f41ec](https://github.com/thi-ng/umbrella/commit/16f41ec))
|
|
223
223
|
|
|
224
224
|
#### ♻️ Refactoring
|
|
225
225
|
|
|
226
|
-
-
|
|
227
|
-
- rename compG => mapG ([95244dd](https://github.com/thi-ng/umbrella/commit/95244dd))
|
|
226
|
+
- various minor additions, updates, renames, docs ([e5e1a22](https://github.com/thi-ng/umbrella/commit/e5e1a22))
|
|
228
227
|
- update/rename DelayLine => Delay ([ec0e521](https://github.com/thi-ng/umbrella/commit/ec0e521))
|
|
229
228
|
- update Delay to impl `IProc` interface
|
|
230
229
|
- add `IClear` impls for all current IProc impls
|
|
231
|
-
-
|
|
230
|
+
- rename compG => mapG ([95244dd](https://github.com/thi-ng/umbrella/commit/95244dd))
|
|
231
|
+
- restructure oscillators, fft, window, update gen-diagrams ([9efd69f](https://github.com/thi-ng/umbrella/commit/9efd69f))
|
|
232
232
|
|
|
233
233
|
### [1.0.10](https://github.com/thi-ng/umbrella/tree/@thi.ng/dsp@1.0.10) (2019-04-26)
|
|
234
234
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/dsp",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.22",
|
|
4
4
|
"description": "Composable signal generators, oscillators, filters, FFT, spectrum, windowing & related DSP utils",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -34,19 +34,19 @@
|
|
|
34
34
|
"test": "testament test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.4.
|
|
38
|
-
"@thi.ng/checks": "^3.3.
|
|
39
|
-
"@thi.ng/errors": "^2.2.
|
|
40
|
-
"@thi.ng/math": "^5.3.
|
|
41
|
-
"@thi.ng/random": "^3.3.
|
|
42
|
-
"@thi.ng/transducers": "^8.3.
|
|
37
|
+
"@thi.ng/api": "^8.4.6",
|
|
38
|
+
"@thi.ng/checks": "^3.3.3",
|
|
39
|
+
"@thi.ng/errors": "^2.2.4",
|
|
40
|
+
"@thi.ng/math": "^5.3.13",
|
|
41
|
+
"@thi.ng/random": "^3.3.15",
|
|
42
|
+
"@thi.ng/transducers": "^8.3.23"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@microsoft/api-extractor": "^7.33.5",
|
|
46
|
-
"@thi.ng/testament": "^0.3.
|
|
46
|
+
"@thi.ng/testament": "^0.3.5",
|
|
47
47
|
"rimraf": "^3.0.2",
|
|
48
48
|
"tools": "^0.0.1",
|
|
49
|
-
"typedoc": "^0.23.
|
|
49
|
+
"typedoc": "^0.23.20",
|
|
50
50
|
"typescript": "^4.8.4"
|
|
51
51
|
},
|
|
52
52
|
"keywords": [
|
|
@@ -86,8 +86,8 @@
|
|
|
86
86
|
"node": ">=12.7"
|
|
87
87
|
},
|
|
88
88
|
"files": [
|
|
89
|
-
"
|
|
90
|
-
"
|
|
89
|
+
"./*.js",
|
|
90
|
+
"./*.d.ts",
|
|
91
91
|
"internal"
|
|
92
92
|
],
|
|
93
93
|
"exports": {
|
|
@@ -272,5 +272,5 @@
|
|
|
272
272
|
],
|
|
273
273
|
"year": 2015
|
|
274
274
|
},
|
|
275
|
-
"gitHead": "
|
|
275
|
+
"gitHead": "044ee6a3895720fc78e115032d4d831b63510929\n"
|
|
276
276
|
}
|
package/dev/fftjs.js
DELETED
|
@@ -1,512 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function FFT(size) {
|
|
4
|
-
this.size = size | 0;
|
|
5
|
-
if (this.size <= 1 || (this.size & (this.size - 1)) !== 0)
|
|
6
|
-
throw new Error("FFT size must be a power of two and bigger than 1");
|
|
7
|
-
|
|
8
|
-
this._csize = size << 1;
|
|
9
|
-
|
|
10
|
-
// NOTE: Use of `var` is intentional for old V8 versions
|
|
11
|
-
var table = new Array(this.size * 2);
|
|
12
|
-
for (var i = 0; i < table.length; i += 2) {
|
|
13
|
-
const angle = (Math.PI * i) / this.size;
|
|
14
|
-
table[i] = Math.cos(angle);
|
|
15
|
-
table[i + 1] = -Math.sin(angle);
|
|
16
|
-
}
|
|
17
|
-
this.table = table;
|
|
18
|
-
|
|
19
|
-
// Find size's power of two
|
|
20
|
-
var power = 0;
|
|
21
|
-
for (var t = 1; this.size > t; t <<= 1) power++;
|
|
22
|
-
|
|
23
|
-
// Calculate initial step's width:
|
|
24
|
-
// * If we are full radix-4 - it is 2x smaller to give inital len=8
|
|
25
|
-
// * Otherwise it is the same as `power` to give len=4
|
|
26
|
-
this._width = power % 2 === 0 ? power - 1 : power;
|
|
27
|
-
|
|
28
|
-
// Pre-compute bit-reversal patterns
|
|
29
|
-
this._bitrev = new Array(1 << this._width);
|
|
30
|
-
for (var j = 0; j < this._bitrev.length; j++) {
|
|
31
|
-
this._bitrev[j] = 0;
|
|
32
|
-
for (var shift = 0; shift < this._width; shift += 2) {
|
|
33
|
-
var revShift = this._width - shift - 2;
|
|
34
|
-
this._bitrev[j] |= ((j >>> shift) & 3) << revShift;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
this._out = null;
|
|
39
|
-
this._data = null;
|
|
40
|
-
this._inv = 0;
|
|
41
|
-
}
|
|
42
|
-
module.exports = FFT;
|
|
43
|
-
|
|
44
|
-
FFT.prototype.fromComplexArray = function fromComplexArray(complex, storage) {
|
|
45
|
-
var res = storage || new Array(complex.length >>> 1);
|
|
46
|
-
for (var i = 0; i < complex.length; i += 2) res[i >>> 1] = complex[i];
|
|
47
|
-
return res;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
FFT.prototype.createComplexArray = function createComplexArray() {
|
|
51
|
-
const res = new Array(this._csize);
|
|
52
|
-
for (var i = 0; i < res.length; i++) res[i] = 0;
|
|
53
|
-
return res;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
FFT.prototype.toComplexArray = function toComplexArray(input, storage) {
|
|
57
|
-
var res = storage || this.createComplexArray();
|
|
58
|
-
for (var i = 0; i < res.length; i += 2) {
|
|
59
|
-
res[i] = input[i >>> 1];
|
|
60
|
-
res[i + 1] = 0;
|
|
61
|
-
}
|
|
62
|
-
return res;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
FFT.prototype.completeSpectrum = function completeSpectrum(spectrum) {
|
|
66
|
-
var size = this._csize;
|
|
67
|
-
var half = size >>> 1;
|
|
68
|
-
for (var i = 2; i < half; i += 2) {
|
|
69
|
-
spectrum[size - i] = spectrum[i];
|
|
70
|
-
spectrum[size - i + 1] = -spectrum[i + 1];
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
FFT.prototype.transform = function transform(out, data) {
|
|
75
|
-
if (out === data)
|
|
76
|
-
throw new Error("Input and output buffers must be different");
|
|
77
|
-
|
|
78
|
-
this._out = out;
|
|
79
|
-
this._data = data;
|
|
80
|
-
this._inv = 0;
|
|
81
|
-
this._transform4();
|
|
82
|
-
this._out = null;
|
|
83
|
-
this._data = null;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
FFT.prototype.realTransform = function realTransform(out, data) {
|
|
87
|
-
if (out === data)
|
|
88
|
-
throw new Error("Input and output buffers must be different");
|
|
89
|
-
|
|
90
|
-
this._out = out;
|
|
91
|
-
this._data = data;
|
|
92
|
-
this._inv = 0;
|
|
93
|
-
this._realTransform4();
|
|
94
|
-
this._out = null;
|
|
95
|
-
this._data = null;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
FFT.prototype.inverseTransform = function inverseTransform(out, data) {
|
|
99
|
-
if (out === data)
|
|
100
|
-
throw new Error("Input and output buffers must be different");
|
|
101
|
-
|
|
102
|
-
this._out = out;
|
|
103
|
-
this._data = data;
|
|
104
|
-
this._inv = 1;
|
|
105
|
-
this._transform4();
|
|
106
|
-
for (var i = 0; i < out.length; i++) out[i] /= this.size;
|
|
107
|
-
this._out = null;
|
|
108
|
-
this._data = null;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// radix-4 implementation
|
|
112
|
-
//
|
|
113
|
-
// NOTE: Uses of `var` are intentional for older V8 version that do not
|
|
114
|
-
// support both `let compound assignments` and `const phi`
|
|
115
|
-
FFT.prototype._transform4 = function _transform4() {
|
|
116
|
-
var out = this._out;
|
|
117
|
-
var size = this._csize;
|
|
118
|
-
|
|
119
|
-
// Initial step (permute and transform)
|
|
120
|
-
var width = this._width;
|
|
121
|
-
var step = 1 << width;
|
|
122
|
-
var len = (size / step) << 1;
|
|
123
|
-
|
|
124
|
-
var outOff;
|
|
125
|
-
var t;
|
|
126
|
-
var bitrev = this._bitrev;
|
|
127
|
-
if (len === 4) {
|
|
128
|
-
for (outOff = 0, t = 0; outOff < size; outOff += len, t++) {
|
|
129
|
-
const off = bitrev[t];
|
|
130
|
-
this._singleTransform2(outOff, off, step);
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
// len === 8
|
|
134
|
-
for (outOff = 0, t = 0; outOff < size; outOff += len, t++) {
|
|
135
|
-
const off = bitrev[t];
|
|
136
|
-
this._singleTransform4(outOff, off, step);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Loop through steps in decreasing order
|
|
141
|
-
var inv = this._inv ? -1 : 1;
|
|
142
|
-
var table = this.table;
|
|
143
|
-
for (step >>= 2; step >= 2; step >>= 2) {
|
|
144
|
-
len = (size / step) << 1;
|
|
145
|
-
var quarterLen = len >>> 2;
|
|
146
|
-
|
|
147
|
-
// Loop through offsets in the data
|
|
148
|
-
for (outOff = 0; outOff < size; outOff += len) {
|
|
149
|
-
// Full case
|
|
150
|
-
var limit = outOff + quarterLen;
|
|
151
|
-
for (var i = outOff, k = 0; i < limit; i += 2, k += step) {
|
|
152
|
-
const A = i;
|
|
153
|
-
const B = A + quarterLen;
|
|
154
|
-
const C = B + quarterLen;
|
|
155
|
-
const D = C + quarterLen;
|
|
156
|
-
|
|
157
|
-
// Original values
|
|
158
|
-
const Ar = out[A];
|
|
159
|
-
const Ai = out[A + 1];
|
|
160
|
-
const Br = out[B];
|
|
161
|
-
const Bi = out[B + 1];
|
|
162
|
-
const Cr = out[C];
|
|
163
|
-
const Ci = out[C + 1];
|
|
164
|
-
const Dr = out[D];
|
|
165
|
-
const Di = out[D + 1];
|
|
166
|
-
|
|
167
|
-
// Middle values
|
|
168
|
-
const MAr = Ar;
|
|
169
|
-
const MAi = Ai;
|
|
170
|
-
|
|
171
|
-
const tableBr = table[k];
|
|
172
|
-
const tableBi = inv * table[k + 1];
|
|
173
|
-
const MBr = Br * tableBr - Bi * tableBi;
|
|
174
|
-
const MBi = Br * tableBi + Bi * tableBr;
|
|
175
|
-
|
|
176
|
-
const tableCr = table[2 * k];
|
|
177
|
-
const tableCi = inv * table[2 * k + 1];
|
|
178
|
-
const MCr = Cr * tableCr - Ci * tableCi;
|
|
179
|
-
const MCi = Cr * tableCi + Ci * tableCr;
|
|
180
|
-
|
|
181
|
-
const tableDr = table[3 * k];
|
|
182
|
-
const tableDi = inv * table[3 * k + 1];
|
|
183
|
-
const MDr = Dr * tableDr - Di * tableDi;
|
|
184
|
-
const MDi = Dr * tableDi + Di * tableDr;
|
|
185
|
-
|
|
186
|
-
// Pre-Final values
|
|
187
|
-
const T0r = MAr + MCr;
|
|
188
|
-
const T0i = MAi + MCi;
|
|
189
|
-
const T1r = MAr - MCr;
|
|
190
|
-
const T1i = MAi - MCi;
|
|
191
|
-
const T2r = MBr + MDr;
|
|
192
|
-
const T2i = MBi + MDi;
|
|
193
|
-
const T3r = inv * (MBr - MDr);
|
|
194
|
-
const T3i = inv * (MBi - MDi);
|
|
195
|
-
|
|
196
|
-
// Final values
|
|
197
|
-
const FAr = T0r + T2r;
|
|
198
|
-
const FAi = T0i + T2i;
|
|
199
|
-
|
|
200
|
-
const FCr = T0r - T2r;
|
|
201
|
-
const FCi = T0i - T2i;
|
|
202
|
-
|
|
203
|
-
const FBr = T1r + T3i;
|
|
204
|
-
const FBi = T1i - T3r;
|
|
205
|
-
|
|
206
|
-
const FDr = T1r - T3i;
|
|
207
|
-
const FDi = T1i + T3r;
|
|
208
|
-
|
|
209
|
-
out[A] = FAr;
|
|
210
|
-
out[A + 1] = FAi;
|
|
211
|
-
out[B] = FBr;
|
|
212
|
-
out[B + 1] = FBi;
|
|
213
|
-
out[C] = FCr;
|
|
214
|
-
out[C + 1] = FCi;
|
|
215
|
-
out[D] = FDr;
|
|
216
|
-
out[D + 1] = FDi;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
// radix-2 implementation
|
|
223
|
-
//
|
|
224
|
-
// NOTE: Only called for len=4
|
|
225
|
-
FFT.prototype._singleTransform2 = function _singleTransform2(
|
|
226
|
-
outOff,
|
|
227
|
-
off,
|
|
228
|
-
step
|
|
229
|
-
) {
|
|
230
|
-
const out = this._out;
|
|
231
|
-
const data = this._data;
|
|
232
|
-
|
|
233
|
-
const evenR = data[off];
|
|
234
|
-
const evenI = data[off + 1];
|
|
235
|
-
const oddR = data[off + step];
|
|
236
|
-
const oddI = data[off + step + 1];
|
|
237
|
-
|
|
238
|
-
const leftR = evenR + oddR;
|
|
239
|
-
const leftI = evenI + oddI;
|
|
240
|
-
const rightR = evenR - oddR;
|
|
241
|
-
const rightI = evenI - oddI;
|
|
242
|
-
|
|
243
|
-
out[outOff] = leftR;
|
|
244
|
-
out[outOff + 1] = leftI;
|
|
245
|
-
out[outOff + 2] = rightR;
|
|
246
|
-
out[outOff + 3] = rightI;
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
// radix-4
|
|
250
|
-
//
|
|
251
|
-
// NOTE: Only called for len=8
|
|
252
|
-
FFT.prototype._singleTransform4 = function _singleTransform4(
|
|
253
|
-
outOff,
|
|
254
|
-
off,
|
|
255
|
-
step
|
|
256
|
-
) {
|
|
257
|
-
const out = this._out;
|
|
258
|
-
const data = this._data;
|
|
259
|
-
const inv = this._inv ? -1 : 1;
|
|
260
|
-
const step2 = step * 2;
|
|
261
|
-
const step3 = step * 3;
|
|
262
|
-
|
|
263
|
-
// Original values
|
|
264
|
-
const Ar = data[off];
|
|
265
|
-
const Ai = data[off + 1];
|
|
266
|
-
const Br = data[off + step];
|
|
267
|
-
const Bi = data[off + step + 1];
|
|
268
|
-
const Cr = data[off + step2];
|
|
269
|
-
const Ci = data[off + step2 + 1];
|
|
270
|
-
const Dr = data[off + step3];
|
|
271
|
-
const Di = data[off + step3 + 1];
|
|
272
|
-
|
|
273
|
-
// Pre-Final values
|
|
274
|
-
const T0r = Ar + Cr;
|
|
275
|
-
const T0i = Ai + Ci;
|
|
276
|
-
const T1r = Ar - Cr;
|
|
277
|
-
const T1i = Ai - Ci;
|
|
278
|
-
const T2r = Br + Dr;
|
|
279
|
-
const T2i = Bi + Di;
|
|
280
|
-
const T3r = inv * (Br - Dr);
|
|
281
|
-
const T3i = inv * (Bi - Di);
|
|
282
|
-
|
|
283
|
-
// Final values
|
|
284
|
-
const FAr = T0r + T2r;
|
|
285
|
-
const FAi = T0i + T2i;
|
|
286
|
-
|
|
287
|
-
const FBr = T1r + T3i;
|
|
288
|
-
const FBi = T1i - T3r;
|
|
289
|
-
|
|
290
|
-
const FCr = T0r - T2r;
|
|
291
|
-
const FCi = T0i - T2i;
|
|
292
|
-
|
|
293
|
-
const FDr = T1r - T3i;
|
|
294
|
-
const FDi = T1i + T3r;
|
|
295
|
-
|
|
296
|
-
out[outOff] = FAr;
|
|
297
|
-
out[outOff + 1] = FAi;
|
|
298
|
-
out[outOff + 2] = FBr;
|
|
299
|
-
out[outOff + 3] = FBi;
|
|
300
|
-
out[outOff + 4] = FCr;
|
|
301
|
-
out[outOff + 5] = FCi;
|
|
302
|
-
out[outOff + 6] = FDr;
|
|
303
|
-
out[outOff + 7] = FDi;
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
// Real input radix-4 implementation
|
|
307
|
-
FFT.prototype._realTransform4 = function _realTransform4() {
|
|
308
|
-
var out = this._out;
|
|
309
|
-
var size = this._csize;
|
|
310
|
-
|
|
311
|
-
// Initial step (permute and transform)
|
|
312
|
-
var width = this._width;
|
|
313
|
-
var step = 1 << width;
|
|
314
|
-
var len = (size / step) << 1;
|
|
315
|
-
|
|
316
|
-
var outOff;
|
|
317
|
-
var t;
|
|
318
|
-
var bitrev = this._bitrev;
|
|
319
|
-
if (len === 4) {
|
|
320
|
-
for (outOff = 0, t = 0; outOff < size; outOff += len, t++) {
|
|
321
|
-
const off = bitrev[t];
|
|
322
|
-
this._singleRealTransform2(outOff, off >>> 1, step >>> 1);
|
|
323
|
-
}
|
|
324
|
-
} else {
|
|
325
|
-
// len === 8
|
|
326
|
-
for (outOff = 0, t = 0; outOff < size; outOff += len, t++) {
|
|
327
|
-
const off = bitrev[t];
|
|
328
|
-
this._singleRealTransform4(outOff, off >>> 1, step >>> 1);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Loop through steps in decreasing order
|
|
333
|
-
var inv = this._inv ? -1 : 1;
|
|
334
|
-
var table = this.table;
|
|
335
|
-
for (step >>= 2; step >= 2; step >>= 2) {
|
|
336
|
-
len = (size / step) << 1;
|
|
337
|
-
var halfLen = len >>> 1;
|
|
338
|
-
var quarterLen = halfLen >>> 1;
|
|
339
|
-
var hquarterLen = quarterLen >>> 1;
|
|
340
|
-
|
|
341
|
-
// Loop through offsets in the data
|
|
342
|
-
for (outOff = 0; outOff < size; outOff += len) {
|
|
343
|
-
for (var i = 0, k = 0; i <= hquarterLen; i += 2, k += step) {
|
|
344
|
-
var A = outOff + i;
|
|
345
|
-
var B = A + quarterLen;
|
|
346
|
-
var C = B + quarterLen;
|
|
347
|
-
var D = C + quarterLen;
|
|
348
|
-
|
|
349
|
-
// Original values
|
|
350
|
-
var Ar = out[A];
|
|
351
|
-
var Ai = out[A + 1];
|
|
352
|
-
var Br = out[B];
|
|
353
|
-
var Bi = out[B + 1];
|
|
354
|
-
var Cr = out[C];
|
|
355
|
-
var Ci = out[C + 1];
|
|
356
|
-
var Dr = out[D];
|
|
357
|
-
var Di = out[D + 1];
|
|
358
|
-
|
|
359
|
-
// Middle values
|
|
360
|
-
var MAr = Ar;
|
|
361
|
-
var MAi = Ai;
|
|
362
|
-
|
|
363
|
-
var tableBr = table[k];
|
|
364
|
-
var tableBi = inv * table[k + 1];
|
|
365
|
-
var MBr = Br * tableBr - Bi * tableBi;
|
|
366
|
-
var MBi = Br * tableBi + Bi * tableBr;
|
|
367
|
-
|
|
368
|
-
var tableCr = table[2 * k];
|
|
369
|
-
var tableCi = inv * table[2 * k + 1];
|
|
370
|
-
var MCr = Cr * tableCr - Ci * tableCi;
|
|
371
|
-
var MCi = Cr * tableCi + Ci * tableCr;
|
|
372
|
-
|
|
373
|
-
var tableDr = table[3 * k];
|
|
374
|
-
var tableDi = inv * table[3 * k + 1];
|
|
375
|
-
var MDr = Dr * tableDr - Di * tableDi;
|
|
376
|
-
var MDi = Dr * tableDi + Di * tableDr;
|
|
377
|
-
|
|
378
|
-
// Pre-Final values
|
|
379
|
-
var T0r = MAr + MCr;
|
|
380
|
-
var T0i = MAi + MCi;
|
|
381
|
-
var T1r = MAr - MCr;
|
|
382
|
-
var T1i = MAi - MCi;
|
|
383
|
-
var T2r = MBr + MDr;
|
|
384
|
-
var T2i = MBi + MDi;
|
|
385
|
-
var T3r = inv * (MBr - MDr);
|
|
386
|
-
var T3i = inv * (MBi - MDi);
|
|
387
|
-
|
|
388
|
-
// Final values
|
|
389
|
-
var FAr = T0r + T2r;
|
|
390
|
-
var FAi = T0i + T2i;
|
|
391
|
-
|
|
392
|
-
var FBr = T1r + T3i;
|
|
393
|
-
var FBi = T1i - T3r;
|
|
394
|
-
|
|
395
|
-
out[A] = FAr;
|
|
396
|
-
out[A + 1] = FAi;
|
|
397
|
-
out[B] = FBr;
|
|
398
|
-
out[B + 1] = FBi;
|
|
399
|
-
|
|
400
|
-
// Output final middle point
|
|
401
|
-
if (i === 0) {
|
|
402
|
-
var FCr = T0r - T2r;
|
|
403
|
-
var FCi = T0i - T2i;
|
|
404
|
-
out[C] = FCr;
|
|
405
|
-
out[C + 1] = FCi;
|
|
406
|
-
continue;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
// Do not overwrite ourselves
|
|
410
|
-
if (i === hquarterLen) continue;
|
|
411
|
-
|
|
412
|
-
// In the flipped case:
|
|
413
|
-
// MAi = -MAi
|
|
414
|
-
// MBr=-MBi, MBi=-MBr
|
|
415
|
-
// MCr=-MCr
|
|
416
|
-
// MDr=MDi, MDi=MDr
|
|
417
|
-
var ST0r = T1r;
|
|
418
|
-
var ST0i = -T1i;
|
|
419
|
-
var ST1r = T0r;
|
|
420
|
-
var ST1i = -T0i;
|
|
421
|
-
var ST2r = -inv * T3i;
|
|
422
|
-
var ST2i = -inv * T3r;
|
|
423
|
-
var ST3r = -inv * T2i;
|
|
424
|
-
var ST3i = -inv * T2r;
|
|
425
|
-
|
|
426
|
-
var SFAr = ST0r + ST2r;
|
|
427
|
-
var SFAi = ST0i + ST2i;
|
|
428
|
-
|
|
429
|
-
var SFBr = ST1r + ST3i;
|
|
430
|
-
var SFBi = ST1i - ST3r;
|
|
431
|
-
|
|
432
|
-
var SA = outOff + quarterLen - i;
|
|
433
|
-
var SB = outOff + halfLen - i;
|
|
434
|
-
|
|
435
|
-
out[SA] = SFAr;
|
|
436
|
-
out[SA + 1] = SFAi;
|
|
437
|
-
out[SB] = SFBr;
|
|
438
|
-
out[SB + 1] = SFBi;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
// radix-2 implementation
|
|
445
|
-
//
|
|
446
|
-
// NOTE: Only called for len=4
|
|
447
|
-
FFT.prototype._singleRealTransform2 = function _singleRealTransform2(
|
|
448
|
-
outOff,
|
|
449
|
-
off,
|
|
450
|
-
step
|
|
451
|
-
) {
|
|
452
|
-
const out = this._out;
|
|
453
|
-
const data = this._data;
|
|
454
|
-
|
|
455
|
-
const evenR = data[off];
|
|
456
|
-
const oddR = data[off + step];
|
|
457
|
-
|
|
458
|
-
const leftR = evenR + oddR;
|
|
459
|
-
const rightR = evenR - oddR;
|
|
460
|
-
|
|
461
|
-
out[outOff] = leftR;
|
|
462
|
-
out[outOff + 1] = 0;
|
|
463
|
-
out[outOff + 2] = rightR;
|
|
464
|
-
out[outOff + 3] = 0;
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
// radix-4
|
|
468
|
-
//
|
|
469
|
-
// NOTE: Only called for len=8
|
|
470
|
-
FFT.prototype._singleRealTransform4 = function _singleRealTransform4(
|
|
471
|
-
outOff,
|
|
472
|
-
off,
|
|
473
|
-
step
|
|
474
|
-
) {
|
|
475
|
-
const out = this._out;
|
|
476
|
-
const data = this._data;
|
|
477
|
-
const inv = this._inv ? -1 : 1;
|
|
478
|
-
const step2 = step * 2;
|
|
479
|
-
const step3 = step * 3;
|
|
480
|
-
|
|
481
|
-
// Original values
|
|
482
|
-
const Ar = data[off];
|
|
483
|
-
const Br = data[off + step];
|
|
484
|
-
const Cr = data[off + step2];
|
|
485
|
-
const Dr = data[off + step3];
|
|
486
|
-
|
|
487
|
-
// Pre-Final values
|
|
488
|
-
const T0r = Ar + Cr;
|
|
489
|
-
const T1r = Ar - Cr;
|
|
490
|
-
const T2r = Br + Dr;
|
|
491
|
-
const T3r = inv * (Br - Dr);
|
|
492
|
-
|
|
493
|
-
// Final values
|
|
494
|
-
const FAr = T0r + T2r;
|
|
495
|
-
|
|
496
|
-
const FBr = T1r;
|
|
497
|
-
const FBi = -T3r;
|
|
498
|
-
|
|
499
|
-
const FCr = T0r - T2r;
|
|
500
|
-
|
|
501
|
-
const FDr = T1r;
|
|
502
|
-
const FDi = T3r;
|
|
503
|
-
|
|
504
|
-
out[outOff] = FAr;
|
|
505
|
-
out[outOff + 1] = 0;
|
|
506
|
-
out[outOff + 2] = FBr;
|
|
507
|
-
out[outOff + 3] = FBi;
|
|
508
|
-
out[outOff + 4] = FCr;
|
|
509
|
-
out[outOff + 5] = 0;
|
|
510
|
-
out[outOff + 6] = FDr;
|
|
511
|
-
out[outOff + 7] = FDi;
|
|
512
|
-
};
|