@audio/shift-hybrid 1.0.1 → 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/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # @audio/shift-hybrid [![npm](https://img.shields.io/npm/v/@audio/shift-hybrid)](https://www.npmjs.com/package/@audio/shift-hybrid) [![MIT](https://img.shields.io/badge/MIT-%E0%A5%90-white)](https://github.com/krishnized/license)
2
+
3
+ Hybrid pitch shift — runs phase-lock + WSOLA in parallel, crossfades by transient confidence
4
+
5
+ ```
6
+ npm install @audio/shift-hybrid
7
+ ```
8
+
9
+ ```js
10
+ import hybrid from '@audio/shift-hybrid'
11
+ ```
12
+
13
+ Runs `phaseLock` and `wsola` in parallel, crossfades sample-by-sample by spectral-flux transient confidence. Tonal regions resolve via the phase vocoder; attacks resolve via WSOLA similarity search, time-aligned against phaseLock before blending so the two engines' attacks land together.
14
+
15
+ ```js
16
+ hybrid(audio, { ratio: 1.5 })
17
+ hybrid(audio, { ratio: 1.5, hybridThreshold: 0.6 })
18
+ ```
19
+
20
+ | Param | Default | |
21
+ |---|---|---|
22
+ | `hybridThreshold` | `0.8` | Spectral-flux z-score for full WSOLA blend |
23
+
24
+ **Preserves** tonal phase coherence + attack shape — simultaneously.<br>
25
+ **Destroys** CPU budget (≈2×), formants.
26
+
27
+ | f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
28
+ |-------:|-----:|------:|------------:|-------------:|----------:|------:|
29
+ | 0.00 | 0.0 | 0.000 | 0.984 | 1.423 | 0.999 | 1.824 |
30
+
31
+ Same phaseLock-derived numbers as `phaseLock`/`transient` on this non-percussive suite — the WSOLA blend never activates because nothing here crosses `hybridThreshold`. Worst shift score among the frequency-adjacent methods for the same reason: it's carrying `wsola`'s parallel computation for a blend that stays at zero.
32
+
33
+ **Use when:** Mixed dynamic material where a single domain compromises the other.<br>
34
+ **Not for:** Pure tonal (just use `phaseLock`) or pure percussive (just use `transient`).
35
+
36
+ ## Stream
37
+
38
+ ```js
39
+ let write = hybrid({ ratio: 1.5 })
40
+ let out = write(inputBlock)
41
+ let tail = write() // flush
42
+ ```
43
+
44
+ `hybrid` buffers the whole input; `write(chunk)` accumulates and the batch algorithm runs once on `write()` (flush, no argument), returning everything at once.
45
+
46
+ ## Data
47
+
48
+ Input is a `Float32Array` (mono) or an array of `Float32Array` channels (`[left, right, ...]`) — anything else throws `TypeError`. `ratio` here is a fixed number for the whole call — a function or `Float32Array` throws.
49
+
50
+ ---
51
+
52
+ Part of [@audio/shift](https://github.com/audiojs/shift) — the shift family umbrella. This README is generated from the umbrella docs.
53
+
54
+ 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 'pitchHybrid' */
12
+ export interface PitchHybridOptions {
13
+ /** -24..24 (default 0) */
14
+ "semitones"?: Auto
15
+ at?: number | string
16
+ duration?: number | string
17
+ }
18
+
19
+ export declare const pitchHybrid: {
20
+ (ctx: Ctx): Process
21
+ channels: "any"
22
+ streaming: false
23
+ tail: 0
24
+ params: {
25
+ /** -24..24 (default 0) */
26
+ "semitones": { type: "number", default: 0 }
27
+ }
28
+ }
package/audio.js ADDED
@@ -0,0 +1,19 @@
1
+ // audio manifest — this one pitch shift per @audio/compile CONTRACT (tonal and transient parts each their own way: full mixes), so a host loads it
2
+ // alone: @audio/shift's pitch-shift chooses among every method and loads them all. Whole-render (streaming: false), as
3
+ // that umbrella hosts every method: the host buffers the input and calls process once.
4
+
5
+ import shift from './index.js'
6
+
7
+ export const pitchHybrid = (ctx) => {
8
+ return (inputs, outputs, params) => {
9
+ const inp = inputs[0], out = outputs[0]
10
+ if (!inp || !inp.length) return
11
+ for (let c = 0; c < inp.length; c++) out[c].set(shift(inp[c], { semitones: params.semitones[0], sampleRate: ctx.sampleRate, fs: ctx.sampleRate }))
12
+ }
13
+ }
14
+ pitchHybrid.channels = 'any'
15
+ pitchHybrid.streaming = false
16
+ pitchHybrid.tail = 0
17
+ pitchHybrid.params = {
18
+ semitones: { type: 'number', min: -24, max: 24, default: 0 },
19
+ }
package/index.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ /** Runs phaseLock and wsola in parallel, crossfading sample-by-sample by spectral-flux transient confidence — tonal regions resolve via the phase vocoder, attacks via WSOLA, time-aligned before blending. */
2
+ export interface HybridOptions {
3
+ /** target ratio (1.5 = +7 semitones, 2 = octave); fixed only — a function or Float32Array throws */
4
+ ratio?: number
5
+ /** semitones, applied when `ratio` is omitted (1.5 ratio = +7 semitones), default 0 */
6
+ semitones?: number
7
+ /** sample rate in Hz, default 44100 */
8
+ sampleRate?: number
9
+ /** spectral-flux z-score for full WSOLA blend, default 0.8 */
10
+ hybridThreshold?: number
11
+ }
12
+
13
+ /** Streaming writer: feed chunks matching the first call's shape (mono or channel array); call with no argument to flush the tail. */
14
+ export interface ShiftWriter {
15
+ (chunk: Float32Array): Float32Array
16
+ (chunk: Float32Array[]): Float32Array[]
17
+ (chunk?: undefined): Float32Array | Float32Array[]
18
+ }
19
+
20
+ /** Process a whole buffer. Returns a new Float32Array of the same length. */
21
+ export default function hybrid(data: Float32Array, options?: HybridOptions): Float32Array
22
+ /** Process channels independently — [left, right, ...]. Returns matching channels. */
23
+ export default function hybrid(data: Float32Array[], options?: HybridOptions): Float32Array[]
24
+ /** Streaming form: returns a writer — call with chunks, call with no argument to flush. */
25
+ export default function hybrid(options?: HybridOptions): ShiftWriter
package/package.json CHANGED
@@ -1,17 +1,24 @@
1
1
  {
2
2
  "name": "@audio/shift-hybrid",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Hybrid pitch shift — runs phase-lock + WSOLA in parallel, crossfades by transient confidence",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "main": "index.js",
8
8
  "exports": {
9
9
  ".": "./index.js",
10
+ "./audio": {
11
+ "types": "./audio.d.ts",
12
+ "default": "./audio.js"
13
+ },
10
14
  "./package.json": "./package.json"
11
15
  },
12
16
  "files": [
13
17
  "index.js",
14
- "host.js"
18
+ "audio.d.ts",
19
+ "audio.js",
20
+ "host.js",
21
+ "index.d.ts"
15
22
  ],
16
23
  "dependencies": {
17
24
  "@audio/shift-pvoc-lock": "^1.0.0",
@@ -40,5 +47,8 @@
40
47
  ],
41
48
  "engines": {
42
49
  "node": ">=18"
43
- }
50
+ },
51
+ "funding": "https://github.com/sponsors/audiojs",
52
+ "types": "index.d.ts",
53
+ "audio": "./audio.js"
44
54
  }