Bug Report
Issue
In host.js, the resolvePitchParams() function has a hardcoded error message listing specific algorithms that support variable ratios. This error message becomes outdated when new algorithms are added that support variable ratios.
Location
host.js lines 25-30
Details
export function resolvePitchParams(opts) {
let semitones = opts?.semitones ?? 0
if (!Number.isFinite(semitones)) throw new TypeError('pitchShift: `semitones` must be a finite number')
let raw = opts?.ratio
if (typeof raw === 'function' || raw instanceof Float32Array) {
throw new TypeError('pitchShift: variable `ratio` (function or Float32Array) is supported by vocoder, phaseLock, transient, formant, paulstretch, sms, hpss, and sample')
}
// ...
}
The Bug: The error message explicitly lists algorithms: "vocoder, phaseLock, transient, formant, paulstretch, sms, hpss, and sample". When a new algorithm is added that supports variable ratios (e.g., a future melody algorithm), the error message won't be updated, misleading users.
Additionally, lpc and delay algorithms were added later (as seen in pitch-shift.js and test.js) and also support variable ratios, but they're not in this error message list.
Impact
- Medium: Misleading error messages when using variable ratios with newer algorithms
- Maintenance burden: every new variable-ratio algorithm requires updating this error message
Suggested Fix
Replace the hardcoded list with a reference to a central capability registry, or at minimum make the message generic:
if (typeof raw === 'function' || raw instanceof Float32Array) {
throw new TypeError('pitchShift: variable `ratio` (function or Float32Array) is not supported by this algorithm. Use the main `pitchShift()` entry point which auto-selects a compatible method, or use one of the algorithms that explicitly supports variable ratios.')
}
Or better, maintain a SUPPORTS_VARIABLE_RATIO Set/Map that algorithms register themselves into:
// At top of host.js or in a shared capabilities file
const VARIABLE_RATIO_ALGORITHMS = new Set([
'vocoder', 'phaseLock', 'transient', 'formant',
'paulstretch', 'sms', 'hpss', 'sample', 'delay', 'lpc'
])
export function resolvePitchParams(opts) {
// ...
if (typeof raw === 'function' || raw instanceof Float32Array) {
const algos = [...VARIABLE_RATIO_ALGORITHMS].join(', ')
throw new TypeError(`pitchShift: variable \`ratio\` (function or Float32Array) is supported by: ${algos}. Use the main \`pitchShift()\` entry point for auto-selection.`)
}
// ...
}
Then each algorithm file can import and register itself:
// In delay.js, lpc.js, etc.
import { VARIABLE_RATIO_ALGORITHMS } from './host.js'
VARIABLE_RATIO_ALGORITHMS.add('delay')
This makes the capability explicit and self-documenting.
Related Note
The lpc and delay algorithms (added in recent commits) support variable ratios per the tests but are missing from the error message list.
Bug Report
Issue
In
host.js, theresolvePitchParams()function has a hardcoded error message listing specific algorithms that support variable ratios. This error message becomes outdated when new algorithms are added that support variable ratios.Location
host.jslines 25-30Details
The Bug: The error message explicitly lists algorithms: "vocoder, phaseLock, transient, formant, paulstretch, sms, hpss, and sample". When a new algorithm is added that supports variable ratios (e.g., a future
melodyalgorithm), the error message won't be updated, misleading users.Additionally,
lpcanddelayalgorithms were added later (as seen in pitch-shift.js and test.js) and also support variable ratios, but they're not in this error message list.Impact
Suggested Fix
Replace the hardcoded list with a reference to a central capability registry, or at minimum make the message generic:
Or better, maintain a
SUPPORTS_VARIABLE_RATIOSet/Map that algorithms register themselves into:Then each algorithm file can import and register itself:
This makes the capability explicit and self-documenting.
Related Note
The
lpcanddelayalgorithms (added in recent commits) support variable ratios per the tests but are missing from the error message list.