|Written by Harry Fairhead|
|Monday, 07 January 2013|
Page 2 of 2
Producing a tune
If you want to use an FM synthesizer to produce a tune you have to write a program to generate the right notes at the right time.
Well this isn’t entirely true because there is a way to record music using an FM chip. Using an industry standard MIDI interface even an early SoundBlaster card could be connected to a keyboard – usually a synthesizer in its own right. A musician plays on the keyboard and the software records what notes were hit and when. The result can be edited and replayed as part of a game or as background music.
If you have never heard a MIDI file then it’s worth having a listen. Open whatever media player your machine has and look for files ending .mid or .midi. If you are using a recent version of Windows then you probably wont find any but you can find some examples to download by searching the web - Wikipedia has an interesting public domain example.
MIDI files can be impressive, even more so when you consider how little space they take up, but they often sound a like a mechanical fairground organ. Perhaps for this reason MIDI files aren’t as common as they once were. An exception to this observation is their use in web pages to provide some, usually annoying, background music! A MIDI file is much more compact than the corresponding wave file, no matter how much it is compressed, and this makes it ideal for fast downloading.
MIDI wasn't included in the original HTML5 audio tag specification but it has been recently added. What this means is that playing MIDI files is about to get a lot easier and a lot more standards. Chrome already supports MIDI in its implementation of the audio tag.
Although MIDI is often assumed to mean FM Synthesis today’s sound hardware has mostly given up this method of creating musical instruments. Instead they use the more advanced approach of “sampling”. The idea is fairly simple. Instead of trying to find a recipe for a set of frequencies that make a sound like a trumpet, sampling uses an ADC to record a trumpet playing a single note.
This sounds simple enough but the clever part is to use the single sample to create a trumpet note of any desired pitch. This isn’t that hard to do in principle but difficult enough in practice to keep FM Synthesis in business until comparatively recently.
Today’s sound hardware mostly don’t use an FM Synthesis chip to implement MIDI music. Instead they contain a table of samples for each of the standard musical instruments and a digital signal processor chip capable of shifting the pitch of the sample – hence the alternative name “wave table synthesis”.
This produces much more realistic sounding instruments but the basic method of using the facility remains the same as for an FM chip. More expensive addon sound cards also offer the facility to record your own samples to extend the range of instruments that can be played via MIDI. Although this can be fun, it’s obviously something that you are only going to really need if you are a keen music maker.
It is worth mentioning that a sound card with a MIDI interface can take control of external MIDI instruments and play them under software control.
So you want to gain control over the sound hardware.
If you are using Windows then the top level API is the DirectSound and/or the DirectMusic component of DirectX. Put simply DirectSound does wave synthesis via a DAC and DirectSound does MIDI synthesis and replay. The only problem is that DirectSound is deprecated and isn't available on 64-bit processors.
In fact both DirectSound and DirectMusic along with a more general API Windows Multimedia are listed as Legacy APIs and to be avoided if possible.
At a lower level the Core Audio APIs were rewritten for Window Vista /7 but these are not available for earlier versions of Windows.
What all this means is that using sound under Windows is either a matter of using well tried but legacy APIs or using more modern APIs that are not backwards compatible.
Today’s sound cards are improved in their use of a digital signal processor (DSP) to produce effects such as reverberation and echo, and to perform compression and decompression without involving the main processor. Given a good set of speakers and a suitable surround sound amplifier the DSP can produce good 3D sound. When the plane flies overhead the sound appears to come from above, even though there are no speakers stuck to the ceiling.
As far as sound goes – the PC has reached its evolutionary pinnacle, or has it…
To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin, or sign up for our weekly newsletter.
or email your comment to: firstname.lastname@example.org
|Last Updated ( Monday, 07 January 2013 )|