Many copies of the same sound.

Camille Goudeseune
If you have just a few sounds, you can use AUDinit/AUDupdate/AUDterminate in the usual way to initialize, modify, and eventually turn off these sounds.

This gets awkward, for example, when continuous sounds come from objects that come and go on the fly. Vehicles in a traffic simulation, enemies in a shoot-em-up.

In such cases you may not know until runtime how many copies of a sound you'll need; then your C application has to keep track of each sound instead of the .aud file. You can do this as follows:

  1. In your .aud file, create message groups to initialize and terminate one copy of the sound. The initialization message group should have a single BeginSound (or BeginSoundPaused) statement in it. The termination message group should "Delete" one of its parameters ("AddMessage MyTerminator Delete *0;" instead of the more conventional "AddMessage MyTerminator Delete MySound;").

  2. If needed, create more message groups to modify one copy of the sound.

  3. In your C code, use AUDupdate to invoke the initialization message group whenever you need another copy of the sound. Save the return value of AUDupdate: this is the handle to the sound created by BeginSound.

  4. In your C code, whenever you need to modify or delete a copy of the sound, use AUDupdate to invoke the appropriate message group, passing in the handle you saved earlier as just another member of the data array.
Here is example C code and a .aud file which creates several sounds, modifies them, and then deletes them, with the .aud file not specifying how many sounds there are:

Of course, beware of things getting too loud or too CPU-intensive, if you play dozens of continuous sounds at once. You may want to run vss -limit to keep the volume under control.


[ back ] [ up to main page ]