// How many ringing extension notes can this device render? Instruments like Chaos gong are costly // per ringing voice (strongly coupled modes can't be culled), so measure one voice's cost in a // render worker (see instruments/stream/capacity.ts) and allow as many voices as fit the budget. import { DEFAULTS } from "@modal-synth/engine/params.ts"; import { PRESETS } from "@modal-synth/presets.ts"; import type { Params } from "../../core/params.ts"; import { parseModalPreset } from "../../instruments/modal.ts"; import { VOICE_BUDGET, voiceCost, voicesThatFit } from "../../instruments/stream/capacity.ts"; export interface VoiceCapacity { cap: number; // voices allowed perVoice: number; // measured load of one ringing voice } function sound(P: Params): Params | null { const name = P.extInstrument as string; if (!name.startsWith("modal: ")) return null; const p = name === "modal: custom" ? parseModalPreset(P.modalCustom as string) : PRESETS.find((x) => `modal: ${x.name}` === name)?.p; return { ...DEFAULTS, ...(p ?? {}) }; } export async function overlapCapacity(P: Params, sampleRate: number, wanted: number): Promise { const s = sound(P); if (!s) return { cap: wanted, perVoice: 0 }; const perVoice = await voiceCost({ ...s, voices: 1 }, sampleRate); return { cap: voicesThatFit(perVoice, wanted), perVoice }; } export const OVERLAP_BUDGET = VOICE_BUDGET;