How to MID to WAV

Post fully complete "how to" guides and tutorials here. This is a great place to get feedback on stuff you might put in the wiki.

Moderators: MattKingUSA, khz

Post Reply
Shadow_7
Established Member
Posts: 175
Joined: Tue Jun 08, 2010 3:35 pm

How to MID to WAV

Post by Shadow_7 »

I saw in the request thread a request for this. I've done this in the past with timidity, so it can be done. It can also be done with fluidsynth. I created a short bash script for the fluidsynth way because I hate remembering complex command lines. Here's what my script does in it's ugly form.

Code: Select all

$ fluidsynth -C no -R no -n -i -L 2 -r 48000 \
             -a file -o audio.file.name="temp.RAW" \
             /usr/share/sounds/sf2/FluidR3_GM.sf2 \
             /home/user/file.MID
$ sox -s -2 -c 2 -r 48000 temp.RAW \
      -s -2 -c 2 -r 48000 temp.WAV
And that's basically it. The timidity way is a much shorter command line, which you can fairly easily derive from it's help/man pages. But timidity .pat files can sound quite hideous. Feel free to add to this any other ways for the same deal.

The script looks like this, with the option of 1 parm for the input .MID file. Or two parms for the soundfont and .MID as the 2nd parm.

Code: Select all

#!/bin/sh

if [ ! $1 ]; then
  echo "USAGE: fs2wave file.mid"
  exit 0
fi

FILE_RAW="temp_test.raw"
FILE_WAV="temp_test.wav"

MIDI_INPUT=$1

SOUNDFONT="/usr/share/sounds/sf2/FluidR3_GM.sf2"
if [ $2 ]; then
  SOUNDFONT=$1
  MIDI_INPUT=$2
fi

OTHERPARM=" -C no -R no -n -i "
AUDIOPARM=" -L 2 -r 48000 "
FILERAW=" -a file -o audio.file.name="$FILE_RAW" "

echo -e "\nCreating -"$FILE_RAW"- ..."
fluidsynth $OTHERPARM \
           $AUDIOPARM \
           $FILERAW \
           $SOUNDFONT \
           $MIDI_INPUT

SOXINPUT=" -s -2 -c 2 -r 48000 "$FILE_RAW" "
SOXOUTPUT=" -s -2 -c 2 -r 48000 "$FILE_WAV" "

echo -e "\nConverting -"$FILE_RAW"- to -"$FILE_WAV"- ..."
sox $SOXINPUT \
    $SOXOUTPUT

exit 0
StudioDave
Established Member
Posts: 753
Joined: Sat Nov 01, 2008 1:12 pm

Re: How to MID to WAV

Post by StudioDave »

Shadow_7 wrote:... But timidity .pat files can sound quite hideous.
Instead of PAT files you can use SF2 fonts with TiMidity. My /etc/timidity/timidity.cfg contains only this line:

source /etc/timidity/fluidr3_gm.cfg

That file is also in /etc/timidity. It's a lengthy list of the Fluid_R3 soundfont's contents. Of course you can substitute any other font you prefer.

Best,

dp
Post Reply