/ music / double-pendulum
Sign in
music / double-pendulum
double-pendulum / src / compositions / c04-descent / capacity.ts
30 lines · 1.4 KBBlameHistoryRaw
1// How many ringing extension notes can this device render? Instruments like Chaos gong are costly
2// per ringing voice (strongly coupled modes can't be culled), so measure one voice's cost in a
3// render worker (see instruments/stream/capacity.ts) and allow as many voices as fit the budget.
5import { DEFAULTS } from "@modal-synth/engine/params.ts";
6import { PRESETS } from "@modal-synth/presets.ts";
7import type { Params } from "../../core/params.ts";
8import { parseModalPreset } from "../../instruments/modal.ts";
9import { VOICE_BUDGET, voiceCost, voicesThatFit } from "../../instruments/stream/capacity.ts";
11export interface VoiceCapacity {
12 cap: number; // voices allowed
13 perVoice: number; // measured load of one ringing voice
16function sound(P: Params): Params | null {
17 const name = P.extInstrument as string;
18 if (!name.startsWith("modal: ")) return null;
19 const p = name === "modal: custom" ? parseModalPreset(P.modalCustom as string) : PRESETS.find((x) => `modal: ${x.name}` === name)?.p;
20 return { ...DEFAULTS, ...(p ?? {}) };
23export async function overlapCapacity(P: Params, sampleRate: number, wanted: number): Promise<VoiceCapacity> {
24 const s = sound(P);
25 if (!s) return { cap: wanted, perVoice: 0 };
26 const perVoice = await voiceCost({ ...s, voices: 1 }, sampleRate);
27 return { cap: voicesThatFit(perVoice, wanted), perVoice };
30export const OVERLAP_BUDGET = VOICE_BUDGET;
↑↓ move↵openescclose