@audio/shift-pvoc 1.1.3 → 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.
Files changed (3) hide show
  1. package/README.md +49 -0
  2. package/index.d.ts +26 -0
  3. package/package.json +6 -3
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # @audio/shift-pvoc [![npm](https://img.shields.io/npm/v/@audio/shift-pvoc)](https://www.npmjs.com/package/@audio/shift-pvoc) [![MIT](https://img.shields.io/badge/MIT-%E0%A5%90-white)](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/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,6 +1,6 @@
1
1
  {
2
2
  "name": "@audio/shift-pvoc",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Canonical phase vocoder (Bernsee/SMB) pitch shift",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -17,7 +17,8 @@
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",
@@ -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
  }