AGI Sound Tutorial - Sound in Your Game

From AGI Wiki
Jump to: navigation, search

Tutorials and Guides Table of Contents
AGI Sound Tutorial Index

Page: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12

Sound in Your Game

by Nick Sonneveld

Last Updated 4th March, 2002


Sound in your game

Sndt larry.png
Here's the section where you get to find out how to play a sound in your game. Most of this is probably obvious to the veteran AGI developer, but at least it's all laid out. The interpreter's sound system is fairly simple: only letting you play one sound at a time, and lets you set a flag when the sound is done. Sounds cannot be played across rooms, games, if you quit or pause. The sound must exist in the volume resources or the interpreter will just print an error and quit.

Sound in AGI are controlled by a handful of flags, variables and commands:

  • command - "load.sound(sound number)"
  • command - "sound(sound number, done flag)"
  • command - "stop.sound()"
  • command - "discard.sound(sound number)' (only on Amiga v3 interpreters)
  • flag 9 - sound state
  • done flag (variable) - flag which is reset when the sound is playing, set when it is finished.
  • variable 22 - sound type
  • variable 23 - sound volume.

Sample code

Here is a basic logic template for a room which plays a sound:

    // only true if a new room (flag 5)
    if (isset(f5))
        // init code
        // ...
        // load up the new sound
        // more init code
        // ...
        // go through logic 0 again before doing anything else.
    if (/*certain event occurs*/)
        // event code
        // ...
        // play a sound, set flag 240 when finished
        sound(10, f240);
    // the sound is finished, so clean up
    if (isset(f240))
        // another action
        // ...
    // in case we have to stop the sound early
    if (/*another event occurs*/)


The interpreter looks at two flags whenever you play a sound. Flag 9 which defines whether or not to actually play sounds and then the flag you define when you play a sound.

  • Flag 9: If this is set, then sounds will play. If it is not set. then.. hey, sounds won't play.
  • Done flag: Whenever you play a sound, this flag is cleared. This is always done, even if flag 9 is not set. When it gets to playing the sound itself, when the sound is finished, or it discovers flag 9 is set (even whilst in the middle of a song), it will stop the sound and set the done flag. So if sound is disabled, the done flag will appear to have been set instantaneously.


There are three variables that dictate how the sound works.

  • Sound type (var 22)- defines how many tone channels are available to play. PC interpreters set this to 1. Amiga, Mac and PCjr set this to 3.
  • Sound volume (var 23) - defines the overall volume of games. The volume in agi sounds go from 0 (maximum volume) to 15 (silent). Notice how 0 is the MAXIMUM volume and not 15. It seems like it is in reverse, but just think of it as a value subtracted from the max volume. A lot of fan made games incorrectly set this value wrong, so their music comes out silent on interpreters that properly handle the volume variable.

Interpreter Capabilities

The capabilities of different AGI interpreters differ from interpreter to interpreter. Hopefully this table will help you pick the interpreter you wish to use for your game:

  • PC - supports only the first channel for music out of the pc speaker. Old reliable. You have to make sure the music sounds semi-good on this interpreter at least.
  • Amiga, Macintosh, PCjr - supports the 3 channels and the noise channel. Amiga v3 interpreters allow you to discard games. Will require you to use an emulator to run the interpreter however.pre envelope interpreters
  • AGIL - Supports the full 3 channels and proper noise support (different noise frequencies). I've noticed with one sound it missed the first note but otherwise it's great. Don't know how it supports the done flag.
  • NAGI - Supports the full 3 channels, proper noise and envelopes for notes add a bit more emphasis. Properly supports the done flag.
  • Sarien - Supports the full 3 channels, basic noise support and envelopes as well. Sarien was the first interpreter to have all of these features. The noise support is only white noise and does not support the different frequencies. Earlier versions had problems with not resetting the done flag, but recent version have this fixed.
  • Interpreter patches - patches to the original PC interpreter to support SoundBlaster or MIDI. Full 3 channels but no noise support.


Through the ingenuity of the AGI community, some people managed to patch onto the original interpreter the ability to play sounds through the sound blaster or a midi device. Considering the PC interpreter was designed to only use the PC or PCjr speaker, this is pretty amazing. The two known sound patches available are AGISB and AGI-MIDI. Unless you have a midi device connected to your soundcard, I would recommend using AGISB. The command to call either of these programs is pretty easy. Call it in the same directory as your interpreter:

agisb <infile> <outfile>
agimidi <infile> <outfile>

where infile and outfile are exectuable names.


Page: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12


Tutorials and Guides Table of Contents
AGI Sound Tutorial Index

< Previous: Playing Sounds with External ToolsNext: In the Future >