Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

TiMidity: Fast and Easy MIDI Rendering

tai

Member

I just remembered an old program I used to render MIDIs into MP3s or Ogg vorbis whatever audio you choose. It can also be used as a general MIDI player, capable of outputting directly to your soundcard. I will give a brief overview and how-to of this program, TiMidity. If you would like to start downloading the files necessary to complete the tutorial now and allow them to complete as you are reading this, check the spoiler at the end of this post. You will need my TiMidity package, LAME MP3 Encoder and OggEnc2.

Firstly, why would we prefer MP3/Ogg over MIDI?

  • 1. Most obviously, it sounds much better. There's an infinite choice of soundfonts to pick from to find the right 'feel' for your song.

    2. It will sound the same on all systems. A problem with MIDI is that different soundcards make the same MIDI sound different. This is due to the nature of MIDI, since the file itself doesn't hold any samples (actual audio data), just instructions of which samples the sound card should retrieve from its bank and the rhythm/pitch of such samples etc. Thus, a MIDI may sound decent on your card but totally awful on another.

    3. It will be extremely difficult to extract the tracks from a non-midi song. MIDI is basically a digital score, but transcribing an MP3/Ogg/etc. will require a. special software   and/or b. tons of time.

But before you jump and say "midi sucks", here are some reasons why MIDI is superior over other formats.

  • 1. MIDI files are tiny. REALLY tiny. a full 3-minute song can be contained in a file less of than 10kB. On the other hand, an average-quality MP3 of the same length will be about 3MB, about 30,000% the size.

    2. MP3/Ogg files are difficult to have repeat over and over properly. It is very likely that you will need a special script if you want MP3/Ogg audio files to repeat as well as MIDI.

    3. it will be extremely difficult to extract the tracks from a non-midi song. MIDI is basically a digital score, but transcribing an MP3/Ogg/etc. will require a. special software   and/or b. tons of time.


So, onto TiMidity. I uploaded TiMidity with a small soundfont and corresponding config file here. Download that and extract it to any folder. It's a stand-alone application, no installation needed. timw32g.exe is the main program file; open it up. We see a little retro-style program with a large green block on the right side. This will be a brief overview more than a full in-depth tutorial, so I'll only go over the crucial aspects of this software. There are lots of other resources around the web if you want to dig deeper into this program. (see spoiler at end of post)

Open up the preferences. Config > Preferences. You'll see it looking for the config in K:\. Unless by fluke that is correct, re-point it to the correct location of the merlin_gmv22.cfg file. (you can click Config File to bring up a browse dialogue). Click Reload Config File after you re-point it to the directory for it to load the config file, otherwise... it acts stupid and does nothing. A lot of the options in the Player or Effect tab of the preferences window will change the sound, but best to leave it alone for now. OK-close the preferences and return to the main program window. Now, load up a MIDI file. You can File > Open or drag-and-drop. You should hear the song; press play if it didn't auto-play. If you don't hear anything, check your console. My console shows this:
Working Console Window":ofbq7ijv said:
MIDI file: H:\Multimedia\Audio\RM\NunoAle\02 Avanbel.mid
Format: 1  Tracks: 5  Divisions: 480
Sequence:
Track name: Track 1
Track name: Track 2
Track name: Track 3
Track name: Track 4
If you see anything significantly different, post here and I'll try to help you out.

Now, onto rendering the file. You'll need some additional programs to do this, these will convert the file from a raw waveform (a .wav file) to the format of your choice.  I know TiMidity has some features to automatically render to popular formats, but I can't remember how to get those working (you need additional files and config settings). It's good to learn some command-line work, anyway.
Firstly, we must use TiMidity to create a .wav file for the encoders to work from. To do this, select RIFF WAVE file from the Output menu. By default, it will save it to output.wav in the folder TiMidity is in, you can change this in Output tab of the Preferences window. Press Play. You'll see TiMidity speed through the file; it is rendering it to .wav using the soundfont specified in the preferences.

