Art and animation, written as code. Illustrations, loops, interactive web art, launch-videos and scored films in dozens of styles, identical on every render.
TypeScript agent-skillsanimationcanvasclaude-codeclaude-pluginclaude-skillscodex-plugincreative-codecreative-codingcreative-toolsdeterministicgenerative-arthand-drawnillustrationlaunch-videomotion-designmotion-graphicspluginprocedural-generationskill
Play verified recordings in film audio exports
Alex Greenshpune65f64c161fc
diff --git a/skills/anidoodle/engine/src/hosts/audio.ts b/skills/anidoodle/engine/src/hosts/audio.tsnew file mode 100644index 0000000..1070d1d--- /dev/null+++ b/skills/anidoodle/engine/src/hosts/audio.ts@@ -0,0 +1,24 @@+import { Biquad } from '../canvas-core/music/dsp';+export type AudioPayload = { sampleRate: number; frames: number; float32: string };++/** Embedded Float32 is the complete Node mix, including cues. No decoder or fetch changes it. */+export const embeddedAudio = (a: AudioPayload) => {+ const bytes = atob(a.float32), data = new Uint8Array(bytes.length);+ for (let i = 0; i < data.length; i++) data[i] = bytes.charCodeAt(i);+ if (data.length !== a.frames * 8 || !Number.isSafeInteger(a.sampleRate) || a.sampleRate <= 0) throw new Error('invalid embedded film audio');+ const view = new DataView(data.buffer), L = new Float32Array(a.frames), R = new Float32Array(a.frames);+ for (let i = 0; i < a.frames; i++) { L[i] = view.getFloat32(i * 8, true); R[i] = view.getFloat32(i * 8 + 4, true); }+ const cache = new Map<number, [Float32Array, Float32Array]>([[a.sampleRate, [L, R]]]);+ return (sr: number): [Float32Array, Float32Array] => {+ if (!Number.isSafeInteger(sr) || sr <= 0) throw new Error('invalid film audio sample rate');+ const hit = cache.get(sr); if (hit) return hit;+ const resample = (c: Float32Array) => {+ const source = Float32Array.from(c);+ if (sr < a.sampleRate) for (const q of [0.5412, 1.3066]) Biquad.make(a.sampleRate, 'lp', sr * 0.45, q).run(source);+ const out = new Float32Array(Math.round(a.frames * sr / a.sampleRate));+ for (let i = 0; i < out.length; i++) { const x = i * a.sampleRate / sr, j = Math.floor(x), f = x - j; out[i] = (source[j] ?? 0) * (1 - f) + (source[Math.min(j + 1, source.length - 1)] ?? 0) * f; }+ return out;+ };+ const out: [Float32Array, Float32Array] = [resample(L), resample(R)]; cache.set(sr, out); return out;+ };+};diff --git a/skills/anidoodle/engine/src/hosts/page.ts b/skills/anidoodle/engine/src/hosts/page.tsindex d1422fb..eafcbcb 100644--- a/skills/anidoodle/engine/src/hosts/page.ts+++ b/skills/anidoodle/engine/src/hosts/page.ts@@ -3,8 +3,9 @@// Audio) lives HERE; the art core never sees it.import type { Ctx, Env, Layer, ProbeRec } from "../canvas-core/core";import { Film, renderFrame, validate } from "../canvas-core/film";+import { embeddedAudio, type AudioPayload } from './audio';-declare global { interface Window { FILM: unknown; __ASSETS__?: Record<string, string>; __BAKE_SRC__?: Record<string, string>; __ANIDOODLE_SRC__?: WeakMap<object, string>; __SHAPE__?: string } }+declare global { interface Window { FILM: unknown; __ASSETS__?: Record<string, string>; __BAKE_SRC__?: Record<string, string>; __ANIDOODLE_SRC__?: WeakMap<object, string>; __SHAPE__?: string; __AUDIO__?: AudioPayload } }// THE BAKE STORE (Env.bake). A finished plate frame, keyed by the hash of the source that draws it// (build-page.mjs hashes each film module's whole import closure, plus the engine's own renderer),@@ -34,6 +35,7 @@ const bakeStore = (surface: (w: number, h: number) => Layer) => {export const mountFilm = (film: Film) => {// <film>-<shape> (build-page.mjs sets __SHAPE__): the same film, re-composed for that frameif (window.__SHAPE__) { if (!film.reshape) throw new Error(`${film.meta.title} has one shape; ${window.__SHAPE__} is for launch template films (film.reshape)`); film = film.reshape(window.__SHAPE__); }+ const filmSound = window.__AUDIO__ ? embeddedAudio(window.__AUDIO__) : film.audio;const canvas = document.getElementById("film") as HTMLCanvasElement, images = new Map<string, CanvasImageSource>();let env: Env, ctx: Ctx, current = 0;// Safari before 16.4 has no 2D OffscreenCanvas: fall back to a detached <canvas>. The core cannot tell the difference.@@ -150,7 +152,7 @@ export const mountFilm = (film: Film) => {} finally { protos.forEach((p, i) => (p.fillText = orig[i] as never)); delete g.__ANIDOODLE_PROBE__; }return out;};- const audio = (sr: number) => { if (!film.audio) return null; const [L, R] = film.audio(sr); if (L.length !== R.length) throw new Error("audio channels have different lengths"); const pcm = new Float32Array(L.length * 2); for (let i = 0; i < L.length; i++) { pcm[i * 2] = L[i]; pcm[i * 2 + 1] = R[i]; } return { sampleRate: sr, frames: L.length, float32: b64(new Uint8Array(pcm.buffer)) }; };+ const audio = (sr: number) => { if (!filmSound) return null; const [L, R] = filmSound(sr); if (L.length !== R.length) throw new Error("audio channels have different lengths"); const pcm = new Float32Array(L.length * 2); for (let i = 0; i < L.length; i++) { pcm[i * 2] = L[i]; pcm[i * 2 + 1] = R[i]; } return { sampleRate: sr, frames: L.length, float32: b64(new Uint8Array(pcm.buffer)) }; };const warm = () => film.shots.forEach((s) => { seek(s.start); seek(s.start + ((s.end - s.start) >> 1)); }); // first + middle frame of every shot: builds tiles, pre-allocates the layer pool// POSTER. Platforms show frame 0 as the thumbnail, so a delivery may open on a chosen frame (the// wall of styles, the logo) and dissolve into the film's real opening over `fade` frames. The@@ -181,7 +183,7 @@ export const mountFilm = (film: Film) => {const stop = () => { playing = false; node?.stop(); node = null; };const play = () => {ac ??= new (window.AudioContext || (window as unknown as { webkitAudioContext: typeof AudioContext }).webkitAudioContext)(); playing = true; f0 = current >= film.meta.durationFrames - 1 ? 0 : current; t0 = ac.currentTime;- if (film.audio) { const [L, R] = film.audio(ac.sampleRate), buf = ac.createBuffer(2, L.length, ac.sampleRate); buf.getChannelData(0).set(L); buf.getChannelData(1).set(R); node = ac.createBufferSource(); node.buffer = buf; node.connect(ac.destination); node.start(0, f0 / film.meta.fps); }+ if (filmSound) { const sr = window.__AUDIO__?.sampleRate ?? ac.sampleRate, [L, R] = filmSound(sr), buf = ac.createBuffer(2, L.length, sr); buf.getChannelData(0).set(L); buf.getChannelData(1).set(R); node = ac.createBufferSource(); node.buffer = buf; node.connect(ac.destination); node.start(0, f0 / film.meta.fps); }const tick = () => { if (!playing) return; const f = f0 + Math.floor((ac!.currentTime - t0) * film.meta.fps); if (f >= film.meta.durationFrames) { seek(film.meta.durationFrames - 1); stop(); return; } if (f !== current) seek(f); requestAnimationFrame(tick); }; tick();};const toggle = () => (playing ? stop() : play());diff --git a/skills/anidoodle/engine/test/hostAudio.test.ts b/skills/anidoodle/engine/test/hostAudio.test.tsnew file mode 100644index 0000000..8b54044--- /dev/null+++ b/skills/anidoodle/engine/test/hostAudio.test.ts@@ -0,0 +1,12 @@+import { embeddedAudio } from '../src/hosts/audio';+export const name = 'embedded film track';+export const run = (ok: (cond: boolean, label: string) => void) => {+ const sr = 48000, n = sr / 10, bytes = new Uint8Array(n * 8), view = new DataView(bytes.buffer);+ for (let i = 0; i < n; i++) { view.setFloat32(i * 8, 1.4 * Math.sin(2 * Math.PI * 18000 * i / sr), true); view.setFloat32(i * 8 + 4, -0.25, true); }+ const audio = embeddedAudio({ sampleRate: sr, frames: n, float32: btoa(String.fromCharCode(...bytes)) }), [L, R] = audio(sr);+ ok(L.every((v, i) => v === view.getFloat32(i * 8, true)) && R.every(v => v === -0.25), 'embedded stereo keeps every Float32 sample, including unclipped values');+ const [down] = audio(24000), [up] = audio(96000), [device] = audio(44100);+ ok(down.length === n / 2 && up.length === n * 2 && device.length === 4410, 'alternate sample rates keep the complete track duration');+ ok(down.slice(100).reduce((e, x) => e + x * x, 0) / down.length < 0.01, 'downsampling removes tones above the new Nyquist frequency');+ ok(audio(sr)[0].every((v, i) => v === view.getFloat32(i * 8, true)), 'sample-rate conversion leaves the pinned 48 kHz master untouched');+};diff --git a/skills/anidoodle/engine/tools/adapters/hyperframes.mjs b/skills/anidoodle/engine/tools/adapters/hyperframes.mjsindex 27f2269..b648594 100644--- a/skills/anidoodle/engine/tools/adapters/hyperframes.mjs+++ b/skills/anidoodle/engine/tools/adapters/hyperframes.mjs@@ -33,6 +33,7 @@ import { mkdirSync, readFileSync } from "node:fs";import { join, resolve } from "node:path";import { pathToFileURL } from "node:url";import { buildPage } from "../build-page.mjs";+import { loadFilmModule, prepareFilmSounds, filmFloat32 } from '../audio.mjs';const require = createRequire(import.meta.url);const version = (id) => { try { return require(`${id}/package.json`).version; } catch { return null; } };@@ -87,6 +88,8 @@ export const open = async (film, opts = {}) => {mkdirSync(dir, { recursive: true });const out = join(dir, `${film}.html`);const built = await buildPage({ entry: `src/hosts/page-${film}.ts`, out, title: film });+ const source = await loadFilmModule(film);+ prepareFilmSounds(source.film, source.music);const { writeFileSync } = await import("node:fs");writeFileSync(out, readFileSync(out, "utf8").replace("</body>", `<script>${FRAME_ADAPTER(film)}</script></body>`));@@ -112,7 +115,7 @@ export const open = async (film, opts = {}) => {info: () => built.meta,frame: async (n, w = 0) => { const r = await grab(n, w); return { png: r.png, shot: null, drawMs: r.drawMs }; },hash: async (n, w = 0) => createHash("sha256").update((await grab(n, w)).png).digest("hex").slice(0, 16),- audio: async (sr) => { const s = pick(0); return s && engine.captureAudio ? engine.captureAudio(s, sr) : null; }, /* the engine mixes audio from <audio> elements; this film synthesizes its score in the page, so there is none to mix */+ audio: async (sr) => filmFloat32(source.film, sr),artifact: () => null,close: async () => { for (const s of sessions) await engine.closeCaptureSession(s); for (const l of leases) await l.release(); },};diff --git a/skills/anidoodle/engine/tools/adapters/remotion.mjs b/skills/anidoodle/engine/tools/adapters/remotion.mjsindex dc4b261..231e3ac 100644--- a/skills/anidoodle/engine/tools/adapters/remotion.mjs+++ b/skills/anidoodle/engine/tools/adapters/remotion.mjs@@ -13,7 +13,7 @@ import { createHash } from "node:crypto";import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";import { createRequire } from "node:module";import { join, resolve } from "node:path";-import { overlay } from "../overlay.mjs";+import { loadFilmModule, prepareFilmSounds, filmFloat32 } from '../audio.mjs';const require = createRequire(import.meta.url);const tryRequire = (id) => { try { return require(id); } catch { return null; } };@@ -35,17 +35,9 @@ export const probe = () => {// The film module is the source of truth for meta and for the score. It is read the way// build-page.mjs reads it: bundled on its own, with no host attached, so nothing can disagree.const loadFilm = async (film) => {- const { build } = await import("esbuild");- const out = (await build({ stdin: { contents: `export { ${film} as film } from "./src/canvas-core/${film}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral", plugins: [overlay] })).outputFiles[0].text;- return (await import("data:text/javascript;base64," + Buffer.from(out).toString("base64"))).film;-};--const float32 = (film, sr) => {- if (!film.audio) return null;- const [L, R] = film.audio(sr), pcm = new Float32Array(L.length * 2);- if (L.length !== R.length) throw new Error("audio channels have different lengths");- for (let i = 0; i < L.length; i++) { pcm[i * 2] = L[i]; pcm[i * 2 + 1] = R[i]; }- return { sampleRate: sr, frames: L.length, float32: Buffer.from(pcm.buffer).toString("base64") };+ const data = await loadFilmModule(film);+ prepareFilmSounds(data.film, data.music);+ return data.film;};// Bundling is per FILM, not per session: the gate opens an adapter many times in one process and@@ -111,7 +103,7 @@ export const open = async (film, opts = {}) => {// Hashed through the PNG the renderer wrote: that file IS what this backend produces, so// hashing anything else would be grading something the backend does not actually deliver.hash: async (n, w = 0) => createHash("sha256").update((await still(n, w)).png).digest("hex").slice(0, 16),- audio: async (sr) => float32(data, sr),+ audio: async (sr) => filmFloat32(data, sr),artifact: () => null, /* like playwright: a means to an MP4, not a deliverable of its own */close: async () => { for (const b of browsers) await b.close({ silent: true }); },};diff --git a/skills/anidoodle/engine/tools/audio.mjs b/skills/anidoodle/engine/tools/audio.mjsindex b6890db..1d78da2 100644--- a/skills/anidoodle/engine/tools/audio.mjs+++ b/skills/anidoodle/engine/tools/audio.mjs@@ -1,4 +1,40 @@// Interleaved stereo Float32 transport stays unclipped until the final AAC encoder.+import { build } from 'esbuild';+import { writeFileSync } from 'node:fs';+import { resolve } from 'node:path';+import { pathToFileURL } from 'node:url';+import { overlay } from './overlay.mjs';+import { splitShape, requireFilm } from './names.mjs';+import { loadBanks, soundIds, printSounds, codeBuiltNotice } from './sounds.mjs';+let filmModuleId = 0;++/** Film and music registry share one bundle, so its audio closure sees the loaded banks. */+export const loadFilmModule = async (title, plugins = [overlay]) => {+ const { base, shape } = splitShape(title);+ const js = (await build({ stdin: { contents: `export { ${base} as film } from "./src/canvas-core/${base}"; export * as music from "./src/canvas-core/music/index";`, resolveDir: process.cwd(), loader: 'ts' }, bundle: true, format: 'esm', write: false, platform: 'neutral', plugins })).outputFiles[0].text;+ const mod = await import('data:text/javascript;base64,' + Buffer.from(js).toString('base64') + `#film-${++filmModuleId}`);+ if (shape && !mod.film.reshape) throw new Error(`${base} has one shape; ${shape} needs film.reshape`);+ return { film: shape ? mod.film.reshape(shape) : mod.film, music: mod.music };+};+export const prepareFilmSounds = (film, M, pack = process.env.ANIDOODLE_SOUNDS) => {+ M.clearBanks(); M.clearRooms();+ if (!film.audio) return false;+ const scores = film.audio.scores ?? [];+ loadBanks(M, pack, [...new Set(scores.flatMap(soundIds))]);+ for (const p of scores) printSounds(M, p);+ const recorded = scores.some(p => !p.legacy && (p.parts.some(part => part.notes.length && part.opts?.sampled !== false && M.bankFor(part.inst, typeof part.opts?.variant === 'string' ? part.opts.variant : undefined)) ||+ [p.plan.space?.room ?? M.mixProfile(p.plan.style, p.mix).space?.room, M.mixProfile(p.plan.style, p.mix).drumRoom?.room].some(id => M.roomFor(id))));+ if (!recorded) codeBuiltNotice();+ return recorded;+};+export const filmFloat32 = (film, sampleRate = 48000) => {+ if (!film.audio) return null;+ const [L, R] = film.audio(sampleRate);+ if (L.length !== R.length) throw new Error('audio channels have different lengths');+ const pcm = Buffer.alloc(L.length * 8);+ for (let i = 0; i < L.length; i++) { pcm.writeFloatLE(L[i], i * 8); pcm.writeFloatLE(R[i], i * 8 + 4); }+ return { sampleRate, frames: L.length, float32: pcm.toString('base64') };+};export const float32Wav = ({ sampleRate, frames, float32 }) => {const pcm = Buffer.from(float32, "base64");if (!Number.isSafeInteger(sampleRate) || sampleRate < 1 || pcm.length !== frames * 8) throw new Error("invalid stereo Float32 audio payload");@@ -10,3 +46,13 @@ export const float32Wav = ({ sampleRate, frames, float32 }) => {h.write("data", 36); h.writeUInt32LE(pcm.length, 40);return Buffer.concat([h, pcm]);};+if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {+ const title = requireFilm(process.argv[2], 'audio', 'node tools/audio.mjs <film> <out.wav>');+ if (!process.argv[3]) throw new Error('audio needs an output WAV path');+ const { film, music } = await loadFilmModule(title);+ prepareFilmSounds(film, music);+ const audio = filmFloat32(film);+ if (!audio) throw new Error(`${title}: silent film`);+ writeFileSync(process.argv[3], float32Wav(audio));+ console.log(`audio: ${audio.frames} frames @ ${audio.sampleRate} Hz -> ${process.argv[3]}`);+}diff --git a/skills/anidoodle/engine/tools/build-page.mjs b/skills/anidoodle/engine/tools/build-page.mjsindex 106c404..15900ab 100644--- a/skills/anidoodle/engine/tools/build-page.mjs+++ b/skills/anidoodle/engine/tools/build-page.mjs@@ -6,6 +6,7 @@ import { createHash } from "node:crypto";import { extname, join, relative, resolve } from "node:path";import { overlay, resolveOverlay } from "./overlay.mjs";import { requireFilm, splitShape } from "./names.mjs";+import { loadFilmModule, prepareFilmSounds, filmFloat32 } from './audio.mjs';// BAKE KEYS (see Env.bake and hosts/page.ts). Every module that exports `const X: Film` is tagged// in the bundle with its own path, and each tagged module gets a hash of its WHOLE import closure@@ -48,20 +49,20 @@ export const buildPage = async ({ entry, out, title, plugins: extra = [] }) => {if (shape) { entry = entry.replace(`page-${title}.ts`, `page-${base}.ts`); title = base; }if (!existsSync(entry)) entry = resolveOverlay("./" + entry, process.cwd()) ?? entry; // e.g. the example's own host pageif (!existsSync(entry) && title) requireFilm(title, "build", "a film name: src/hosts/page-<film>.ts"); // a clear exit with the known films, not an esbuild trace- const main = await build({ entryPoints: [entry], bundle: true, format: "iife", target: "es2020", minify: true, write: false, legalComments: "none", metafile: true, plugins: [...plugins, tagFilms] });+ const main = await build({ absWorkingDir: process.cwd(), entryPoints: [resolve(entry)], bundle: true, format: "iife", target: "es2020", minify: true, write: false, legalComments: "none", metafile: true, plugins: [...plugins, tagFilms] });const js = main.outputFiles[0].text;// read the manifest out of the film module itself, so the page and the film can never disagree- const probe = (await build({ stdin: { contents: `export { ${title} as film } from "./src/canvas-core/${title}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral", plugins })).outputFiles[0].text;- const { film } = await import("data:text/javascript;base64," + Buffer.from(probe).toString("base64"));+ const { film, music } = await loadFilmModule(shape ? `${title}-${shape}` : title, plugins);+ const recorded = prepareFilmSounds(film, music), audio = recorded ? filmFloat32(film) : null;const assets = Object.fromEntries(Object.entries(film.assets.images).map(([name, file]) => { const mime = MIME[extname(file).toLowerCase()]; if (!mime) throw new Error(`asset '${name}': unsupported type ${file}`); return [name, `data:${mime};base64,${readFileSync(join(process.cwd(), file)).toString("base64")}`]; }));// the renderer that draws every plate frame, and the assets any plate may read, salt every keyconst salt = [BAKE_FORMAT, ...["src/canvas-core/film.ts", "src/canvas-core/core.ts"].map((f) => readFileSync(resolve(f), "utf8")), JSON.stringify(assets)].join("\0");const bakeSrc = bakeHashes(main.metafile, salt);const html = `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${film.meta.title}</title><style>html,body{margin:0;height:100%;background:#1b1a1a;display:grid;place-items:center}canvas{max-width:100vw;max-height:100vh;aspect-ratio:${film.meta.W}/${film.meta.H};cursor:pointer;background:#fff}</style></head>-<body><canvas id="film"></canvas><script>window.__ASSETS__=${JSON.stringify(assets)};window.__BAKE_SRC__=${JSON.stringify(bakeSrc)};${shape ? `window.__SHAPE__=${JSON.stringify(shape)};` : ""}</script><script>${js.replace(/<\/script/g, "<\\/script")}</script></body></html>`;+<body><canvas id="film"></canvas><script>window.__ASSETS__=${JSON.stringify(assets)};window.__BAKE_SRC__=${JSON.stringify(bakeSrc)};${audio ? `window.__AUDIO__=${JSON.stringify(audio)};` : ''}${shape ? `window.__SHAPE__=${JSON.stringify(shape)};` : ""}</script><script>${js.replace(/<\/script/g, "<\\/script")}</script></body></html>`;mkdirSync(join(out, ".."), { recursive: true }); writeFileSync(out, html);- const meta = shape ? (film.reshape ? film.reshape(shape).meta : (() => { throw new Error(`${base} has one shape (it has no reshape); ${shape} is for launch template films`); })()) : film.meta;+ const meta = film.meta;return { out, bytes: html.length, meta, assets: Object.keys(film.assets.images) };};if (import.meta.url === `file://${process.argv[1]}`) { const title = requireFilm(process.argv[2], "build-page", "node tools/build-page.mjs <film>"); const r = await buildPage({ entry: `src/hosts/page-${title}.ts`, out: `dist/${title}.html`, title }); console.log(`built ${r.out} (${(r.bytes / 1024).toFixed(0)} KB, self-contained)`); }diff --git a/skills/anidoodle/engine/tools/emit.mjs b/skills/anidoodle/engine/tools/emit.mjsindex b8aa7c6..8cdc9a0 100644--- a/skills/anidoodle/engine/tools/emit.mjs+++ b/skills/anidoodle/engine/tools/emit.mjs@@ -88,7 +88,7 @@ say(bad.length === 0, `${frames.length} frames across the film hash the same asconst sr = 48000;const [aShip, aGold] = [await shipped.page.evaluate((s) => window.FILM.audio(s), sr), await golden.page.evaluate((s) => window.FILM.audio(s), sr)];const sameAudio = !aShip && !aGold || aShip && aGold && aShip.frames === aGold.frames && aShip.sampleRate === aGold.sampleRate && aShip.float32 === aGold.float32;-say(!!sameAudio, "the page synthesizes the same score, in the page", sameAudio ? (aShip ? `${aShip.frames} samples @ ${aShip.sampleRate} Hz` : "silent film") : "audio missing or different");+say(!!sameAudio, "the emitted page plays the same complete audio track", sameAudio ? (aShip ? `${aShip.frames} samples @ ${aShip.sampleRate} Hz` : "silent film") : "audio missing or different");await browser.close();console.log(`\n${"=".repeat(58)}\nEMIT: ${fails ? `FAIL ${fails} of ${checks} checks failed` : `PASS ${checks}/${checks} checks`} ${out}`);diff --git a/skills/anidoodle/engine/tools/music.mjs b/skills/anidoodle/engine/tools/music.mjsindex 552facc..bf616d2 100644--- a/skills/anidoodle/engine/tools/music.mjs+++ b/skills/anidoodle/engine/tools/music.mjs@@ -32,7 +32,7 @@ import { dirname, join, resolve, basename } from "node:path";import { fileURLToPath } from "node:url";import { Worker } from "node:worker_threads";import { availableParallelism } from "node:os";-import { loadBanks, soundIds, printSounds } from "./sounds.mjs";+import { loadBanks, soundIds, printSounds, codeBuiltNotice } from "./sounds.mjs";const here = dirname(fileURLToPath(import.meta.url));const SR = 48000;@@ -40,7 +40,8 @@ let ENGINE_URL = "";let SOUNDS_DIR;let ROOM_ID;const SOUNDS_URL = new URL("./sounds.mjs", import.meta.url).href;-const loadSounds = (M, piece) => loadBanks(M, SOUNDS_DIR, soundIds(piece));+let noticed = false;+const loadSounds = (M, piece) => { loadBanks(M, SOUNDS_DIR, soundIds(piece)); if (!SOUNDS_DIR && !noticed) { codeBuiltNotice(); noticed = true; } };const load = async () => {const r = await build({ entryPoints: [join(here, "../src/canvas-core/music/index.ts")], bundle: true, write: false, format: "esm", platform: "neutral", target: "es2022", logLevel: "error" });ENGINE_URL = "data:text/javascript;base64," + Buffer.from(r.outputFiles[0].text).toString("base64");diff --git a/skills/anidoodle/engine/tools/render.mjs b/skills/anidoodle/engine/tools/render.mjsindex ebbdf63..0a97fa2 100644--- a/skills/anidoodle/engine/tools/render.mjs+++ b/skills/anidoodle/engine/tools/render.mjs@@ -95,7 +95,8 @@ console.log(`film: "${meta.title}" ${meta.W}x${meta.H} @ ${meta.fps} fps, ${N} fif (BLURRED) console.log(`motion blur: ${BLUR === "auto" ? `adaptive (subframes <= ${BPX} px apart, max ${BMAX})` : `${BLUR} subframes per frame`}, ${SHUTTER}-degree shutter, linear light`);if (ranged) console.log(`range render: frames [${FROM}, ${TO}) of ${N}, silent by design`);-// audio: pure JS in the page -> WAV here (skipped for a range render: the score would not line up)+// audio: the page returns its embedded recorded track or its code-built mix -> WAV here+// (skipped for a range render: the score would not line up).mkdirSync(resolve(".tmp"), { recursive: true }); const wav = resolve(`.tmp/${film}.wav`), a = ranged ? null : await session.audio(48000);if (a) writeFileSync(wav, float32Wav(a));if (a) { // the audio report: loudness and true peak, and the score's fit against the picture's griddiff --git a/skills/anidoodle/engine/tools/sounds.mjs b/skills/anidoodle/engine/tools/sounds.mjsindex 4191b9d..8b50676 100644--- a/skills/anidoodle/engine/tools/sounds.mjs+++ b/skills/anidoodle/engine/tools/sounds.mjs@@ -50,3 +50,4 @@ export const printSounds = (M, piece) => {}console.log(`voices recordings: ${recorded.join(", ") || "none"}; modeled: ${modeled.join(", ") || "none"}`);};+export const codeBuiltNotice = () => console.log('audio: using code-built instruments; download the optional anidoodle sound pack and set ANIDOODLE_SOUNDS=<pack-dir> to use recordings');