Created
January 7, 2023 15:47
-
-
Save cassdeckard/0aa9bac93f6bf36c1957bfda8d5e8276 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Shamelessly stolen from https://github.com/neonichu/Core-Audio-Samples/blob/master/Samples/extract-sf2.sh | |
| # | |
| ## Convert a SoundFont + MIDI file to a CAF audio file. | |
| ## | |
| ## needs: | |
| ## fluidsynth, sox (installable via brew) | |
| ## afconvert (part of OS X) | |
| # | |
| if [ "$#" -lt 2 ] | |
| then | |
| echo "Usage: `basename $0` [SoundFont] [MIDI]" | |
| exit 1 | |
| fi | |
| SOUNDFONT="$1" | |
| MIDI="$2" | |
| OUT="`basename \"$SOUNDFONT\" .sf2`.wav" | |
| # Play MIDI file using the given SoundFont | |
| fluidsynth -nli -F "temp.raw" "$SOUNDFONT" "$MIDI" >/dev/null | |
| # Convert raw output to WAV | |
| sox -r 44100 -2 -c 2 -s "temp.raw" "temp.wav" | |
| # Trim the WAV to one second | |
| sox "temp.wav" "$OUT" trim 0.0 1.0 | |
| # Convert the WAV to CAF | |
| afconvert -f caff -d LEI16 "$OUT" | |
| # Cleanup | |
| rm -f temp.raw temp.wav "$OUT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment