Tricks of the Windows Game Programming Gurus:Sounding Off with DirectSound and DirectMusic

All ITKnowledge Source Code Search Tips Advanced Search |

| Tricks of the Windows Game Programming Gurus by Andre LaMothe Sams, Macmillan Computer Publishing ISBN: 0672313618 Pub Date: 09/27/99

Search this book:

Previous | Table of Contents | Next

#### Synthesized Sound and MIDI

Although digital sound is currently the best-sounding, synthesized sound has been around a long time and is getting better and better. Synthesized sound isn’t digitally recorded; it’s a mathematical reproduction of a sound based on a description. Synthesizers use hardware and algorithms to generate sounds on-the-fly from a description of the desired sound. For example, let’s say you wanted to hear a 440Hz pure concert A note. You could design a piece of hardware that generated a pure analog sine wave of any frequency from 0-20,000Hz and then instruct it to create a 440Hz tone. This is the basis of synthesis.

The only problem is that most people want to hear more than a single tone (unless you’re listening to a musical birthday card), so hardware is needed that supports at least 16-32 different tones at the same time, as shown in Figure 10.6. This isn’t bad, and a number of different video game consoles used something like this back in the ’70s and ’80s. But people still weren’t satisfied. The problem is that most sounds have many frequencies in them; they have undertones, overtones, and harmonics (multiples of each frequency). This is what makes them sound textured and full.

Figure 10.6 Crude sound synthesis with multiple channels.

> Warning: Normally, I wouldn’t use the words textured and full to describe sound because it lowers my public cool factor, but I had to because they’re common terms used by music people. So please bear with me.

The first attempt at better sound was FM synthesis. Remember the old Ad-Lib card? It was the precursor of the Sound Blaster and the first PC card to support multiple-channel FM synthesis. (The FM stands for frequency modulation.) An FM synthesizer can alter not only the amplitude of a sine wave sound, but also the frequency of the wave.

FM synthesis operates on the mathematical basis of feedback. An FM synthesizer feeds the output of the signals back into themselves, thereby modulating the signals and creating harmonics and phase-shifted tones from the original single sine wave. The bottom line is that they sound very real compared to single tones.

#### It’s MIDI Time!

At about the same time all this FM synthesis stuff came out, a file format for music synthesis was catching on called MIDI (Musical Instrument Digital Interface). MIDI is a language that describes musical compositions as a function of time. Instead of digitizing a sound, a MIDI piece describes it as keys, instruments, and special codes. For example, a MIDI file might look like this:

    Turn on Channel 1 with a B flat.

    Turn on Channel 2 with a C sharp.

    Turn off Channel 1.

    .

    .

    .

    Turn all channels off.

Of course, this information is encoded in a binary serial stream, but you get the picture. Moreover, each channel in the MIDI specification is connected to a different instrument or sound. You might have 16 channels, each one representing a different instrument such as piano, drums, guitar, bass, flute, trumpet, and so on. So MIDI is an indirect method of encoding music.

However, it leaves the synthesis up to the hardware and records only the actual musical notes and timing. Alas, MIDI on one computer may sound completely different than on another, due to the method of synthesis and the instrument data. On the other hand, a MIDI file for an hour of music might only be a few hundred kilobytes of memory, instead of requiring megabytes for the same music in digital form! So it’s been worth it, in many cases.

The only problem with MIDI and FM synthesis is that they are only good for music. Sure, you can design FM synthesizers to create white noise for explosions or laser blasts, but the sounds will always be simple and won’t have the organic feel that digitized sound has. So more advanced methods of hardware synthesis have been created, such as wave table and wave guide technology.

### Sound Hardware

There are three major classes of sound synthesis these days: FM, wave table (software versions, too), and wave guide. You’ve already learned about FM, so let’s take a look at the wave table and wave guide models for a minute.

#### Wave Table Synthesis

Wave table synthesis is a mix between synthesis and digital recording. It works like this: The wave table has a number of real, sampled digital sounds within it. This data is then processed by a DSP (Digital Signal Processor), which takes the real sample and plays it back at any frequency and amplitude that you need. Hence, you can sample a real piano and then play any note on that piano using wave table synthesis. It sounds almost as good as digital, but you still have to have the original sources sampled. Again, that takes memory. The Creative Labs AWE32 is a good example of this.

In addition to hardware wave table, there are software synthesizer-based wave table systems, such as the MOD format for Amigas and the DLS system used in DirectMusic. Computers are so fast now that if you just have a D-to-A converter that plays digital sound, you can use it to synthesize digital sound based on software samples of real instruments much like the wave table does. As long as you can make the DSP happen in real-time and can perform frequency, amplitude, and other processing functions, you don’t need any hardware! This is exactly how DirectMusic works.

#### Wave Guide Synthesis

Wave guide synthesis is the ultimate synthesis technology. Through the use of DSP chips and very special hardware, the sound synthesizer can actually generate a mathematical model of an instrument virtually and then simply play it! This may seem like science fiction, but it’s a fact. With this technology, the human ear can’t perceive the difference between a sampled instrument, the real one, and the wave guide simulated instrument. Thus, you can create MIDI files that control a wave table or wave guide synthesizer and get great results. The Creative Labs AWE64 Gold has this technology.

So the verdict is, a synthesizer can create music as real as real can get, but the musical piece still must be encoded as MIDI. Also, if you want speech or special sound effects, they’re hard to do with synthesizers, and even with wave guide technology you’ll need special software.

However, with DirectMusic you can program instruments with digitized sounds and play them like notes, so that problem is solved. Thus, you can use digital sound for all your sound effects and DirectMusic for the music. Granted, there may be a little more work involved than just playing a wave file, but DirectMusic sounds the same on all machines, is free, can read standard MIDI files, and has a ton of features if you want to use them. Therefore, you may decide to use a mix of both: DirectSound for sound effects and DirectMusic for music.

Previous | Table of Contents | Next

Copyright © Macmillan Computer Publishing, Inc.

Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.