@audio/spectral-pvoc 1.0.0 → 1.0.1

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 (2) hide show
  1. package/index.d.ts +79 -0
  2. package/package.json +6 -3
package/index.d.ts ADDED
@@ -0,0 +1,79 @@
1
+ /** Phase-vocoder engine — frame-level primitives over STFT magnitude/phase arrays. Pure math, no defaults. */
2
+
3
+ /** Per-frame geometry the scatter/lock primitives read from. */
4
+ export interface PvocCtx {
5
+ /** Nyquist bin index (frameSize / 2) */
6
+ half: number
7
+ /** hop size, samples */
8
+ hop: number
9
+ /** Hz per FFT bin (fs / N) */
10
+ freqPerBin: number
11
+ /** analysis window / FFT size */
12
+ N: number
13
+ }
14
+
15
+ export const PI2: number
16
+ /** rms(w)/mean(w) for the engine's periodic Hann — energy-preserving OLA gain for scatterGated. */
17
+ export const WIN_GAIN: number
18
+
19
+ /** Wrap a phase (radians) into (−π, π]. */
20
+ export function wrapPhase(p: number): number
21
+
22
+ /** Local magnitude maxima of `mag[0..half]` above a fraction of the frame's peak. Returns bin indices, ascending. */
23
+ export function findPeaks(mag: Float32Array | Float64Array, half: number): number[]
24
+
25
+ /** Binary-search the peak (from `findPeaks`) nearest bin `k`. Returns −1 if `peaks` is empty. */
26
+ export function nearestPeak(peaks: number[], k: number): number
27
+
28
+ /**
29
+ * Bernsee/SMB peak-gated bin scatter — pitch shift by `ratio`, RMS-preserving collisions.
30
+ * `newMag`/`newFreq`/`peakMag` are caller-owned scratch sized `half+1`, zero-filled before the call.
31
+ * Writes into `newMag`/`newFreq` in place.
32
+ */
33
+ export function scatterGated(
34
+ mag: Float32Array | Float64Array,
35
+ phase: Float32Array | Float64Array,
36
+ prevPhase: Float32Array | Float64Array | null,
37
+ ratio: number,
38
+ ctx: PvocCtx,
39
+ newMag: Float64Array,
40
+ newFreq: Float64Array,
41
+ peakMag: Float64Array,
42
+ ): void
43
+
44
+ /**
45
+ * Laroche-Dolson rigid-ROI peak-locked bin scatter — phase-coherent shift by `ratio`.
46
+ * `syn` is the caller-owned running per-bin phase accumulator (persists across frames), mutated in place.
47
+ * `newMag`/`newPhase`/`peakMag` are caller-owned scratch sized `half+1`; `peakDest`/`peakSynPhase` sized `peaks.length`. All zero-filled before the call.
48
+ */
49
+ export function scatterLocked(
50
+ mag: Float32Array | Float64Array,
51
+ phase: Float32Array | Float64Array,
52
+ prevPhase: Float32Array | Float64Array | null,
53
+ reset: boolean,
54
+ peaks: number[],
55
+ ratio: number,
56
+ ctx: PvocCtx,
57
+ syn: Float64Array,
58
+ newMag: Float64Array,
59
+ newPhase: Float64Array,
60
+ peakDest: Int32Array,
61
+ peakSynPhase: Float64Array,
62
+ peakMag: Float64Array,
63
+ ): void
64
+
65
+ /** Scalar or time-varying ratio → per-frame resolver. */
66
+ export function makeFrameRatio(ratio: number | ((t: number) => number)): {
67
+ /** ratio at t = 0 */
68
+ scalar: number
69
+ /** ratio at a given frame position */
70
+ at(frameStart: number, sampleRate: number): number
71
+ }
72
+
73
+ /** Lock non-peak bin phases to their nearest peak's rotation, in place on `propPhase` (time-stretch coherence). */
74
+ export function lockPhase(
75
+ phase: Float32Array | Float64Array,
76
+ propPhase: Float32Array | Float64Array,
77
+ mag: Float32Array | Float64Array,
78
+ half: number,
79
+ ): void
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@audio/spectral-pvoc",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Phase-vocoder engine — peak-gated and peak-locked spectral bin scatter (Bernsee, Laroche-Dolson), phase locking, peak finding; powers @audio/shift-pvoc* and @audio/stretch-pvoc*",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -10,7 +10,8 @@
10
10
  "./package.json": "./package.json"
11
11
  },
12
12
  "files": [
13
- "pvoc.js"
13
+ "pvoc.js",
14
+ "index.d.ts"
14
15
  ],
15
16
  "dependencies": {},
16
17
  "keywords": [
@@ -30,8 +31,10 @@
30
31
  "publishConfig": {
31
32
  "access": "public"
32
33
  },
34
+ "types": "index.d.ts",
33
35
  "repository": {
34
36
  "directory": "packages/spectral-pvoc"
35
37
  },
36
- "homepage": "https://github.com/audiojs/spectral/tree/main/packages/spectral-pvoc"
38
+ "homepage": "https://github.com/audiojs/spectral/tree/main/packages/spectral-pvoc",
39
+ "funding": "https://github.com/sponsors/audiojs"
37
40
  }