GTGE API

com.golden.gamedev.engine
Class BaseAudio

java.lang.Object
  extended by com.golden.gamedev.engine.BaseAudio
All Implemented Interfaces:
Runnable

public class BaseAudio
extends Object
implements Runnable

Audio manager that manages playing, stopping, looping of multiple audio sounds (BaseAudioRenderers).

Audio manager takes up a single base renderer parameter. The base is used to create new instance of BaseAudioRenderer to play new audio sound.

Audio manager also take care any idle renderer and looping audio renderer.

This class is using BaseIO to get the external resources.


Field Summary
static int MULTIPLE
          Multiple audio clips can be played at the same time (simultaneous).
static int SINGLE
          Audio clip with a same name only can be played once at a time.
static int SINGLE_REPLAY
          Same as SINGLE policy except the audio clip is force to replay.
 
Constructor Summary
BaseAudio(BaseIO base, BaseAudioRenderer baseRenderer)
          Creates new audio manager with specified renderer as the base renderer of all audio sounds created by this audio manager.
 
Method Summary
protected  BaseAudioRenderer createRenderer()
          Constructs new audio renderer to play new audio sound.
 int getAudioPolicy()
          Returns the default audio policy used by this audio manager to play audio sound when no audio policy is specified.
 BaseAudioRenderer getAudioRenderer(int slot)
          Returns audio renderer in specified slot.
 BaseAudioRenderer getAudioRenderer(String audiofile)
          Returns audio renderer with specified audio file or null if not found.
 BaseIO getBaseIO()
          Returns BaseIO from where this audio manager is getting all audio sound resources.
 BaseAudioRenderer getBaseRenderer()
          Returns the base renderer of this audio manager.
 int getBuffer()
          Returns total renderer allowed to create before audio manager attempt to replace idle renderer.
 int getCountRenderers()
          Returns total audio renderer created within this audio manager.
 String getLastAudioFile()
          Returns the last played audio file.
 int getMaxSimultaneous()
          Returns maximum simultaneous same audio sound can be played at a time.
 BaseAudioRenderer[] getRenderers()
          Returns all audio renderers (playing and idle renderer) associated with this audio manager.
 float getVolume()
          Returns audio manager volume.
 boolean isActive()
          Returns true, if this audio manager is fully functional.
 boolean isAvailable()
          Returns whether this audio manager is available to use or not.
 boolean isExclusive()
          Returns true, if only one clip is allowed to play at a time.
 boolean isLoop()
          Returns true, if all the audio sounds are played continously.
 int play(String audiofile)
          Plays audio clip with default policy.
 int play(String audiofile, int policy)
          Plays an audio clip based on specified policy (SINGLE, MULTIPLE, SINGLE_REPLAY).
 void run()
          Thread implementation for managing audio renderers looping.
 void setActive(boolean b)
          Turn on/off this audio manager.
 void setAudioPolicy(int i)
          Sets the default audio policy used by this audio manager to play audio sound when no audio policy is specified.
 void setBaseIO(BaseIO base)
          Sets BaseIO from where this audio manager is getting all audio sound resources.
 void setBaseRenderer(BaseAudioRenderer renderer)
          Sets specified audio renderer as this audio manager base renderer.
 void setBuffer(int i)
          Sets total renderer allowed to create before audio manager attempt to replace idle renderer.
 void setExclusive(boolean exclusive)
          Sets whether only one clip is allowed to play at a time or not.
 void setLoop(boolean loop)
          Sets whether all the audio sounds should be played continously or not.
 void setMaxSimultaneous(int i)
          Sets maximum simultaneous same audio sound can be played at a time.
 void setVolume(float volume)
          Sets audio manager volume range in [0.0f - 1.0f].
 void stop(int slot)
          Stops audio playback in specified slot.
 void stop(String audiofile)
          Stops audio playback with specified name.
 void stopAll()
          Stops all played audio playbacks in this audio manager.
 void stopAll(BaseAudioRenderer except)
          Stops all played audio playbacks in this audio manager except specified renderer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SINGLE

public static final int SINGLE
Audio clip with a same name only can be played once at a time. The audio clip is continued if the clip is currently playing.

To force the clip to replay, set the audio policy to SINGLE_REPLAY instead.

See Also:
setAudioPolicy(int), play(String, int), Constant Field Values

MULTIPLE

public static final int MULTIPLE
Multiple audio clips can be played at the same time (simultaneous).
Note: when using exclusive mode (only one audio clip can be played at a time), MULTIPLE policy is obsolete, and automatically changed into SINGLE.

See Also:
setAudioPolicy(int), play(String, int), Constant Field Values

SINGLE_REPLAY

public static final int SINGLE_REPLAY
Same as SINGLE policy except the audio clip is force to replay.

See Also:
setAudioPolicy(int), play(String, int), Constant Field Values
Constructor Detail

BaseAudio

public BaseAudio(BaseIO base,
                 BaseAudioRenderer baseRenderer)
Creates new audio manager with specified renderer as the base renderer of all audio sounds created by this audio manager.

Parameters:
base - the BaseIO to get audio resources
baseRenderer - the base renderer of this audio manager
Method Detail

