Step 2


Next go into the  Concertina.h file, locate the bestGuessAudio structure and replace the wave file names and associated settings with your own. For example, if your game is a simulation of four-wheel-drive vehicles, and you have wave files for engine sounds, squeaky wheels, gear changes, exploding engines, collisions, and breaking glass, along with ambient rain and thunder sounds, then your soundIDenum enumeration and bestGuessAudio structure might look like the following code.

 enum soundIDenum{      ID_engine = 0,      ID_squeakyWheel,      ID_gearChange,      ID_explodingEngine,      ID_collision,      ID_breakingGlass,      ID_rain,      ID_thunder,      // Terminate this enumeration with these values.      ID_end,      eNUM_fixedSounds = ID_end,      eNUM_allSounds = ID_end + Max_overflow_buffers  };  struct bestGuessAudioStruct bestGuessAudio[] = {  // ID file name 3-D Buffers (min 1, max 16).  {   ID_engine,              "engine.wav",           1,  4  },  {   ID_squeakyWheel,        "squeaky wheel.wav",    1,  16 },  {   ID_gearChange,          "gear change.wav",      1,  4  },  {   ID_explodingEngine,     "exploding engine.wav", 1,  1  },  {   ID_collision,           "collision.wav",        1,  1  },   {   ID_breakingGlass,       "breaking glass.wav",  1,  1  },  {   ID_rain,                "rain.wav",            0,  1  },  {   ID_thunder,             "thunder.wav",         0,  1  },  // Must have ID_end to terminate table.  {   ID_end,                 "end"  }  }; 

When you have completed this table, make sure that the order of the members of soundIDenum matches their order in the bestGuessAudio structure.

start sidebar
Performance Tip

Always create the sound buffers that are used most often, or are of greatest importance, first. This is because if you are using hardware acceleration, with each buffer you are consuming hardware resources, and eventually these resources will run out. If you do run out of resources, but buffers requiring hardware acceleration are continually requested , DirectSound will try to make a best guess, based on such things as distance from the listener, the time that a sound has been playing, and other criteria, to juggle the hardware resources available.

end sidebar
 

Note that the IDs are given names that match the wave files, but only to make it easy to understand, because there is no need here for an exact copy. The number that follows the wave file name is a flag set to either 1 (for sounds requiring 3-D effects), or 0 (for ambient sounds), and the last number is a best guess at the number of buffers required for each sound. The values that we entered in the previous code represent a game where up to four four-wheel-drive vehicles can be active at any one moment.

Notice that there is only one exploding engine sound. If you want to have more (for example, you want two engines exploding so close in time to each other that both cannot share the same buffer), then the overflow area should easily accommodate the second buffer. However, for engine sounds, you might be able to hear all four at once, and so should declare four buffers to make sure that all can be played simultaneously .

It is perfectly alright for you to enter zero for the number of buffers required. This means that the sound will only be played in the overflow area, and no buffers will be reserved for it. This is more efficient if you know that the sound will be rarely played.

Note that the bestGuessAudio structure assumes the wave files are all in the AVBook/Audio directory. If they are in a sub-directory of Audio, then that directory name should be added to the previous code, for example, if the sub-directory was called FWD, then enter all the wave file names preceded by FWD// .




Fundamentals of Audio and Video Programming for Games
Fundamentals of Audio and Video Programming for Games (Pro-Developer)
ISBN: 073561945X
EAN: 2147483647
Year: 2003
Pages: 120

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net