@audio/shift-pvoc 1.1.3 → 1.1.5
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 +49 -0
- package/audio.js +6 -8
- package/index.d.ts +26 -0
- package/index.js +1 -1
- package/package.json +7 -4
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# @audio/shift-pvoc [](https://www.npmjs.com/package/@audio/shift-pvoc) [](https://github.com/krishnized/license)
|
|
2
|
+
|
|
3
|
+
Canonical phase vocoder (Bernsee/SMB) pitch shift
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm install @audio/shift-pvoc
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import vocoder from '@audio/shift-pvoc'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
SMB/Bernsee bin-shift. Computes true instantaneous frequency per bin from consecutive-frame phase advance, scatters peaks to shifted bins, accumulates synthesis phase at the shifted frequency.
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
vocoder(audio, { ratio: 1.5 })
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Preserves** dominant-partial pitch, long-horizon phase per bin.<br>
|
|
20
|
+
**Destroys** transients, vertical phase coherence ("phasiness"), formants.
|
|
21
|
+
|
|
22
|
+
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|
|
23
|
+
|-------:|-----:|------:|------------:|-------------:|----------:|------:|
|
|
24
|
+
| 0.00 | 0.0 | 0.000 | 0.981 | 1.158 | 0.928 | 1.553 |
|
|
25
|
+
|
|
26
|
+
Phase coh 0.928 from independent per-bin phase accumulation — no inter-bin locking. Best shift score among the general phase vocoders — the simpler scatter avoids the peak-locked family's own assignment overhead on these fixtures.
|
|
27
|
+
|
|
28
|
+
**Use when:** Simple tonal material, educational baseline.<br>
|
|
29
|
+
**Not for:** Music with percussion, voice.
|
|
30
|
+
|
|
31
|
+
## Stream
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
let write = vocoder({ ratio: 1.5 })
|
|
35
|
+
let out = write(inputBlock)
|
|
36
|
+
let tail = write() // flush
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`vocoder` streams per-frame: each `write(chunk)` call renormalizes and emits audio as soon as a frame completes, and re-chunking the same input differently reproduces the batch output byte for byte.
|
|
40
|
+
|
|
41
|
+
## Data
|
|
42
|
+
|
|
43
|
+
Input is a `Float32Array` (mono) or an array of `Float32Array` channels (`[left, right, ...]`) — anything else throws `TypeError`. `ratio` also accepts a function `t => ratio` (seconds from stream start) or a `Float32Array` breakpoint envelope (resampled across the input via `ratioDuration`, default the input's own duration) for time-varying pitch.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
Part of [@audio/shift](https://github.com/audiojs/shift) — the shift family umbrella. This README is generated from the umbrella docs.
|
|
48
|
+
|
|
49
|
+
MIT © [audiojs](https://github.com/audiojs)
|
package/audio.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
// audio manifest — wraps the phase-vocoder pitch shift per @audio/compile CONTRACT.
|
|
2
2
|
// The kernel streams (stftStream writer), but write(chunk) returns variable-length
|
|
3
|
-
// bursts
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// 4× hopSize, block-size-invariant, confirmed independently by input/output
|
|
8
|
-
// sample-count bookkeeping (steady-state deficit 2048).
|
|
3
|
+
// bursts: fourier-transform/stft holds a sample back at most FRAME samples, with output
|
|
4
|
+
// sample j aligned to input sample j. A per-channel FIFO primed with FRAME zeros turns
|
|
5
|
+
// the bursts into the fixed equal-frames-in/out shape §process requires: it never runs
|
|
6
|
+
// dry, so the delay is exactly FRAME under any block size (pinned in test.js).
|
|
9
7
|
//
|
|
10
8
|
// `semitones` is live: the writer is constructed with a function ratio (the kernel
|
|
11
9
|
// samples it per analysis frame via makeFrameRatio), reading a cell this manifest
|
|
@@ -15,9 +13,9 @@
|
|
|
15
13
|
import vocoderFn from './index.js'
|
|
16
14
|
|
|
17
15
|
const FRAME = 2048, HOP = 512
|
|
18
|
-
const LATENCY =
|
|
16
|
+
const LATENCY = FRAME
|
|
19
17
|
|
|
20
|
-
function makeFifo() { return { buf: new Float32Array(1 << 14), len:
|
|
18
|
+
function makeFifo() { return { buf: new Float32Array(1 << 14), len: LATENCY } } // primed with zeros
|
|
21
19
|
function fifoPush(f, chunk) {
|
|
22
20
|
if (!chunk.length) return
|
|
23
21
|
let need = f.len + chunk.length
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** SMB/Bernsee bin-shift phase vocoder — true instantaneous frequency per bin from phase advance, independent per-bin phase accumulation. */
|
|
2
|
+
export interface VocoderOptions {
|
|
3
|
+
/** target ratio (1.5 = +7 semitones, 2 = octave); accepts a fixed number, a function `t => ratio` (seconds), or a `Float32Array` breakpoint envelope paired with `ratioDuration` */
|
|
4
|
+
ratio?: number | ((t: number) => number) | Float32Array
|
|
5
|
+
/** semitones, applied when `ratio` is omitted (1.5 ratio = +7 semitones), default 0 */
|
|
6
|
+
semitones?: number
|
|
7
|
+
/** duration in seconds spanned by a `Float32Array` ratio envelope, default the input length at `sampleRate` */
|
|
8
|
+
ratioDuration?: number
|
|
9
|
+
/** sample rate in Hz, default 44100 */
|
|
10
|
+
sampleRate?: number
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Streaming writer: feed chunks matching the first call's shape (mono or channel array); call with no argument to flush the tail. */
|
|
15
|
+
export interface ShiftWriter {
|
|
16
|
+
(chunk: Float32Array): Float32Array
|
|
17
|
+
(chunk: Float32Array[]): Float32Array[]
|
|
18
|
+
(chunk?: undefined): Float32Array | Float32Array[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Process a whole buffer. Returns a new Float32Array of the same length. */
|
|
22
|
+
export default function vocoder(data: Float32Array, options?: VocoderOptions): Float32Array
|
|
23
|
+
/** Process channels independently — [left, right, ...]. Returns matching channels. */
|
|
24
|
+
export default function vocoder(data: Float32Array[], options?: VocoderOptions): Float32Array[]
|
|
25
|
+
/** Streaming form: returns a writer — call with chunks, call with no argument to flush. */
|
|
26
|
+
export default function vocoder(options?: VocoderOptions): ShiftWriter
|
package/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { makeFrameRatio, wrapPhase, scatterGated } from '@audio/spectral-pvoc'
|
|
|
10
10
|
function process(mag, phase, state, ctx) {
|
|
11
11
|
if (!state.fr) state.fr = makeFrameRatio(ctx.ratioFn || ctx.ratio || 1)
|
|
12
12
|
let { half, hop } = ctx
|
|
13
|
-
let ratio = state.fr.at(ctx.frameStart, ctx.sampleRate)
|
|
13
|
+
let ratio = state.fr.at(ctx.frameStart + ctx.N / 2, ctx.sampleRate)
|
|
14
14
|
if (!state.prev) {
|
|
15
15
|
state.prev = new Float64Array(half + 1)
|
|
16
16
|
state.syn = new Float64Array(half + 1)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audio/shift-pvoc",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Canonical phase vocoder (Bernsee/SMB) pitch shift",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -17,11 +17,12 @@
|
|
|
17
17
|
"index.js",
|
|
18
18
|
"audio.js",
|
|
19
19
|
"host.js",
|
|
20
|
-
"audio.d.ts"
|
|
20
|
+
"audio.d.ts",
|
|
21
|
+
"index.d.ts"
|
|
21
22
|
],
|
|
22
23
|
"dependencies": {
|
|
23
24
|
"@audio/spectral-pvoc": "^1.0.0",
|
|
24
|
-
"fourier-transform": "^2.
|
|
25
|
+
"fourier-transform": "^2.4.2"
|
|
25
26
|
},
|
|
26
27
|
"publishConfig": {
|
|
27
28
|
"access": "public"
|
|
@@ -45,5 +46,7 @@
|
|
|
45
46
|
"engines": {
|
|
46
47
|
"node": ">=18"
|
|
47
48
|
},
|
|
48
|
-
"audio": "./audio.js"
|
|
49
|
+
"audio": "./audio.js",
|
|
50
|
+
"funding": "https://github.com/sponsors/audiojs",
|
|
51
|
+
"types": "index.d.ts"
|
|
49
52
|
}
|