@audio/shift-hybrid 1.0.1 → 1.0.2
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 +54 -0
- package/index.d.ts +25 -0
- package/package.json +6 -3
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @audio/shift-hybrid [](https://www.npmjs.com/package/@audio/shift-hybrid) [](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/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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audio/shift-hybrid",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Hybrid pitch shift — runs phase-lock + WSOLA in parallel, crossfades by transient confidence",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"index.js",
|
|
14
|
-
"host.js"
|
|
14
|
+
"host.js",
|
|
15
|
+
"index.d.ts"
|
|
15
16
|
],
|
|
16
17
|
"dependencies": {
|
|
17
18
|
"@audio/shift-pvoc-lock": "^1.0.0",
|
|
@@ -40,5 +41,7 @@
|
|
|
40
41
|
],
|
|
41
42
|
"engines": {
|
|
42
43
|
"node": ">=18"
|
|
43
|
-
}
|
|
44
|
+
},
|
|
45
|
+
"funding": "https://github.com/sponsors/audiojs",
|
|
46
|
+
"types": "index.d.ts"
|
|
44
47
|
}
|