/** * Synthetic snippet library for the node tests: three event types (low * ringing tone, high short tone, repeatable noise burst) standing in for * recorded taps. A tap excites the struck object's impulse response, so * instances of one type are highly repeatable up to gain and small * decay/pitch drift; the burst type reuses one fixed noise pattern (the * "object") rather than fresh noise per instance. */ import { mulberry32 } from '../src/bench/rng.ts'; import { FS, type SnippetLibrary } from '../src/bench/types.ts'; export const PRE_S = 0.02, POST_S = 0.18; export function makeSyntheticLibrary(perType = 120, seed = 42): SnippetLibrary { const pre = Math.round(PRE_S * FS), post = Math.round(POST_S * FS); const snipLen = pre + post; const rng = mulberry32(seed); const burstBase = new Float32Array(post); { const brng = mulberry32(7); for (let i = 0; i < post; i++) burstBase[i] = brng() * 2 - 1; } function makeSnippet(kind: number): Float32Array { const s = new Float32Array(snipLen); const jitF = 1 + 0.01 * (rng() - 0.5); const jitT = 1 + 0.2 * (rng() - 0.5); if (kind === 0) { const f = 300 * jitF, tau = 0.06 * jitT; for (let i = 0; i < post; i++) { const t = i / FS; s[pre + i] = Math.exp(-t / tau) * Math.sin(2 * Math.PI * f * t) * 0.8; } } else if (kind === 1) { const f = 1400 * jitF, tau = 0.025 * jitT; for (let i = 0; i < post; i++) { const t = i / FS; s[pre + i] = Math.exp(-t / tau) * Math.sin(2 * Math.PI * f * t) * 0.8; } } else { const tau = 0.012 * jitT; for (let i = 0; i < post; i++) { const t = i / FS; s[pre + i] = Math.exp(-t / tau) * (burstBase[i] + 0.15 * (rng() * 2 - 1)) * 0.7; } } for (let i = 0; i < snipLen; i++) s[i] += (rng() * 2 - 1) * 0.002; return s; } const lib: SnippetLibrary = { names: ['low', 'high', 'burst'], pre, post, snippets: [] }; for (let k = 0; k < 3; k++) { for (let e = 0; e < perType; e++) lib.snippets.push({ typeIndex: k, samples: makeSnippet(k) }); } return lib; }