mwg API
    Preparing search index...

    Function fitToBudget

    • Fits a rendered track to a budget: cuts it to maxSeconds with a fade, folds it to mono and halves its rate, in that order. A mono track shares one array between both channels, so it costs half the memory in the renderer's hands even though a stereo AudioBuffer made from it later still has two. Loop points past the cut are pulled back to the new end.

      Type Parameters

      • T extends StereoFrames & { duration?: number; loopEnd?: number; loopStart?: number }

      Parameters

      Returns T

      import { fitToBudget, renderMidiToBuffer, parseMidi } from '@datamoc/mwg/audio';

      declare const midiBytes: ArrayBuffer;

      const ambience = fitToBudget(renderMidiToBuffer(parseMidi(midiBytes)), { maxSeconds: 60, mono: true, halfRate: true });
      console.log(ambience.duration);