@audio/stft 1.0.7 → 1.0.8
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/README.md +1 -1
- package/package.json +2 -2
- package/stft.js +1 -1
- package/util.js +5 -3
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ let tail = s.flush()
|
|
|
24
24
|
stftAnalyse(input, (mag, phase, ctx) => { /* inspect */ }, { fs: 44100 })
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
Also exports `wrapPhase`, `hannWindow
|
|
27
|
+
Also exports `wrapPhase`, `hannWindow` (periodic Hann, from [`window-function`](https://github.com/scijs/window-function)), `normFloor`, `PI2`.
|
|
28
28
|
|
|
29
29
|
## See also
|
|
30
30
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audio/stft",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Canonical STFT — batch / stream / analyse with normalized Hann OLA; stream ≡ batch under any chunking",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"fourier-transform": "^2.3.0",
|
|
23
|
-
"
|
|
23
|
+
"window-function": "^3.0.0"
|
|
24
24
|
},
|
|
25
25
|
"keywords": [
|
|
26
26
|
"audio",
|
package/stft.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { fft, ifft } from 'fourier-transform'
|
|
11
11
|
import { hannWindow, makeStreamBufs, appendIn, growOut, compactIn, take, normFloor, PI2 } from './util.js'
|
|
12
12
|
|
|
13
|
-
export function wrapPhase(p) { return p - Math.
|
|
13
|
+
export function wrapPhase(p) { return p - Math.floor(p / PI2 + 0.5) * PI2 } // floor(x + 0.5) rounds like Math.round here, several times faster in V8 (hot: per bin per frame)
|
|
14
14
|
|
|
15
15
|
function frame(data, pos, win, half, process, state, ctx, sc) {
|
|
16
16
|
let N = win.length, f = sc.f
|
package/util.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
// Internal — Hann window
|
|
1
|
+
// Internal — Hann window + stream ring buffers + OLA normalization.
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import hann from 'window-function/hann'
|
|
4
4
|
|
|
5
5
|
export const PI2 = Math.PI * 2
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
// Periodic (DFT-even) Hann: the N+1-point window without its last point. The one window, not the whole kit.
|
|
8
9
|
let _hannCache = new Map()
|
|
9
10
|
export function hannWindow(N) {
|
|
10
11
|
let w = _hannCache.get(N)
|
|
11
12
|
if (w) return w
|
|
12
|
-
w =
|
|
13
|
+
w = new Float64Array(N)
|
|
14
|
+
for (let i = 0; i < N; i++) w[i] = hann(i, N + 1)
|
|
13
15
|
_hannCache.set(N, w)
|
|
14
16
|
return w
|
|
15
17
|
}
|