run

public void run()
Thread implementation for managing audio renderers looping.

Specified by:
run in interface Runnable

play

public int play(String audiofile)
Plays audio clip with default policy.

Returns:
Slot which the audio is played.
See Also:
getAudioRenderer(int)

play

public int play(String audiofile,
                int policy)
Plays an audio clip based on specified policy (SINGLE, MULTIPLE, SINGLE_REPLAY).

Returns:
Slot which the audio is played.
See Also:
getAudioRenderer(int)

stop

public void stop(int slot)
Stops audio playback in specified slot.


stop

public void stop(String audiofile)
Stops audio playback with specified name.


stopAll

public void stopAll()
Stops all played audio playbacks in this audio manager.


stopAll

public void stopAll(BaseAudioRenderer except)
Stops all played audio playbacks in this audio manager except specified renderer.

See Also:
getAudioRenderer(String), getAudioRenderer(int)

getAudioRenderer

public BaseAudioRenderer getAudioRenderer(int slot)
Returns audio renderer in specified slot.


getAudioRenderer

public BaseAudioRenderer getAudioRenderer(String audiofile)
Returns audio renderer with specified audio file or null if not found.


getLastAudioFile

public String getLastAudioFile()
Returns the last played audio file.

This method is used for example when audio manager is set to active state from inactive state, if the game wish to play the last played audio, call play(getLastAudioFile()).

See Also:
play(String)

getRenderers

public BaseAudioRenderer[] getRenderers()
Returns all audio renderers (playing and idle renderer) associated with this audio manager.

See Also:
getCountRenderers()

getCountRenderers

public int getCountRenderers()
Returns total audio renderer created within this audio manager.

See Also:
getRenderers()

getVolume

public float getVolume()
Returns audio manager volume.

See Also:
setVolume(float)

setVolume

public void setVolume(float volume)
Sets audio manager volume range in [0.0f - 1.0f].

If setting volume of base renderer is not supported, this method will return immediately.

See Also:
getVolume()

getAudioPolicy

public int getAudioPolicy()
Returns the default audio policy used by this audio manager to play audio sound when no audio policy is specified.

See Also:
play(String)

setAudioPolicy

public void setAudioPolicy(int i)
Sets the default audio policy used by this audio manager to play audio sound when no audio policy is specified.

Parameters:
i - the default audio policy, one of SINGLE, MULTIPLE, SINGLE_REPLAY
See Also:
play(String)

getMaxSimultaneous

public int getMaxSimultaneous()
Returns maximum simultaneous same audio sound can be played at a time.


setMaxSimultaneous

public void setMaxSimultaneous(int i)
Sets maximum simultaneous same audio sound can be played at a time.


isExclusive

public boolean isExclusive()
Returns true, if only one clip is allowed to play at a time.

See Also:
setExclusive(boolean)

setExclusive

public void setExclusive(boolean exclusive)
Sets whether only one clip is allowed to play at a time or not.

Parameters:
exclusive - true, only one clip is allowed to play at a time
See Also:
isExclusive()

getBuffer

public int getBuffer()
Returns total renderer allowed to create before audio manager attempt to replace idle renderer.

See Also:
setBuffer(int)

setBuffer

public void setBuffer(int i)
Sets total renderer allowed to create before audio manager attempt to replace idle renderer.

See Also:
getBuffer()

isLoop

public boolean isLoop()
Returns true, if all the audio sounds are played continously.

See Also:
setLoop(boolean)

setLoop

public void setLoop(boolean loop)
Sets whether all the audio sounds should be played continously or not.

See Also:
isLoop()

getBaseIO

public BaseIO getBaseIO()
Returns BaseIO from where this audio manager is getting all audio sound resources.

See Also:
setBaseIO(BaseIO)

setBaseIO

public void setBaseIO(BaseIO base)
Sets BaseIO from where this audio manager is getting all audio sound resources.

See Also:
getBaseIO()

isActive

public boolean isActive()
Returns true, if this audio manager is fully functional.

See Also:
setActive(boolean)

setActive

public void setActive(boolean b)
Turn on/off this audio manager.

Note: unavailable audio manager can't be switch to on.

Parameters:
b - true, turn on this audio manager
See Also:
isActive(), isAvailable()

isAvailable

public boolean isAvailable()
Returns whether this audio manager is available to use or not.

Unavailable audio manager is caused by unavailable base renderer.


getBaseRenderer

public BaseAudioRenderer getBaseRenderer()
Returns the base renderer of this audio manager.

See Also:
setBaseRenderer(BaseAudioRenderer)

setBaseRenderer

public void setBaseRenderer(BaseAudioRenderer renderer)
Sets specified audio renderer as this audio manager base renderer.

All renderers in this audio manager is created based on this base renderer.

See Also:
getBaseRenderer()

createRenderer

protected BaseAudioRenderer createRenderer()
Constructs new audio renderer to play new audio sound.

The new audio renderer is created using Class.forName(String) from the base renderer class name.

See Also:
getBaseRenderer()

GTGE API

Copyright © 2003-2005 Golden T Studios. All rights reserved. Use is subject to license terms.
GoldenStudios.or.id