mwg API
    Preparing search index...

    Function encodeSoundFont

    • Compresses a SoundFont 2 into a SoundFont 3: every sample a preset reaches goes through encode (one call per sample, mono 16-bit frames, the codec named by codec, options passed along: an Opus bitrate or a Vorbis quality level) and its bytes replace the frames; a sample no preset reaches is dropped. Loop points become relative to their sample, as the format has them, and each compressed sample's type gains the compressed flag. The font states the SoundFont 3 version in its INFO. Nothing here compresses: encode does, so a build tool can hand it ffmpeg for Vorbis or Opus, or flacSampleEncoder for lossless FLAC with nothing installed. A SoundFont that is already a SoundFont 3 comes back unchanged and encode is never called, whatever its codec: to change the codec, decodeSoundFont it first.

      Parameters

      Returns Promise<ArrayBuffer>

      import { encodeSoundFont, flacSampleEncoder } from '@datamoc/mwg/audio';

      declare const sf2Bytes: ArrayBuffer;

      const sf3 = await encodeSoundFont(sf2Bytes, flacSampleEncoder, 'flac');
      console.log(sf3.byteLength < sf2Bytes.byteLength);