Negligible Psychological Misery

    mpg123-decoder

    0.0.3 • Public • Published

    mpg123-decoder

    mpg123-decoder is a Web Assembly MPEG Layer (I/II/II) audio decoder based on mpg123.

    See the homepage of this repository for more Web Assembly audio decoders like this one.

    Installing

    Install via NPM.

    Usage

    1. Create a new instance and wait for the WASM to finish compiling.

      import {MPEGDecoder} from 'mpg123-decoder';
      
      const decoder = new MPEGDecoder();
      
      // wait for the WASM to be compiled
      await decoder.ready;
    2. Begin decoding MPEG data.

      // Decode Uint8Array of MPEG data
      const {channelData, samplesDecoded, sampleRate} = decoder.decode(mpegData);
      
      // Decode an individual MPEG frame
      const {channelData, samplesDecoded, sampleRate} = decoder.decodeFrame(mpegFrame);
      
      // Decode an array of individual MPEG frames
      const {channelData, samplesDecoded, sampleRate} = decoder.decodeFrames(mpegFrameArray);
    3. When done decoding, free up the memory being used by the WASM module. You will need to create a new instance to start decoding again.

      decoder.free();

    API

    Getters

    • decoder.ready
      • Returns a promise that is resolved when the WASM is compiled and ready to use.

    Methods

    Each method returns an object containing the decoded audio, number of samples decoded, and sample rate of the decoded audio.

    The channelData contains the raw decoded PCM for each channel (left, and right). Each Float32Array can be used directly in the WebAudio api.

    // decoded audio return value
    {
        channelData: [leftAudio, rightAudio],
        samplesDecoded: 1234,
        sampleRate: 44100
    }
    • decoder.decode(mpegData)
      • mpegData Uint8Array of MPEG audio data.
    • decoder.decodeFrame(mpegFrame)
      • mpegFrame Uint8Array containing a single MPEG frame.
    • decoder.decodeFrames(mpegFrames)
      • mpegFrames Array of Uint8Arrays containing MPEG frames.

    Install

    npm i mpg123-decoder

    DownloadsWeekly Downloads

    14

    Version

    0.0.3

    License

    MIT

    Unpacked Size

    101 kB

    Total Files

    4

    Last publish

    Collaborators

    • eshaz