Something I always wanted to do was to write a program that took a MIDI file and output an audio file. This is obviously a massive undertaking to do well, but I wanted to see how far I could get in a few days. I downloaded the MIDI file spec, and a couple of sample MIDI files and commenced coding. I understand some of the basics, like the fact that pure tones are sine waves, that you can combine waves by adding them together, that changes in frequency are multiplicative, not additive, and that in general, the world of sound is a place of gradual changes, in that pressure can change rapidly, but not instantly. From those basic concepts I was able to write a simple program to take my MIDI file and generate a PCM audio file.
Something I didn’t learn about until after trying this was not all sound pressures are equally loud. Humans are much more sensitive to frequencies in the 1 kHz to 4 kHz range than other frequencies. Some higher frequencies are perceived as louder than lower frequencies at the same amplitude. This gives way to a measurement of loudness called dBA rather than simply dB. The relationship of this measurement to loudness is, of course, dependent on your own ear! (Try measuring your own hearing response curve.) (This is very noticeable in the impromptu sample below.)
Something else I wasn’t expecting was that tempo can change in strange ways in MIDI files, and it’s not trivial to process all this data. I’m still not sure what exactly went wrong, but it has something to do with tempo tracks, which are not optional to process apparently.
So a few things I would like to add to this apart from dBA weighting and proper tempo processing are: different timbres, percussion, and effects like reverb and chorus, etc.
Anyway, check out my first attempt at pure music synthesis:
impromptu.mp3 (1 MB, 5 min)
wtc1021.mp3 (290 kB, 1 min 13 sec)

Comment from Wyck on February 6th, 2007
Link to impromptu.mp3 is fixed.