mwg API
    Preparing search index...

    Function createAudioLoader

    • One loader for AudioBus music, 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 (under budget when 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 a MusicPlayer.

      Parameters

      Returns BusLoader

      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 });