Microsoft DirectX 9.0

Audio Scripts

An audio script is a file containing variables and routines that can be accessed from within an application. Scripts can be written using any Microsoft ActiveX® Scripting language, but DirectMusic Producer also enables scripting in a special language called AudioVBScript. The advantage of using AudioVBScript is that it requires a very small run-time library, which is one of the DirectMusic system components. AudioVBScript is a subset of Microsoft Visual Basic® Scripting Edition.

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

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

DirectMusic scripts make it easier for application developers and sound designers to coordinate their efforts. Scripts give sound designers 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.

The following scenario is one in which scripting might be helpful. It supposes that the sound effects for a game are stored as individual WAV 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 times in the game. But now the sound designers want to make some changes. They decide, for example, that the boss monster should have a different grunt than normal monsters. The sound designers 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.

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 play a grunt. Assume that that szGrunter has been set to a string constant such as "Player", "Boss", or "NormalMonster", 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, who is probably a member of the sound design team, decides what the routine does. For example, the routine 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 in the existing application.

The scripting API is documented in the DirectMusic Producer Help file.

See Also