mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-06 08:46:06 -10:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a17f745d49 | ||
|
|
be812fc7ba | ||
|
|
2f1e10076a | ||
|
|
1d51c09c0b |
No files matched your search
@@ -219,7 +219,7 @@ pub(crate) fn contrast(video: &str, runs: &[Run], w: f64, h: f64, probe: &Probe,
|
||||
measured += 1;
|
||||
if ratio < 3.0 {
|
||||
low += 1;
|
||||
issues.push(Issue { rule: "contrast", p: 1, at: Some(t), says: format!("{} is {ratio:.1}:1 against what's behind it; make it at least 3:1 (a band, a shadow for separation, or another colour)", quote(&r.text)) });
|
||||
issues.push(Issue { rule: "contrast", p: 1, at: Some(t), says: format!("{} is {:.2}:1 against what's behind it; make it at least 3:1 (a band, a shadow for separation, or another colour)", quote(&r.text), (ratio * 100.0).floor() / 100.0) });
|
||||
}
|
||||
}
|
||||
if measured > 0 && low == 0 {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// pace.ts on made-up words and levels: a short run between two long pauses joins a neighbour; level evening measures
|
||||
// only clips with a second of speech and gives a short clip its own take's gain
|
||||
import { expect, test } from "bun:test";
|
||||
import { evenLevels, pace, type Levels } from "../src/pace";
|
||||
import { evenLevels, linesIn, pace, unsqueezed, type Levels } from "../src/pace";
|
||||
|
||||
/** levels at 10 ms: speech (-20 dB) inside each word, quiet (-70 dB) elsewhere, over `seconds` */
|
||||
function levels(ws: { from: number; to: number }[], seconds: number): Levels {
|
||||
@@ -66,3 +66,15 @@ test("a line stopping mid-sentence with no pause runs on to its sentence's end;
|
||||
const r = pace(long, l2, [[0, 2]], { hook: 0 });
|
||||
expect(r.pieces[0].to).toBeLessThanOrEqual(1.06 + 1 / 30);
|
||||
});
|
||||
|
||||
test("a phrase a transcriber heard twice and squeezed into one instant is dropped, and the line is found where it was said", () => {
|
||||
// 12-05, run 28: "Sign up for the news, sign up for the newsletter", with "up for the news sign" all at 10.32-10.34 s
|
||||
const w = (text: string, a: number, b: number) => ({ text, from: a / 1000, to: b / 1000 });
|
||||
const heard = [w("for", 9280, 9360), w("the", 9360, 9440), w("newsletter.", 9440, 9460), w("Sign", 10080, 10320), w("up", 10320, 10340), w("for", 10320, 10340), w("the", 10320, 10340), w("news", 10320, 10340), w("sign", 10320, 10340), w("up", 10320, 10400), w("for", 10400, 10560), w("the", 10560, 10640), w("newsletter", 10640, 10960)];
|
||||
const ws = unsqueezed(heard);
|
||||
expect(ws.map((x) => x.text).join(" ")).toBe("for the newsletter. Sign up for the newsletter");
|
||||
const { spans } = linesIn(ws, ["sign up for the newsletter"]);
|
||||
expect(ws[spans[0][0]].from).toBe(10.08);
|
||||
// two short words together are speech, kept
|
||||
expect(unsqueezed([w("a", 0, 20), w("cat", 20, 40), w("sat", 300, 500)]).length).toBe(3);
|
||||
});
|
||||
@@ -255,6 +255,44 @@ ${Array.from({ length: 40 }, (_, i) => `.u${i} { margin: ${i}px; }`).join("\n")}
|
||||
}
|
||||
});
|
||||
|
||||
// a take's jump cuts read through the ffmpeg CLI (cutplan.ts ffmpegCuts): where raea media cuts finds them
|
||||
test.skipIf(spawnSync("ffmpeg", ["-version"]).status !== 0)("raea cut reads a take's jump cuts through ffmpeg, where the engine finds them", async () => {
|
||||
const { ffmpegCuts } = await import("../src/cutplan.ts");
|
||||
const dir = mkdtempSync(join(tmpdir(), "raea-ffcuts-"));
|
||||
try {
|
||||
const color = (c: string) => ["-f", "lavfi", "-i", `color=c=${c}:s=320x180:r=30:d=2`];
|
||||
spawnSync("ffmpeg", ["-v", "error", "-y", ...color("red"), ...color("blue"), ...color("green"), "-filter_complex", "[0][1][2]concat=n=3:v=1:a=0", "-c:v", "libx264", "-pix_fmt", "yuv420p", join(dir, "t.mp4")]);
|
||||
expect(ffmpegCuts(join(dir, "t.mp4"), 0.08)).toEqual([2, 4]);
|
||||
expect(ffmpegCuts(join(dir, "missing.mp4"), 0.08)).toBeNull();
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
// raea cloud's footage/faces.json (prep's faces, found on its farm): perception.json takes each clip's face from it,
|
||||
// with no still and no raea-perceive (a box has none). A made clip and made-up faces, never real footage
|
||||
test.skipIf(spawnSync("ffmpeg", ["-version"]).status !== 0)("raea cut takes each clip's face from footage/faces.json", () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "raea-cut-faces-"));
|
||||
const run = (...a: string[]) => spawnSync("bun", [join(here, "src/native.ts"), bin, ...a], { cwd: dir, encoding: "utf8", env: { ...process.env, RAEA_PERCEIVE: "/nonexistent/raea-perceive" } });
|
||||
try {
|
||||
mkdirSync(join(dir, "media"));
|
||||
mkdirSync(join(dir, "footage"));
|
||||
spawnSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "color=c=gray:s=160x120:r=30:d=4", "-c:v", "libx264", "-pix_fmt", "yuv420p", join(dir, "media/take01.mp4")]);
|
||||
const said: [string, number, number][] = [["Hello", 200, 600], ["there.", 650, 1000], ["This", 1500, 1700], ["is", 1750, 1850], ["the", 1900, 2000], ["second", 2100, 2500], ["line.", 2550, 2900]];
|
||||
writeFileSync(join(dir, "media/take01.words.json"), JSON.stringify(said.map(([text, start_ms, end_ms]) => ({ text, start_ms, end_ms }))));
|
||||
// no face by the first clip's middle (0.6 s, nearest 1 s); two at 2 s, by the second's (2.4 s): the larger is kept
|
||||
const face = [0.25, 0.25, 0.5, 0.5, 0.9];
|
||||
writeFileSync(join(dir, "footage/faces.json"), JSON.stringify({ take01: { w: 160, h: 120, t: [0, 1, 2, 3], s: [[], [], [[0.1, 0.1, 0.1, 0.1, 0.99], face], [face]] } }));
|
||||
const r = run("cut", "take01", "hello there", "the second line");
|
||||
expect(r.stderr).toBe("");
|
||||
const band = { safe: { top: 220, bottom: 1500 } };
|
||||
// 160x120 covering 1080x1920 is 16x, centred: x 0.25*160*16 - 740, y 0.25*120*16, w 0.5*160*16, h 0.5*120*16
|
||||
expect(JSON.parse(readFileSync(join(dir, "perception.json"), "utf8"))).toEqual({ "0": band, "33": { ...band, face: { x: -100, y: 480, w: 1280, h: 960 } } });
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
// a stock talking take (fixtures/CREDITS.md): the face branch of frame and perception.json. The footage fixtures are
|
||||
// the maintainers' (tools/public-first/private.paths), so a checkout without them skips this
|
||||
test.skipIf(!existsSync(join(raea, "engine/media/fixtures")))("raea frame and raea cut find the face in a talking take", () => {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// How raea cut times a take's lines: the take's light copy when raea cloud keeps one, its jump cuts (kept in raea's
|
||||
// cache) and sound level, and pace.ts's timing, kept off the take's own jump cuts. native.ts gives it the engine.
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
||||
import { homedir, tmpdir } from "node:os";
|
||||
@@ -11,6 +12,35 @@ export type TakeIO = { at: (p: string) => string; engineRun: (a: string[]) => st
|
||||
|
||||
const ms = (s: number) => Math.round(s * 1000) / 1000;
|
||||
|
||||
/** A take's jump cuts read through the ffmpeg CLI where there is one: its luma at 160x90, every frame, scored as raea
|
||||
* media cuts scores them (ffmpeg's select scene: each frame's mean absolute difference from the last, less the
|
||||
* difference before it, over 100). ffmpeg decodes on every core; the engine's own decoder on a Linux box is openh264 on
|
||||
* one (12-05: 38 s for a 3.5-minute light copy, 66 s for a 6-minute one, against 4 s for ffmpeg), and a box step has
|
||||
* 3 minutes. The small picture leaves a hard cut's score where it was and a frame's grain out. null where ffmpeg
|
||||
* can't read it: the engine reads it then. */
|
||||
export function ffmpegCuts(file: string, threshold: number): number[] | null {
|
||||
const [w, h] = [160, 90];
|
||||
const r = spawnSync("ffmpeg", ["-v", "info", "-nostats", "-i", file, "-an", "-vf", `scale=${w}:${h}:flags=area,format=gray,showinfo`, "-f", "rawvideo", "-"], { maxBuffer: 1 << 30 });
|
||||
if (r.error || r.status !== 0 || !r.stdout?.length) return null;
|
||||
// each frame's time, from showinfo's lines in order
|
||||
const times = [...String(r.stderr).matchAll(/\bn:\s*\d+\s+pts:\s*-?\d+\s+pts_time:(-?[\d.]+)/g)].map((m) => Number(m[1]));
|
||||
const n = w * h;
|
||||
const frames = Math.floor(r.stdout.length / n);
|
||||
if (!frames || times.length !== frames) return null;
|
||||
const y = r.stdout as Buffer;
|
||||
const out: number[] = [];
|
||||
let prev = 0;
|
||||
for (let f = 1; f < frames; f++) {
|
||||
let sad = 0;
|
||||
for (let i = f * n, j = (f - 1) * n, e = i + n; i < e; i++, j++) sad += Math.abs(y[i] - y[j]);
|
||||
const mafd = sad / n;
|
||||
const score = Math.min(Math.max(Math.min(mafd, Math.abs(mafd - prev)) / 100, 0), 1);
|
||||
prev = mafd;
|
||||
if (score > threshold) out.push(ms(times[f]));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** cutPlan and takeLevels over `io`, each take's levels kept for the run */
|
||||
export function timing({ at, engineRun, engineJson, isAudio }: TakeIO) {
|
||||
/** The take to read for timing: its light copy when raea cloud keeps one (.raea-cloud/proxies/NAME.mp4 in the project,
|
||||
@@ -37,7 +67,7 @@ export function timing({ at, engineRun, engineJson, isAudio }: TakeIO) {
|
||||
} catch {
|
||||
kept = "";
|
||||
}
|
||||
const cuts = (engineJson(["media", "cuts", file, "--threshold", "0.08"]).cuts as { at: number }[]).map((c) => c.at);
|
||||
const cuts = ffmpegCuts(file, 0.08) ?? (engineJson(["media", "cuts", file, "--threshold", "0.08"]).cuts as { at: number }[]).map((c) => c.at);
|
||||
if (kept)
|
||||
try {
|
||||
mkdirSync(dirname(kept), { recursive: true });
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// A take's faces from raea cloud's footage/faces.json, for raea cut's perception.json (native.ts perception)
|
||||
import { readFileSync } from "node:fs";
|
||||
import { basename, extname } from "node:path";
|
||||
|
||||
type Box = { x: number; y: number; w: number; h: number };
|
||||
|
||||
/** footage/faces.json in the project (raea cloud's prep: each take's faces about once a second, found on its farm, as
|
||||
* shares of the take's picture, [x, y, w, h, score] each), read once. A box has no raea-perceive, so a still per clip
|
||||
* found no face there and cost each `raea cut --append` every earlier clip's lookup again (12-05: a step of 13 cuts ran
|
||||
* past a box's 3 minutes, and no cut on a box had a face in its perception.json) */
|
||||
let facesKept: Record<string, { w?: number; h?: number; t?: number[]; s?: number[][][] }> | null | undefined;
|
||||
function facesFile() {
|
||||
if (facesKept === undefined)
|
||||
try {
|
||||
facesKept = JSON.parse(readFileSync(`${process.cwd()}/footage/faces.json`, "utf8"));
|
||||
} catch {
|
||||
facesKept = null;
|
||||
}
|
||||
return facesKept;
|
||||
}
|
||||
|
||||
/** The largest face at the sample of faces.json nearest `t` (never one more than 1.5 s away), with the take's size: a
|
||||
* face, none there (face undefined), or null when faces.json doesn't hold the take */
|
||||
export function faceKept(file: string, t: number): { face?: Box; sw: number; sh: number } | null {
|
||||
const take = facesFile()?.[basename(file, extname(file))];
|
||||
const ts = take?.t, ss = take?.s;
|
||||
if (!take || !Array.isArray(ts) || !Array.isArray(ss) || !ts.length || !take.w || !take.h) return null;
|
||||
let k = 0;
|
||||
ts.forEach((x, i) => {
|
||||
if (Math.abs(x - t) < Math.abs(ts[k] - t)) k = i;
|
||||
});
|
||||
if (Math.abs(ts[k] - t) > 1.5) return null;
|
||||
const faces = (ss[k] ?? []).filter((f) => Array.isArray(f) && f.length >= 4);
|
||||
if (!faces.length) return { sw: take.w, sh: take.h };
|
||||
const [x, y, w, h] = faces.reduce((a, b) => (b[2] * b[3] > a[2] * a[3] ? b : a));
|
||||
return { face: { x, y, w, h }, sw: take.w, sh: take.h };
|
||||
}
|
||||
@@ -10,8 +10,9 @@ import { basename, delimiter, dirname, extname } from "node:path";
|
||||
import { brandKit, pixelsOf } from "./brand";
|
||||
import { readSite, stylesOf } from "./scrape";
|
||||
import { wordsOf } from "./heard";
|
||||
import { evenLevels, markJumps, speechOf, toSound, type PaceOptions } from "./pace";
|
||||
import { evenLevels, unsqueezed, linesIn, markJumps, speechOf, toSound, type PaceOptions } from "./pace";
|
||||
import { timing } from "./cutplan";
|
||||
import { faceKept } from "./faces";
|
||||
import { harness, library, show, task } from "./app";
|
||||
import { fromCwd } from "./show";
|
||||
import { clothesHost } from "./wardrobe";
|
||||
@@ -90,9 +91,11 @@ function words(take: string, hear = false): Word[] {
|
||||
if (!hear) return [];
|
||||
hearTake(take, file);
|
||||
}
|
||||
return (JSON.parse(readFileSync(file, "utf8")) as { text: string; start_ms: number; end_ms: number }[])
|
||||
.filter((w) => w.text?.trim())
|
||||
.map((w) => ({ text: w.text.trim(), from: w.start_ms / 1000, to: w.end_ms / 1000 }));
|
||||
return unsqueezed(
|
||||
(JSON.parse(readFileSync(file, "utf8")) as { text: string; start_ms: number; end_ms: number }[])
|
||||
.filter((w) => w.text?.trim())
|
||||
.map((w) => ({ text: w.text.trim(), from: w.start_ms / 1000, to: w.end_ms / 1000 })),
|
||||
);
|
||||
}
|
||||
|
||||
/** A tool a clean Mac lacks, found or installed once by raea's tools/ensure.sh (docs/app.feature AP6), which sits in
|
||||
@@ -275,8 +278,10 @@ function perception(edit: { width: number; height: number; fps: number }, clips:
|
||||
if (!seen.has(key)) {
|
||||
let face: Box | undefined;
|
||||
try {
|
||||
const f = faceAt(c.file, mid);
|
||||
const { sw, sh } = probeOf(c.file);
|
||||
// faces.json's when it holds the take, else a still of it read here
|
||||
const kept = faceKept(c.file, mid);
|
||||
const f = kept ? kept.face : faceAt(c.file, mid);
|
||||
const { sw, sh } = kept ?? probeOf(c.file);
|
||||
if (f && sw && sh) {
|
||||
const s = Math.max(edit.width / sw, edit.height / sh);
|
||||
const [ox, oy] = [(edit.width - sw * s) / 2, (edit.height - sh * s) / 2];
|
||||
|
||||
@@ -18,6 +18,23 @@
|
||||
|
||||
/** a word in its take's seconds */
|
||||
export type Word = { text: string; from: number; to: number };
|
||||
|
||||
/** A transcript's words less the runs it squeezed: three or more words each SQUEEZED s long or less, all starting within
|
||||
* 50 ms of the first. No one says three words in 50 ms; a transcriber writes them when it hears a phrase twice and
|
||||
* times the copy at one instant (12-05, run 28: Body Shop's "Sign up for the news, sign up for the newsletter" came
|
||||
* as "Sign up for the news sign up for the newsletter" with "up for the news sign" all at 10.32-10.34 s, raea cut took
|
||||
* the line from that "sign", and the CTA clip started inside "up") */
|
||||
export const SQUEEZED = 0.03;
|
||||
export function unsqueezed<W extends Word>(ws: W[]): W[] {
|
||||
const out: W[] = [];
|
||||
for (let i = 0; i < ws.length; ) {
|
||||
let j = i;
|
||||
while (j < ws.length && ws[j].to - ws[j].from <= SQUEEZED && ws[j].from - ws[i].from <= 0.05) j++;
|
||||
if (j - i >= 3) i = j;
|
||||
else out.push(ws[i++]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
/** a take's sound level every 10 ms (dB), from `start` seconds */
|
||||
export type Levels = { start: number; db: number[] };
|
||||
/** a stretch of quiet in a take: from its first quiet 10 ms to the first sound after it (s) */
|
||||
|
||||
@@ -226,7 +226,7 @@ const HOOK_S = 5
|
||||
* had none, read from its brief's "captions OR a text hook"): a cut with talking and no captions at all is an error,
|
||||
* and so is a stretch of talking with none up. A text hook may be on screen beside them; it doesn't stand in for them.
|
||||
* A brief that wants no captions says so, and the render says it with --despite captions WHY */
|
||||
export function uncaptioned(shown: Shown[], heard: Word[], textUp: (t: number) => boolean = () => false): Finding[] {
|
||||
export function uncaptioned(shown: Shown[], heard: Word[], textUp: (t: number) => boolean = () => false, onCard: (w: Word) => boolean = () => false): Finding[] {
|
||||
heard = asDigits(heard)
|
||||
// a brief's "captions OR a text hook, never both" means not both in one frame (12-03, Shane): the hook may hold the
|
||||
// opening alone, so words in the first HOOK_S with other text up are covered by it; anywhere later it's no caption
|
||||
@@ -237,7 +237,9 @@ export function uncaptioned(shown: Shown[], heard: Word[], textUp: (t: number) =
|
||||
if (said.length < BARE.error.words) return []
|
||||
const fix = "caption every line from the words file (whole phrases in the brand's caption style); a text hook goes with the captions, never instead of them. If the brief asks for no captions, render with --despite captions WHY"
|
||||
if (!shown.length) return [{ level: "error", kind: "uncaptioned", at: said[0].start, says: `no captions over the talking: ${said.length} words, ${(said[said.length - 1].end - said[0].start).toFixed(1)} s, and no caption track (captions one after another under ${Math.round(TRACK * 100)}% of what's said, or fewer than ${CARDS} of them). ${fix}` }]
|
||||
const up = (w: Word) => shown.some((s) => w.end >= s.from - 0.6 && w.start <= s.to + 0.3)
|
||||
// a word is up when a caption is, or when text the render drew says it there (an end card with the line being said:
|
||||
// captionsOf takes a frame full of text for a card, not captions; 12-05, run 28's Elfster end cards)
|
||||
const up = (w: Word) => shown.some((s) => w.end >= s.from - 0.6 && w.start <= s.to + 0.3) || onCard(w)
|
||||
const out: Finding[] = []
|
||||
for (let i = 0; i < said.length; ) {
|
||||
if (up(said[i])) { i++; continue }
|
||||
@@ -310,6 +312,13 @@ export default check<FileFacts>(
|
||||
const rate = own ? own.rate : sc!.rate || 2
|
||||
const shown = captionsOf(frames, rate, heard)
|
||||
const textUp = (t: number) => (frames[Math.round(t * rate)]?.lines ?? []).some(([, , , , text, score]) => score >= LEAST && letters(text).length >= 4)
|
||||
for (const x of [...uncaptioned(shown, heard, textUp), ...compare(shown, heard, own ? await placedWords(f) : [])].sort((a, b) => a.at - b.at)) found({ level: x.level, says: x.says, seconds: x.at })
|
||||
// only the render's own texts say a word on screen: the footage's own (a sign, a phone) never caption anything
|
||||
const onCard = (w: Word) => {
|
||||
if (!own) return false
|
||||
const k = letters(w.text)
|
||||
const at = (t: number) => letters((frames[Math.round(t * rate)]?.lines ?? []).map((l) => l[4]).join(" "))
|
||||
return k.length > 0 && [w.start, (w.start + w.end) / 2, w.end].some((t) => at(t).includes(k))
|
||||
}
|
||||
for (const x of [...uncaptioned(shown, heard, textUp, onCard), ...compare(shown, heard, own ? await placedWords(f) : [])].sort((a, b) => a.at - b.at)) found({ level: x.level, says: x.says, seconds: x.at })
|
||||
},
|
||||
)
|
||||
@@ -6,7 +6,9 @@
|
||||
// (no one reads it on a phone), under 48 px a warning.
|
||||
// faces: frames two a second through the scene reader (raea cloud's farm). A face of a person in the shot (5% of the
|
||||
// frame's height or more) touching an edge or a split screen's seam: a second or more is an error, shorter a
|
||||
// warning. A split screen with a face in one half only is a warning.
|
||||
// warning. The reader takes a hand or a bag at the edge for a face now and then (12-05, run 28: Elfster's "face cut by
|
||||
// the left edge" was a hand at 0.79 then 0.65, where the people in the shot read 0.92 and over), so a run it's less
|
||||
// than FACE_SURE sure of is a warning, never an error. A split screen with a face in one half only is a warning.
|
||||
// A face at the edge that's meant (someone walking out of shot) is said, with its reason, in OUT.despite.txt beside
|
||||
// the video: its findings are then warnings.
|
||||
import { existsSync, readFileSync } from "node:fs"
|
||||
@@ -17,6 +19,9 @@ import { quote } from "../text.ts"
|
||||
|
||||
/** a face this share of the frame's height or more is someone in the shot, not a passer-by far behind */
|
||||
export const FACE_MIN = 0.05
|
||||
/** a cut face is an error only when the reader is this sure, over its run, that it's a face (a face's score; 1 when the
|
||||
* reader gives none) */
|
||||
export const FACE_SURE = 0.8
|
||||
/** least font sizes, in pixels of a frame 1080 wide (its shorter side): the Direct Response skill's table */
|
||||
export const TEXT_ERROR = 40
|
||||
export const TEXT_WARN = 48
|
||||
@@ -43,17 +48,21 @@ export function splitsOf(fr: NonNullable<Faces>): Split[] {
|
||||
const near = (a: Split, b: Split) => a.axis === b.axis && Math.abs(a.at - b.at) <= 6
|
||||
const big = (fr: NonNullable<Faces>) => fr.faces.filter((f) => f[3] >= fr.h * FACE_MIN)
|
||||
|
||||
/** what cuts a face in a frame: an edge of the frame, or a split screen's seam */
|
||||
function cutBy(fr: NonNullable<Faces>, splits: Split[]): string | null {
|
||||
for (const [x, y, fw, fh] of big(fr)) {
|
||||
if (x <= 1) return "the left edge"
|
||||
if (x + fw >= fr.w - 1) return "the right edge"
|
||||
if (y <= 1) return "the top edge"
|
||||
if (y + fh >= fr.h - 1) return "the bottom edge"
|
||||
for (const sp of splits) {
|
||||
const [a, b] = sp.axis === "h" ? [y, y + fh] : [x, x + fw]
|
||||
if ((a < sp.at - 2 && b > sp.at + 2) || Math.abs(b - sp.at) <= 3 || Math.abs(a - sp.at) <= 3) return "the split screen's seam"
|
||||
}
|
||||
/** what cuts a face in a frame (an edge of the frame, or a split screen's seam), with how sure the reader is it's a face */
|
||||
function cutBy(fr: NonNullable<Faces>, splits: Split[]): { by: string; score: number } | null {
|
||||
for (const [x, y, fw, fh, s] of big(fr)) {
|
||||
const score = Number.isFinite(s) ? s : 1
|
||||
const by =
|
||||
x <= 1 ? "the left edge"
|
||||
: x + fw >= fr.w - 1 ? "the right edge"
|
||||
: y <= 1 ? "the top edge"
|
||||
: y + fh >= fr.h - 1 ? "the bottom edge"
|
||||
: splits.some((sp) => {
|
||||
const [a, b] = sp.axis === "h" ? [y, y + fh] : [x, x + fw]
|
||||
return (a < sp.at - 2 && b > sp.at + 2) || Math.abs(b - sp.at) <= 3 || Math.abs(a - sp.at) <= 3
|
||||
}) ? "the split screen's seam"
|
||||
: null
|
||||
if (by) return { by, score }
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -83,10 +92,12 @@ export function cutFaces(frames: Faces[], rate = RATE): Finding[] {
|
||||
const held = raw.map((ss, i) => ss.filter((s) => (raw[i - 1] ?? []).some((o) => near(s, o)) || (raw[i + 1] ?? []).some((o) => near(s, o))))
|
||||
const out: Finding[] = []
|
||||
const hits = frames.map((fr, i) => (fr ? cutBy(fr, held[i]) : null))
|
||||
for (const [i, j, by] of runs(hits)) {
|
||||
for (const [i, j, { by }] of runs(hits, (a, b) => a.by === b.by)) {
|
||||
const from = i / rate
|
||||
const to = j / rate
|
||||
out.push({ level: to - from >= 1 ? "error" : "warn", kind: "face-cut", at: from, until: to, says: `a face is cut by ${by} from ${from.toFixed(1)} s to ${to.toFixed(1)} s: reframe on the person (both eyes, mouth and chin inside the picture)${by.includes("seam") ? ", or cut between two singles" : " or cut away"}` })
|
||||
const sure = hits.slice(i, j).reduce((n, h) => n + (h?.score ?? 0), 0) / (j - i)
|
||||
const doubt = sure < FACE_SURE ? ` (the reader is ${Math.round(sure * 100)}% sure it's a face: look)` : ""
|
||||
out.push({ level: to - from >= 1 && !doubt ? "error" : "warn", kind: "face-cut", at: from, until: to, says: `a face${doubt} is cut by ${by} from ${from.toFixed(1)} s to ${to.toFixed(1)} s: reframe on the person (both eyes, mouth and chin inside the picture)${by.includes("seam") ? ", or cut between two singles" : " or cut away"}` })
|
||||
}
|
||||
const split = held.map((ss) => ss[0] ?? null)
|
||||
for (const [i, j, sp] of runs(split, near)) {
|
||||
|
||||
@@ -36,6 +36,8 @@ const SUBJECT_MIN = 0.25
|
||||
const FACE_IN_SHOT = 0.05
|
||||
/** a thing this share of the frame's area or more is what the shot shows (a dog at someone's feet, a phone held up) */
|
||||
const THING_MIN = 0.006
|
||||
/** words in the shot are hidden (text over them an error) when a text covers this share of them or more */
|
||||
export const SIGN_HIDDEN = 0.3
|
||||
/** a text is badly placed when it costs this much or more, and a clear place costs this much less */
|
||||
export const BAD = 1.6
|
||||
export const BETTER = 1.2
|
||||
@@ -123,7 +125,11 @@ function thingsUnder(s: NonNullable<Scene>, b: Box, ours: Box[] = []): string[]
|
||||
const [x, y, w, h] = [t[0] / s.w, t[1] / s.h, t[2] / s.w, t[3] / s.h]
|
||||
const ix = Math.max(0, Math.min(b[0] + b[2], x + w) - Math.max(b[0], x))
|
||||
const iy = Math.max(0, Math.min(b[1] + b[3], y + h) - Math.max(b[1], y))
|
||||
if (ix * iy > 0.12 * Math.min(w * h, b[2] * b[3])) out.add(t[4] === "person" ? "a person in the shot" : t[4] === "face" ? "a face" : t[4] === "text" ? "words in the shot (a sign)" : `a ${t[4].replace(/_/g, " ")}`)
|
||||
if (!(ix * iy > 0.12 * Math.min(w * h, b[2] * b[3]))) continue
|
||||
// words in the shot are covered when a good part of them is hidden; a caption over a sign's top edge leaves them read
|
||||
// (12-05, run 28: Dutch's "Would" and "this." sat on the edge of a handwritten sign, its words all clear)
|
||||
if (t[4] === "text") out.add(ix * iy >= SIGN_HIDDEN * w * h ? "words in the shot (a sign)" : "the edge of a sign")
|
||||
else out.add(t[4] === "person" ? "a person in the shot" : t[4] === "face" ? "a face" : `a ${t[4].replace(/_/g, " ")}`)
|
||||
}
|
||||
return [...out]
|
||||
}
|
||||
|
||||
@@ -90,6 +90,9 @@ test("captions are a must: a cut that talks with only a text hook up fails, a ba
|
||||
expect(uncaptioned(captionsOf(hookThenCaps, 2, said), said, hookUp)).toEqual([])
|
||||
// text up all through doesn't stand in for captions after the opening
|
||||
expect(uncaptioned(track, said, () => true).map((x) => x.level)).toEqual(["error"])
|
||||
// the bare stretch said on an end card the render drew (12-05, run 28's Elfster): the card says it, nothing more
|
||||
const card = new Set(said.filter((w) => w.start >= 7).map((w) => w.text))
|
||||
expect(uncaptioned(track, said, () => false, (w) => card.has(w.text))).toEqual([])
|
||||
// a cut with hardly any talking needs none
|
||||
expect(uncaptioned([], said.slice(0, 4))).toEqual([])
|
||||
})
|
||||
|
||||
@@ -11,6 +11,10 @@ test("the frames pack's measures", () => {
|
||||
let f = cutFaces([fr([whole]), fr([edge]), fr([edge]), fr([whole]), fr([edge]), fr([[0, 50, 10, 12, 0.9]])])
|
||||
assert.deepEqual(f.map((x) => [x.level, x.at, x.until]), [["error", 0.5, 1.5], ["warn", 2, 2.5]])
|
||||
assert.match(f[0].says, /left edge/)
|
||||
// a hand at the edge the reader half takes for a face (12-05, run 28: 0.79 then 0.65): a warning that says so
|
||||
f = cutFaces([fr([[0, 598, 41, 82, 0.79]]), fr([[0, 594, 40, 84, 0.65]]), fr([whole])])
|
||||
assert.deepEqual(f.map((x) => [x.level, x.at, x.until]), [["warn", 0, 1]])
|
||||
assert.match(f[0].says, /72% sure it's a face/)
|
||||
// a split screen: a lone line held; a caption's box (two lines close together) isn't one
|
||||
assert.deepEqual(splitsOf(fr([], [["h", 480, 0.8]])), [{ axis: "h", at: 480 }])
|
||||
assert.deepEqual(splitsOf(fr([], [["h", 446, 0.8], ["h", 513, 0.8]])), [])
|
||||
|
||||
@@ -41,6 +41,13 @@ test("the place pack's model", async () => {
|
||||
assert.ok(pa.places[0].top < 400, JSON.stringify(pa.places[0]))
|
||||
ok("raea make place keeps a caption off the sign in the shot")
|
||||
|
||||
// a caption over a sign's top edge, its words all read, is a warning (12-05, run 28's Dutch: "Would" and "this." on
|
||||
// the edge of a handwritten sign): 30% of the words' box hidden makes it "words in the shot", an error
|
||||
const signed = { w: 540, h: 960, grid: { cols: 27, rows: 48, people: Array(48).fill("0".repeat(27)) }, faces: [], things: [[60, 520, 420, 70, "text", 0.95], [60, 600, 420, 70, "text", 0.95]] }
|
||||
const onEdge = textOver(man([t("Would", 400, 950, 280, 110)]), [signed], 1)
|
||||
assert.ok(onEdge.every((x) => x.level === "warn" && /the edge of a sign/.test(x.says)), JSON.stringify(onEdge))
|
||||
ok("a caption over a sign's edge is a warning")
|
||||
|
||||
// b: a woman filling the frame; a caption over her coat is at most a warning
|
||||
const b = textOver(man([t("Did you know you", 272, 1344, 536, 88)]), [sc.b], 1)
|
||||
assert.ok(b.every((x) => x.level === "warn"), JSON.stringify(b))
|
||||
|
||||
@@ -238,10 +238,10 @@ registerRoot(() => <Composition id="hop3d" component={Hop} width={1280} height={
|
||||
|
||||
## Sound: one-shots on transitions, music ducked under the voice
|
||||
|
||||
A game's sound is Tone.js on raea (`motion/music` has the whole of it). Every input and outcome gets a sound, the
|
||||
world's own sounds (machines, footsteps, a room's tone) sit where they are, and music, when the game has some, is a
|
||||
loop written to come round, not a pad. Build the instruments at the top level, give the music and the sounds their
|
||||
buses, and fire each one-shot on the frame its event happens:
|
||||
A game's sounds are Tone.js on raea (`motion/music` has the whole of it). Every input and outcome gets a sound, the
|
||||
world's own sounds (machines, footsteps, a room's tone) sit where they are, and music, when the game has some, is one
|
||||
bed from `raea gen music` on the music bus, never notes written by hand or a pad. Build the instruments at the top
|
||||
level, give the music and the sounds their buses, and fire each one-shot on the frame its event happens:
|
||||
|
||||
- `useGameEvents(INITIAL, fold, (before, after) => machine.state(after.hero) === "land" && machine.state(before.hero) !== "land")`
|
||||
gives the frames where a transition happened. `<Tone.Sfx when={landings.includes(frame)} play={(t) => thump.triggerAttackRelease("C2", "8n", t)} />`
|
||||
|
||||
@@ -80,7 +80,7 @@ No reason makes these right:
|
||||
- **Invented facts.** No number, result, price, quote, customer or comparison that the brief, the person or the
|
||||
footage didn't give you. If the piece needs proof you don't have, make it without the proof and say what would help.
|
||||
- **Generated images or video.** Pictures come from real footage, stock in the project's media, or are built:
|
||||
components, drawn shapes, 3D. Generated sound is allowed: TokenSynth instruments, SAO foley and Pocket TTS
|
||||
narration (all local).
|
||||
components, drawn shapes, 3D. Generated sound is allowed: the music bed from `raea gen music`, SAO foley and
|
||||
Pocket TTS narration.
|
||||
- **Redrawn logos.** Use the real files.
|
||||
- **Calling it done without looking.** A render nobody looked at isn't finished.
|
||||
@@ -68,10 +68,9 @@ Read the files a task needs with `raea guide motion/NAME`, one or two at a time,
|
||||
or `var(--brand-*)` where a class can't reach. Never write a hex palette of your own. A role the kit leaves empty
|
||||
is yours to decide from the brand's own colours (`motion/brand`).
|
||||
8. **Sound is part of the edit.** Decide what each scene is heard as (silence, its own sound, source music, score,
|
||||
effects) before placing any; music is composed for the cut, never a bed by default. Each sound goes in its own
|
||||
`<Sequence from layout="none">`. Use `gainDb` for levels, Tone.js for music (`motion/music`: sample-library or
|
||||
TokenSynth instruments in a Sampler, playing a motif, chords that move and a rhythm) and `sao()` for foley, and
|
||||
put one `<Mix lufs={-14} />` in the composition. Put the sounds in the tree in time order.
|
||||
effects) before placing any; whether it has music is the brief's or its method's call. Each sound goes in its own
|
||||
`<Sequence from layout="none">`. Use `gainDb` for levels, one instrumental bed from `raea gen music` for music
|
||||
(`motion/music`) and `sao()` for foley, and put one `<Mix lufs={-14} />` in the composition. Put the sounds in the tree in time order.
|
||||
9. **Keep animated styles present on every frame.** The engine keeps a style property that React stops sending.
|
||||
Write `transform: scale(1)` and `opacity: 1` rather than leaving them out when an animation settles. Always set
|
||||
`fontFamily`, because the engine's default face is a serif.
|
||||
|
||||
@@ -11,13 +11,11 @@
|
||||
catches a wrong name before anything renders.
|
||||
- The brand's styles come from `./styles.gen` (`<style>{css}</style>`), and `brand/brand.json` imports as JSON
|
||||
(`motion/brand`).
|
||||
- Describe generated sound as values: `sao(prompt, {seconds})` for foley, given to `<Audio src>` (`motion/sound`),
|
||||
and `Tone.tokensynth(timbre, notes)` for an instrument's notes in a `Tone.Sampler` (`motion/music`).
|
||||
- Recorded instruments are cast for each part from the thousands of free sampled instruments (Pianobook, Karoryfer,
|
||||
the SFZ index, Decent Samples, Versilian and more: `motion/music` "Cast the instruments", `motion/sources`). For a
|
||||
sketch, `raea make sounds WORDS` searches the four packs raea carries, and `raea make sounds get PACK/INSTRUMENT` copies one
|
||||
into `media/sounds/PACK-INSTRUMENT/` with a `LICENCE.txt` and prints the `staticFile` paths and the Sampler that
|
||||
plays them. How to set up SAO and TokenSynth is in `motion/sources`.
|
||||
- Describe generated sound as values: `sao(prompt, {seconds})` for foley, given to `<Audio src>` (`motion/sound`).
|
||||
The music bed is a file `raea gen music` wrote (`motion/music`), played with `<Audio src>` like any other.
|
||||
- A game's one-shots can play a recorded pack's notes: `raea make sounds WORDS` searches the four packs raea carries,
|
||||
and `raea make sounds get PACK/INSTRUMENT` copies one into `media/sounds/PACK-INSTRUMENT/` with a `LICENCE.txt` and
|
||||
prints the `staticFile` paths and the Sampler that plays them. How to set up SAO is in `motion/sources`.
|
||||
- Show stills with `<Img src>`. The frame waits for the image to load, and a missing one fails the render, naming
|
||||
`src`.
|
||||
- Keep pictures real: the person's footage, stock already in the object's media, or things you build (components,
|
||||
@@ -30,8 +28,7 @@ error and so is a URL (`https://...`). `staticFile` checks both. A module import
|
||||
fails loudly with the line that has it instead of rendering a black clip.
|
||||
|
||||
Generated imagery is banned outright (floor): no AI-generated images or video, ever. Generated sound is allowed by
|
||||
policy, and made on this computer: TokenSynth for an instrument's notes where no library has the timbre, SAO for
|
||||
foley, Pocket TTS (`<Speech>`) for narration over the picture. The sample libraries are recordings under open licences
|
||||
policy: the music bed from `raea gen music`, SAO for foley, Pocket TTS (`<Speech>`) for narration over the picture. The sample libraries are recordings under open licences
|
||||
(CC0, CC-BY, public domain); a CC-BY one is credited where the piece is shown.
|
||||
|
||||
## Common mistakes
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
time shown at the clip's frame `f` is `(startFrom + f * playbackRate) / fps`. `trimBefore` and `trimAfter` are other
|
||||
names for the same two props: use one name or the other, never both.
|
||||
- Frame a talking head on its face. `raea frame TAKE` says whether the take is a talking take (`<FaceFrame>`, from
|
||||
`raea make component add face-frame`) or a wide screen recording (`<ScreenFit>`). `<FaceFrame src={take} />` (or
|
||||
`<Video framing="face">`) has the engine find the face and keep the eyes 38% down the frame as the speaker moves; an
|
||||
objectPosition or transform of your own on that Video turns the framing off. Zoom a clip for emphasis with
|
||||
`raea make component add face-frame`) or a wide screen recording (`<ScreenFit>`). `<FaceFrame src={take} />` has the engine find the face and keep the eyes 38% down the frame as the speaker moves; an
|
||||
objectPosition or transform of your own on it turns the framing off. A project with `components/Framed.tsx` (raea
|
||||
cloud's footage projects) frames through it instead: `<Framed src startFrom endAt>` crops on the face from
|
||||
`footage/faces.json`. Zoom a clip for emphasis with
|
||||
`punchIn={1.15}`. Alternating punched and unpunched clips between cuts gives a talking head rhythm without a zoom
|
||||
on every sentence. The face track comes from raea-perceive (the render is refused without it, or with no face found)
|
||||
and is kept beside the take as TAKE.faces.json, so a second render reads it.
|
||||
@@ -67,8 +68,8 @@ take the in- and out-points from the take's words (the gaps between them), not f
|
||||
- `endAt` at or before `startFrom`: it throws.
|
||||
- Every clip without a Sequence, so all of them play from frame 0 on top of each other.
|
||||
- `transform: scale(1.2)` on a Video inside a box without `overflow: hidden`: the zoom spills over the parts around it.
|
||||
- An `objectPosition` or `transform` on a Video with `framing="face"`: either one turns the framing off, and the crop
|
||||
stays where you put it while the speaker moves. Zoom a framed take with `punchIn`.
|
||||
- An `objectPosition` or `transform` on a `<FaceFrame>`: either one turns the framing off, and the crop stays where
|
||||
you put it while the speaker moves. Zoom a framed take with `punchIn`.
|
||||
- A zoom on every sentence. That is the template ad the floor refuses. Punch in where the line earns it.
|
||||
- Cutting on round seconds instead of word gaps.
|
||||
- Leaving the clip's sound at unity under a loud bed. Balance it in `motion/sound`.
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
## What to do
|
||||
|
||||
- Generate a picture, a clip, music, an effect, a voice, a 3D model or words with `raea gen` when the piece needs
|
||||
something that isn't in the footage, the stock or the scene. Music only when the person asks for a generated
|
||||
track: a score is composed on instruments for the cut (`motion/music`), and a generated track can't be cut on the
|
||||
bar or edited note by note. `-o` is the folder; each command prints the files it wrote; use it like any
|
||||
something that isn't in the footage, the stock or the scene. A piece's music is always
|
||||
one instrumental bed from `raea gen music` (`motion/music`). `-o` is the folder; each command prints the files it wrote; use it like any
|
||||
other media (`<Img src>`, `<Video src>`, `<Audio src>`, `<Model src>`).
|
||||
- Quote first. `raea gen plan FLOW` and `--plan` on a one-shot cost nothing and say where each step runs and what it
|
||||
costs in cents. A run past its cap is refused before anything is spent: `--max-cents N`, else
|
||||
@@ -15,6 +14,7 @@
|
||||
```sh
|
||||
raea gen image "a paper kite over dunes at dawn, 35mm" --aspect 16:9 -o media/gen
|
||||
raea gen video "the kite climbs into the light" --image media/gen/<the still>.png --seconds 5 -o media/gen
|
||||
raea gen music "a light acoustic groove, warm and playful, instrumental, no vocals" --seconds 40 -o media/music
|
||||
raea gen sfx "paper flutter in wind, close, no music" --seconds 3 -o media/gen
|
||||
raea gen speech "Find your wind." -o media/gen
|
||||
raea gen mesh "a paper kite" --image media/gen/<the still>.png -o media/gen # the GLB and its textures together
|
||||
|
||||
@@ -1,72 +1,30 @@
|
||||
# Music and sound effects: Tone.js on raea (raea/tone)
|
||||
# Music and sound: a bed from raea gen, a game's sounds on Tone.js (raea/tone)
|
||||
|
||||
## Decide what the picture needs before writing a note
|
||||
## Music: one bed, from raea gen
|
||||
|
||||
Music is never a default. A bed under every second makes every piece sound like every other one, and a held pad or
|
||||
drone under a long reverb is what generated music sounds like. Before any instrument goes in:
|
||||
Whether a piece has music is its brief's call, or its method's (a method that says every cut has music means every
|
||||
cut). Decide what each stretch is heard as first: silence, the scene's own sound, effects, a voice, the bed.
|
||||
|
||||
- Name what each stretch is heard as: silence; the scene's own sound (diegetic: footsteps, a room, a radio, a game's
|
||||
machines, anything the people on screen could hear); source music (music playing in the scene); score (music only
|
||||
the audience hears); effects; a voice. Several at once is fine, and none is a choice too: a pitch with a voice may
|
||||
need only effects and a four-second sting on the end card. Write the decision in the storyboard or DIRECTION.md,
|
||||
one line a scene.
|
||||
- Spot the cut the way a music editor does: number each cue (1m1, 1m2...) with the frame it starts on, the moments
|
||||
it has to hit (the hook, a reveal, the logo), where it turns (where the edit changes idea) and where it stops. A
|
||||
cue ends on a hit, the "button" (the last chord on the last cut or the logo), not on a fade. Half a bar of silence
|
||||
before a reveal is what makes the reveal.
|
||||
- Take the tempo from the cut. Frames per beat = fps × 60 / bpm: at 30 fps, 12 frames at 150 bpm, 15 at 120, 20 at
|
||||
90. Pick the bpm that puts the main cuts on beats and the biggest on downbeats, or set it so they do
|
||||
(`bpm.value = (bars * 4 * 60 * fps) / framesToTheCut`). Shots of 1 to 1.5 s suit 120 to 160 bpm; shots of 3 to 5 s
|
||||
suit 70 to 100, or a half-time feel. With a song, cut to its map instead (`motion/timing`).
|
||||
- A sustained texture (a held pad, a drone, a reverb wash) goes in only when the scene asks for one by name ("dread",
|
||||
"the ship's hum") and the direction says why in a line. Even then something over it moves.
|
||||
- The music is one instrumental bed for the piece: `raea gen music "warm, playful light acoustic groove, no vocals"
|
||||
--seconds 40 -o media/music` (`motion/gen`: quote it with `--plan` first). On raea cloud, the `generate` tool makes
|
||||
the same bed. Name the feel the brief asks for, and say "instrumental, no vocals".
|
||||
- Lay it under the whole cut: `<Audio src={staticFile("music/bed.mp3")} bus="music" gainDb={-10} fadeIn={0.3}
|
||||
fadeOut={1} />`, with the voices on `bus="voice"`. raea's mix brings every line of dialogue to one level, and
|
||||
`raea check` says when the bed is lost under the voice or fights it, with the gainDb that fixes it; change the level
|
||||
only on what it says. A footage cut made with `components/Cut.tsx` takes the bed as its `bed` prop and lays it so.
|
||||
- One bed a piece. A second track, a sting or a riser made to fix the first is a second way to make music: make the bed
|
||||
again with a better prompt instead.
|
||||
|
||||
## Cast the instruments for this piece
|
||||
## A game's sounds and the buses: Tone.js on raea
|
||||
|
||||
Every agent that reaches for "a piano" gets the same Salamander grand, and every "MIDI" part the same General MIDI
|
||||
bank, so every score sounds alike. Thousands of sampled instruments are free to use, and choosing them is part of
|
||||
writing the music. Shane, 2026-11-23: "when i say midi it just picks the same ones there thousands of insturments out
|
||||
there to go use".
|
||||
|
||||
- Cast each part the way a composer books a player. Write a line per part: what it is, what it's like and how it's
|
||||
played ("an old upright, a little out of tune, felt down, close-miked"; "one cello, dry, in a small room, played
|
||||
low"; "a harmonium with its bellows audible"). Let the picture choose: its place, its era, what is in the room.
|
||||
- Search for that line in `motion/sources`' instrument libraries: Pianobook's thousands of community instruments,
|
||||
Karoryfer, the SFZ index, Decent Samples, Versilian, musical-artifacts and the rest. Listen to a few candidates on
|
||||
the part's own notes before choosing. A character instrument (a prepared piano, a music box, a bowed vibraphone, an
|
||||
out-of-tune upright, a particular cello) does more for a piece than a clean generic one.
|
||||
- `raea make sounds` (the Salamander grand, FluidR3's General MIDI set, tonejs-instruments, VCSL's single takes) is for a
|
||||
sketch, or for a part that really is that instrument. It isn't the cast. A score made only of its packs needs a
|
||||
reason in the direction.
|
||||
- "MIDI" means notes, not General MIDI sounds. A General MIDI bank (FluidR3, MuseScore General) plays a MIDI file
|
||||
as it is, to check it. A score's parts are cast instruments playing those notes.
|
||||
- Write the cast in the piece's notes: each part's instrument, where it came from and its licence. When a part
|
||||
can't be cast (no free library has it), that's when TokenSynth or a synth comes in.
|
||||
|
||||
## What to do
|
||||
|
||||
- Write music and sound effects in Tone.js, as its docs write them: `import * as Tone from "raea/tone"`, then
|
||||
- Write a game's sounds in Tone.js, as its docs write them: `import * as Tone from "raea/tone"`, then
|
||||
instruments, effects, `connect`/`toDestination`/`chain`, `triggerAttackRelease`, and the Transport with `Loop`,
|
||||
`Part`, `Sequence` and `Pattern`. What you know of Tone works; the differences are below. It's a DAW in code: a
|
||||
track is an instrument and its effects into a bus, a clip is a `Part` or `Sequence`, the arrangement is where each
|
||||
starts and stops on the Transport.
|
||||
- Make music from instruments playing notes, not from a generated track. Each instrument is a `Tone.Sampler` (a kit
|
||||
is `Tone.Players`); fill it one of three ways:
|
||||
- **A sampled instrument cast for the part** (above), first. Most come as SFZ or Decent Sampler presets: read the
|
||||
preset's map (SFZ `<region>`: `sample=`, `pitch_keycenter=`, `lokey`/`hikey`, `lovel`/`hivel`; a `.dspreset`'s
|
||||
`<sample path rootNote loNote hiNote loVel hiVel>`) into the Sampler's `urls`, one Sampler per velocity layer
|
||||
you use. For a quick sketch, `raea make sounds cello` searches the four packs raea carries (the Salamander grand;
|
||||
FluidR3's 128 General MIDI instruments; tonejs-instruments' strings, brass, woodwinds and guitars; VCSL's
|
||||
keyboards, harps, mallets, drums and percussion), and `raea make sounds get tonejs-instruments/cello` copies its notes
|
||||
into `media/sounds/` and prints the `Sampler` that plays them. Drums and hits come as takes for `Tone.Player`s.
|
||||
Everything else is fetched by hand (`motion/sources`; `raea make sounds get` reaching it all is docs/sound.feature SN4).
|
||||
- **TokenSynth** for a timbre no library has: `Tone.tokensynth("a bowed saw, close, eerie", ["C3", "E3", "G#3",
|
||||
"C4", "E4", "G#4", "C5"], { seconds: 2 })` renders those root notes, a major third apart, once on this computer,
|
||||
and the Sampler pitches between them. Describe
|
||||
the timbre the way you'd describe a patch ("a soft wooden marimba, felt mallet, warm"; "a bright analog synth
|
||||
lead, saw, short decay"); a note's `seconds` is how long it's held (under 5). Its takes need curating (below).
|
||||
- Tone's own synths (`Synth`, `PolySynth`, `MonoSynth`, `MembraneSynth`, `MetalSynth`, `NoiseSynth`, `FMSynth`) for
|
||||
parts that are synthetic on purpose: an 808 kick, an analog bass, a chiptune lead, a riser.
|
||||
`Part`, `Sequence` and `Pattern`. What you know of Tone works; the differences are below.
|
||||
- Fill an instrument for a game's one-shots with a `Tone.Sampler` (a kit is `Tone.Players`): SAO's takes
|
||||
(`Tone.sao("a bright arcade coin chime, short", { seconds: 1 })`), a recorded pack (`raea make sounds get
|
||||
vcsl/marimba` copies its notes into `media/sounds/` and prints the Sampler), or Tone's own synths (`MembraneSynth`
|
||||
for a thump, `MetalSynth` for a clank, `NoiseSynth` for a whoosh). These are effects, not a score: a game's music is
|
||||
a bed from `raea gen music`, as above.
|
||||
- Make sound effects and foley with SAO or a recorded pack: `Tone.sao("a bright arcade coin chime, short", { seconds:
|
||||
1 })` in a Sampler or Player, or `sao(...)` in an `<Audio>`, built in layers (`motion/sound`). Narration over the
|
||||
picture is `<Speech>` from `raea/speech` (Pocket TTS, local; `motion/sound`).
|
||||
@@ -88,80 +46,13 @@ there to go use".
|
||||
`when` true on that frame only (a frame from `useGameEvents`, or a machine's transition). Give one-shots
|
||||
`Tone.vary(instrument, { pitch: 0.3, volume: 2 })` so repeats don't sound copied (the variation is seeded by the
|
||||
frame, so a replay is the same). Cap their voices with `maxPolyphony` (the oldest is stolen, faded in 5 ms).
|
||||
- In a timeline, cut on the music: `Tone.Time("1m").toFrames(fps)` is a bar in frames, and `Tone.Time("4n")` a beat.
|
||||
- To hear a sound before writing it in, `raea make sao "PROMPT" --seconds 1 --dir EDIT_DIR -o EDIT_DIR/media/sfx/try.wav`
|
||||
or `raea make tokensynth "TIMBRE" --notes C3 --dir EDIT_DIR -o EDIT_DIR/media/try/` makes it now and keeps it in the
|
||||
edit's asset store (`--dir` is the edit's folder; without it, the folder you run it from), so the edit's own call
|
||||
with the same words and settings then plays what was made instead of making it again. Another `--seed` makes
|
||||
makes it now and keeps it in the edit's asset store (`--dir` is the edit's folder; without it, the folder you run it
|
||||
from), so the edit's own call with the same words and settings then plays what was made instead of making it again. Another `--seed` makes
|
||||
another take; play a seed's file by its path (`staticFile("sfx/try.wav")`), since `sao()` in the edit has no seed.
|
||||
- When SAO or TokenSynth isn't installed yet, `raea setup-audio` installs it (`motion/sources` says what it fetches
|
||||
- When SAO isn't installed yet, `raea setup-audio` installs it (`motion/sources` says what it fetches
|
||||
and what to do when it fails).
|
||||
|
||||
## Writing music for picture
|
||||
|
||||
Write it as a composer would, for this cut:
|
||||
|
||||
- **A motif first.** Three to seven notes over two to four bars, with a rhythm of its own, before any chord. Then
|
||||
vary it rather than loop it: answer it, fragment it, move it to another instrument or register, put new chords
|
||||
under it. End the cue on it.
|
||||
- **Harmony that moves.** In an active cue, change chord every bar or every two beats; keep chords of two to four bars
|
||||
for a slow passage. Move the inner voices by step or hold a common tone, set the bass against the tune (contrary
|
||||
motion, inversions so it walks), and resolve a pedal when it ends. Keep the low end open: no thirds below about C3,
|
||||
fifths down to about C2, only octaves under that.
|
||||
- **Rhythm and groove.** At least one part moves in eighths or sixteenths: an ostinato, a pizzicato, an arpeggio, a
|
||||
kit, hand percussion. Accent where the picture moves. Spread velocities (0.35 to 0.95, not all 0.8), and put a
|
||||
played part a few milliseconds off the grid (5 to 15 ms, written into the note's time: `humanize` is ignored here).
|
||||
A drummer's recorded groove beats one typed in (Groove MIDI, `motion/sources`).
|
||||
- **Orchestrate by register.** One job each: a bass (E1 to C3), sparse harmony (C3 to C5), one lead (C4 to C6), the
|
||||
rhythm, colour on top (glockenspiel, celesta, harp). Hand the tune to a new instrument each section, and use the
|
||||
articulations the library has (staccato, legato, pizzicato, tremolo, a swell). A pad, where the scene names one,
|
||||
is glue 12 dB or more under the lead, never the part.
|
||||
- **The arrangement follows the edit.** Sections change where the edit changes idea: build by adding parts and by
|
||||
switching sections, on bar lines; peak, then strip back; drop out before the reveal; end on the button. A sting
|
||||
lasts 1 to 4 s, sits in the cue's key and lands on a beat.
|
||||
- **Write around the voice.** The tune answers in the gaps between lines, and the arrangement thins under speech.
|
||||
- **Each instrument its own room.** A short reverb per instrument or per section (decay 1.2 to 2.5 s, wet 0.15 to
|
||||
0.3), never one long wash over the bus: a 6 s reverb and a low-pass on the whole music bus erase every attack, and
|
||||
that is how a score turns into a drone.
|
||||
- **Source music lives in the scene.** A radio, a band in the room, a phone: narrow it to the device (a high-pass
|
||||
around 300 Hz and a low-pass around 3.5 kHz for a small speaker), pan it to where it is (`Tone.Panner`), put it in
|
||||
the room's reverb, and let the scene's own sound sit with it. Crossing over is strong: a radio song that opens out
|
||||
to full range as it becomes the score, a score hit that lands on an action in the scene.
|
||||
- Leave silence. Let the music start after a chapter card clears and stop before the next; let a card sit on one low
|
||||
note.
|
||||
- Write for this picture's feeling, not a genre's surface: a stock walking bass and brushes under everything reads as
|
||||
pastiche as surely as a pad does.
|
||||
- Period source music can be real: US sound recordings published before 1926 and compositions published before 1931
|
||||
are public domain in the US (2026). archive.org's 78rpm transfers give the period's own sound; play them as
|
||||
`<Audio bus="music">`, narrowed and placed as source music, ducked with the rest.
|
||||
- Synth drums (`MembraneSynth` kicks, noise "brushes") sound synthetic on anything acoustic; use a library's recorded
|
||||
kit (`raea make sounds kick`, `snare`, `hihat`).
|
||||
|
||||
## Instruments from TokenSynth: build a library, don't trust a take
|
||||
|
||||
A TokenSynth note is one sample from a model, and a lot of takes are bad. In a 35-minute documentary score (2026-10-20),
|
||||
12 of 30 single-seed root notes failed: hiss and buzz in place of a horn, a sax or accordion an octave (or 34
|
||||
semitones) off, a piano note still at full level when its file ends, so every held note stopped with a click. That is
|
||||
the "vanilla and abrasive" sound. It learned from 5-second notes at four velocities, so it gives one dynamic and can
|
||||
miss the pitch asked for. So:
|
||||
|
||||
- Reach for a recorded instrument first, cast for the part (above): a recording, no gamble. Use TokenSynth for what
|
||||
no library has, or a timbre you can describe better than find.
|
||||
- Declare each instrument as a candidate, not a call: its timbre, roots every 3 to 4 semitones over the range it plays
|
||||
(a Sampler pitched further than that starts to sound fake), 3 or more seeds, and `seconds` long enough for the
|
||||
sound to die away on its own (4 for piano, 6 for sustained strings).
|
||||
- Render every candidate through a `Sampler` (one per instrument and seed, each root played once), never through an
|
||||
`<Audio>` of a tokensynth note: today an `<Audio>` drops the note's pitch and seed and makes the prompt alone.
|
||||
- Measure and pick: `uv run --with numpy --with soundfile python3 -I TOOLS/tokensynth/curate.py EDIT_DIR` (TOOLS is
|
||||
`tools/` in a raea checkout, `share/raea/tools/` beside an installed raea) checks each
|
||||
take's pitch (cents off the note), energy above 4 kHz, spectral flatness (noise), whether it has decayed by the end,
|
||||
and its onset, and writes `instruments.gen.json` ({timbre: {midi: seed}}) with the best passing seed per root.
|
||||
Build the score's Samplers from that file only; a root with no passing take gets more seeds, not a pass.
|
||||
- Prefer timbres TokenSynth does well (felt or soft piano, sustained cello section, bowed or plucked bass, vibraphone,
|
||||
clarinet in its low register) to the ones it does badly (muted trumpet, tenor sax, accordion: breath and reed
|
||||
noise come out as hiss).
|
||||
- For dynamics, render a soft and a loud velocity as two Samplers and pick one by each note's velocity.
|
||||
|
||||
## Why
|
||||
|
||||
Tone code here builds an edit's graph and an event list instead of driving Web Audio. The Transport's callbacks run in
|
||||
@@ -170,151 +61,33 @@ and a play of the same frames identical, and the same holds after a seek. A node
|
||||
rebuilds the graph (a pause in the sound), and a note triggered while rendering would fire again on every re-render.
|
||||
So the graph goes at the top level, and in-game sounds go through `<Sfx>`.
|
||||
|
||||
Generated sources are made once per their inputs: the prompt, the length, a TokenSynth note's pitch, velocity, seed
|
||||
and precision. They're normalised, cached as PCM in the object's `assets/`, and played like any file. TokenSynth and
|
||||
SAO run on this computer and install themselves the first time they're used (minutes, once; `raea setup-audio` does
|
||||
it ahead of time). Music written as notes on instruments can be edited note by note, cut on the bar and ducked per
|
||||
part; a generated track can't.
|
||||
Generated sources are made once per their inputs (the prompt, the length, the seed), cached in the object's
|
||||
`assets/`, and played like any file. SAO runs on this computer and installs itself the first time it's used
|
||||
(`raea setup-audio` does it ahead of time).
|
||||
|
||||
Policy: music is notes on Tone.js instruments (sample libraries first, TokenSynth for a timbre no library has, synths
|
||||
for synthetic parts), effects and foley are SAO or recorded packs (`motion/sources`), narration is Pocket TTS
|
||||
(`<Speech>`), all local. Any other generation is a `raea gen` step, quoted and capped (`motion/gen`). (`lyria()`, a
|
||||
remote music model, is retired: an older edit keeps the take it made, and a new one is refused.)
|
||||
Policy, the same everywhere raea runs (this guide, the raea skill, raea cloud's boxes and the desktop): a piece's music
|
||||
is one instrumental bed from `raea gen music` (raea cloud's `generate` tool is the same model); effects and foley are
|
||||
SAO or recorded packs (`motion/sources`); narration is Pocket TTS (`<Speech>`). Never music written note by note, a
|
||||
held pad or drone, a voice or lyrics in the bed, or a second track to fix the first. (`lyria()` is retired: an older
|
||||
edit keeps the take it made, and a new one is refused.)
|
||||
|
||||
## Common mistakes
|
||||
|
||||
- A pad and a sine sub through a low-pass into a long reverb as the score. That's a drone, not music: write a motif,
|
||||
chords that move and a part with rhythm.
|
||||
- One chord every four bars for a minute, or a two-bar loop for thirty seconds. Change the harmony every bar or two
|
||||
and the arrangement every four to eight.
|
||||
- Every note at the same velocity, on the grid. Spread the dynamics and move played parts a few milliseconds.
|
||||
- A cue that fades out at the end. End it on the last cut, on a chord or a hit.
|
||||
- Music under every scene because the piece "needs music". Decide per scene; silence and the scene's own sound count.
|
||||
- `synth.triggerAttackRelease(...)` in a component body. It fires on every render; use `<Tone.Sfx>`.
|
||||
- `<Tone.Sfx when={g.coinTaken}>` on a flag the state holds for many frames: it fires on every one. Give it the
|
||||
frames the event happens on (`useGameEvents`).
|
||||
- `new Tone.Synth()` inside a component. Make instruments at the top level.
|
||||
- A `https://` URL for a Sampler or a Player. Sources are media files or generated assets, and the render has no
|
||||
network: `raea make sounds get` puts a library's files in `media/` first.
|
||||
- One root for a whole part, or one an octave. A Sampler stretched far from its root sounds chipmunked or muddy;
|
||||
give it a root every 3 to 4 semitones over the range the part plays: a library's own roots (`raea make sounds get`
|
||||
with no `--notes` takes them a minor third apart, or every note the library sampled if it's sparser), or as many
|
||||
TokenSynth roots.
|
||||
- Rewording a `tokensynth()` timbre on every pass: each new wording makes its notes again. Settle the timbre first.
|
||||
- A sample library's licence ignored. CC-BY ones (FluidR3, Salamander, tonejs-instruments) need their credit where
|
||||
the piece is shown; `LICENCE.txt` beside the files has the line. VCSL is CC0.
|
||||
- `part.loop = true` after `part.start()`: the Part plays once. Set `loop` and `loopEnd` first.
|
||||
- `Tone.Draw.schedule` for visuals. There's no draw loop: read the frame (`useCurrentFrame`) and the same times.
|
||||
- Cutting on `Tone.Time("1m").toFrames(fps)` across a tempo ramp. `Tone.getTransport().bpm.rampTo(120, 4)` bends the
|
||||
grid, as in Tone (the notes come closer together; an exponential ramp runs linear), but `Time(...)` is at the tempo
|
||||
when it's read, so after a ramp a bar is no longer that many frames.
|
||||
- An LFO on an instrument's parameter (a synth's `detune`, a Sampler's `volume`): it does nothing yet. On an effect's
|
||||
or a `Gain`'s, `Volume`'s or `Channel`'s it works, as in Tone (`new Tone.LFO("4n", 400, 4000).start()
|
||||
.connect(filter.frequency)`).
|
||||
- A Sequence or Loop with no `Tone.getTransport().start()`. Nothing plays until the Transport starts, as in Tone.
|
||||
|
||||
## Example: a cue with a motif, chords that move and a kit, cut on the bar
|
||||
|
||||
Spotted as one cue over nine one-bar cards: A (bars 1 to 4) piano and a pizzicato ostinato, the flute's motif from
|
||||
bar 3; B (bars 5 to 8) the ostinato drops out, bass and kit come in, the motif climbs; the button on the end card's
|
||||
cut. The instruments are `raea make sounds` packs so the example runs anywhere with one command each; a real piece casts
|
||||
its own (above). Each command prints the roots it fetched (with no `--notes`, a minor third apart from C1 to C7, or
|
||||
every note the library sampled when that's sparser):
|
||||
|
||||
```sh
|
||||
raea make sounds get salamander/piano
|
||||
raea make sounds get fluid/pizzicato_strings
|
||||
raea make sounds get tonejs-instruments/flute
|
||||
raea make sounds get fluid/acoustic_bass
|
||||
raea make sounds get vcsl/bass-drum-1 && raea make sounds get vcsl/snare-drum-modern-1 && raea make sounds get vcsl/hi-hat-cymbal
|
||||
```
|
||||
|
||||
```tsx
|
||||
import { AbsoluteFill, Composition, Mix, Series, registerRoot, staticFile } from "raea";
|
||||
import * as Tone from "raea/tone";
|
||||
|
||||
Tone.getTransport().bpm.value = 96; // first: a Part reads its times at the tempo when it's made
|
||||
const BAR = Tone.Time("1m").toFrames(30); // 75 frames
|
||||
|
||||
// the roots each part's range needs, of those `raea make sounds get` printed (D#3 is the file Ds3.mp3)
|
||||
const notes = (dir: string, names: string[]) => Object.fromEntries(names.map((n) => [n, staticFile(`sounds/${dir}/${n.replace("#", "s")}.mp3`)]));
|
||||
const room = new Tone.Reverb({ decay: 1.6, wet: 0.2 }).connect(Tone.buses.music);
|
||||
const piano = new Tone.Sampler({ urls: notes("salamander-piano", ["A2", "C3", "D#3", "F#3", "A3", "C4", "D#4", "F#4"]), release: 1, volume: -8 }).connect(room);
|
||||
const pizz = new Tone.Sampler({ urls: notes("fluid-pizzicato_strings", ["D#2", "F#2", "A2", "C3", "D#3", "F#3", "A3", "C4"]), release: 0.2, volume: -12 }).connect(room);
|
||||
const flute = new Tone.Sampler({ urls: notes("tonejs-instruments-flute", ["E4", "A4", "C5", "E5", "A5", "C6"]), release: 0.4, volume: -6 }).connect(room);
|
||||
const bass = new Tone.Sampler({ urls: notes("fluid-acoustic_bass", ["D#1", "F#1", "A1", "C2", "D#2"]), release: 0.3, volume: -6 }).connect(Tone.buses.music);
|
||||
const kit = new Tone.Players({
|
||||
kick: staticFile("sounds/vcsl-bass-drum-1/BDrumNew_hit_v5_rr1_Sum.wav"),
|
||||
snare: staticFile("sounds/vcsl-snare-drum-modern-1/Snare2_HitSN_v5_rr1_Mid.wav"),
|
||||
hat: staticFile("sounds/vcsl-hi-hat-cymbal/HiHat_HitC_v3_rr1_Mid.wav"),
|
||||
ghost: staticFile("sounds/vcsl-hi-hat-cymbal/HiHat_HitC_v1_rr1_Mid.wav"), // the soft take, for the off-beats
|
||||
}).connect(Tone.buses.music);
|
||||
|
||||
// a chord a bar, voiced so the inner notes move by step: Am F C G, then F G Am E
|
||||
const CHORDS = [["A3", "C4", "E4"], ["A3", "C4", "F4"], ["G3", "C4", "E4"], ["G3", "B3", "D4"], ["A3", "C4", "F4"], ["G3", "B3", "D4"], ["A3", "C4", "E4"], ["G#3", "B3", "E4"]];
|
||||
// comped, not held: the downbeat and the and-of-two, the second softer
|
||||
new Tone.Part((t, c) => piano.triggerAttackRelease(c.notes, "8n", t, c.vel), CHORDS.flatMap((chord, bar) => [
|
||||
{ time: `${bar}:0`, notes: chord, vel: 0.62 },
|
||||
{ time: `${bar}:1:2`, notes: chord, vel: 0.42 },
|
||||
])).start(0);
|
||||
|
||||
// A: an eighth-note ostinato on each chord's root (root, fifth, octave, fifth), accented on the beat
|
||||
new Tone.Part((t, n) => pizz.triggerAttackRelease(n.note, "16n", t, n.vel), ["A2", "F2", "C3", "G2"].flatMap((root, bar) =>
|
||||
[0, 7, 12, 7, 0, 7, 12, 7].map((up, i) => ({ time: `${bar}:${i >> 1}:${(i & 1) * 2}`, note: Tone.Frequency(root).transpose(up).toNote(), vel: i % 2 ? 0.45 : 0.75 })),
|
||||
)).start(0);
|
||||
|
||||
// the motif (E D C D, then B A G) from bar 3, sequenced up and answered in B; each note a few ms off the grid
|
||||
const TUNE: [string, string, string, number][] = [
|
||||
["2:0", "E5", "4n", 0.7], ["2:1", "D5", "8n", 0.55], ["2:1:2", "C5", "8n", 0.6], ["2:2", "D5", "2n", 0.75],
|
||||
["3:0", "B4", "4n.", 0.65], ["3:1:2", "A4", "8n", 0.5], ["3:2", "G4", "2n", 0.6],
|
||||
["4:0", "A5", "4n", 0.8], ["4:1", "G5", "8n", 0.6], ["4:1:2", "F5", "8n", 0.65], ["4:2", "G5", "2n", 0.8],
|
||||
["5:0", "D5", "4n.", 0.7], ["5:1:2", "B4", "8n", 0.55], ["5:2", "D5", "2n", 0.7],
|
||||
["6:0", "E5", "4n", 0.75], ["6:1", "C5", "8n", 0.6], ["6:1:2", "E5", "8n", 0.7], ["6:2", "A5", "2n", 0.9],
|
||||
["7:0", "G#5", "2n.", 0.8], ["7:3", "B4", "4n", 0.6],
|
||||
];
|
||||
new Tone.Part((t, n) => flute.triggerAttackRelease(n.note, n.dur, t + n.late, n.vel),
|
||||
TUNE.map(([time, note, dur, vel], i) => ({ time, note, dur, vel, late: ((i * 5) % 3 - 1) * 0.007 }))).start(0);
|
||||
|
||||
// B: the bass walks up under the climb (F G A, then E to come home), root on one and fifth on three
|
||||
new Tone.Part((t, n) => bass.triggerAttackRelease(n.note, "4n.", t, n.vel), [["F1", "C2"], ["G1", "D2"], ["A1", "E2"], ["E1", "B1"]].flatMap(([root, fifth], i) => [
|
||||
{ time: `${4 + i}:0`, note: root, vel: 0.85 },
|
||||
{ time: `${4 + i}:2`, note: fifth, vel: 0.6 },
|
||||
])).start(0);
|
||||
|
||||
// B: the kit, four bars of sixteenth-note lanes (null rests)
|
||||
const _ = null;
|
||||
for (const steps of [
|
||||
["kick", _, _, _, _, _, "kick", _, "kick", _, _, _, _, _, _, _],
|
||||
[_, _, _, _, "snare", _, _, _, _, _, _, _, "snare", _, _, _],
|
||||
["hat", _, "ghost", _, "hat", _, "ghost", "ghost", "hat", _, "ghost", _, "hat", _, "ghost", _],
|
||||
]) {
|
||||
const lane = new Tone.Sequence((t, hit) => kit.player(hit).start(t), steps, "16n");
|
||||
lane.loop = 4; // set before start: four bars, then it stops
|
||||
lane.start("4m");
|
||||
}
|
||||
|
||||
// the button: everything on the end card's downbeat, then nothing
|
||||
Tone.getTransport().schedule((t) => {
|
||||
piano.triggerAttackRelease(["A2", "A3", "C4", "E4"], "2n", t, 0.85);
|
||||
bass.triggerAttackRelease("A1", "2n", t, 0.9);
|
||||
flute.triggerAttackRelease("A5", "4n", t, 0.8);
|
||||
kit.player("kick").start(t);
|
||||
}, "8m");
|
||||
Tone.getTransport().start();
|
||||
|
||||
// each card is one bar, so every cut lands on a downbeat; the ninth is the end card
|
||||
const Edit = () => (
|
||||
<AbsoluteFill>
|
||||
<Mix lufs={-14} ceiling={-1.5} />
|
||||
<Series>{Array.from({ length: 9 }, (_, i) => <Series.Sequence key={i} durationInFrames={BAR}>{/* card i */}</Series.Sequence>)}</Series>
|
||||
</AbsoluteFill>
|
||||
);
|
||||
|
||||
registerRoot(() => <Composition id="cue" component={Edit} width={1080} height={1920} fps={30} durationInFrames={BAR * 9} />);
|
||||
```
|
||||
|
||||
FluidR3, Salamander and tonejs-instruments (the flute) are CC-BY 3.0, so the piece credits all three (the line is in
|
||||
each `LICENCE.txt`); VCSL is CC0.
|
||||
- A score written in Tone.js, TokenSynth or `raea/music` for a piece. Its music is a `raea gen music` bed.
|
||||
|
||||
## Example: a game's sound
|
||||
|
||||
@@ -327,26 +100,9 @@ type State = { hits: number; coinTaken: boolean };
|
||||
const INITIAL: State = { hits: 0, coinTaken: false };
|
||||
const fold = (s: State): State => s;
|
||||
|
||||
Tone.getTransport().bpm.value = 112;
|
||||
Tone.buses.music.duck(Tone.buses.voice, { amount: -12 });
|
||||
const thump = Tone.vary(new Tone.MembraneSynth({ octaves: 4, maxPolyphony: 4, poly: true }), { pitch: 0.5, volume: 2 }).connect(Tone.buses.sfx);
|
||||
const coin = new Tone.Sampler({ urls: { C5: Tone.sao("a bright arcade coin chime, short", { seconds: 1 }) } }).connect(Tone.buses.sfx);
|
||||
// a recorded marimba (`raea make sounds get vcsl/marimba`: CC0, every note VCSL sampled, four to seven semitones apart)
|
||||
const marimba = new Tone.Sampler({
|
||||
urls: Object.fromEntries(["F3", "C4", "G4", "B4", "F5"].map((n) => [n, staticFile(`sounds/vcsl-marimba/${n}.wav`)])),
|
||||
release: 0.4,
|
||||
volume: -10,
|
||||
}).connect(new Tone.Reverb({ decay: 1.2, wet: 0.15 }).connect(Tone.buses.music));
|
||||
// a loop that wants to come round: a question (bars 1-2) and its answer (bars 3-4), rhythm before pitch
|
||||
const tune = new Tone.Part((t, n) => marimba.triggerAttackRelease(n.note, "8n", t, n.vel), [
|
||||
{ time: "0:0", note: "C4", vel: 0.8 }, { time: "0:0:2", note: "E4", vel: 0.5 }, { time: "0:1:2", note: "G4", vel: 0.6 }, { time: "0:3", note: "A4", vel: 0.7 },
|
||||
{ time: "1:0", note: "G4", vel: 0.8 }, { time: "1:1:2", note: "E4", vel: 0.5 }, { time: "1:2", note: "D4", vel: 0.6 },
|
||||
{ time: "2:0", note: "C4", vel: 0.8 }, { time: "2:0:2", note: "E4", vel: 0.5 }, { time: "2:1:2", note: "G4", vel: 0.6 }, { time: "2:3", note: "C5", vel: 0.75 },
|
||||
{ time: "3:0", note: "B4", vel: 0.7 }, { time: "3:1", note: "G4", vel: 0.55 }, { time: "3:2", note: "C4", vel: 0.85 },
|
||||
]);
|
||||
tune.loop = true;
|
||||
tune.loopEnd = "4m";
|
||||
tune.start(0);
|
||||
Tone.getTransport().start();
|
||||
|
||||
function Game() {
|
||||
@@ -359,6 +115,8 @@ function Game() {
|
||||
{/* ...the game's picture... */}
|
||||
<Tone.Sfx when={hits.includes(frame)} play={(t) => thump.triggerAttackRelease("C2", "8n", t)} />
|
||||
<Tone.Sfx when={coins.includes(frame)} play={(t) => coin.triggerAttackRelease("C5", "8n", t)} />
|
||||
{/* the game's music: a bed from `raea gen music "a playful marimba loop, 112 bpm, no voice" --seconds 30 -o public/music` */}
|
||||
<Audio src={staticFile("music/bed.mp3")} bus="music" gainDb={-10} fadeIn={0.3} />
|
||||
<Sequence from={90} durationInFrames={150} layout="none">
|
||||
<Audio src={staticFile("voice.wav")} bus="voice" />
|
||||
</Sequence>
|
||||
@@ -369,7 +127,5 @@ function Game() {
|
||||
registerRoot(() => <Composition id="game" component={Game} width={1920} height={1080} fps={60} durationInFrames={600} />);
|
||||
```
|
||||
|
||||
`raea/music` is the shorthand for notes on named instruments (`new Part("bass", [...])`, `<Music>`). It plays
|
||||
through the same Tone layer, so the two mix. Its named instruments are Tone synth presets (`pad` is a PolySynth of
|
||||
fat saws, `kick` a MembraneSynth), good for a sketch or a test, not a score: write the score on sampled instruments,
|
||||
as above. It also reads and writes MIDI files (`parseMidi`, `toMidi`; `motion/sources`).
|
||||
`raea/music` (notes on named Tone presets, and MIDI files read and written: `parseMidi`, `toMidi`) is for tests of
|
||||
the sound layer, never a piece's music.
|
||||
@@ -3,9 +3,9 @@
|
||||
## What to do
|
||||
|
||||
- Decide what each scene is heard as before placing anything: silence, the scene's own sound (footsteps, a room, a
|
||||
machine: what the people on screen would hear), source music, score, effects, a voice. Music is a decision per
|
||||
scene, never a bed by default (`motion/music` has the spotting and the writing; `motion/sources` where each sound
|
||||
can come from).
|
||||
machine: what the people on screen would hear), source music, effects, a voice, the music bed. Whether the piece
|
||||
has music is its brief's or method's call; when it has, it's one bed from `raea gen music` (`motion/music`;
|
||||
`motion/sources` says where each other sound can come from).
|
||||
- Put each sound in its own `<Sequence from={frame} layout="none" name>` with an `<Audio>` inside. The Sequence's
|
||||
`from` is when the sound starts, and its `durationInFrames` (optional) cuts it off. `layout="none"` because a sound
|
||||
draws nothing.
|
||||
@@ -28,11 +28,10 @@
|
||||
- Place what's in the scene where it is: pan it to its side of the frame (`Tone.Panner`, a Channel's `pan`), give
|
||||
it the room's reverb, and narrow a device (a phone, a radio) with a high-pass and a low-pass. In 3D, `<Sound3D
|
||||
src at>` places it and the camera hears it move.
|
||||
- When the piece has music, write it in Tone.js on `Tone.buses.music` (`motion/music`): instruments in a `Sampler`
|
||||
(a sample library's notes, or TokenSynth's), parts in a `Part` or `Sequence`, composed for the cut. Duck it under
|
||||
the voice with `Tone.buses.music.duck(Tone.buses.voice, { amount: -12 })`, give the voice `<Audio bus="voice">`,
|
||||
and set the music's level on the bus: `Tone.buses.music.volume.value = -21`, then
|
||||
`Tone.buses.music.volume.rampTo(-12, 0.3, t)` to lift it at `t` seconds for the end card.
|
||||
- When the piece has music, it's one instrumental bed from `raea gen music` (`motion/music`), laid under the whole
|
||||
piece on `bus="music"` with the voice on `<Audio bus="voice">`. Duck it under the voice with
|
||||
`Tone.buses.music.duck(Tone.buses.voice, { amount: -12 })`; `raea check` says when it's lost or fights the voice,
|
||||
with the gainDb that fixes it.
|
||||
- Narration over the picture, when the footage has no voice for it, is
|
||||
`<Speech text="the words" start={frame} />` from `raea/speech` (Pocket TTS, on this computer; `voice` picks a
|
||||
Pocket voice or a WAV of one).
|
||||
@@ -84,10 +83,10 @@ says what that fetches). It does better on effects and field recordings than on
|
||||
the same sound, and changing one word of the prompt makes a new one. So settle the prompt before you iterate on
|
||||
gains.
|
||||
|
||||
Policy: music is notes on Tone.js instruments (sample libraries first, TokenSynth, synths), SAO and recorded packs
|
||||
make effects and foley, and Pocket TTS (`<Speech>`) says narration over the picture, all on this computer. Any other
|
||||
generation is a `raea gen` step (`motion/gen`). (`lyria()`, a remote music model, is retired: a new take is refused,
|
||||
and music written as notes can be cut on the bar and edited note by note anyway.)
|
||||
Policy, the same everywhere raea runs: a piece's music is one instrumental bed from `raea gen music` (raea cloud's
|
||||
`generate` tool is the same model; `motion/music`), SAO and recorded packs make effects and foley, and Pocket TTS
|
||||
(`<Speech>`) says narration over the picture. Any other generation is a `raea gen` step (`motion/gen`). (`lyria()` is
|
||||
retired: a new take is refused.)
|
||||
|
||||
Sound sells the cut, but one move everywhere is a lint: a whoosh on every entrance flattens all of them. Give
|
||||
foley to the moments that are physical (a slam, a strike-through, a card landing on the beat) and let others be
|
||||
@@ -130,8 +129,8 @@ ends up shouting over the narrator while another is inaudible.
|
||||
- Rewording a `sao()` prompt on every pass. Each new prompt makes a new sound.
|
||||
- `style` on an `<Audio>`: Audio has no picture and takes no style.
|
||||
- Hand-placing dozens of game sounds from a log. Cue them from `useGameEvents` (`motion/games`).
|
||||
- Writing music note by note in `<Audio>` files, or a game's sounds by hand. Write them in Tone.js (`motion/music`):
|
||||
instruments, the Transport, buses with ducking, and `<Tone.Sfx>` for one-shots.
|
||||
- Music written note by note, in `<Audio>` files or in Tone.js: a piece's music is a `raea gen music` bed
|
||||
(`motion/music`). A game's sounds placed by hand: fire each one-shot with `<Tone.Sfx>` on its event's frame.
|
||||
|
||||
## Example: a cue that lands on the end card, a voice, a layered hit
|
||||
|
||||
@@ -143,31 +142,10 @@ import { css } from "./styles.gen";
|
||||
const FRAMES = 300;
|
||||
const END_CARD = 252; // the voice stops here
|
||||
|
||||
// the music (motion/music): a sampled piano, chords that change every bar under a motif that answers the voice,
|
||||
// ducked under it, lifted for the end card, and ending on a chord on that cut. The tempo is set from the cut:
|
||||
// four bars to the end card, so its cut is a downbeat.
|
||||
Tone.getTransport().bpm.value = (4 * 4 * 60 * 30) / END_CARD; // about 114 bpm
|
||||
// the music (motion/music): one bed from `raea gen music "warm acoustic, light, instrumental, no vocals" --seconds 12
|
||||
// -o public/music`, ducked under the voice
|
||||
Tone.buses.music.duck(Tone.buses.voice, { amount: -12 });
|
||||
Tone.buses.music.volume.value = -21;
|
||||
Tone.buses.music.volume.rampTo(-12, 0.33, END_CARD / 30);
|
||||
// `raea make sounds get salamander/piano` printed its roots a minor third apart (D#2 is the file Ds2.mp3); these cover
|
||||
// F2 to G5, what the cue plays
|
||||
const ROOTS = ["D#2", "F#2", "A2", "C3", "D#3", "F#3", "A3", "C4", "D#4", "F#4", "A4", "C5", "D#5", "F#5"];
|
||||
const piano = new Tone.Sampler({
|
||||
urls: Object.fromEntries(ROOTS.map((n) => [n, staticFile(`sounds/salamander-piano/${n.replace("#", "s")}.mp3`)])),
|
||||
release: 1,
|
||||
}).connect(new Tone.Reverb({ decay: 1.4, wet: 0.2 }).connect(Tone.buses.music));
|
||||
const CHORDS = [["A2", "E3", "C4"], ["F2", "C3", "A3"], ["C3", "G3", "E4"], ["G2", "D3", "B3"]];
|
||||
new Tone.Part((t, c) => piano.triggerAttackRelease(c.notes, "4n", t, c.vel), CHORDS.flatMap((chord, bar) => [
|
||||
{ time: `${bar}:0`, notes: chord, vel: 0.55 },
|
||||
{ time: `${bar}:2:2`, notes: chord, vel: 0.4 },
|
||||
])).start(0);
|
||||
new Tone.Part((t, n) => piano.triggerAttackRelease(n.note, "8n", t, n.vel), [
|
||||
{ time: "1:1", note: "E5", vel: 0.7 }, { time: "1:1:2", note: "D5", vel: 0.5 }, { time: "1:2", note: "C5", vel: 0.6 }, { time: "1:3", note: "A4", vel: 0.65 },
|
||||
{ time: "3:1", note: "G5", vel: 0.75 }, { time: "3:1:2", note: "F5", vel: 0.5 }, { time: "3:2", note: "E5", vel: 0.6 }, { time: "3:3", note: "D5", vel: 0.7 },
|
||||
]).start(0);
|
||||
Tone.getTransport().schedule((t) => piano.triggerAttackRelease(["A2", "E3", "A3", "C4", "E4"], "1m", t, 0.8), "4m");
|
||||
Tone.getTransport().start();
|
||||
const BED = staticFile("music/bed.mp3");
|
||||
|
||||
// one hit in three layers, on the same frame: the snap that starts it, the body that says what it is, the room's tail
|
||||
const SNAP = sao("sharp wooden snap, close, very short, dry", { seconds: 0.3 });
|
||||
@@ -183,6 +161,7 @@ const SOUNDS = [
|
||||
{ id: "hit-tail", from: 0, gainDb: -24, src: TAIL, fade: 0, bus: "sfx" },
|
||||
{ id: "voice", from: 15, to: END_CARD, gainDb: 0, src: VOICE, fade: 0.012, bus: "voice" },
|
||||
{ id: "pop", from: END_CARD + 2, gainDb: -17, src: POP, fade: 0, bus: "sfx" },
|
||||
{ id: "bed", from: 0, gainDb: -10, src: BED, fade: 0.3, bus: "music" },
|
||||
] as const;
|
||||
|
||||
export default function SoundBed() {
|
||||
|
||||
@@ -33,23 +33,15 @@ piece's modes isn't asked.
|
||||
- again (play): After a failure, is it clear what went wrong and is the next attempt one press away?
|
||||
- task (tool): Can the task the screen exists for be done without stopping to work out where to look?
|
||||
|
||||
## Music that sounds generated
|
||||
## Music
|
||||
|
||||
Listen for these before the decision model does; each is how a made score gives itself away, and the fix
|
||||
(`motion/music`):
|
||||
A piece's music is one instrumental bed from `raea gen music` (`motion/music`). Listen for:
|
||||
|
||||
- **One held texture.** A pad, a sine sub and a long reverb under everything, no attack anywhere. Write a motif, chords
|
||||
that move and a part with rhythm; reverb per instrument, nothing on the bus.
|
||||
- **Harmony that stands still.** One chord for four bars or more in a cue that's meant to move. Change it every bar or two.
|
||||
- **A loop, not a cue.** The same two bars for thirty seconds. Vary the motif, change the arrangement every four to
|
||||
eight bars, and turn where the edit turns.
|
||||
- **Played by a machine.** Every note at one velocity, exactly on the grid. Spread the dynamics; move played parts a
|
||||
few milliseconds; use a recorded groove.
|
||||
- **No ending.** A fade-out. End on a chord or a hit on the last cut.
|
||||
- **Everywhere.** Music under every scene because the piece "needs music". Some scenes belong to silence or to their
|
||||
own sound.
|
||||
- **The wrong source.** A whole score from TokenSynth takes (organ-like sustains, buzz) or from an SAO "ambient
|
||||
music" prompt. Recorded instruments play the parts; TokenSynth fills a timbre no library has; SAO makes effects.
|
||||
- **A voice in the bed.** Lyrics or a sung line under someone talking. Make it again, "instrumental, no vocals".
|
||||
- **A bed that fights the voice, or is lost under it.** `raea check` measures both and gives the gainDb.
|
||||
- **The wrong feel.** A bed that isn't what the brief or the brand asks for (upbeat where it says warm, a club beat
|
||||
under a quiet interview). Make it again with the brief's words.
|
||||
- **More than one.** A second track, a sting or a riser added to fix the first. Make the one bed better instead.
|
||||
|
||||
## Ranking
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@ sound: voice, music, foley and the master.
|
||||
## Change
|
||||
- The voice first; duck music and foley under it.
|
||||
- Sound marks moments: a hit on the cut that matters, silence before the drop. Remove what only fills.
|
||||
- Music: composed for the cut (`motion/music`) on recorded instruments first; TokenSynth takes are curated, not
|
||||
trusted. Under a voice, thin the arrangement and let the tune answer between lines.
|
||||
- Music: one instrumental bed from `raea gen music` (`motion/music`), ducked under the voice.
|
||||
- Effects: layered (a transient, a body, a tail), with repeats varied (`motion/sound`).
|
||||
- Master at -14 LUFS integrated, true peak at or below -1 dBTP.
|
||||
|
||||
|
||||
+1
-1
Submodule skills updated: a67a08005f...d8c16de985.
Reference in new issue
Block a user