@audio/shift-pvoc 1.0.0 → 1.1.0
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/atom.js +62 -0
- package/package.json +6 -3
package/atom.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// atom manifest — wraps the phase-vocoder pitch shift per @audio/atom CONTRACT.
|
|
2
|
+
// The kernel streams (stftStream writer), but write(chunk) returns variable-length
|
|
3
|
+
// bursts (frame/hop bookkeeping is not 1:1 with input chunking) — a per-channel FIFO
|
|
4
|
+
// absorbs that into the fixed equal-frames-in/out shape §process requires, at a fixed
|
|
5
|
+
// extra delay. Measured end-to-end through this manifest (tone-burst envelope
|
|
6
|
+
// cross-correlation at ratio 1, blocks 128–4096): 2048 samples = 1× frameSize =
|
|
7
|
+
// 4× hopSize, block-size-invariant, confirmed independently by input/output
|
|
8
|
+
// sample-count bookkeeping (steady-state deficit 2048).
|
|
9
|
+
//
|
|
10
|
+
// `semitones` is live: the writer is constructed with a function ratio (the kernel
|
|
11
|
+
// samples it per analysis frame via makeFrameRatio), reading a cell this manifest
|
|
12
|
+
// updates from the per-block params — no reconstruction on change. The function
|
|
13
|
+
// form also defeats the ratio-1 identity shortcut, keeping latency constant.
|
|
14
|
+
|
|
15
|
+
import vocoderFn from './index.js'
|
|
16
|
+
|
|
17
|
+
const FRAME = 2048, HOP = 512
|
|
18
|
+
const LATENCY = 2048
|
|
19
|
+
|
|
20
|
+
function makeFifo() { return { buf: new Float32Array(1 << 14), len: 0 } }
|
|
21
|
+
function fifoPush(f, chunk) {
|
|
22
|
+
if (!chunk.length) return
|
|
23
|
+
let need = f.len + chunk.length
|
|
24
|
+
if (need > f.buf.length) {
|
|
25
|
+
let nb = new Float32Array(Math.max(need * 2, f.buf.length * 2))
|
|
26
|
+
nb.set(f.buf.subarray(0, f.len)); f.buf = nb
|
|
27
|
+
}
|
|
28
|
+
f.buf.set(chunk, f.len); f.len += chunk.length
|
|
29
|
+
}
|
|
30
|
+
function fifoPull(f, out) {
|
|
31
|
+
let n = out.length
|
|
32
|
+
if (f.len >= n) { out.set(f.buf.subarray(0, n)); f.buf.copyWithin(0, n, f.len); f.len -= n }
|
|
33
|
+
else { out.set(f.buf.subarray(0, f.len)); out.fill(0, f.len); f.len = 0 }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const vocoder = (ctx) => {
|
|
37
|
+
const cell = { r: 2 ** (ctx.params.semitones[0] / 12) }
|
|
38
|
+
const ratio = () => cell.r
|
|
39
|
+
const chans = []
|
|
40
|
+
for (let c = 0, N = ctx.maxChannels ?? 8; c < N; c++) {
|
|
41
|
+
chans.push({
|
|
42
|
+
write: vocoderFn({ ratio, frameSize: FRAME, hopSize: HOP, sampleRate: ctx.sampleRate, fs: ctx.sampleRate }),
|
|
43
|
+
fifo: makeFifo()
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
return (inputs, outputs, params) => {
|
|
47
|
+
const inp = inputs[0], out = outputs[0]
|
|
48
|
+
if (!inp || !inp.length) return
|
|
49
|
+
cell.r = 2 ** (params.semitones[0] / 12)
|
|
50
|
+
for (let c = 0; c < inp.length; c++) {
|
|
51
|
+
const ch = chans[c]
|
|
52
|
+
fifoPush(ch.fifo, ch.write(inp[c]))
|
|
53
|
+
fifoPull(ch.fifo, out[c])
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
vocoder.channels = 'any'
|
|
58
|
+
vocoder.latency = LATENCY
|
|
59
|
+
vocoder.tail = 0
|
|
60
|
+
vocoder.params = {
|
|
61
|
+
semitones: { type: 'number', min: -24, max: 24, default: 0, smoothing: 0.01 },
|
|
62
|
+
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audio/shift-pvoc",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Canonical phase vocoder (Bernsee/SMB) pitch shift",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./index.js",
|
|
10
|
+
"./atom": "./atom.js",
|
|
10
11
|
"./package.json": "./package.json"
|
|
11
12
|
},
|
|
12
13
|
"files": [
|
|
13
|
-
"index.js"
|
|
14
|
+
"index.js",
|
|
15
|
+
"atom.js"
|
|
14
16
|
],
|
|
15
17
|
"dependencies": {
|
|
16
18
|
"@audio/shift-core": "^1.0.0"
|
|
@@ -36,5 +38,6 @@
|
|
|
36
38
|
],
|
|
37
39
|
"engines": {
|
|
38
40
|
"node": ">=18"
|
|
39
|
-
}
|
|
41
|
+
},
|
|
42
|
+
"atom": "./atom.js"
|
|
40
43
|
}
|