Skip to content

Instantly share code, notes, and snippets.

@woudsma
Last active April 11, 2023 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woudsma/7d6899d7bff50dee28adfd3c4f9ef8f0 to your computer and use it in GitHub Desktop.
Save woudsma/7d6899d7bff50dee28adfd3c4f9ef8f0 to your computer and use it in GitHub Desktop.
Convert samples for JoMoX Alpha Base compatibility with FFmpeg

Converting samples before import to JoMoX Alpha Base

Samples need to be 16 bit / 48kHz mono wav files.

Requirements:

  • Zsh (run zsh --version to check if it's installed already)
  • FFmpeg (brew install ffmpeg)

This guide is for UNIX (MacOS or Linux) users, the process would be similar on Windows machines with FFmpeg though. The required FFmpeg options are:

ffmpeg -i $INPUT -acodec pcm_s16le -ac 1 -ar 48000 $OUTPUT

# -i: This parameter specifies the input file to be processed.
# $INPUT: This is a placeholder for the actual input file path.
# -acodec pcm_s16le: This parameter specifies the audio codec to be used for the output file. In this case, pcm_s16le is a codec that specifies uncompressed 16-bit audio data.
# -ac 1: This parameter specifies the number of audio channels to be used in the output file. In this case, 1 specifies a mono audio output.
# -ar 48000: This parameter specifies the audio sampling rate to be used in the output file. In this case, 48000 specifies a sampling rate of 48 kHz.
# $OUTPUT: This is a placeholder for the actual output file path.

Helper function to convert an audio sample to Alpha Base compatible format:

Tested only with zsh. Add this function to your ~/.zshrc file for example (and reload with source ~/.zshrc)

function wav2mono16bit48khzwav() {
  INPUT=$1
  OUTPUT=${INPUT:r}-16bit-48khz-mono.wav
  ffmpeg -i $INPUT -acodec pcm_s16le -ac 1 -ar 48000 $OUTPUT
}

Usage: wav2mono16bit48khzwav /path/to/sample.wav
Creates a file next to the original file named sample-16bit-48khz-mono.wav
Should also work with mp3 and other audio files as input


To convert an entire directory including subdirectories with samples:

Note that the Alpha Base doesn't support subdirectories, all samples must either be placed in the SD card root, or you can store samples in directories. Those can't have subdirectories, so samples should be placed max 1 level deep

# Go to your samples directory
cd /path/to/samples-directory

# (optional) Remove any .asd Ableton files if you want
rm ./**/*.asd

# Convert all wavs to 16 bit / 48kHz mono wavs
for f in ./**/*.wav; do wav2mono16bit48khzwav $f; done
# Or if you have both mp3 and wav files:
for f in ./**/*.{mp3,wav}; do wav2mono16bit48khzwav $f; done

# Remove the old (non-mono) wavs
for f in ./**/*.wav; do test "${f#*16bit-48khz-mono}" = "$f" && rm $f; done

# Rename all samples by removing "-16bit-48khz-mono" from the filename
for f in ./**/*.wav; do mv "$f" ${f//-16bit-48khz-mono/}; done

Or optionally do it all at once. I personally like the above approach because I want to check things before removing/renaming/etc.

I strongly recommend to make a copy/backup of the folder with the wavs that you want to convert. This script removes the original wavs with the rm $f command after converting them.

# Go to your samples directory
cd /path/to/samples-directory

# Convert and replace all samples with 16 bit / 48kHz mono wavs
for f in ./**/*.wav; do
  OUTPUT=${f:r}-16bit-48khz-mono.wav
  ffmpeg -i $f -acodec pcm_s16le -ac 1 -ar 48000 $OUTPUT && rm $f && mv $OUTPUT ${f:r}.wav
done

Now you can copy the samples to the SD card for use on the Alpha Base 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment