@schmooky/zvuk 1.7.3 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +310 -2
- package/dist/index.js +649 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -136,7 +136,7 @@ async function expandGlob(pattern) {
|
|
|
136
136
|
}
|
|
137
137
|
const dir = dirname(pattern);
|
|
138
138
|
const base = basename(pattern);
|
|
139
|
-
const re = new RegExp(
|
|
139
|
+
const re = new RegExp(`^${base.replace(/\./g, "\\.").replace(/\*/g, ".*")}$`);
|
|
140
140
|
try {
|
|
141
141
|
const entries = await readdir(dir);
|
|
142
142
|
return entries.filter((n) => re.test(n)).map((n) => join(dir, n));
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/gen.ts","../src/cli/transcode.ts","../src/cli/index.ts"],"names":["parseArgs","resolve"],"mappings":";;;;;AA0BA,eAAsB,OAAO,IAAA,EAA+B;AAC1D,EAAA,MAAM,IAAA,GAAO,UAAU,IAAI,CAAA;AAC3B,EAAA,MAAM,GAAA,GAAM,MAAM,QAAA,CAAS,IAAA,CAAK,OAAO,OAAO,CAAA;AAC9C,EAAA,MAAM,QAAA,GAAyB,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA;AAC7C,EAAA,MAAM,OAAA,GAAU,UAAU,QAAQ,CAAA;AAClC,EAAA,MAAM,GAAA,GAAM,MAAA,CAAO,OAAA,EAAS,QAAA,CAAS,UAAU,CAAA;AAC/C,EAAA,MAAM,SAAA,CAAU,IAAA,CAAK,GAAA,EAAK,GAAA,EAAK,OAAO,CAAA;AACtC,EAAA,OAAA,CAAQ,OAAO,KAAA,CAAM,CAAA,MAAA,EAAS,KAAK,GAAG,CAAA,EAAA,EAAK,QAAQ,MAAM,CAAA;A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KAAA,EAAO;AACV,MAAA,MAAM,OAAO,IAAI,CAAA;AACjB,MAAA;AAAA,IACF;AAAA,IACA,KAAK,QAAA;AAAA,IACL,KAAK,IAAA;AAAA,IACL,KAAK,MAAA,EAAW;AACd,MAAA,OAAA,CAAQ,MAAA,CAAO,MAAM,KAAK,CAAA;AAC1B,MAAA;AAAA,IACF;AAAA,IACA,SAAS;AACP,MAAA,OAAA,CAAQ,MAAA,CAAO,KAAA,CAAM,CAAA,iBAAA,EAAoB,GAAG;;AAAA,EAAO,KAAK,CAAA,CAAE,CAAA;AAC1D,MAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,IAChB;AAAA;AAEJ;AAEA,IAAA,EAAK,CAAE,KAAA,CAAM,CAAC,CAAA,KAAM;AAClB,EAAA,OAAA,CAAQ,OAAO,KAAA,CAAM,CAAA,EAAI,CAAA,CAAY,KAAA,IAAU,EAAY,OAAO;AAAA,CAAI,CAAA;AACtE,EAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAChB,CAAC,CAAA","file":"cli.js","sourcesContent":["import { readFile, writeFile } from 'node:fs/promises';\nimport { resolve } from 'node:path';\n\ninterface BankEntry {\n name: string;\n url: string | string[];\n bus?: string;\n loop?: boolean;\n}\n\ninterface BankManifest {\n /** Optional default bus that all entries fall back to. */\n defaultBus?: string;\n /** Sound entries — keyed by name or as an array. */\n sounds: BankEntry[] | Record<string, Omit<BankEntry, 'name'>>;\n}\n\n/**\n * Read a sound manifest JSON and emit a typed module:\n *\n * - the union of every sound name (`SoundName`)\n * - a `loadBank(engine)` function that calls `engine.loadSound` for each\n *\n * Drop the generated file into your repo and `engine.sound(\"coin\")` will be\n * autocompleted as a literal type.\n */\nexport async function runGen(argv: string[]): Promise<void> {\n const args = parseArgs(argv);\n const raw = await readFile(args.input, 'utf-8');\n const manifest: BankManifest = JSON.parse(raw);\n const entries = normalize(manifest);\n const out = render(entries, manifest.defaultBus);\n await writeFile(args.out, out, 'utf-8');\n process.stdout.write(`Wrote ${args.out} (${entries.length} entries).\\n`);\n}\n\ninterface ParsedArgs {\n input: string;\n out: string;\n}\n\nfunction parseArgs(argv: string[]): ParsedArgs {\n const out: ParsedArgs = { input: '', out: 'bank.gen.ts' };\n for (let i = 0; i < argv.length; i++) {\n const a = argv[i]!;\n if (a === '--out') out.out = argv[++i] ?? out.out;\n else out.input = a;\n }\n if (!out.input) {\n process.stderr.write('Usage: zvuk gen <bank.json> [--out bank.gen.ts]\\n');\n process.exit(1);\n }\n out.input = resolve(out.input);\n out.out = resolve(out.out);\n return out;\n}\n\nfunction normalize(manifest: BankManifest): BankEntry[] {\n if (Array.isArray(manifest.sounds)) return manifest.sounds;\n return Object.entries(manifest.sounds).map(([name, entry]) => ({ name, ...entry }));\n}\n\nfunction render(entries: BankEntry[], defaultBus: string | undefined): string {\n const names = entries.map((e) => e.name);\n const lines: string[] = [];\n lines.push('// AUTOGENERATED by `zvuk gen`. Do not edit.');\n lines.push(\"import type { Engine, LoadSoundOptions } from '@schmooky/zvuk';\");\n lines.push('');\n lines.push('export type SoundName =');\n for (let i = 0; i < names.length; i++) {\n lines.push(` | ${JSON.stringify(names[i])}${i === names.length - 1 ? ';' : ''}`);\n }\n lines.push('');\n lines.push('export const BANK = [');\n for (const e of entries) {\n const url = JSON.stringify(e.url);\n const opts: string[] = [];\n if (e.bus) opts.push(`bus: ${JSON.stringify(e.bus)}`);\n if (e.loop) opts.push('loop: true');\n lines.push(\n ` { name: ${JSON.stringify(e.name)}, url: ${url}${opts.length ? `, options: { ${opts.join(', ')} }` : ''} },`,\n );\n }\n lines.push('] as const;');\n lines.push('');\n lines.push('export interface BankLoadOptions extends Omit<LoadSoundOptions, \"bus\"> {}');\n lines.push('');\n lines.push(\n 'export async function loadBank(engine: Engine, options: BankLoadOptions = {}): Promise<void> {',\n );\n lines.push(' await Promise.all(');\n lines.push(' BANK.map((entry) =>');\n if (defaultBus) {\n lines.push(\n ` engine.loadSound(entry.name, entry.url, { bus: ${JSON.stringify(defaultBus)}, ...entry.options, ...options }),`,\n );\n } else {\n lines.push(' engine.loadSound(entry.name, entry.url, { ...entry.options, ...options }),');\n }\n lines.push(' ),');\n lines.push(' );');\n lines.push('}');\n lines.push('');\n return lines.join('\\n');\n}\n","import { spawn } from 'node:child_process';\nimport { mkdir, readdir, stat } from 'node:fs/promises';\nimport { basename, dirname, extname, join, resolve } from 'node:path';\n\ninterface TranscodeArgs {\n inputs: string[];\n out: string;\n bitrate: string;\n formats: ('webm' | 'm4a')[];\n}\n\n/**\n * The asset-formats guide ffmpeg loop, packaged. For each input file produces:\n * <name>.webm (libopus) — small, plays everywhere except old iOS Safari.\n * <name>.m4a (aac) — fallback for the codec ladder.\n *\n * Requires ffmpeg on PATH. The CLI is a thin wrapper — we don't bundle ffmpeg.\n */\nexport async function runTranscode(argv: string[]): Promise<void> {\n const args = parseArgs(argv);\n await mkdir(args.out, { recursive: true });\n const expanded = await expandInputs(args.inputs);\n if (expanded.length === 0) {\n process.stderr.write('No input files matched.\\n');\n process.exit(1);\n }\n for (const input of expanded) {\n const name = basename(input, extname(input));\n for (const fmt of args.formats) {\n const target = join(args.out, `${name}.${fmt}`);\n const codecArgs =\n fmt === 'webm'\n ? ['-c:a', 'libopus', '-b:a', args.bitrate, '-vn']\n : ['-c:a', 'aac', '-b:a', args.bitrate, '-vn'];\n await runFfmpeg(['-y', '-i', input, ...codecArgs, target]);\n process.stdout.write(` → ${target}\\n`);\n }\n }\n}\n\nfunction parseArgs(argv: string[]): TranscodeArgs {\n const out: TranscodeArgs = {\n inputs: [],\n out: 'dist',\n bitrate: '96k',\n formats: ['webm', 'm4a'],\n };\n for (let i = 0; i < argv.length; i++) {\n const a = argv[i]!;\n if (a === '--out') {\n out.out = argv[++i] ?? out.out;\n } else if (a === '--bitrate') {\n out.bitrate = argv[++i] ?? out.bitrate;\n } else if (a === '--formats') {\n const list = (argv[++i] ?? '').split(',').map((s) => s.trim());\n out.formats = list.filter((s): s is 'webm' | 'm4a' => s === 'webm' || s === 'm4a');\n } else {\n out.inputs.push(a);\n }\n }\n return out;\n}\n\nasync function expandInputs(patterns: string[]): Promise<string[]> {\n const out: string[] = [];\n for (const p of patterns) {\n const abs = resolve(p);\n const matches = await expandGlob(abs);\n out.push(...matches);\n }\n return out;\n}\n\n/**\n * Minimal glob expander — handles `dir/*.wav` and explicit files only.\n * Avoids pulling in a glob dependency for a tool that's mostly an ffmpeg loop.\n */\nasync function expandGlob(pattern: string): Promise<string[]> {\n if (!pattern.includes('*')) {\n try {\n const s = await stat(pattern);\n return s.isFile() ? [pattern] : [];\n } catch {\n return [];\n }\n }\n const dir = dirname(pattern);\n const base = basename(pattern);\n const re = new RegExp('^' + base.replace(/\\./g, '\\\\.').replace(/\\*/g, '.*') + '$');\n try {\n const entries = await readdir(dir);\n return entries.filter((n) => re.test(n)).map((n) => join(dir, n));\n } catch {\n return [];\n }\n}\n\nfunction runFfmpeg(args: string[]): Promise<void> {\n return new Promise((res, rej) => {\n const proc = spawn('ffmpeg', args, { stdio: ['ignore', 'inherit', 'inherit'] });\n proc.on('error', rej);\n proc.on('exit', (code) => {\n if (code === 0) res();\n else rej(new Error(`ffmpeg exited with code ${code}`));\n });\n });\n}\n","#!/usr/bin/env node\nimport { runGen } from './gen';\nimport { runTranscode } from './transcode';\n\nconst USAGE = `zvuk — audio engine CLI\n\nUsage:\n zvuk transcode <glob> Run the standard ffmpeg ladder (webm/opus + m4a/aac) on each input.\n zvuk gen <bank.json> Emit a typed sound-name module from a manifest.\n\nOptions for \"transcode\":\n --out <dir> Output directory (default: dist).\n --bitrate <kbps> Audio bitrate, e.g. \"96k\" (default: 96k).\n --formats <list> Comma-separated formats: webm, m4a (default: webm,m4a).\n\nOptions for \"gen\":\n --out <file> Output .ts module path (default: bank.gen.ts).\n`;\n\nasync function main(): Promise<void> {\n const [, , cmd, ...rest] = process.argv;\n switch (cmd) {\n case 'transcode': {\n await runTranscode(rest);\n return;\n }\n case 'gen': {\n await runGen(rest);\n return;\n }\n case '--help':\n case '-h':\n case undefined: {\n process.stdout.write(USAGE);\n return;\n }\n default: {\n process.stderr.write(`Unknown command: ${cmd}\\n\\n${USAGE}`);\n process.exit(1);\n }\n }\n}\n\nmain().catch((e) => {\n process.stderr.write(`${(e as Error).stack ?? (e as Error).message}\\n`);\n process.exit(1);\n});\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/cli/gen.ts","../src/cli/transcode.ts","../src/cli/index.ts"],"names":["parseArgs","resolve"],"mappings":";;;;;AA0BA,eAAsB,OAAO,IAAA,EAA+B;AAC1D,EAAA,MAAM,IAAA,GAAO,UAAU,IAAI,CAAA;AAC3B,EAAA,MAAM,GAAA,GAAM,MAAM,QAAA,CAAS,IAAA,CAAK,OAAO,OAAO,CAAA;AAC9C,EAAA,MAAM,QAAA,GAAyB,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA;AAC7C,EAAA,MAAM,OAAA,GAAU,UAAU,QAAQ,CAAA;AAClC,EAAA,MAAM,GAAA,GAAM,MAAA,CAAO,OAAA,EAAS,QAAA,CAAS,UAAU,CAAA;AAC/C,EAAA,MAAM,SAAA,CAAU,IAAA,CAAK,GAAA,EAAK,GAAA,EAAK,OAAO,CAAA;AACtC,EAAA,OAAA,CAAQ,OAAO,KAAA,CAAM,CAAA,MAAA,EAAS,KAAK,GAAG,CAAA,EAAA,EAAK,QAAQ,MAAM,CAAA;AAAA,CAAc,CAAA;AACzE;AAOA,SAAS,UAAU,IAAA,EAA4B;AAC7C,EAAA,MAAM,GAAA,GAAkB,EAAE,KAAA,EAAO,EAAA,EAAI,KAAK,aAAA,EAAc;AACxD,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,IAAA,CAAK,QAAQ,CAAA,EAAA,EAAK;AACpC,IAAA,MAAM,CAAA,GAAI,KAAK,CAAC,CAAA;AAChB,IAAA,IAAI,CAAA,KAAM,SAAS,GAAA,CAAI,GAAA,GAAM,KAAK,EAAE,CAAC,KAAK,GAAA,CAAI,GAAA;A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OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,IAChB;AAAA;AAEJ;AAEA,IAAA,EAAK,CAAE,KAAA,CAAM,CAAC,CAAA,KAAM;AAClB,EAAA,OAAA,CAAQ,OAAO,KAAA,CAAM,CAAA,EAAI,CAAA,CAAY,KAAA,IAAU,EAAY,OAAO;AAAA,CAAI,CAAA;AACtE,EAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAChB,CAAC,CAAA","file":"cli.js","sourcesContent":["import { readFile, writeFile } from 'node:fs/promises';\nimport { resolve } from 'node:path';\n\ninterface BankEntry {\n name: string;\n url: string | string[];\n bus?: string;\n loop?: boolean;\n}\n\ninterface BankManifest {\n /** Optional default bus that all entries fall back to. */\n defaultBus?: string;\n /** Sound entries — keyed by name or as an array. */\n sounds: BankEntry[] | Record<string, Omit<BankEntry, 'name'>>;\n}\n\n/**\n * Read a sound manifest JSON and emit a typed module:\n *\n * - the union of every sound name (`SoundName`)\n * - a `loadBank(engine)` function that calls `engine.loadSound` for each\n *\n * Drop the generated file into your repo and `engine.sound(\"coin\")` will be\n * autocompleted as a literal type.\n */\nexport async function runGen(argv: string[]): Promise<void> {\n const args = parseArgs(argv);\n const raw = await readFile(args.input, 'utf-8');\n const manifest: BankManifest = JSON.parse(raw);\n const entries = normalize(manifest);\n const out = render(entries, manifest.defaultBus);\n await writeFile(args.out, out, 'utf-8');\n process.stdout.write(`Wrote ${args.out} (${entries.length} entries).\\n`);\n}\n\ninterface ParsedArgs {\n input: string;\n out: string;\n}\n\nfunction parseArgs(argv: string[]): ParsedArgs {\n const out: ParsedArgs = { input: '', out: 'bank.gen.ts' };\n for (let i = 0; i < argv.length; i++) {\n const a = argv[i]!;\n if (a === '--out') out.out = argv[++i] ?? out.out;\n else out.input = a;\n }\n if (!out.input) {\n process.stderr.write('Usage: zvuk gen <bank.json> [--out bank.gen.ts]\\n');\n process.exit(1);\n }\n out.input = resolve(out.input);\n out.out = resolve(out.out);\n return out;\n}\n\nfunction normalize(manifest: BankManifest): BankEntry[] {\n if (Array.isArray(manifest.sounds)) return manifest.sounds;\n return Object.entries(manifest.sounds).map(([name, entry]) => ({ name, ...entry }));\n}\n\nfunction render(entries: BankEntry[], defaultBus: string | undefined): string {\n const names = entries.map((e) => e.name);\n const lines: string[] = [];\n lines.push('// AUTOGENERATED by `zvuk gen`. Do not edit.');\n lines.push(\"import type { Engine, LoadSoundOptions } from '@schmooky/zvuk';\");\n lines.push('');\n lines.push('export type SoundName =');\n for (let i = 0; i < names.length; i++) {\n lines.push(` | ${JSON.stringify(names[i])}${i === names.length - 1 ? ';' : ''}`);\n }\n lines.push('');\n lines.push('export const BANK = [');\n for (const e of entries) {\n const url = JSON.stringify(e.url);\n const opts: string[] = [];\n if (e.bus) opts.push(`bus: ${JSON.stringify(e.bus)}`);\n if (e.loop) opts.push('loop: true');\n lines.push(\n ` { name: ${JSON.stringify(e.name)}, url: ${url}${opts.length ? `, options: { ${opts.join(', ')} }` : ''} },`,\n );\n }\n lines.push('] as const;');\n lines.push('');\n lines.push('export interface BankLoadOptions extends Omit<LoadSoundOptions, \"bus\"> {}');\n lines.push('');\n lines.push(\n 'export async function loadBank(engine: Engine, options: BankLoadOptions = {}): Promise<void> {',\n );\n lines.push(' await Promise.all(');\n lines.push(' BANK.map((entry) =>');\n if (defaultBus) {\n lines.push(\n ` engine.loadSound(entry.name, entry.url, { bus: ${JSON.stringify(defaultBus)}, ...entry.options, ...options }),`,\n );\n } else {\n lines.push(' engine.loadSound(entry.name, entry.url, { ...entry.options, ...options }),');\n }\n lines.push(' ),');\n lines.push(' );');\n lines.push('}');\n lines.push('');\n return lines.join('\\n');\n}\n","import { spawn } from 'node:child_process';\nimport { mkdir, readdir, stat } from 'node:fs/promises';\nimport { basename, dirname, extname, join, resolve } from 'node:path';\n\ninterface TranscodeArgs {\n inputs: string[];\n out: string;\n bitrate: string;\n formats: ('webm' | 'm4a')[];\n}\n\n/**\n * The asset-formats guide ffmpeg loop, packaged. For each input file produces:\n * <name>.webm (libopus) — small, plays everywhere except old iOS Safari.\n * <name>.m4a (aac) — fallback for the codec ladder.\n *\n * Requires ffmpeg on PATH. The CLI is a thin wrapper — we don't bundle ffmpeg.\n */\nexport async function runTranscode(argv: string[]): Promise<void> {\n const args = parseArgs(argv);\n await mkdir(args.out, { recursive: true });\n const expanded = await expandInputs(args.inputs);\n if (expanded.length === 0) {\n process.stderr.write('No input files matched.\\n');\n process.exit(1);\n }\n for (const input of expanded) {\n const name = basename(input, extname(input));\n for (const fmt of args.formats) {\n const target = join(args.out, `${name}.${fmt}`);\n const codecArgs =\n fmt === 'webm'\n ? ['-c:a', 'libopus', '-b:a', args.bitrate, '-vn']\n : ['-c:a', 'aac', '-b:a', args.bitrate, '-vn'];\n await runFfmpeg(['-y', '-i', input, ...codecArgs, target]);\n process.stdout.write(` → ${target}\\n`);\n }\n }\n}\n\nfunction parseArgs(argv: string[]): TranscodeArgs {\n const out: TranscodeArgs = {\n inputs: [],\n out: 'dist',\n bitrate: '96k',\n formats: ['webm', 'm4a'],\n };\n for (let i = 0; i < argv.length; i++) {\n const a = argv[i]!;\n if (a === '--out') {\n out.out = argv[++i] ?? out.out;\n } else if (a === '--bitrate') {\n out.bitrate = argv[++i] ?? out.bitrate;\n } else if (a === '--formats') {\n const list = (argv[++i] ?? '').split(',').map((s) => s.trim());\n out.formats = list.filter((s): s is 'webm' | 'm4a' => s === 'webm' || s === 'm4a');\n } else {\n out.inputs.push(a);\n }\n }\n return out;\n}\n\nasync function expandInputs(patterns: string[]): Promise<string[]> {\n const out: string[] = [];\n for (const p of patterns) {\n const abs = resolve(p);\n const matches = await expandGlob(abs);\n out.push(...matches);\n }\n return out;\n}\n\n/**\n * Minimal glob expander — handles `dir/*.wav` and explicit files only.\n * Avoids pulling in a glob dependency for a tool that's mostly an ffmpeg loop.\n */\nasync function expandGlob(pattern: string): Promise<string[]> {\n if (!pattern.includes('*')) {\n try {\n const s = await stat(pattern);\n return s.isFile() ? [pattern] : [];\n } catch {\n return [];\n }\n }\n const dir = dirname(pattern);\n const base = basename(pattern);\n const re = new RegExp(`^${base.replace(/\\./g, '\\\\.').replace(/\\*/g, '.*')}$`);\n try {\n const entries = await readdir(dir);\n return entries.filter((n) => re.test(n)).map((n) => join(dir, n));\n } catch {\n return [];\n }\n}\n\nfunction runFfmpeg(args: string[]): Promise<void> {\n return new Promise((res, rej) => {\n const proc = spawn('ffmpeg', args, { stdio: ['ignore', 'inherit', 'inherit'] });\n proc.on('error', rej);\n proc.on('exit', (code) => {\n if (code === 0) res();\n else rej(new Error(`ffmpeg exited with code ${code}`));\n });\n });\n}\n","#!/usr/bin/env node\nimport { runGen } from './gen';\nimport { runTranscode } from './transcode';\n\nconst USAGE = `zvuk — audio engine CLI\n\nUsage:\n zvuk transcode <glob> Run the standard ffmpeg ladder (webm/opus + m4a/aac) on each input.\n zvuk gen <bank.json> Emit a typed sound-name module from a manifest.\n\nOptions for \"transcode\":\n --out <dir> Output directory (default: dist).\n --bitrate <kbps> Audio bitrate, e.g. \"96k\" (default: 96k).\n --formats <list> Comma-separated formats: webm, m4a (default: webm,m4a).\n\nOptions for \"gen\":\n --out <file> Output .ts module path (default: bank.gen.ts).\n`;\n\nasync function main(): Promise<void> {\n const [, , cmd, ...rest] = process.argv;\n switch (cmd) {\n case 'transcode': {\n await runTranscode(rest);\n return;\n }\n case 'gen': {\n await runGen(rest);\n return;\n }\n case '--help':\n case '-h':\n case undefined: {\n process.stdout.write(USAGE);\n return;\n }\n default: {\n process.stderr.write(`Unknown command: ${cmd}\\n\\n${USAGE}`);\n process.exit(1);\n }\n }\n}\n\nmain().catch((e) => {\n process.stderr.write(`${(e as Error).stack ?? (e as Error).message}\\n`);\n process.exit(1);\n});\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -130,6 +130,18 @@ interface BusConfig {
|
|
|
130
130
|
concurrency?: ConcurrencyConfig;
|
|
131
131
|
sidechain?: SidechainConfig;
|
|
132
132
|
}
|
|
133
|
+
interface SendOptions {
|
|
134
|
+
/** Send level (0..1). Default 1. */
|
|
135
|
+
amount?: number;
|
|
136
|
+
/**
|
|
137
|
+
* Tap the source bus's output (post-fader, post-FX) when `true`,
|
|
138
|
+
* or input (pre-fader, pre-FX) when `false`. Default `true` — almost
|
|
139
|
+
* always what you want. Pre-fader sends are mainly useful for
|
|
140
|
+
* monitoring buses that should hear the dry signal regardless of how
|
|
141
|
+
* the user has faded the source bus down.
|
|
142
|
+
*/
|
|
143
|
+
post?: boolean;
|
|
144
|
+
}
|
|
133
145
|
interface MasterLimiterConfig {
|
|
134
146
|
/** Threshold in dB. Default -1 (just below 0 dBFS). */
|
|
135
147
|
threshold?: number;
|
|
@@ -348,6 +360,47 @@ interface LoadSoundOptions {
|
|
|
348
360
|
*/
|
|
349
361
|
normalize?: boolean | LoudnessOptions$1;
|
|
350
362
|
}
|
|
363
|
+
/**
|
|
364
|
+
* A three-part music asset: optional intro stinger, mandatory loop body,
|
|
365
|
+
* optional outro tail. Modelled on the Wwise / FMOD pattern every casino
|
|
366
|
+
* slot, action game, and rhythm game uses for combat/win/menu music.
|
|
367
|
+
*
|
|
368
|
+
* Each part accepts a single URL or a codec ladder — the same shape as
|
|
369
|
+
* `engine.loadSound`'s second argument.
|
|
370
|
+
*/
|
|
371
|
+
interface MusicParts {
|
|
372
|
+
intro?: string | readonly string[];
|
|
373
|
+
loop: string | readonly string[];
|
|
374
|
+
outro?: string | readonly string[];
|
|
375
|
+
}
|
|
376
|
+
interface MusicLoadOptions extends LoadSoundOptions {
|
|
377
|
+
/**
|
|
378
|
+
* Equal-power crossfade (seconds) at the loop boundary. Mirrors
|
|
379
|
+
* `PlayOptions.loopCrossfade` — masks the click that would otherwise
|
|
380
|
+
* fire if the loop region doesn't end on a zero crossing. Default `0`.
|
|
381
|
+
*/
|
|
382
|
+
loopCrossfade?: number;
|
|
383
|
+
}
|
|
384
|
+
interface MusicPlayOptions {
|
|
385
|
+
/** Initial volume (0..1). Default 1. */
|
|
386
|
+
volume?: number;
|
|
387
|
+
/**
|
|
388
|
+
* Fade-in duration (seconds) applied to the music's gain stage at start.
|
|
389
|
+
* Default 0 (instant). Convenience for "drop into the menu" style intros.
|
|
390
|
+
*/
|
|
391
|
+
fadeIn?: number;
|
|
392
|
+
}
|
|
393
|
+
interface SkipToOutroOptions {
|
|
394
|
+
/**
|
|
395
|
+
* - `'loop-end'` (default) — finish the current loop iteration, then play
|
|
396
|
+
* the outro at the natural loop boundary. Musical, no click.
|
|
397
|
+
* - `'now'` — fade out whatever's playing right now (~50 ms equal-power)
|
|
398
|
+
* and start the outro immediately. Right call for "user pressed Stop"
|
|
399
|
+
* where waiting feels unresponsive.
|
|
400
|
+
*/
|
|
401
|
+
at?: 'loop-end' | 'now';
|
|
402
|
+
}
|
|
403
|
+
type MusicState = 'intro' | 'loop' | 'outro' | 'ended';
|
|
351
404
|
/**
|
|
352
405
|
* One entry in a `engine.preload(...)` batch. Mirrors `engine.loadSound`'s
|
|
353
406
|
* signature so callers can hand the same data to either path.
|
|
@@ -537,6 +590,26 @@ declare class Voice {
|
|
|
537
590
|
private computeOffset;
|
|
538
591
|
}
|
|
539
592
|
|
|
593
|
+
/**
|
|
594
|
+
* One configured send from a source bus to a target bus. Returned by
|
|
595
|
+
* `bus.send(target, ...)`; held by callers so the level can be adjusted
|
|
596
|
+
* (or the send removed) at runtime.
|
|
597
|
+
*/
|
|
598
|
+
declare class Send {
|
|
599
|
+
readonly source: Bus;
|
|
600
|
+
readonly target: Bus;
|
|
601
|
+
readonly post: boolean;
|
|
602
|
+
private gainNode;
|
|
603
|
+
private ctx;
|
|
604
|
+
private disposed;
|
|
605
|
+
constructor(source: Bus, target: Bus, options: SendOptions, ctx: AudioContext);
|
|
606
|
+
/** Live send level (0..1). Setter ramps over 10 ms to avoid clicks. */
|
|
607
|
+
get amount(): number;
|
|
608
|
+
set amount(v: number);
|
|
609
|
+
/** Fade the send to `target` over `duration` seconds. */
|
|
610
|
+
fadeTo(target: number, duration: number, curve?: FadeCurve): Promise<void>;
|
|
611
|
+
dispose(): void;
|
|
612
|
+
}
|
|
540
613
|
/**
|
|
541
614
|
* A Bus is a named mix bucket with its own gain stage, optional FX inserts,
|
|
542
615
|
* a voice-concurrency limit, and an optional sidechain key.
|
|
@@ -556,13 +629,21 @@ declare class Bus {
|
|
|
556
629
|
readonly output: GainNode;
|
|
557
630
|
private _level;
|
|
558
631
|
private _muted;
|
|
559
|
-
private
|
|
632
|
+
private _soloed;
|
|
560
633
|
private readonly ctx;
|
|
561
634
|
private _concurrency;
|
|
562
635
|
private _voices;
|
|
563
636
|
private _fxChain;
|
|
637
|
+
private _sends;
|
|
564
638
|
private _meterAnalyser;
|
|
565
639
|
private _meterBuf;
|
|
640
|
+
/**
|
|
641
|
+
* Engine-injected callback fired when this bus's solo state changes.
|
|
642
|
+
* The Engine uses it to coordinate the global "any soloed → mute the
|
|
643
|
+
* rest" rule across every bus in the graph. Bus does not depend on
|
|
644
|
+
* Engine; the callback is the only escape hatch.
|
|
645
|
+
*/
|
|
646
|
+
notifySoloChange?: (bus: Bus, soloed: boolean) => void;
|
|
566
647
|
constructor(ctx: AudioContext, name: string, config?: BusConfig);
|
|
567
648
|
get level(): number;
|
|
568
649
|
set level(v: number);
|
|
@@ -602,6 +683,47 @@ declare class Bus {
|
|
|
602
683
|
* reacts to overall bus level, or implement custom voice-stealing rules.
|
|
603
684
|
*/
|
|
604
685
|
meter(): AudioLevel;
|
|
686
|
+
/**
|
|
687
|
+
* Route a copy of this bus's signal into another bus at the configured
|
|
688
|
+
* level. `target.input` mixes the send naturally with whatever else is
|
|
689
|
+
* already feeding it, so the typical pattern — "send 30 % of music to a
|
|
690
|
+
* dedicated reverb bus" — is just two lines:
|
|
691
|
+
*
|
|
692
|
+
* ```ts
|
|
693
|
+
* const verbSend = engine.bus('music').send(engine.bus('reverb'), { amount: 0.3 });
|
|
694
|
+
* verbSend.amount = 0.5; // turn it up live
|
|
695
|
+
* verbSend.dispose(); // remove the send entirely
|
|
696
|
+
* ```
|
|
697
|
+
*
|
|
698
|
+
* Default tap is post-fader / post-FX (`post: true`); set `post: false`
|
|
699
|
+
* if you want a monitor send that hears the dry pre-fader signal.
|
|
700
|
+
*/
|
|
701
|
+
send(target: Bus, options?: SendOptions): Send;
|
|
702
|
+
/** Remove a previously-created send. Idempotent. */
|
|
703
|
+
removeSend(send: Send): void;
|
|
704
|
+
/** Read-only snapshot of every active send originating on this bus. */
|
|
705
|
+
sends(): readonly Send[];
|
|
706
|
+
/**
|
|
707
|
+
* Solo this bus. The engine coordinates the global rule: while any bus
|
|
708
|
+
* is soloed, every non-soloed bus is muted. Soloing multiple buses is
|
|
709
|
+
* additive — they all stay audible. Calling `unsolo()` (or `solo(false)`)
|
|
710
|
+
* removes this bus from the soloed set.
|
|
711
|
+
*
|
|
712
|
+
* Solo state is independent of `muted`; un-soloing returns the bus to
|
|
713
|
+
* whatever its `muted` setting was. Useful in mixer UIs where the user
|
|
714
|
+
* wants to A/B a single channel without disturbing the rest of the mix.
|
|
715
|
+
*/
|
|
716
|
+
solo(on?: boolean): void;
|
|
717
|
+
/** Turn solo off on this bus. Equivalent to `solo(false)`. */
|
|
718
|
+
unsolo(): void;
|
|
719
|
+
/** True when this bus is in the engine's solo set. */
|
|
720
|
+
get soloed(): boolean;
|
|
721
|
+
/**
|
|
722
|
+
* Engine-only. Apply a transient mute (or restore) driven by the global
|
|
723
|
+
* solo state. Distinct from `muted` so un-soloing returns the bus to its
|
|
724
|
+
* user-visible mute state without re-rendering.
|
|
725
|
+
*/
|
|
726
|
+
applySoloVeil(soloMute: boolean): void;
|
|
605
727
|
private rewireFxChain;
|
|
606
728
|
private rampOutput;
|
|
607
729
|
private ramp;
|
|
@@ -774,6 +896,44 @@ declare function ensureStretchWorklet(ctx: AudioContext): Promise<void>;
|
|
|
774
896
|
*/
|
|
775
897
|
declare function createStretchWorkletNode(ctx: AudioContext, options?: StretchWorkletOptions): StretchWorkletNode;
|
|
776
898
|
|
|
899
|
+
/**
|
|
900
|
+
* A logical handle that addresses several buses at once. Doesn't change
|
|
901
|
+
* the audio graph — applies operations (level, fade, mute, solo) to every
|
|
902
|
+
* member in parallel. Useful when several buses form a sub-mix that should
|
|
903
|
+
* always be controlled together: combat = weapons + enemies + environment;
|
|
904
|
+
* voice = dialogue + effort sounds; etc.
|
|
905
|
+
*
|
|
906
|
+
* Construct via `engine.busGroup(name, members)`; look up via
|
|
907
|
+
* `engine.busGroup(name)`. Snapshots and parameters can target a group
|
|
908
|
+
* instead of repeating bus names.
|
|
909
|
+
*/
|
|
910
|
+
declare class BusGroup {
|
|
911
|
+
readonly name: string;
|
|
912
|
+
readonly members: readonly Bus[];
|
|
913
|
+
constructor(name: string, members: readonly Bus[]);
|
|
914
|
+
/** Set the level on every member. Same 10 ms ramp as direct `bus.level =`. */
|
|
915
|
+
set level(v: number);
|
|
916
|
+
/**
|
|
917
|
+
* Read the current level. Returns the average across members — useful
|
|
918
|
+
* when every member shares a level (the common case) and informational
|
|
919
|
+
* otherwise.
|
|
920
|
+
*/
|
|
921
|
+
get level(): number;
|
|
922
|
+
set muted(v: boolean);
|
|
923
|
+
/** True if every member is currently muted. */
|
|
924
|
+
get muted(): boolean;
|
|
925
|
+
/**
|
|
926
|
+
* Fade every member to `target` over `duration` seconds. Returns when
|
|
927
|
+
* the slowest leg completes — in practice they're all equal because
|
|
928
|
+
* each member uses the same duration.
|
|
929
|
+
*/
|
|
930
|
+
fadeTo(target: number, duration: number, curve?: FadeCurve): Promise<void>;
|
|
931
|
+
/** Solo every member of the group. Engine handles the global mute-the-rest rule. */
|
|
932
|
+
solo(on?: boolean): void;
|
|
933
|
+
/** Un-solo every member. */
|
|
934
|
+
unsolo(): void;
|
|
935
|
+
}
|
|
936
|
+
|
|
777
937
|
type ParameterCurve = FadeCurve;
|
|
778
938
|
type Subscriber = (value: number) => void;
|
|
779
939
|
/**
|
|
@@ -807,6 +967,115 @@ declare class Parameter {
|
|
|
807
967
|
|
|
808
968
|
type EngineState = 'cold' | 'unlocking' | 'live' | 'interrupted' | 'closed';
|
|
809
969
|
|
|
970
|
+
interface MusicBuffers {
|
|
971
|
+
intro?: AudioBuffer;
|
|
972
|
+
loop: AudioBuffer;
|
|
973
|
+
outro?: AudioBuffer;
|
|
974
|
+
}
|
|
975
|
+
interface MusicDeps {
|
|
976
|
+
ctx: AudioContext;
|
|
977
|
+
buffers: MusicBuffers;
|
|
978
|
+
destination: AudioNode;
|
|
979
|
+
loopCrossfade: number;
|
|
980
|
+
defaultStopFade?: number;
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* Stinger → loop → outro music asset. The pattern every casino slot,
|
|
984
|
+
* action game, and rhythm game uses for combat/win/menu music: an intro
|
|
985
|
+
* that plays once, a body that loops cleanly until you ask it to stop,
|
|
986
|
+
* and an outro tail that plays once at the natural loop boundary so the
|
|
987
|
+
* music ends musically instead of cutting off mid-bar.
|
|
988
|
+
*
|
|
989
|
+
* Construct via `engine.loadMusic(name, parts)`; spawn live instances via
|
|
990
|
+
* `music.play()`. Each instance is a `MusicVoice` you can fade, pause,
|
|
991
|
+
* resume, stop, or `skipToOutro()` independently.
|
|
992
|
+
*/
|
|
993
|
+
declare class Music {
|
|
994
|
+
readonly name: string;
|
|
995
|
+
private deps;
|
|
996
|
+
constructor(name: string, deps: MusicDeps);
|
|
997
|
+
get loopDuration(): number;
|
|
998
|
+
get hasIntro(): boolean;
|
|
999
|
+
get hasOutro(): boolean;
|
|
1000
|
+
play(options?: MusicPlayOptions): MusicVoice;
|
|
1001
|
+
}
|
|
1002
|
+
interface MusicVoiceDeps {
|
|
1003
|
+
ctx: AudioContext;
|
|
1004
|
+
buffers: MusicBuffers;
|
|
1005
|
+
destination: AudioNode;
|
|
1006
|
+
loopCrossfade: number;
|
|
1007
|
+
defaultStopFade?: number;
|
|
1008
|
+
options: MusicPlayOptions;
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* One live playback instance of a `Music` asset. Tracks which part is
|
|
1012
|
+
* currently sounding (`'intro' | 'loop' | 'outro' | 'ended'`), exposes
|
|
1013
|
+
* `fade`/`pause`/`resume`/`stop`, and adds two music-specific operations:
|
|
1014
|
+
*
|
|
1015
|
+
* - `skipToOutro({ at: 'loop-end' })` — wait for the current loop iteration
|
|
1016
|
+
* to complete, then play the outro at the natural loop boundary.
|
|
1017
|
+
* - `skipToOutro({ at: 'now' })` — fade the loop out (~50 ms) and start
|
|
1018
|
+
* the outro immediately. Right call for "user pressed Stop."
|
|
1019
|
+
*
|
|
1020
|
+
* `stop()` is the click-free cut — no outro. Use `skipToOutro` if you want
|
|
1021
|
+
* the music to end musically.
|
|
1022
|
+
*/
|
|
1023
|
+
declare class MusicVoice {
|
|
1024
|
+
readonly ended: Promise<void>;
|
|
1025
|
+
private ctx;
|
|
1026
|
+
private buffers;
|
|
1027
|
+
private destination;
|
|
1028
|
+
private gain;
|
|
1029
|
+
private state;
|
|
1030
|
+
private done;
|
|
1031
|
+
private resolveEnded;
|
|
1032
|
+
private stopFade;
|
|
1033
|
+
private loopCrossfadeSec;
|
|
1034
|
+
private introSource;
|
|
1035
|
+
private outroSource;
|
|
1036
|
+
private loopChain;
|
|
1037
|
+
private loopArmTimer;
|
|
1038
|
+
private outroTimer;
|
|
1039
|
+
private nextLoopBoundaryAt;
|
|
1040
|
+
constructor(deps: MusicVoiceDeps);
|
|
1041
|
+
/** Currently-sounding part. Transitions automatically as parts hand off. */
|
|
1042
|
+
get currentPart(): MusicState;
|
|
1043
|
+
fade(opts: FadeOptions): Promise<void>;
|
|
1044
|
+
/**
|
|
1045
|
+
* Stop the music with the same click-free fade-out semantics as
|
|
1046
|
+
* `voice.stop()`. Skips the outro — call `skipToOutro` first if you
|
|
1047
|
+
* want the music to end musically.
|
|
1048
|
+
*/
|
|
1049
|
+
stop(opts?: StopOptions): void;
|
|
1050
|
+
/**
|
|
1051
|
+
* Schedule the outro. With `at: 'loop-end'` (default) the outro starts
|
|
1052
|
+
* at the next natural loop boundary so the music ends musically. With
|
|
1053
|
+
* `at: 'now'` the loop fades out (~50 ms) and the outro starts
|
|
1054
|
+
* immediately — useful when responsiveness matters more than musicality
|
|
1055
|
+
* (e.g. user pressed Stop).
|
|
1056
|
+
*
|
|
1057
|
+
* No-op if there is no outro buffer, or if the music is already past
|
|
1058
|
+
* the loop part. Calling `skipToOutro` more than once is a no-op too —
|
|
1059
|
+
* the first call wins.
|
|
1060
|
+
*/
|
|
1061
|
+
skipToOutro(opts?: SkipToOutroOptions): void;
|
|
1062
|
+
private start;
|
|
1063
|
+
private scheduleIntro;
|
|
1064
|
+
private scheduleLoopStart;
|
|
1065
|
+
private spawnLoopSegment;
|
|
1066
|
+
private armNextLoopSegment;
|
|
1067
|
+
private crossfadeViable;
|
|
1068
|
+
private releaseLoopSegment;
|
|
1069
|
+
private skipToOutroAtLoopEnd;
|
|
1070
|
+
private skipToOutroNow;
|
|
1071
|
+
private cancelLoopArm;
|
|
1072
|
+
private stopLoopSourcesAt;
|
|
1073
|
+
private scheduleOutro;
|
|
1074
|
+
private cancelTimers;
|
|
1075
|
+
private stopAllSources;
|
|
1076
|
+
private finish;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
810
1079
|
interface SoundDeps {
|
|
811
1080
|
ctx: AudioContext;
|
|
812
1081
|
buffer: AudioBuffer;
|
|
@@ -998,6 +1267,22 @@ interface Engine {
|
|
|
998
1267
|
sprite(name: string): Sprite;
|
|
999
1268
|
/** True if `name` was loaded as a sprite. */
|
|
1000
1269
|
hasSprite(name: string): boolean;
|
|
1270
|
+
/**
|
|
1271
|
+
* Load a three-part music asset — optional intro, mandatory loop, optional
|
|
1272
|
+
* outro — and register it as a `Music` source. Use this for combat/win/menu
|
|
1273
|
+
* music where you need a stinger that plays once, a body that loops cleanly,
|
|
1274
|
+
* and (optionally) an outro that fires at the next loop boundary so the
|
|
1275
|
+
* music ends musically instead of cutting off mid-bar.
|
|
1276
|
+
*
|
|
1277
|
+
* Each part accepts the same shape as `loadSound`'s second argument —
|
|
1278
|
+
* a single URL or a codec ladder — and is loaded through the same
|
|
1279
|
+
* decoder cache, so codec fallback and `resolveAsset` apply per part.
|
|
1280
|
+
*/
|
|
1281
|
+
loadMusic(name: string, parts: MusicParts, options?: MusicLoadOptions): Promise<Music>;
|
|
1282
|
+
/** Look up a previously loaded music asset. Throws SoundNotFoundError on miss. */
|
|
1283
|
+
music(name: string): Music;
|
|
1284
|
+
/** True if `name` was loaded as a music asset. */
|
|
1285
|
+
hasMusic(name: string): boolean;
|
|
1001
1286
|
/**
|
|
1002
1287
|
* Stream a long media file via HTMLAudioElement + MediaElementAudioSource.
|
|
1003
1288
|
* Use for music tracks > 30s — avoids decoding the whole file into RAM,
|
|
@@ -1009,6 +1294,20 @@ interface Engine {
|
|
|
1009
1294
|
hasStream(name: string): boolean;
|
|
1010
1295
|
sound(name: string): Sound;
|
|
1011
1296
|
bus(name: string): Bus;
|
|
1297
|
+
/**
|
|
1298
|
+
* Define (with `members`) or look up (without) a `BusGroup` — a logical
|
|
1299
|
+
* handle that addresses several buses at once. Setting `group.level` or
|
|
1300
|
+
* `group.muted`, calling `group.fadeTo`, or `group.solo()` applies to
|
|
1301
|
+
* every member in parallel. Doesn't change the audio graph; pure
|
|
1302
|
+
* convenience for sub-mixes that always move together.
|
|
1303
|
+
*/
|
|
1304
|
+
busGroup(name: string, members?: readonly Bus[]): BusGroup;
|
|
1305
|
+
/**
|
|
1306
|
+
* Live amplitude readout on the master input. Same `{ rms, peak }`
|
|
1307
|
+
* shape as `bus.meter()` and `voice.level()`, just at the top of the
|
|
1308
|
+
* chain. First call lazily attaches a passive AnalyserNode tap.
|
|
1309
|
+
*/
|
|
1310
|
+
masterMeter(): AudioLevel;
|
|
1012
1311
|
/**
|
|
1013
1312
|
* Crossfade helper. Stops `from` over `duration` seconds while playing `to`
|
|
1014
1313
|
* over the same window with `equal-power` curves so the perceived loudness
|
|
@@ -1062,6 +1361,8 @@ declare class Master {
|
|
|
1062
1361
|
private limiterNode;
|
|
1063
1362
|
private limiterCfg;
|
|
1064
1363
|
private destination;
|
|
1364
|
+
private _meterAnalyser;
|
|
1365
|
+
private _meterBuf;
|
|
1065
1366
|
constructor(ctx: AudioContext, config?: MasterConfig);
|
|
1066
1367
|
setHeadroom(db: number): void;
|
|
1067
1368
|
get headroom(): number;
|
|
@@ -1072,6 +1373,13 @@ declare class Master {
|
|
|
1072
1373
|
setLimiter(cfg: MasterLimiterConfig | null): void;
|
|
1073
1374
|
/** Live gain reduction in dB. 0 if no limiter is engaged. */
|
|
1074
1375
|
get reduction(): number;
|
|
1376
|
+
/**
|
|
1377
|
+
* Live amplitude readout on the master input. Returns `{ rms, peak }`
|
|
1378
|
+
* as linear values in [0..1]. The first call lazily attaches an
|
|
1379
|
+
* AnalyserNode as a passive sibling of the master gain — no audio-path
|
|
1380
|
+
* change. Same shape as `bus.meter()` and `voice.level()`.
|
|
1381
|
+
*/
|
|
1382
|
+
meter(): AudioLevel;
|
|
1075
1383
|
dispose(): void;
|
|
1076
1384
|
private rewire;
|
|
1077
1385
|
}
|
|
@@ -1131,4 +1439,4 @@ type NormalizeFlag = boolean | LoudnessOptions;
|
|
|
1131
1439
|
declare function applyLoudnessNormalization(buffer: AudioBuffer, flag: NormalizeFlag): AudioBuffer;
|
|
1132
1440
|
declare function computeNormalizationGain(buffer: AudioBuffer, opts: Required<LoudnessOptions>): number;
|
|
1133
1441
|
|
|
1134
|
-
export { AggregateDecodeError, type ApplyOptions, type AssetResolver, type AudioLevel, type AudioMimeType, Bus, type BusConfig, BusNotFoundError, Compressor, type CompressorConfig, type ConcurrencyConfig, type CrossfadeOptions, type DecodeAttempt, DecodeError, Ducker, type DuckerConfig, type Engine, EngineClosedError, type EngineConfig, type EngineState, type FadeCurve, type FadeOptions, Filter, type FilterConfig, type FilterKind, type FxInsert, type LoadSoundOptions, type LoudnessOptions, Master, type MasterConfig, type MasterLimiterConfig, type NormalizeFlag, Parameter, type ParameterCurve, type PlayOptions, PreloadError, type PreloadFailure, type PreloadItem, type PreloadOptions, type PreloadProgressEvent, type ResolveAssetContext, type ResolvedAsset, Reverb, type ReverbConfig, type SidechainConfig, Snapshot, type SnapshotState, Sound, SoundNotFoundError, type SpatialOptions, Spatializer, Sprite, type SpriteMap, type SpriteRegion, type SpriteRegionPlayOptions, type StopOptions, StreamSound, StretchProcessor, type StretchWorkletNode, type StretchWorkletOptions, type TickSource, Voice, type VoiceDefaults, type VoiceJitter, ZvukError, applyLoudnessNormalization, canPlay, computeNormalizationGain, createEngine, createStretchWorkletNode, ensureStretchWorklet, mimeForUrl, pickSource, pickSourceOrder };
|
|
1442
|
+
export { AggregateDecodeError, type ApplyOptions, type AssetResolver, type AudioLevel, type AudioMimeType, Bus, type BusConfig, BusGroup, BusNotFoundError, Compressor, type CompressorConfig, type ConcurrencyConfig, type CrossfadeOptions, type DecodeAttempt, DecodeError, Ducker, type DuckerConfig, type Engine, EngineClosedError, type EngineConfig, type EngineState, type FadeCurve, type FadeOptions, Filter, type FilterConfig, type FilterKind, type FxInsert, type LoadSoundOptions, type LoudnessOptions, Master, type MasterConfig, type MasterLimiterConfig, Music, type MusicLoadOptions, type MusicParts, type MusicPlayOptions, type MusicState, MusicVoice, type NormalizeFlag, Parameter, type ParameterCurve, type PlayOptions, PreloadError, type PreloadFailure, type PreloadItem, type PreloadOptions, type PreloadProgressEvent, type ResolveAssetContext, type ResolvedAsset, Reverb, type ReverbConfig, Send, type SendOptions, type SidechainConfig, type SkipToOutroOptions, Snapshot, type SnapshotState, Sound, SoundNotFoundError, type SpatialOptions, Spatializer, Sprite, type SpriteMap, type SpriteRegion, type SpriteRegionPlayOptions, type StopOptions, StreamSound, StretchProcessor, type StretchWorkletNode, type StretchWorkletOptions, type TickSource, Voice, type VoiceDefaults, type VoiceJitter, ZvukError, applyLoudnessNormalization, canPlay, computeNormalizationGain, createEngine, createStretchWorkletNode, ensureStretchWorklet, mimeForUrl, pickSource, pickSourceOrder };
|