zombie.core.sound
Class SoundEngine

java.lang.Object
  extended by zombie.core.sound.SoundEngine

public class SoundEngine
extends java.lang.Object

The sound player. This queues up commands to play one-shot sound effects using a limited pool of sources. Each sound effect is given a priority. When a sound of higher priority is requested and there are no spare sources, the oldest, lowest priority sound effect is stopped and replaced with the new one. Every video frame you should call tick() which will play your requested sounds. This syncs it up nicely with the video.


Field Summary
static SoundEngine instance
           
 
Constructor Summary
SoundEngine()
          C'tor
 
Method Summary
 void create()
          Create the SoundEngine.
 void destroy()
          Destroy the sound player and all associated resources.
 void fadeIn()
          Fade in the entire sound engine quickly
 void fadeOut()
          Fade out the entire sound engine quickly
 Attenuator getDefaultAttenuator()
          Accessor for defaultAttenuator (unlikely you'll ever need this, but here just for completeness)
 float getGain()
          gets the master gain
 SoundEffect getMusic()
          gets a handle to the currently playing music.
 float getOriginX()
           
 float getOriginY()
           
 float getOriginZ()
           
 boolean isCreated()
           
 void music(Sound sound, int fadeDuration)
          Crossfade some music in
 SoundEffect play(Sound buf)
           
 void setDefaultAttenuator(Attenuator defaultAttenuator)
          Sets the default attenuator for this SoundEngine
 void setGain(float gain)
          Sets the master gain when the sound engine is faded in
 void setOrigin(float x, float y, float z)
          Sets the origin of the listener for the purposes of attenuation.
 void tick()
          Tick: call this every logic frame or every video frame you render, whichever occurs most often
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

public static SoundEngine instance
Constructor Detail

SoundEngine

public SoundEngine()
C'tor

Method Detail

create

public void create()
Create the SoundEngine. Does nothing if AL has not been initialised, or it has already been created.


destroy

public void destroy()
Destroy the sound player and all associated resources. Does nothing if create() has not been called successfully.


setGain

public void setGain(float gain)
Sets the master gain when the sound engine is faded in

Parameters:
gain - Must be between 0.0f and 1.0f inclusive

getGain

public float getGain()
gets the master gain

Returns:
0.0f...1.0f

tick

public void tick()
Tick: call this every logic frame or every video frame you render, whichever occurs most often


isCreated

public boolean isCreated()
Returns:
true if the SoundEngine has been created

play

public SoundEffect play(Sound buf)
Parameters:
buf - The sound buffer to play
owner - The owner of the sound effect
Returns:
a SoundEffect

fadeOut

public void fadeOut()
Fade out the entire sound engine quickly


fadeIn

public void fadeIn()
Fade in the entire sound engine quickly


music

public void music(Sound sound,
                  int fadeDuration)
Crossfade some music in


getMusic

public SoundEffect getMusic()
gets a handle to the currently playing music. You might conceivably use this to fade the volume of the music down to different levels in order to highlight speech or similar.

Returns:
the currently playing music effect, or null, if none is playing

setDefaultAttenuator

public void setDefaultAttenuator(Attenuator defaultAttenuator)
Sets the default attenuator for this SoundEngine

Parameters:
defaultAttenuator - Cannot be null

getDefaultAttenuator

public Attenuator getDefaultAttenuator()
Accessor for defaultAttenuator (unlikely you'll ever need this, but here just for completeness)

Returns:
the default attenuator for this SoundEngine (never null)

setOrigin

public void setOrigin(float x,
                      float y,
                      float z)
Sets the origin of the listener for the purposes of attenuation.

Parameters:
x -
y -

getOriginX

public float getOriginX()
Returns:
the X origin

getOriginY

public float getOriginY()
Returns:
the Y origin

getOriginZ

public float getOriginZ()
Returns:
the Y origin