Skip to content

Art and animation, written as code. Illustrations, loops, interactive web art, launch-videos and scored films in dozens of styles, identical on every render.

fix(music): no default key or tempo for tuned sfx: take them from the film's score (plan.score) or throw

Alex Greenshpunf0236415d776
diff --git a/skills/anidoodle/engine/src/canvas-core/music/sfx.ts b/skills/anidoodle/engine/src/canvas-core/music/sfx.ts
index bb38491..15a3d41 100644
--- a/skills/anidoodle/engine/src/canvas-core/music/sfx.ts
+++ b/skills/anidoodle/engine/src/canvas-core/music/sfx.ts
@@ -1,5 +1,5 @@
// anidoodle sound effects: the kit (sfxKit), its building blocks (sfxCore) and film placement (sfxMix).
// Docs: references/music/sound-design.md. Tool: engine/tools/sfx.mjs.
-export { SFX, SFX_KINDS, sfxVariants, sfxInfo, renderSfx, validateSfx, parseKey, type SfxKind, type SfxOpts, type SfxSound } from "./sfxKit";
-export { placeSfx, sfxDuck, sfxAudibility, mixSfx, assertSfxAudible, filmSfx, validateSfxPlan, type SfxCue, type SfxPlan, type SfxSnap, type PlacedCue, type SfxAudibility, type SfxMix } from "./sfxMix";
+export { SFX, SFX_KINDS, sfxVariants, sfxInfo, renderSfx, validateSfx, sfxNeeds, parseKey, type SfxKind, type SfxOpts, type SfxSound } from "./sfxKit";
+export { placeSfx, sfxDuck, sfxAudibility, mixSfx, assertSfxAudible, filmSfx, validateSfxPlan, resolveSfxPlan, type SfxCue, type SfxPlan, type SfxSnap, type PlacedCue, type SfxAudibility, type SfxMix } from "./sfxMix";
export { type SfxStereo } from "./sfxCore";
diff --git a/skills/anidoodle/engine/src/canvas-core/music/sfxKit.ts b/skills/anidoodle/engine/src/canvas-core/music/sfxKit.ts
index 8d39003..78b48c1 100644
--- a/skills/anidoodle/engine/src/canvas-core/music/sfxKit.ts
+++ b/skills/anidoodle/engine/src/canvas-core/music/sfxKit.ts
@@ -27,12 +27,12 @@ export type SfxSound = { L: Float32Array; R: Float32Array; sr: number; kind: Sfx
/** [a, b) samples where the sound speaks (used for ducking and the audibility check). */
window: [number, number]; lufs: number };
-type Ctx = { sr: number; r: Rng; P: number; o: SfxOpts; dir: number; key: { pc: number; minor: boolean }; bpm: number;
+type Ctx = { sr: number; r: Rng; P: number; o: SfxOpts; dir: number; key: { pc: number; minor: boolean } | null; bpm: number;
/** x jittered by +-amt (relative). */ j: (x: number, amt: number) => number };
type Made = { bus: Bus; hit: number };
type Def = { variants: readonly string[]; level: number; duckDb: number; use: string; make: (c: Ctx, v: string) => Made };
-const keyHz = (c: Ctx, octave: number, semis = 0) => 440 * Math.pow(2, (c.key.pc + semis + 12 * (octave + 1) - 69) / 12);
+const keyHz = (c: Ctx, octave: number, semis = 0) => 440 * Math.pow(2, (c.key!.pc + semis + 12 * (octave + 1) - 69) / 12);
const PENTA = { major: [0, 2, 4, 7, 9], minor: [0, 3, 5, 7, 10] };
/** Glockenspiel-bar partials: a bright tuned strike that sits above a lo-fi mix. */
const glock = (f: number, tau: number, a: number, t0 = 0): Mode[] => [
@@ -327,7 +327,7 @@ const impact: Def = {
// a breath in before it: a reversed swell that stops on the hit
for (const side of [0, 1]) { const s = pink(r, pre); sweep(s, sr, (t) => 400 * Math.pow(8, t / 0.28), 1, "lp"); shape(s, sr, (t) => Math.pow(t / 0.28, 3)); b.add(s, 0, 0.8, side ? 0.4 : -0.4); }
// and a tuned shimmer on the key: root, 3rd, 5th, 9th in the upper octaves, spread across the field
- const third = c.key.minor ? 3 : 4;
+ const third = c.key!.minor ? 3 : 4;
[[keyHz(c, 5), -0.6], [keyHz(c, 5, third), 0.6], [keyHz(c, 5, 7), -0.3], [keyHz(c, 6, 2), 0.3], [keyHz(c, 6), 0]].forEach(([f, p], k) => {
const ms = glock(f * c.P, 1.5, 1, 0.02 + k * 0.012).map((m) => ({ ...m, att: 0.03 }));
b.add(modal(sr, n, ms), pre, 0.09, p);
@@ -342,7 +342,7 @@ const chime: Def = {
variants: ["sparkle", "bell", "glint"], level: -17, duckDb: 1.5,
use: "magic / success, tuned to the film's key: a rising pentatonic sparkle (sparkle), one bell (bell), a tiny glint on a highlight (glint)",
make(c, v) {
- const { sr, r } = c, n = secs(sr, v === "bell" ? 6 : v === "glint" ? 2 : 4), b = new Bus(sr, n), scale = PENTA[c.key.minor ? "minor" : "major"];
+ const { sr, r } = c, n = secs(sr, v === "bell" ? 6 : v === "glint" ? 2 : 4), b = new Bus(sr, n), scale = PENTA[c.key!.minor ? "minor" : "major"];
if (v === "bell") {
b.add(modal(sr, n, glock(keyHz(c, 5) * c.P, 1.4, 1)), 0, 1, -0.1);
b.add(modal(sr, n, glock(keyHz(c, 6, 7) * c.P, 0.9, 1, 0.004)), 0, 0.3, 0.3);
@@ -482,6 +482,14 @@ export const validateSfx = (kind: string, o: SfxOpts = {}) => {
if (o.key !== undefined) parseKey(o.key);
};
+/**
+ * What a sound needs from the film: a key (tuned kinds) and a bpm (tempo-synced kinds). Never
+ * defaulted: an effect tuned to a key the score isn't in, or pulsing at a tempo it isn't at, is wrong.
+ */
+export const sfxNeeds = (kind: SfxKind, variant: string, o: SfxOpts = {}) => ({
+ key: kind === "chime" || (kind === "riser" && variant !== "air") || (kind === "press" && variant === "confirm") || (kind === "impact" && variant === "bloom"),
+ bpm: kind === "riser" && !(variant === "air" && o.lengthS !== undefined),
+});
/**
* Render one sound. Pure in (kind, opts, sr). The level is calibrated: the kind's target loudness
* over its speaking window, +-1 dB of per-seed variation, + opts.gainDb; sample peak capped at -1 dBFS.
@@ -490,7 +498,10 @@ export const renderSfx = (kind: SfxKind, o: SfxOpts = {}, sr = 48000): SfxSound
validateSfx(kind, o);
if (!Number.isSafeInteger(sr) || sr < 22050 || sr > 192000) throw new Error(`sfx: sample rate must be an integer 22050..192000, got ${sr}`);
const d = SFX[kind], variant = o.variant ?? d.variants[0], seed = o.seed ?? 1, r = mkRng((seed ^ 0x5f3759df) >>> 0);
- const c: Ctx = { sr, r, P: Math.pow(2, (o.pitch ?? 0) / 12), o, dir: o.dir ?? 1, key: parseKey(o.key ?? "C"), bpm: o.bpm ?? 90, j: (x, amt) => x * (1 + (r() * 2 - 1) * amt) };
+ const need = sfxNeeds(kind, variant, o);
+ if (need.key && o.key === undefined) throw new Error(`sfx: ${kind}:${variant} is tuned and needs a key (opts.key, or in a plan: plan.key or plan.score = the film's piece); there is no default key`);
+ if (need.bpm && o.bpm === undefined) throw new Error(`sfx: ${kind}:${variant} is tempo-synced and needs a bpm (opts.bpm, or in a plan: plan.bpm or plan.score); there is no default tempo`);
+ const c: Ctx = { sr, r, P: Math.pow(2, (o.pitch ?? 0) / 12), o, dir: o.dir ?? 1, key: o.key === undefined ? null : parseKey(o.key), bpm: o.bpm ?? NaN, j: (x, amt) => x * (1 + (r() * 2 - 1) * amt) };
const made = d.make(c, variant), [L, R] = finish(made.bus, made.hit);
const kL = kWeight(L, sr), kR = kWeight(R, sr), window = speakingWindow(kL, kR, sr), now = winLufs(kL, kR, window[0], window[1]);
let g = d.level + (r() * 2 - 1) + (o.gainDb ?? 0) - now;
diff --git a/skills/anidoodle/engine/src/canvas-core/music/sfxMix.ts b/skills/anidoodle/engine/src/canvas-core/music/sfxMix.ts
index 414dccd..aa75d4a 100644
--- a/skills/anidoodle/engine/src/canvas-core/music/sfxMix.ts
+++ b/skills/anidoodle/engine/src/canvas-core/music/sfxMix.ts
@@ -2,9 +2,11 @@
// ducked under the cues that matter, one final master (a look-ahead true-peak ceiling), and an
// audibility guarantee: every cue is measured against the ducked score at its own moment and the
// mix FAILS if a cue sits more than minDb under it (a cue nobody hears is a bug, not a choice).
-import { renderSfx, validateSfx, SFX, SFX_KINDS, type SfxKind, type SfxOpts, type SfxSound } from "./sfxKit";
+import { renderSfx, validateSfx, sfxNeeds, SFX, SFX_KINDS, type SfxKind, type SfxOpts, type SfxSound } from "./sfxKit";
import { kWeight, winLufs, mixSeed, strSeed, secs, type SfxStereo } from "./sfxCore";
import { db } from "./dsp";
+import { MODES } from "./theory";
+import type { Piece } from "./plan";
import { loudness, truePeak } from "./meter";
export type SfxSnap = "none" | "bar" | "beat" | "8th" | "16th";
@@ -24,8 +26,10 @@ export type SfxPlan = {
seed?: number;
/** tempo grid: bpm, the time of beat 1 in seconds (beatZeroS), beats per bar. */
bpm?: number; beatZeroS?: number; beatsPerBar?: number; snap?: SfxSnap;
- /** key for the tuned kinds ("C", "Eb", "Am"). */
+ /** key for the tuned kinds ("C", "Eb", "Am"). No default: set it, or pass `score`. */
key?: string;
+ /** the film's score: key (first section), bpm (tempo, or the fitted tempo) and beats per bar come from it unless set above. */
+ score?: { piece: Piece; tempo?: number };
duck?: { attackS?: number; releaseS?: number; maxDb?: number };
/** audibility floor in dB (cue loudness minus score loudness over the cue's window). Default -6. */
minDb?: number;
@@ -39,7 +43,17 @@ export type SfxMix = { L: Float32Array; R: Float32Array; sfx: SfxStereo; music:
const GRID: Record<Exclude<SfxSnap, "none">, number> = { bar: 0, beat: 1, "8th": 0.5, "16th": 0.25 };
const name = (c: SfxCue, i: number) => `cue #${i} (${c.kind}${c.variant ? ":" + c.variant : ""}${c.label ? ` "${c.label}"` : ""} @ frame ${c.frame})`;
-export const validateSfxPlan = (p: SfxPlan) => {
+/** A plan with key / bpm / beatsPerBar filled in from its score (explicit plan values win). */
+export const resolveSfxPlan = (p: SfxPlan): SfxPlan => {
+ if (!p.score) return p;
+ const pl = p.score.piece?.plan, sec = pl?.sections?.[0];
+ if (!pl || !sec) throw new Error("sfx plan: score.piece has no plan/sections to take the key and tempo from");
+ const minor = (MODES[sec.mode]?.intervals ?? []).includes(3);
+ return { ...p, key: p.key ?? `${sec.key}${minor ? "m" : ""}`, bpm: p.bpm ?? p.score.tempo ?? pl.tempo, beatsPerBar: p.beatsPerBar ?? Number(String(pl.meter).split("/")[0]) };
+};
+
+export const validateSfxPlan = (plan: SfxPlan) => {
+ const p = resolveSfxPlan(plan);
if (!Number.isSafeInteger(p.fps) || p.fps <= 0) throw new Error(`sfx plan: fps must be a positive integer, got ${String(p.fps)}`);
if (!Number.isSafeInteger(p.frames) || p.frames <= 0) throw new Error(`sfx plan: frames must be a positive integer, got ${String(p.frames)}`);
if (p.seed !== undefined && (!Number.isSafeInteger(p.seed) || p.seed < 0 || p.seed > 0xffffffff)) throw new Error(`sfx plan: seed must be an integer 0..4294967295, got ${String(p.seed)}`);
@@ -55,13 +69,17 @@ export const validateSfxPlan = (p: SfxPlan) => {
if ((snap !== "none" || c.beats !== undefined) && p.bpm === undefined && c.bpm === undefined) throw new Error(`sfx plan: ${name(c, i)}: snap/beats need a bpm (plan.bpm)`);
if (c.duckDb !== undefined && (!Number.isFinite(c.duckDb) || c.duckDb < 0 || c.duckDb > 18)) throw new Error(`sfx plan: ${name(c, i)}: duckDb must be 0..18`);
try { validateSfx(c.kind, optsOf(p, c, 0)); } catch (e) { throw new Error(`sfx plan: ${name(c, i)}: ${(e as Error).message}`); }
+ const o = optsOf(p, c, 0), need = sfxNeeds(c.kind, c.variant ?? SFX[c.kind].variants[0], o);
+ if (need.key && o.key === undefined) throw new Error(`sfx plan: ${name(c, i)} is tuned: set plan.key, cue.key, or plan.score (the film's piece); there is no default key`);
+ if (need.bpm && o.bpm === undefined) throw new Error(`sfx plan: ${name(c, i)} is tempo-synced: set plan.bpm, cue.bpm, or plan.score (the film's piece); there is no default tempo`);
});
};
const optsOf = (p: SfxPlan, c: SfxCue, seed: number): SfxOpts => ({ seed: c.seed ?? seed, variant: c.variant, pitch: c.pitch, lengthS: c.lengthS, beats: c.beats, bpm: c.bpm ?? p.bpm, key: c.key ?? p.key, dir: c.dir, gainDb: c.gainDb });
/** Render and place every cue. Throws if a cue's pre-roll (whoosh approach, riser build) would start before 0. */
-export const placeSfx = (p: SfxPlan, sr: number): PlacedCue[] => {
- validateSfxPlan(p);
+export const placeSfx = (plan: SfxPlan, sr: number): PlacedCue[] => {
+ validateSfxPlan(plan);
+ const p = resolveSfxPlan(plan);
const seen = new Map<string, number>(), filmS = p.frames / p.fps;
return p.cues.map((cue, i) => {
const k = `${cue.kind}@${cue.frame}`, occ = seen.get(k) ?? 0; seen.set(k, occ + 1);
diff --git a/skills/anidoodle/engine/tools/sfx.mjs b/skills/anidoodle/engine/tools/sfx.mjs
index 111c526..719d44e 100644
--- a/skills/anidoodle/engine/tools/sfx.mjs
+++ b/skills/anidoodle/engine/tools/sfx.mjs
@@ -63,7 +63,7 @@ const baseline = (M) => {
// The demo: 15 s of the launch score's first bars with the kit on top, the story of the film's opening.
const FPS = 30, DEMO_FRAMES = 450;
-export const demoPlan = () => {
+export const demoPlan = (M) => {
const cues = [];
// typing "make a koi that swims" at a human cadence
const text = "make a koi that swims"; let f = 12;
@@ -82,7 +82,7 @@ export const demoPlan = () => {
{ frame: 400, kind: "riser", variant: "soft", beats: 4, label: "the build" },
{ frame: 400, kind: "impact", variant: "bloom", snap: "bar", label: "the reveal" },
);
- return { fps: FPS, frames: DEMO_FRAMES, bpm: 90, beatZeroS: 0, beatsPerBar: 4, key: "C", seed: 7, cues };
+ return { fps: FPS, frames: DEMO_FRAMES, score: { piece: M.launchLofi3() }, beatZeroS: 0, seed: 7, cues }; // key, bpm, bar length come from the score
};
const demoMusic = (M) => { const r = M.renderPiece(M.launchLofi3(), SR); return [r.L.slice(0, Math.round((DEMO_FRAMES / FPS) * SR)), r.R.slice(0, Math.round((DEMO_FRAMES / FPS) * SR))]; };
@@ -111,7 +111,7 @@ const kit = async (outdir) => {
rows.push([kind, info.use, vs]);
}
for (const [k, [L, R]] of Object.entries(baseline(M))) { writeAudio(join(dir, `baseline-${k}.mp3`), L, R); meters.baseline[k] = { peakDb: +dB(peakOf(L, R)).toFixed(1), centroidHz: Math.round(M.centroid([L, R], SR).energyWeighted), lengthS: +(L.length / SR).toFixed(2) }; }
- const plan = demoPlan(), music = demoMusic(M), mix = M.mixSfx(music, plan, SR);
+ const plan = demoPlan(M), music = demoMusic(M), mix = M.mixSfx(music, plan, SR);
writeAudio(join(dir, "demo.mp3"), mix.L, mix.R);
writeAudio(join(dir, "demo-sfx-only.mp3"), mix.sfx[0], mix.sfx[1]);
writeAudio(join(dir, "demo-music-only.mp3"), music[0], music[1]);
@@ -133,7 +133,7 @@ const test = async () => {
const all = M.SFX_KINDS.flatMap((k) => M.sfxVariants(k).map((v) => [k, v]));
ok(M.SFX_KINDS.length >= 14, `>= 14 kinds (got ${M.SFX_KINDS.length})`);
for (const [k, v] of all) {
- const a = M.renderSfx(k, { variant: v, seed: 11 }, SR), b = M.renderSfx(k, { variant: v, seed: 11 }, SR), c = M.renderSfx(k, { variant: v, seed: 12 }, SR), tag = `${k}:${v}`;
+ const a = M.renderSfx(k, { variant: v, seed: 11, key: "C", bpm: 90 }, SR), b = M.renderSfx(k, { variant: v, seed: 11, key: "C", bpm: 90 }, SR), c = M.renderSfx(k, { variant: v, seed: 12, key: "C", bpm: 90 }, SR), tag = `${k}:${v}`;
ok(md5(a.L, a.R) === md5(b.L, b.R), `${tag} deterministic`);
ok(md5(a.L, a.R) !== md5(c.L, c.R), `${tag} varies with seed`);
let finite = true; for (let i = 0; i < a.L.length; i++) if (!Number.isFinite(a.L[i]) || !Number.isFinite(a.R[i])) { finite = false; break; }
@@ -158,10 +158,24 @@ const test = async () => {
for (let i = 0; i < N; i++) re[i] = bell.L[i] + bell.R[i];
M.fft(re, im); let best = 0, bk = 0; for (let k = 10; k < N / 2; k++) { const m = re[k] * re[k] + im[k] * im[k]; if (m > best) { best = m; bk = k; } }
ok(Math.abs((bk * SR) / N - 880) < 3, `chime in A rings on 880 Hz (got ${((bk * SR) / N).toFixed(1)})`);
+ // no silent defaults: tuned / tempo-synced kinds need a key / bpm, from the plan or the film's score
+ throws(() => M.renderSfx("chime"), /tuned and needs a key.*no default key/, "chime without a key");
+ throws(() => M.renderSfx("press", { variant: "confirm" }), /needs a key/, "press:confirm without a key");
+ throws(() => M.renderSfx("impact", { variant: "bloom" }), /needs a key/, "impact:bloom without a key");
+ throws(() => M.renderSfx("riser", { key: "C" }), /needs a bpm.*no default tempo/, "riser without a bpm");
+ ok(M.renderSfx("press", {}).L.length > 0 && M.renderSfx("riser", { variant: "air", lengthS: 2 }).L.length > 0, "untuned kinds render without key/bpm");
+ throws(() => M.mixSfx(null, { fps: 30, frames: 300, cues: [{ frame: 10, kind: "chime" }] }, SR), /cue #0 \(chime.*is tuned: set plan.key/, "plan cue: chime without a key names the cue");
+ const noct = M.nocturne(), fromScore = M.placeSfx({ fps: 30, frames: 300, score: { piece: noct }, cues: [{ frame: 10, kind: "chime", variant: "bell" }, { frame: 200, kind: "riser", beats: 2 }] }, SR);
+ const rp = M.resolveSfxPlan({ fps: 30, frames: 300, score: { piece: noct }, cues: [] });
+ ok(rp.key === "Ab" && rp.bpm === noct.plan.tempo && rp.beatsPerBar === 3, `plan.score gives key/bpm/bar (got ${rp.key} ${rp.bpm} ${rp.beatsPerBar})`);
+ ok(Math.abs(fromScore[1].sound.hit / SR - 2 * 60 / noct.plan.tempo) < 0.002, "a riser in a scored plan takes the score's tempo");
+ { const b2 = fromScore[0].sound, N2 = 1 << 16, re2 = new Float64Array(N2), im2 = new Float64Array(N2); for (let i = 0; i < N2; i++) re2[i] = b2.L[i] + b2.R[i]; M.fft(re2, im2); let bb = 0, kk = 0; for (let k = 10; k < N2 / 2; k++) { const m = re2[k] * re2[k] + im2[k] * im2[k]; if (m > bb) { bb = m; kk = k; } }
+ ok(Math.abs((kk * SR) / N2 - 830.6) < 3, `a bell under the Ab nocturne rings on Ab5 (got ${((kk * SR) / N2).toFixed(1)})`); }
+ ok(M.resolveSfxPlan({ fps: 30, frames: 300, key: "D", score: { piece: noct }, cues: [] }).key === "D", "an explicit plan.key beats the score's");
// tempo sync: a 4-beat riser at 120 bpm lasts 2 s and its hit is its end
- const rz = M.renderSfx("riser", { beats: 4, bpm: 120, seed: 3 }, SR); ok(Math.abs(rz.hit / SR - 2) < 0.002, `riser 4 beats @120 = 2 s (got ${(rz.hit / SR).toFixed(3)})`);
+ const rz = M.renderSfx("riser", { beats: 4, bpm: 120, key: "G", seed: 3 }, SR); ok(Math.abs(rz.hit / SR - 2) < 0.002, `riser 4 beats @120 = 2 s (got ${(rz.hit / SR).toFixed(3)})`);
// the demo: deterministic, clean, every cue audible
- const plan = demoPlan(), music = demoMusic(M), m1 = M.mixSfx(music, plan, SR), m2 = M.mixSfx(music, plan, SR);
+ const plan = demoPlan(M), music = demoMusic(M), m1 = M.mixSfx(music, plan, SR), m2 = M.mixSfx(music, plan, SR);
ok(md5(m1.L, m1.R) === md5(m2.L, m2.R), "demo mix deterministic");
ok(m1.L.length === Math.round((DEMO_FRAMES / FPS) * SR), "demo mix is exactly the film length");
ok(m1.dbtp <= -0.9, `demo true peak <= -1 dBTP (got ${m1.dbtp.toFixed(2)})`);
@@ -179,7 +193,7 @@ const test = async () => {
throws(() => M.renderSfx("tick", { variant: "loud" }), /no variant "loud"/, "unknown variant");
throws(() => M.mixSfx(null, { ...base, cues: [{ frame: 1, kind: "kazoo" }] }, SR), /unknown kind/, "unknown kind in a plan");
throws(() => M.mixSfx(null, { ...base, cues: [{ frame: 2, kind: "whoosh" }] }, SR), /pre-roll starts before frame 0; move it to frame >= \d+/, "whoosh pre-roll before 0");
- throws(() => M.mixSfx(null, { ...base, bpm: 90, cues: [{ frame: 30, kind: "riser", beats: 8 }] }, SR), /pre-roll/, "riser pre-roll before 0");
+ throws(() => M.mixSfx(null, { ...base, bpm: 90, key: "C", cues: [{ frame: 30, kind: "riser", beats: 8 }] }, SR), /pre-roll/, "riser pre-roll before 0");
for (const s of [-1, 1.5, 2 ** 33, NaN, "7"]) throws(() => M.renderSfx("pop", { seed: s }), /seed must be an integer/, `bad seed ${String(s)}`);
throws(() => M.mixSfx(null, { ...base, seed: -3, cues: [] }, SR), /seed must be an integer/, "bad plan seed");
throws(() => M.mixSfx(null, { ...base, cues: [{ frame: 300, kind: "pop" }] }, SR), /frame must be 0\.\.299/, "cue after the film");
@@ -198,7 +212,7 @@ const test = async () => {
const [cmd, ...args] = process.argv.slice(2);
if (cmd === "list") { const M = await load(); for (const k of M.SFX_KINDS) { const i = M.sfxInfo(k); console.log(`${k.padEnd(8)} [${i.variants.join(", ")}] level ${i.levelLufs} LUFS(win), duck ${i.duckDb} dB\n ${i.use}`); } }
-else if (cmd === "one") { const M = await load(), out = args.pop(), [kind, variant, seed] = args; const s = M.renderSfx(kind, { variant, seed: seed ? Number(seed) : undefined }, SR); writeAudio(out, s.L, s.R); console.log(`${kind}:${s.variant} seed ${s.seed}: ${(s.L.length / SR).toFixed(2)} s, hit @ ${(s.hit / SR).toFixed(3)} s, ${s.lufs.toFixed(1)} LUFS(win)`); }
+else if (cmd === "one") { const M = await load(), out = args.pop(), [kind, variant, seed] = args; const s = M.renderSfx(kind, { variant, seed: seed ? Number(seed) : undefined, key: process.env.KEY, bpm: process.env.BPM ? Number(process.env.BPM) : undefined }, SR); writeAudio(out, s.L, s.R); console.log(`${kind}:${s.variant} seed ${s.seed}: ${(s.L.length / SR).toFixed(2)} s, hit @ ${(s.hit / SR).toFixed(3)} s, ${s.lufs.toFixed(1)} LUFS(win)`); }
else if (cmd === "kit" && args[0]) await kit(args[0]);
else if (cmd === "test") await test();
else { console.log("usage: node tools/sfx.mjs list | one <kind> [variant] [seed] <out> | kit <outdir> | test"); process.exit(cmd ? 1 : 0); }
diff --git a/skills/anidoodle/references/music/sound-design.md b/skills/anidoodle/references/music/sound-design.md
index edcb390..dae09c8 100644
--- a/skills/anidoodle/references/music/sound-design.md
+++ b/skills/anidoodle/references/music/sound-design.md
@@ -21,7 +21,9 @@ Code: `engine/src/canvas-core/music/sfxKit.ts` (the kit), `sfxMix.ts` (placement
key ticks are twenty different ticks. `mixSfx` gives each cue its own seed from (kind, frame), so
inserting a cue never changes the others.
- **Tuned where it is tonal.** chime, riser, `press:confirm` and `impact:bloom` follow the film's
- key (`plan.key`, e.g. `"C"`, `"Eb"`, `"Am"`). A sparkle in the wrong key sounds like a mistake.
+ key. A sparkle in the wrong key sounds like a mistake, so there is **no default key or tempo**.
+ Pass `plan.score: { piece, tempo? }` (key, bpm and bar come from the film's piece) or set
+ `plan.key` / `plan.bpm`. A tuned kind with no key, or a riser with no bpm, throws.
## The kit
@@ -55,7 +57,7 @@ the plan throws and names the earliest legal frame.
```ts
import { filmSfx, launchLofi3, filmAudio, type SfxPlan } from "./music";
const plan: SfxPlan = {
- fps: 30, frames: 450, bpm: 90, beatZeroS: 0, key: "C", seed: 7,
+ fps: 30, frames: 450, score: { piece: launchLofi3() }, beatZeroS: 0, seed: 7, // key, bpm, bar from the score
cues: [
{ frame: 12, kind: "tick" }, // ...one per typed character
{ frame: 157, kind: "press", variant: "thock", snap: "beat", label: "Generate" },