@audio/shift-pvoc 1.1.2 → 1.1.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/README.md +49 -0
- package/audio.d.ts +28 -0
- package/index.d.ts +26 -0
- package/package.json +11 -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.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Generated from the audio.js manifest (params metadata is the source of truth).
|
|
2
|
+
// Regenerate: node tools/dts.js in @audio/compile. Do not edit by hand.
|
|
3
|
+
|
|
4
|
+
/** Automatable number — scalar, `t => value` fn, or breakpoint curve {t, v} */
|
|
5
|
+
type Auto = number | ((t: number) => number) | { t: number[], v: number[] }
|
|
6
|
+
/** Per-block param values as delivered by hosts (numbers arrive as 1-length Float32Array) */
|
|
7
|
+
type Live = Record<string, Float32Array | string | boolean>
|
|
8
|
+
type Ctx = { sampleRate: number, maxBlockSize: number, maxChannels: number, currentTime: number, duration?: number, events?: readonly any[], emit?: (name: string, ...args: any[]) => void, [k: string]: unknown }
|
|
9
|
+
type Process = (inputs: Float32Array[][], outputs: Float32Array[][], params: Live) => void
|
|
10
|
+
|
|
11
|
+
/** Chainable-host options for 'vocoder' */
|
|
12
|
+
export interface VocoderOptions {
|
|
13
|
+
/** -24..24 (default 0) */
|
|
14
|
+
"semitones"?: Auto
|
|
15
|
+
at?: number | string
|
|
16
|
+
duration?: number | string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export declare const vocoder: {
|
|
20
|
+
(ctx: Ctx): Process
|
|
21
|
+
channels: "any"
|
|
22
|
+
latency: 2048
|
|
23
|
+
tail: 0
|
|
24
|
+
params: {
|
|
25
|
+
/** -24..24 (default 0) */
|
|
26
|
+
"semitones": { type: "number", default: 0 }
|
|
27
|
+
}
|
|
28
|
+
}
|
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/package.json
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audio/shift-pvoc",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
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
|
-
"./audio":
|
|
10
|
+
"./audio": {
|
|
11
|
+
"types": "./audio.d.ts",
|
|
12
|
+
"default": "./audio.js"
|
|
13
|
+
},
|
|
11
14
|
"./package.json": "./package.json"
|
|
12
15
|
},
|
|
13
16
|
"files": [
|
|
14
17
|
"index.js",
|
|
15
18
|
"audio.js",
|
|
16
|
-
"host.js"
|
|
19
|
+
"host.js",
|
|
20
|
+
"audio.d.ts",
|
|
21
|
+
"index.d.ts"
|
|
17
22
|
],
|
|
18
23
|
"dependencies": {
|
|
19
24
|
"@audio/spectral-pvoc": "^1.0.0",
|
|
@@ -41,5 +46,7 @@
|
|
|
41
46
|
"engines": {
|
|
42
47
|
"node": ">=18"
|
|
43
48
|
},
|
|
44
|
-
"audio": "./audio.js"
|
|
49
|
+
"audio": "./audio.js",
|
|
50
|
+
"funding": "https://github.com/sponsors/audiojs",
|
|
51
|
+
"types": "index.d.ts"
|
|
45
52
|
}
|