@audio/stft 1.0.2 → 1.0.4
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/package.json +3 -2
- package/stft.js +4 -1
- package/util.js +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audio/stft",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"util.js"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"fourier-transform": "^2.3.0"
|
|
18
|
+
"fourier-transform": "^2.3.0",
|
|
19
|
+
"@audio/window": "^1.0.2"
|
|
19
20
|
},
|
|
20
21
|
"keywords": [
|
|
21
22
|
"audio",
|
package/stft.js
CHANGED
|
@@ -56,7 +56,10 @@ export function stftBatch(data, process, opts) {
|
|
|
56
56
|
let sc = scratch(N, half)
|
|
57
57
|
let pos = 0
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
// Start a frame at every hop up to the last sample so the tail keeps the
|
|
60
|
+
// steady-state overlap count — bounding by `pos + N <= outLen` would stop
|
|
61
|
+
// N−hop samples early (tail under-normalized) and drop inputs shorter than N.
|
|
62
|
+
while (pos < outLen) {
|
|
60
63
|
let sf = frame(data, pos, win, half, process, state, ctx, sc)
|
|
61
64
|
for (let i = 0; i < N && pos + i < outLen; i++) {
|
|
62
65
|
out[pos + i] += sf[i] * win[i]
|
package/util.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// Internal — Hann window + stream ring buffers + OLA normalization.
|
|
2
|
-
|
|
1
|
+
// Internal — Hann window (via @audio/window) + stream ring buffers + OLA normalization.
|
|
2
|
+
|
|
3
|
+
import window from '@audio/window'
|
|
3
4
|
|
|
4
5
|
export const PI2 = Math.PI * 2
|
|
5
6
|
|
|
@@ -8,8 +9,7 @@ let _hannCache = new Map()
|
|
|
8
9
|
export function hannWindow(N) {
|
|
9
10
|
let w = _hannCache.get(N)
|
|
10
11
|
if (w) return w
|
|
11
|
-
w =
|
|
12
|
-
for (let i = 0; i < N; i++) w[i] = 0.5 * (1 - Math.cos(PI2 * i / N))
|
|
12
|
+
w = window('hann', N, { periodic: true })
|
|
13
13
|
_hannCache.set(N, w)
|
|
14
14
|
return w
|
|
15
15
|
}
|