ima-adpcm-decoder

Decode IMA ADPCM WAV Files to AudioContext

Usage no npm install needed!

<script type="module">
  import imaAdpcmDecoder from 'https://cdn.skypack.dev/ima-adpcm-decoder';
</script>

README

ima-adpcm-decoder

AudioContext Decoder for ADPCM-Wavefiles

Installation

npm install ima-adpcm-decoder
yarn add ima-adpcm-decoder

Usage

import { decodeImaAdpcm } from 'ima-adpcm-decoder';

const playAdpcm = async () => {
    const ctx = new AudioContext();

    const response = await fetch('./test.wav');
    const buffer = await response.arrayBuffer();
    const audioBuffer = decodeImaAdpcm(ctx, buffer);

    const src = ctx.createBufferSource();
    src.buffer = audioBuffer;
    src.connect(ctx.destination);
    src.start(0);
};

For streaming, the package also exposes the decodeImaAdpcmBlock function, which decodes a single block of ADPCM samples.

Notes

As this uses the AudioContext directly, this currently only works in Browsers. A future implementation may use webasm to provide async decoding of ADPCM Buffers.

This code runs synchronously in the Browser, meaning it will block the event-loop until the decoding is finished. That may take some time depending on the size of your Wavefiles.

This package correctly handles multi-channel wavefiles.

Do not use if...

  • You need decoding of ADPCM files in nodejs
  • You need async decoding
  • You are not okay with the hefty dependency that is wavefile

Dependencies (1)

Thanks

The code for decoding ADPCM-blocks is ported from ADPCM-XQ

This code draws inspiration from imaadpcm

So thanks go to David Bryant and Rafael da Silva Rocha.