import { AudioBus, createAudioLoader } from '@datamoc/mwg/audio';
declare const context: AudioContext;
declare const soundFontBytes: ArrayBuffer;
const bus = new AudioBus(context, {
load: createAudioLoader(context, { midi: { soundFontBytes, missingProgram: 'synth' } }),
});
await bus.playBgm({ name: 'music/theme.mid', volume: 80, pitch: 100, pan: 0 });
await bus.playSe({ name: 'sounds/hit.wav', volume: 80, pitch: 110, pan: 20 });
One loader for
AudioBusmusic, jingles and effects: MIDI is rendered on a worker, other formats use the browser's audio decoder. MIDI detection uses the file header, so an archive alias does not need a filename extension. Results are cached by path (underbudgetwhen one is given, which also caps and shrinks rendered MIDI); a failed load can be retried. A load reports 0, 0.5 and 1 through the bus's progress context, and skips its render when the request was replaced before the bytes arrived. Returned buffers can also be used by aMusicPlayer.