ADPCM encoder tool (Mac-only)

I've been using a small script wrapped in an app (using Platypus) to convert my audio to ADPCM.

Today I updated that from using ffmpeg to using adpcm-xq (thanks to @mandra via @neven for the tip!)

Results are higher quality, compatible ADPCM audio files albeit with slightly longer conversion time.

usage

  • run app and select files to process
    or
  • drag and drop files onto the app icon

output

  • folder ADPCM next to source files
  • 22KHz MONO, by default

options

hold modifier keys as you select files to change settings:

  • ​CONTROL... sample rate 44KHz
  • OPTION... sample rate 11KHz
  • SHIFT... less look-ahead (faster but slightly worse results)
  • CMD... output stereo

download

  • ADPCM.app.zip (279.6 KB)
  • Universal app for Intel (x86_64) and Apple silicon (arm64)
  • uses adpcm-xq version 0.5 release

latest version

  • adpcm-xq version 0.5 is much faster so have increase the quality to keep processing time roughly the same
  • now uses zsh shell
  • shows time taken for each file

notes

  • app is signed by me, but I can only test on Sonoma - so no support on other versions of macOS, sorry
  • you might need to right-click and choose Open, perhaps a couple of times, to get the app to launch
  • uses macOS built-in tool afconvert to handle the sample rate conversion part of the process

screenshots

source code

#!/usr/bin/env zsh

echo "CONTROL... sample rate 44KHz"
echo "OPTION... sample rate 11KHz"
echo "SHIFT... less look-ahead"
echo "CMD... output stereo"
echo

optKeyDown=$(./keys option)
shiftKeyDown=$(./keys shift)
cmdKeyDown=$(./keys cmd)
controlKeyDown=$(./keys control)
# capslockKeyDown=$(./keys capslock)

RATE="LEI16@22050"
if [[ $optKeyDown -ne 0 ]]; then
    RATE="LEI16@11025"
fi
if [[ $controlKeyDown -ne 0 ]]; then
    RATE="LEI16@44100"
fi

if [[ $shiftKeyDown -eq 0 ]]; then
    LOOK=9
else
    LOOK=5
fi

if [[ $cmdKeyDown -eq 0 ]]; then
    CHANNELS=1
else
    CHANNELS=2
fi

echo "lookahead $LOOK && channels ${CHANNELS: -1:1} && sample rate ${RATE: -5:2}KHz"
echo
echo "Converting..."
echo

for file in "$@"; do
    FILENAME=${file:t:r}
    FOLDER=${file:h}
    mkdir -p "$FOLDER/ADPCM/"
    echo "• $FILENAME"
    afconvert -f WAVE -d $RATE -c $CHANNELS "$file" "$FOLDER/ADPCM/.temp.wav"
    { time ./adpcm-xq -$LOOK -q -y "$FOLDER/ADPCM/.temp.wav" "$FOLDER/ADPCM/$FILENAME.wav"; } 2>&1 | awk '{print $6; exit}'
    rm "$FOLDER/ADPCM/.temp.wav"
    echo
done

echo
echo "done"
8 Likes

Worth noting in the discussion here that this still works on 12.0.1 Monterey on an M1 iMac; thanks for the easy-to-use tool @matt :raised_hands:t5:

1 Like

Inspired by this, I made a quick node cli tool that has a wasm compiled ffmpeg & adpcm-xq lib.

I didn't test this, but the WASM thing should mean that this script works on any system with node 14+.
It also might mean you could make a browser tool out of this. :thinking:

edit: I should also mention that I did not expose any flags. will do that soon-ish.

2 Likes

Thanks for this tool Matt.

Not sure what to think of the results I get when comparing tools.

Your processed version sounds fine on mac simulator, but the waveform seems off and gives a pop at the end of the sample.

thrust_orig.wav.zip (19.0 KB)

@Nino we will need to see if the problem is ffmpeg or admpcm-xq, and then file the issue in the correct place

all I do is wrap those with a GUI

just uploaded a new build in the OP

  • tweaks, changes, improvements since the last build
  • now uses adpcm-xq 0.5 so results are even better
  • new defaults (22KHz, mono, lookahead -9)
  • more options to change that behaviour
  • no longer relies on ffmpeg
  • uses zsh shell and shows time taken for each file
  • includes my self-built universal binaries for arm64 && x86_64
  • so it works on old Macs and is even faster on the latest Macs

You might need to right-click and choose Open, maybe a couple of times, to get the app to launch

Note: it is advised that you only convert to ADPCM in your build process or the final stages, and make your edits to your high fidelity WAV files before that. Do not edit the ADPCM files directly, or they will be resaved/rencoded at lower quality.

3 Likes