Basic sound functions

There are five basic functions related to sounds, two to play a sound, one to check whether a sound is playing, and two to stop sounds. Most take the index of the sound as argument. The name of the sound represents its index. But you can also store the index in a variable, and use that.

sound_play(index) Plays the indicates sound once. If the sound is background music the current background music is stopped.
sound_loop(index) Plays the indicates sound, looping continuously. If the sound is background music the current background music is stopped.
sound_stop(index) Stops the indicates sound. If there are multiple sounds with this index playing simultaneously, all will be stopped.
sound_stop_all() Stops all sounds.
sound_isplaying(index) Returns whether (a copy of) the indicated sound is playing. Note that this functions returns true when the sound actually plays through the speakers. After you call the function to play a sound it does not immediately reach the speakers so the function might still return false for a while. Similar, when the sound is stopped you still hear it for a while (e.g. because of echo) and the function will still return true.

It is possible to use further sound effects. In particular you can change the volume and the pan, that is, whether the sound comes from the left or right speaker. In all these cases the volume can only be reduced. These functions do not work for files that play through the media player (like mp3 files).

sound_volume(index,value) Changes the volume for the indicated sound (0 = low, 1 = high).
sound_global_volume(value) Changes the global volume for all sounds (0 = low, 1 = high).
sound_fade(index,value,time) Changes the volume for the indicated sound to the new value(0 = low, 1 = high) during the indicated time (in milliseconds). This can be used to fade out or fade in music.
sound_pan(index,value) Changes the pan for the indicated sound (-1 = left, 0 = center, 1 = right).
sound_background_tempo(factor) Changes the tempo of the background music (if it is a midi file). factor indicates the factor with which to multiply the tempo. So a value of 1 corresponds to the normal tempo. Larger values correspond to a faster tempo, smaller values to a slower tempo. Must lie between 0.01 and 100.

Besides midi and wave files (and mp3 file) there is actually a fourth type of file that can be played: direct music files. These have the extension .sgt. Such files though often refer to other files describing e.g. band or style information. To find these files, the sound system must know where they are located. To this end you can use the following functions to set the search directory for files. Note though that you must add the files yourself. Game Maker does not automatically include such additional files.

sound_set_search_directory(dir) Sets the directory in which direct music files are to be found. The dir string should not incluce the final backslash.
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)