I will go over how to encode to two of the more popular formats, MPEG-Layer 3 (.mp3) and Ogg Vorbis (.ogg). For MP3, I will cover the tutorial with the LAME MP3 encoder. for Ogg, I will cover the tutorial with OggEnc2. You can get the LAME MP3 encoder here and OggEnc2 (get the generic version if you're uncertain) here.  For simplicity's sake, copy the files to a single directory (this includes your output.wav and whatever files the encoder came packaged with). Open up your command prompt (this is the white-text on black-window thing). You can find it under Start Menu > Programs > Accessories.
  • driveletter: will change the active drive. for example, typing k: [enter] will take you to k:\, if you have one.
  • cd <folder name> will open up <folder name> if it exists in the active directory. For example, typing cd windows when C:\ is active will take you to C:\windows; if you had typed cd windows\system32 it would have taken you to C:\windows\system32.
  • cd .. will go up one level. for example, typing cd .. when C:\windows\fonts is active will take you to C:\windows.
  • cd \ will take you back to the root directory. for example, typing cd \ when C:\windows\temp is active will take you to C:\.
  • exit will close the command prompt.
I believe that's all you need to know for this tutorial.

In the command prompt, navigate to the directory you saved the files in.

Type lame -q 4 output.wav final.mp3 . This will convert the output.wav file into an mp3 file called 'final.mp3' with the setting -q 4. The -q 4 switch indicates that you want a variable bit-rate file of quality index 4. Note that the lower the quality index the higher the quality, i.e. a -q 2 file is bigger and better quality than a -q 8 file. Generally, variable bit rate files are the most efficient, however you can replace -q 4 with -a 192 to produce an output file with an average bitrate of 192 kbps. (e.g. lame -a 112 output.wav average.mp3 will produce an mp3 called average with an average bitrate of 112 kbps) I do not recommend constant bitrate files, but if you so desire, replace -q 4 with -b 128 to produce a file with a constant bitrate of 128 kbps.
You can add tags (title, artist, etc) with LAME but I recommend doing that in your preferred MP3 player since it's easier that way anyway. But for a full list of options, enter lame -? .
Type oggenc2 -q 4 output.wav -o final.ogg . This will convert the output.wav file into an ogg vorbis file called 'final.ogg' with the setting -q 4. The -q 4 switch indicates that you want an ogg vorbis file with quality index 4. For ogg vorbis files, the higher the quality index, the higher the quality and bigger the file. The -o indicates that the following text is the desired output filename. If you don't include this tag, it will save the .ogg with the same name as the .wav file. (i.e. output.ogg)
Tagging ogg files (title, artist, etc.) is a little trickier than MP3s since fewer programs support it. If you wish to use oggenc2 to tag the files, the following are a list of options: (just append these to the end of the command you type) The quotes are necessary if you have spaces in the field. COMMANDS ARE CASE SENSITIVE!
-d "date"
-N "tracknum"
-t "title"
-l "album"
-a "artist"
-G "genre"


For example, oggenc2 -q 3 output.wav -o anvabel.ogg -t "Theme of Anvabel" -a NunoAle will convert output.wav into an ogg vorbis file called anvabel.ogg at quality index 3, with the title Theme of Anvabel and an artist of Nunoale.

I hope that I have explained this complicated process well enough for you to successfully accomplish what you wished to have accomplished. If you have any questions, whether regarding Timidity, the clarity of this guide, audio file formats, feel free to PM me or leave a reply here. In the following spoiler I have placed all the download links, as well as an additional resource where you can find TiMidity config files and links to soundfont banks.

 
Hey tai.

Before anything, thanks for this Tut! I was needing it!

My problem: I can't hear anything. This is what it says on my console:

Working Console Window":30p0eqn4 said:
MIDI file: C:\Documents and Settings\- Nuno\Desktop\Soft Summer Night.mid
Format: 1  Tracks: 2  Divisions: 480
Sequence:
Track name: Track 1
No pre-resampling cache hit

What do I do?
 

tai

Member

Aha. you need to press Reload Config File in the prefs after you re-point it to the directory for it to load the config file. Otherwise... it acts stupid and does nothing. I will edit this into my main post.

p.s. yours should be "quote from: Broken Console Window" =P
 
Another question...

I have heard some very realistic sounds that were made in MIDIs. I know those are resources found on the internet, but, how do you insert the ones you really need on your songs?
 

tai

Member

If I understand correctly, there are some songs you have heard that were created from MIDIs but sound very realistic. Some of the extremely realistic ones (like releases from Dox) use professional soundfonts that cost $$$$$. There are some good ones online though, check the downloads spoiler at the end, tons of resources can be found at that last site. Generally, the bigger the soundfont file (.sf2), the better the quality/realism. Generally.

The voices are defined in the config file, for your case, the merlin_gmv22.sf2 config file. The site I provided has a whole bunch sample config files for many of the popular soundfonts, if you can't find one for the soundfont you downloaded (or it doesn't work) open up a config file in notepad wordpad it should be somewhat self-explanatory:
1 %font merlin_gmv22.sf2 0 1 amp=87 pan=0
means that, for voice 1 (acoustic bright piano), it'll look in the file merlin_gmv22.sf2 and take the samples from the 1st voice of the 0th bank, with a volume of 87(out of 255) and not pan it (0 = center).
The voice and bank settings will be set properly, the only reason why they wouldn't is if the config file was made to replace one instrument with another. It's also possible to combine soundfonts this way, by directing the voices at different soundfonts. But in a typical case, you only need to change all the merlin_gmv22.sf2 to the new soundfont filename and reload the config file. (hint: edit > replace)(so it's easiest to have one config file per soundfont)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top