Audio Handler

by Pokemonred200
A Basic Audio Handler for your games. Enjoy!
ID:1672154
 
Keywords: documentation
Okay, here's time for a long-overdue documentation. so here goes.

Off here with the basics, we have the object itself, audiohandler. This object should always be defined under the object tree for another object, such as a mob or client. To initialize the audio handler, pass the mob into the new() proc as such:
player
parent_type = /mob
audiohandler/Audio
New()
Audio = new(src)
. = ..()


Sounds are stored via id, such as those used in an associative list. To add a sound to the system, simply call addSound:

Audio.addSound(sound('Shell City Dead Ahead.ogg',channel=1),"1")


audiohandler.addSound() has three arguments. sound, the first argument, is the sound object that will be played; id, the second argument, is the id for the sound to be added; autoPlay, the third argument, will determine weather to automatically play the sound if TRUE is passed in, and The sound will not play automatically otherwise, requiring the use of audiohandler.playSound(id).
To allow the system to work properly, it should have a channel applied either via the sound proc or the audiohandler.setChannel(id,channel) procedure. This allows the removeSound(id) procedure to properly stop the sound from playing upon removal.

The music() procedure:
var sound/S = music('Shell City Dead Ahead.ogg',channel=1)


The music procedure, is like a modified version of the sound() procedure. It creates a /sound datum with its repeat variable set to TRUE by default, and the new music variable in /sound datums set to true. This is for the procedures SetGlobalVolume() and ToggleMute() mainly, which I will discuss next.

Audio.SetGlobalVolume(50)


This will set the volume for all sounds currently being held by the audiohandler object, as well as all sounds to be added to in in the future by audiohandler.addSound(). Passing 50 will set all sound/music currently in the datum to use half volume, and the most recently passed sound created by the music() proc will automatically take effect from it. Calling this procedure with a macro to increase/decrease sound (in conjugation with the audiohandler.volume variable) could be used for an in-game volume control.

Audio.toggleMute()


The name is pretty self-explanatory. Currently playing sounds and music will all be muted, and sounds added to the object via addSound() will also be muted by default. However, if the sounds are already muted, the reverse effect will happen and the sounds will be unmuted.

Audio.playSound(id)
Audio.pauseSound(id)
Audio.resumeSound(id)
Audio.muteSound(id)
Audio.removeSound(id)


These five procedures will play, pause, resume, mute, and remove a sound. audiohandler.removeSound() will stop a playing sound (provided the channel is set, as it will not properly stop otherwise) and and remove it from the sound ids list.

issound(S)
ismusic(S)


issound() will detect if S is a sound datum or not, while ismusic() will detect if S is a sound datum whose music variable is set to TRUE. However, ismusic() will return null rather than 0 if the music is not a sound datum, rather than issound() returning 0 in such case.

Audio.setRepeat(id) // Toggles Repeat
Audio.setChannel(id,channel)
Audio.setVolume(id,volume)
Audio.setPos(id,x,y,z)
Audio.setFrequency(id,frequency)
Audio.setEnvironment(id,environment)
Audio.setEcho(id,echo)
Audio.setPriority(id,priority)
Audio.setPan(id,pan)


These 9 procedures will set the corresponding settings of the sound object associated with the given id.