/ music / double-pendulum
Sign in
music / double-pendulum
double-pendulum / src / compositions / c04-descent / capacity.ts
30 lines · 1.4 KBCodeBlameHistory
89519c1crash: extension notes when the arms are fully extendedJeremy Magland 1// How many ringing extension notes can this device render? Instruments like Chaos gong are costly
f7d91baAdd composition 4: crashJeremy Magland 2// per ringing voice (strongly coupled modes can't be culled), so measure one voice's cost in a
97bd308Make streamed audio robust: voice caps, 2 s buffer, soft underrunsJeremy Magland 3// render worker (see instruments/stream/capacity.ts) and allow as many voices as fit the budget.
f7d91baAdd composition 4: crashJeremy Magland 4
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";
97bd308Make streamed audio robust: voice caps, 2 s buffer, soft underrunsJeremy Magland 9import { VOICE_BUDGET, voiceCost, voicesThatFit } from "../../instruments/stream/capacity.ts";
f7d91baAdd composition 4: crashJeremy Magland 10
11export interface VoiceCapacity {
12 cap: number; // voices allowed
13 perVoice: number; // measured load of one ringing voice
16function sound(P: Params): Params | null {
89519c1crash: extension notes when the arms are fully extendedJeremy Magland 17 const name = P.extInstrument as string;
f7d91baAdd composition 4: crashJeremy Magland 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 ?? {}) };
5d7ea1acrash: fixed-pitch 'bottom notes' (no longer called crashes)Jeremy Magland 23export async function overlapCapacity(P: Params, sampleRate: number, wanted: number): Promise<VoiceCapacity> {
f7d91baAdd composition 4: crashJeremy Magland 24 const s = sound(P);
25 if (!s) return { cap: wanted, perVoice: 0 };
97bd308Make streamed audio robust: voice caps, 2 s buffer, soft underrunsJeremy Magland 26 const perVoice = await voiceCost({ ...s, voices: 1 }, sampleRate);
27 return { cap: voicesThatFit(perVoice, wanted), perVoice };
f7d91baAdd composition 4: crashJeremy Magland 28}
97bd308Make streamed audio robust: voice caps, 2 s buffer, soft underrunsJeremy Magland 30export const OVERLAP_BUDGET = VOICE_BUDGET;
↑↓ move↵openescclose