Microsoft DirectX 8.1 (C++)

Audio Scripts

An audio script is a file containing variables and routines that can be accessed from within an application. It is written in a subset of Microsoft® Visual Basic® Scripting Edition called AudioVBScript. DirectMusic Producer includes an authoring environment for scripts and saves them in a special format that includes binary parameters as well as the text of the script.

Scripts implement some of the key DirectX Audio objects and can perform basic functions such as the following:

DirectX Audio scripts are designed to make it easier for application developers and sound designers to coordinate their efforts. Scripts enable sound designers to have greater and more immediate control over the soundtrack. The basic functionality of loading and playing sounds is performed by the script. The application contains generalized code that calls into the script.

Here's an example of how this might be helpful.

The sound effects for a certain game are stored as individual wave files. The game uses these sounds for events such as weapons firing and monsters grunting. Using conventional programming techniques, the developers load the individual sounds by file name and play them as secondary segments at appropriate points in the game.

Suppose the sound designers want to make some changes. They decide, for example, that the boss monster should have a different grunt than his minions. They create the necessary files and hand them off to the developers, who implement the changes in code. Considerable time may pass before the sound designers are able to get a newly compiled version of the game and test it.

Now imagine the same scenario using an audio script. Rather than hard-coding the actual sounds into the application, the developers might write code like the following to respond to a grunt. Assume that that szGrunter has been set to a string constant such as "Player", "Boss" or "Minion", and that pdmScript is an interface to the script object:

pdmScript->SetVariableVariant("Grunter", szGrunter, NULL);
pdmScript->CallRoutine("PlayGrunt", NULL);

This fragment of code sets the value of the Grunter variable in the script and calls the PlayGrunt script routine. The script author—most likely a member of the sound design team—decides what the routine does. For example, it might test the value of Grunter before deciding what sound to play.

To change the response to the game situation, all that is required is an alteration in the text of the script, and the new routine can be tested immediately against the existing application.

The scripting API is documented in the DirectMusic Producer Help file. For more information on how to implement a script in your application, see Using Audio Scripts.

Note   Audio scripts are not designed to be used on Web pages.