diff --git a/tools/dings-voices/src/findings.py b/tools/dings-voices/src/findings.py deleted file mode 100644 index 41d8b0f..0000000 --- a/tools/dings-voices/src/findings.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python3 -"""findings.py : the v2-vs-v3 numbers quoted by the README and page (void ends and tick, libby per-note level and tail, kiko onset and partials, -proposal distances). Reads decoded oggs; prints JSON.""" -import sys, os, json, numpy as np, soundfile as sf -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) -from metriclib import * -v2, v3 = sys.argv[1], sys.argv[2] -rd = lambda p: sf.read(p)[0] -db = lambda x: float(20 * np.log10(max(x, 1e-12))) -out = {} -# Void: last 50 ms, and the tick (largest 1-sample step over the clip, as a multiple of the median step in the 20 ms before the tick) -void = {} -for m in ["mention", "dm", "message", "invite"]: - row = {} - for tag, root in [("v2", v2 + "/void"), ("v3", v3 + "/senders/void")]: - z = rd(f"{root}/{m}.ogg"); k = SR // 20; t = z[-k:]; step = np.abs(np.diff(z)); j = int(np.argmax(step[SR // 20:])) + SR // 20 - base = np.median(step[max(0, j - SR // 50):j]) if j > 0 else 1e-9 - row[tag] = dict(last50TruePeakDbTP=round(true_peak_db(t), 2), last50ClippedSamples=int(np.sum(np.abs(t) >= 0.999)), clipClippedSamples=int(np.sum(np.abs(z) >= 0.999)), - clipTruePeakDbTP=round(true_peak_db(z), 2), maxStepAtMs=round(j / 48, 1), maxStepVsMedianStepX=round(float(step[j] / max(base, 1e-12)), 1)) - void[m] = row -out["void"] = void -# Libby: per-note peak and the level of the previous note when the next lands, plus note-1 first-120ms centroid -ons = {"mention": [0], "message": [0, 230], "dm": [0, 240], "invite": [0, 200, 300]}; lib = {} -for m in ons: - row = {} - for tag, root in [("v2", v2 + "/libby"), ("v3", v3 + "/senders/libby")]: - z = rd(f"{root}/{m}.ogg"); notes = [] - for j, o in enumerate(ons[m]): - seg = z[o * 48:(o + 120) * 48]; X = np.abs(np.fft.rfft(seg * np.hanning(len(seg)), 8192)) ** 2; f = np.fft.rfftfreq(8192, 1 / SR) - prior = round(db(np.max(np.abs(z[(o - 10) * 48:o * 48])) / np.max(np.abs(z))), 1) if o else None - notes.append(dict(onsetMs=o, peakDbFS=round(db(np.max(np.abs(seg))), 1), centroidHz=round(float(np.sum(f * X) / np.sum(X))), priorTailDbReClipPeak=prior)) - row[tag] = dict(durationMs=round(1000 * len(z) / SR, 1), notes=notes) - lib[m] = row -out["libby"] = lib -# Kiko: onset rise (mention), first-5-ms envelope, partial ratios from the first 60 ms spectrum of the mention, decay of each partial -def partials(z): - seg = z[int(0.004 * SR):int(0.20 * SR)]; N = 1 << 17; X = np.abs(np.fft.rfft(seg * np.hanning(len(seg)), N)); f = np.fft.rfftfreq(N, 1 / SR) - ps = []; used = np.zeros(len(X), bool) - for _ in range(4): - m = np.where(used, 0, X); i = int(np.argmax(m)); - if m[i] < X.max() * 10 ** (-50 / 20): break - ps.append((float(f[i]), db(X[i] / X.max()))); used[max(0, i - 400):i + 400] = True - ps.sort(); return [dict(hz=round(h, 1), ratio=round(h / ps[0][0], 3), dbRe1stPartial=round(a - ps[0][1], 1)) for h, a in ps] -k = {} -for tag, root in [("v2", v2 + "/kiko"), ("v3", v3 + "/senders/kiko")]: - z = rd(f"{root}/mention.ogg"); k[tag] = dict(onsetRiseMs=round(onset_rise_ms(z), 2), onsetMs=round(onset_time_ms(z), 1), centroidHz=round(spectral(z)[0]), partials=partials(z)) -out["kiko"] = k -# fundamentals of the bell/glass/FM families, same measure (peaks in the first 200 ms of each mention) -fam = {} -for name, root in [("libby", v3 + "/senders/libby"), ("kiko", v3 + "/senders/kiko"), ("nibu2", v3 + "/proposals/nibu2")]: - z = rd(f"{root}/mention.ogg"); fam[name] = dict(onsetRiseMs=round(onset_rise_ms(z), 2), partials=partials(z)) -out["families"] = fam -print(json.dumps(out, indent=1)) diff --git a/tools/dings-voices/src/polyphony.test.mjs b/tools/dings-voices/src/polyphony.test.mjs index 804c140..806ecb5 100644 --- a/tools/dings-voices/src/polyphony.test.mjs +++ b/tools/dings-voices/src/polyphony.test.mjs @@ -23,4 +23,37 @@ for (const m of ["dm", "invite"]) { assert.ok(len(renderNote("libby", m, on.length - 1)) - Math.round(on[on.length - 1][0] * SR / 1000) > len(x) - Math.round(on[i][0] * SR / 1000), `libby ${m}: last note rings longer than note ${i}`); } } -console.log(`ok: ${names.length * MOTIFS.length} clips are the sum of per-note renders; notes are independent of each other's pitch and noise`); +// 4. One onset per note. An onset is a rise of a 1 ms peak envelope (4 ms window) of at least ONSET_RISE_DB over the quietest point of the 15 ms before it, above +// -45 dB re that band's peak, in the full band or above 1.5 kHz (a dry tick or click is broadband and sits level with the tone, so only the high band shows it). +// Rises within 20 ms of each other are one onset (a note's own attack takes ~9 ms). A hit riding a release (v3 Void's tick), a re-attack or a ring that swells under +// the next note adds one. Void is checked for every motif: a clip must have exactly as many onsets as notes, at the notes' times. +const ONSET_RISE_DB = 6; +function highpass(x, fc) { // two cascaded RBJ biquads, Q 0.707 + const w = 2 * Math.PI * fc / 48000, c = Math.cos(w), al = Math.sin(w) / (2 * 0.707), a0 = 1 + al, b0 = (1 + c) / 2 / a0, b1 = -(1 + c) / a0, a1 = -2 * c / a0, a2 = (1 - al) / a0; + let y = Float64Array.from(x); for (let pass = 0; pass < 2; pass++) { const o = new Float64Array(y.length); for (let n = 0; n < y.length; n++) o[n] = b0 * y[n] + b1 * (y[n - 1] || 0) + b0 * (y[n - 2] || 0) - a1 * (o[n - 1] || 0) - a2 * (o[n - 2] || 0); y = o; } + return y; +} +function riseMs(x, rise) { + const m = Math.floor(x.length / 48), env = new Float64Array(m); + for (let i = 0; i < m; i++) { let p = 0; for (let k = Math.max(0, (i - 3) * 48); k < (i + 1) * 48; k++) p = Math.max(p, Math.abs(x[k])); env[i] = p; } + const top = Math.max(...env), db = (v) => 20 * Math.log10(Math.max(v, 1e-9) / top), out = []; + for (let i = 1; i < m; i++) { const lo = Math.min(...Array.from(env.subarray(Math.max(0, i - 15), i), db)); if (db(env[i]) > -45 && db(env[i]) - lo >= rise) out.push(i); } + return out; +} +function onsetsMs(x) { + const all = [...riseMs(x, ONSET_RISE_DB), ...riseMs(highpass(x, 1500), ONSET_RISE_DB)].sort((p, q) => p - q), out = []; + for (const i of all) if (!out.length || i - out[out.length - 1].last > 20) out.push({ first: i, last: i }); else out[out.length - 1].last = i; + return out.map((o) => o.first); +} +for (const m of MOTIFS) { + const found = onsetsMs(renderClip("void", m)), expect = RHYTHM[m].map(([ms]) => ms); + assert.equal(found.length, expect.length, `void ${m}: onsets at ${found.join(", ")} ms, notes at ${expect.join(", ")} ms`); + found.forEach((f, i) => assert.ok(f >= expect[i] && f < expect[i] + 20, `void ${m}: onset ${f} ms is not at note ${i} (${expect[i]} ms)`)); + RHYTHM[m].forEach((_, i) => assert.equal(onsetsMs(renderNote("void", m, i)).length, 1, `void ${m} note ${i} alone has more than one onset`)); +} +// 5. Nibu (the 8 kHz 5-bit sine): a note something follows is silent by the next onset (notes do not overlap). +for (const m of ["dm", "message", "invite"]) for (let i = 0; i < RHYTHM[m].length - 1; i++) { + const x = renderNote("nibu", m, i), nextAt = Math.round(RHYTHM[m][i + 1][0] * 48), after = x.subarray(nextAt).reduce((a, v) => Math.max(a, Math.abs(v)), 0); + assert.ok(after < 1e-6 * peak(x), `nibu ${m} note ${i} still sounds at ${after / peak(x)} of its peak after note ${i + 1} starts`); +} +console.log(`ok: ${names.length * MOTIFS.length} clips are the sum of per-note renders; notes are independent of each other's pitch and noise; Void has one onset per note; Nibu notes do not overlap`); diff --git a/tools/dings-voices/src/voices.mjs b/tools/dings-voices/src/voices.mjs index f9f1205..effb869 100644 --- a/tools/dings-voices/src/voices.mjs +++ b/tools/dings-voices/src/voices.mjs @@ -40,10 +40,6 @@ function partials(buf, t0, f0, parts, atkMs, lenMs, gain = 1) { const len = Math.min(buf.length - t0, at(lenMs)), atk = at(atkMs), s = Math.min(1, (len / SR) / (4.6 * Math.max(...parts.map((p) => p[2])))), fade = Math.min(at(15), len >> 2); for (let n = 0; n < len; n++) { let y = 0; for (const [r, a, tau] of parts) y += a * Math.exp(-n / SR / (tau * s)) * Math.sin(TAU * f0 * r * n / SR); buf[t0 + n] += gain * y * Math.min(1, (n + 1) / atk) * Math.sin(Math.PI / 2 * Math.min(1, (len - n) / fade)) ** 2; } } -function noiseBurst(buf, t0, rand, type, fc, q, atkMs, tau, lenMs, gain) { - const f = biquad(type, fc, q), len = Math.min(buf.length - t0, at(lenMs)), atk = at(atkMs); - for (let n = 0; n < len; n++) buf[t0 + n] += gain * run(f, rand()) * env(n, atk, tau, len); -} function sine(buf, t0, hz0, hz1, glideTau, atkMs, tau, lenMs, gain) { const len = Math.min(buf.length - t0, at(lenMs)), atk = at(atkMs), s = Math.min(1, (len / SR) / (4.6 * tau)), fade = Math.min(at(15), len >> 2); let ph = 0; for (let n = 0; n < len; n++) { const hz = hz1 + (hz0 - hz1) * Math.exp(-n / SR / glideTau); ph += TAU * hz / SR; buf[t0 + n] += gain * Math.sin(ph) * Math.min(1, (n + 1) / atk) * Math.exp(-n / SR / (tau * s)) * Math.sin(Math.PI / 2 * Math.min(1, (len - n) / fade)) ** 2; } @@ -68,16 +64,16 @@ export const VOICES = { partials(b, t, 1318 * st(d), [[1, 1, 0.12 * k], [2.76, 0.45, 0.07 * k], [5.4, 0.2, 0.04 * k]], 1, len, 0.8); } }, libby: { object: "a small bell", family: "soft bell", caption: "One small bell note with a felt-soft start, no strike. A note that something follows is shortened to settle before the next one lands; the last note rings.", hit(b, t, d, i, n, gap, r, m, room) { const last = i === n - 1, k = last ? 2 : 1, len = last ? Math.min(520, room - 10) : Math.min(gap, room); bell(b, t, 784 * st(d), [[1, 1, 0.1 * k], [2.32, 0.22, 0.06 * k], [3.9, 0.06, 0.03 * k]], 26, len, 0.85); } }, - void: { object: "a hollow wooden note", family: "hollow wood", caption: "One round, hollow, almost wooden note that falls a little, finishing on a tiny dry tick. Higher than the horn.", - hit(b, t, d, i, n, gap, r, m, room) { const f = 300 * st(d); const k = m === "mention" ? 2 : 1; sine(b, t, f * 1.2, f * 0.85, 0.05, 9, 0.085 * k, Math.min(230 * k, room), 0.9); sine(b, t, f * 2.4, f * 1.7, 0.05, 9, 0.03 * k, Math.min(120 * k, room), 0.12); - // the tick is a soft knock, not a click: 4 ms attack (v2: 0.5 ms), peak level with the tone it lands on (v2: 3.3 dB over it) - noiseBurst(b, t + at(95 * k), r, "bp", 1800, 1.0, 4, 0.006, 24, 0.05 * (room > 130 * k ? 1 : 0)); } }, + void: { object: "a hollow wooden note", family: "hollow wood", caption: "One round, hollow, almost wooden note that falls a little and settles. Higher than the horn. One onset per note: nothing rides the release.", + // v4: no tick (v3's soft knock 95 ms into every note was the second hit Meta heard), and a note something follows ends by the next onset (as Libby's do), so a note's ring never re-rises under the next attack. + hit(b, t, d, i, n, gap, r, m, room) { const f = 300 * st(d), k = m === "mention" ? 2 : 1, rm = i + 1 < n ? Math.min(room, gap) : room; + sine(b, t, f * 1.2, f * 0.85, 0.05, 9, 0.085 * k, Math.min(230 * k, rm), 0.9); sine(b, t, f * 2.4, f * 1.7, 0.05, 9, 0.03 * k, Math.min(120 * k, rm), 0.12); } }, weksa: { object: "a plucked brass compass", family: "plucked brass", caption: "A small plucked brass note, then a small bright rise: the sound of finding the thing. In a mention, just the one pluck.", hit(b, t, d, i, n, gap, r, m, room) { const br = 0.35 + 0.3 * i, k = m === "mention" ? 2 : 1; partials(b, t, 880 * st(d), [[1, 1, 0.06 * k], [2, 0.55, 0.045 * k], [3, br, 0.03 * k], [4, br * 0.6, 0.02 * k]], 3.5, Math.min(m === "mention" ? 480 : 240, room), 0.7); } }, }; // Nibu is the one openly synthetic voice. v2's glided saw was rejected (Meta, 2026-11-10: atrocious), so there are three proposals from three -// families, none with a pitch glide; Nibu and Meta choose. VOICES.nibu is proposal 1 as a placeholder until they do. +// families, none with a pitch glide; Nibu and Meta choose. VOICES.nibu is proposal 3 (chosen by Nibu and Meta, 2026-11-10); proposals 1 and 2 stay as non-default alternates. // shape: raised-cosine in over atk samples, raised-cosine out over the last rel samples. const shape = (k, len, atk, rel) => Math.sin(Math.PI / 2 * Math.min(1, (k + 1) / atk)) ** 2 * Math.sin(Math.PI / 2 * Math.min(1, (len - k) / rel)) ** 2; // the held-note length: a note something follows ends by the next onset; the last note rings as long as the motif allows. @@ -93,7 +89,7 @@ export const NIBU_PROPOSALS = { hit(b, t, d, i, n, gap, r, m, room) { const last = i === n - 1, len = heldLen(b, t, 520, last, gap, room), f = 349.2 * st(d), tau = last ? 0.18 : 0.1, s = Math.min(1, (len / SR) / (4.6 * tau)), atk = at(12), rel = Math.min(at(20), len >> 2), lp = [biquad("lp", 2600, 0.7), biquad("lp", 2600, 0.7)]; let held = 0; for (let k = 0; k < len; k++) { if (k % 6 === 0) held = Math.round(Math.sin(TAU * f * k / SR) * 16) / 16; b[t + k] += 0.9 * run(lp[1], run(lp[0], held)) * Math.exp(-k / SR / (tau * s)) * shape(k, len, atk, rel); } } }, }; -VOICES.nibu = { ...NIBU_PROPOSALS.nibu1 }; +VOICES.nibu = { ...NIBU_PROPOSALS.nibu3 }; const ALL = { ...VOICES, ...NIBU_PROPOSALS }; // Each note renders into its own buffer with its own noise stream (seeded by sender and note index), so no note can read or write // another's state; a clip is the sum of its notes. A note knows only what follows it (gap, room), never what precedes it.