-
Notifications
You must be signed in to change notification settings - Fork 0
/
transform.js
51 lines (47 loc) · 1.21 KB
/
transform.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const DIRECTION = {
FORWARDS: +1,
BACKWARDS: -1
};
exports.DIRECTION = DIRECTION;
const child = require('./child.js');
exports.rdft = function (n, dir, aBuffer, ipBuffer, wBuffer) {
const ip = new Int16Array(ipBuffer);
const a = new Float64Array(aBuffer);
const nw = ip[0];
const nc = ip[1];
if (dir === DIRECTION.FORWARDS) {
if (n > 4) {
child.bitrv2(n, ipBuffer, 2, aBuffer);
child.cftfsub(n, aBuffer, wBuffer);
child.rftfsub(n, aBuffer, nc, wBuffer, nw);
} else if (n === 4) {
child.cftfsub(n, aBuffer, wBuffer);
}
const xi = a[0] - a[1];
a[0] += a[1];
a[1] = xi;
} else {
a[1] = 0.5 * (a[0] - a[1]);
a[0] -= a[1];
if (n > 4) {
child.rftbsub(n, aBuffer, nc, wBuffer, nw);
child.bitrv2(n, ipBuffer, 2, aBuffer);
child.cftbsub(n, aBuffer, wBuffer);
} else if (n === 4) {
child.cftfsub(n, aBuffer, wBuffer);
}
}
};
exports.cdft = function (n, dir, aBuffer, ipBuffer, wBuffer) {
if (n > 4) {
if (dir === DIRECTION.FORWARDS) {
child.bitrv2(n, ipBuffer, 2, aBuffer);
child.cftfsub(n, aBuffer, wBuffer);
} else {
child.bitrv2conj(n, ipBuffer, 2, aBuffer);
child.cftbsub(n, aBuffer, wBuffer);
}
} else if (n === 4) {
child.cftfsub(n, aBuffer, wBuffer);
}
};