mwg API
    Preparing search index...

    Function renderMidiToBufferAsync

    • Renders raw MIDI bytes to stereo PCM frames on a worker thread, so the work that costs seconds on a real track (T161 measured 2 to 11.8) does not freeze the loading screen the caller is presumably drawing. Everything cheap stays on this thread: the parse, the schedule, option validation and the SoundFont voice lookup. Only the synthesis crosses to the worker, as structured-cloneable note data, and the stereo buffers come back transferred rather than copied.

      Deterministic to the bit, because both paths call the same renderNotes: for the same bytes and options this resolves exactly what renderMidiToBuffer(parseMidi(bytes), ...) returns. A failure (a malformed file, invalid options, a dead worker) rejects with the same message the synchronous path would have thrown.

      Parameters

      Returns Promise<RenderedMidi>

      import { renderMidiToBufferAsync } from '@datamoc/mwg/audio';

      declare const midi: ArrayBuffer;
      declare const soundFont: ArrayBuffer;

      const track = await renderMidiToBufferAsync(midi, { soundFontBytes: soundFont });
      console.log(track.duration, track.loopStart, track.loopEnd);