mwg API
    Preparing search index...

    Function subsetSoundFont

    • Writes a smaller, valid SoundFont 2 file carrying only the used programs: their presets (names kept), instruments and samples, with zones, ranges, tuning, envelopes and sample loops copied verbatim and every index remapped. Zones that reference samples missing from the file (ROM samples) are dropped, matching what the reader voices for the full font; the library, genre and morphology metadata is zeroed and the INFO list, when present, rides along untouched. Modulator lists are emptied and 24-bit upper bits are dropped: the reader voices neither, so what it plays is unchanged, while a third-party player would miss those.

      Parameters

      • data: ArrayBuffer | ArrayBufferView<ArrayBufferLike>
      • usage: readonly SoundFontProgram[]

      Returns ArrayBuffer

      import { parseMidi, collectSoundFontUsage, subsetSoundFont } from '@datamoc/mwg/audio';

      declare const midiBytes: ArrayBuffer;
      declare const soundfontBytes: ArrayBuffer;

      const usage = collectSoundFontUsage([parseMidi(midiBytes)]);
      const pruned = subsetSoundFont(soundfontBytes, usage);
      console.log(usage.length, pruned.byteLength);