zombie.openal
Class SoundStore

java.lang.Object
  extended by zombie.openal.SoundStore

public class SoundStore
extends java.lang.Object

Responsible for holding and playing the sounds used in the game.

Author:
Kevin Glass, Rockstar setVolume cleanup

Field Summary
 java.util.Stack<AudioImpl> audioStore
           
 java.util.Stack<AudioImpl> usedAudio
           
 
Method Summary
 void clear()
          Clear out the sound store contents
 void disable()
          Disable use of the Sound Store
static SoundStore get()
          get the single instance of this class
 Audio getAIF(java.io.InputStream in)
          get the Sound based on a specified AIF file
 Audio getAIF(java.lang.String ref)
          get the Sound based on a specified AIF file
 Audio getAIF(java.lang.String ref, java.io.InputStream in)
          get the Sound based on a specified AIF file
 AudioImpl getAudio()
           
 float getCurrentMusicVolume()
          get the volume scalar of the music that is currently playing.
 Audio getMOD(java.io.InputStream in)
          get a MOD sound (mod/xm etc)
 Audio getMOD(java.lang.String ref)
          get a MOD sound (mod/xm etc)
 Audio getMOD(java.lang.String ref, java.io.InputStream in)
          get a MOD sound (mod/xm etc)
 float getMusicVolume()
          get the volume for music
 Audio getOgg(java.lang.String ref)
          get the Sound based on a specified OGG file
 Audio getOgg(java.lang.String ref, java.lang.String file)
          get the Sound based on a specified OGG file
 Audio getOggFile(java.lang.String ref)
           
 Audio getOggFile(java.lang.String ref, java.lang.String file)
           
 Audio getOggStream(java.lang.String ref)
          get the Sound based on a specified OGG file
 Audio getOggStream(java.net.URL ref)
          get the Sound based on a specified OGG file
 float getSoundVolume()
          get the volume for sounds
 int getSource(int index)
          get the ID of a given source
 int getSourceCount()
          Retrieve the number of OpenAL sound sources that have been determined at initialisation.
 Audio getWAV(java.io.InputStream in)
          get the Sound based on a specified WAV file
 Audio getWAV(java.lang.String ref)
          get the Sound based on a specified WAV file
 Audio getWAV(java.lang.String ref, java.lang.String in)
          get the Sound based on a specified WAV file
 void init()
          Initialise the sound effects stored.
 boolean isDeferredLoading()
          Check if we're using deferred loading
 boolean isMusicOn()
          Check if music should currently be playing
 boolean isMusicPlaying()
          Check if the music is currently playing
 boolean musicOn()
          Check if music is currently enabled
 void pauseLoop()
          Pause the music loop that is currently playing
 void poll(int delta)
          Poll the streaming system
 void restartLoop()
          Restart the music loop that is currently paused
 void setCurrentMusicVolume(float volume)
          Set the music volume of the current playing music.
 void setDeferredLoading(boolean deferred)
          True if we should only record the request to load in the intention of loading the sound later
 void setMaxSources(int max)
          Set the maximum number of concurrent sound effects that will be attempted
 void setMusicOn(boolean music)
          Inidicate whether music should be playing
 void setMusicPitch(float pitch)
          Set the pitch at which the current music is being played
 void setMusicVolume(float volume)
          Set the music volume
 void setSoundsOn(boolean sounds)
          Indicate whether sound effects should be played
 void setSoundVolume(float volume)
          Set the sound volume
 boolean soundsOn()
          Check if sound effects are currently enabled
 boolean soundWorks()
          Check if sound works at all
 void stopSoundEffect(int id)
          Stop a playing sound identified by the ID returned from playing.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

audioStore

public java.util.Stack<AudioImpl> audioStore

usedAudio

public java.util.Stack<AudioImpl> usedAudio
Method Detail

get

public static SoundStore get()
get the single instance of this class

Returns:
The single instnace of this class

clear

public void clear()
Clear out the sound store contents


disable

public void disable()
Disable use of the Sound Store


getAIF

public Audio getAIF(java.lang.String ref)
             throws java.io.IOException
get the Sound based on a specified AIF file

Parameters:
ref - The reference to the AIF file in the classpath
Returns:
The Sound read from the AIF file
Throws:
java.io.IOException - Indicates a failure to load the AIF

getAIF

public Audio getAIF(java.io.InputStream in)
             throws java.io.IOException
get the Sound based on a specified AIF file

Parameters:
in - The stream to the MOD to load
Returns:
The Sound read from the AIF file
Throws:
java.io.IOException - Indicates a failure to load the AIF

getAIF

public Audio getAIF(java.lang.String ref,
                    java.io.InputStream in)
             throws java.io.IOException
get the Sound based on a specified AIF file

Parameters:
ref - The reference to the AIF file in the classpath
in - The stream to the AIF to load
Returns:
The Sound read from the AIF file
Throws:
java.io.IOException - Indicates a failure to load the AIF

getAudio

public AudioImpl getAudio()

getCurrentMusicVolume

public float getCurrentMusicVolume()
get the volume scalar of the music that is currently playing.

Returns:
The volume of the music currently playing

getMOD

public Audio getMOD(java.lang.String ref)
             throws java.io.IOException
get a MOD sound (mod/xm etc)

Parameters:
ref - The refernece to the mod to load
Returns:
The sound for play back
Throws:
java.io.IOException - Indicates a failure to read the data

getMOD

public Audio getMOD(java.io.InputStream in)
             throws java.io.IOException
get a MOD sound (mod/xm etc)

Parameters:
in - The stream to the MOD to load
Returns:
The sound for play back
Throws:
java.io.IOException - Indicates a failure to read the data

getMOD

public Audio getMOD(java.lang.String ref,
                    java.io.InputStream in)
             throws java.io.IOException
get a MOD sound (mod/xm etc)

Parameters:
ref - The stream to the MOD to load
in - The stream to the MOD to load
Returns:
The sound for play back
Throws:
java.io.IOException - Indicates a failure to read the data

getMusicVolume

public float getMusicVolume()
get the volume for music

Returns:
The volume for music

getOgg

public Audio getOgg(java.lang.String ref)
             throws java.io.IOException
get the Sound based on a specified OGG file

Parameters:
ref - The reference to the OGG file in the classpath
Returns:
The Sound read from the OGG file
Throws:
java.io.IOException - Indicates a failure to load the OGG

getOggFile

public Audio getOggFile(java.lang.String ref)
                 throws java.io.IOException
Throws:
java.io.IOException

getOgg

public Audio getOgg(java.lang.String ref,
                    java.lang.String file)
             throws java.io.IOException
get the Sound based on a specified OGG file

Parameters:
ref - The reference to the OGG file in the classpath
in - The stream to the OGG to load
Returns:
The Sound read from the OGG file
Throws:
java.io.IOException - Indicates a failure to load the OGG

getOggFile

public Audio getOggFile(java.lang.String ref,
                        java.lang.String file)
                 throws java.io.IOException
Throws:
java.io.IOException

getOggStream

public Audio getOggStream(java.lang.String ref)
                   throws java.io.IOException
get the Sound based on a specified OGG file

Parameters:
ref - The reference to the OGG file in the classpath
Returns:
The Sound read from the OGG file
Throws:
java.io.IOException - Indicates a failure to load the OGG

getOggStream

public Audio getOggStream(java.net.URL ref)
                   throws java.io.IOException
get the Sound based on a specified OGG file

Parameters:
ref - The reference to the OGG file in the classpath
Returns:
The Sound read from the OGG file
Throws:
java.io.IOException - Indicates a failure to load the OGG

getSoundVolume

public float getSoundVolume()
get the volume for sounds

Returns:
The volume for sounds

getSource

public int getSource(int index)
get the ID of a given source

Parameters:
index - The ID of a given source
Returns:
The ID of the given source

getSourceCount

public int getSourceCount()
Retrieve the number of OpenAL sound sources that have been determined at initialisation.

Returns:
The number of sources available

getWAV

public Audio getWAV(java.lang.String ref)
             throws java.io.IOException
get the Sound based on a specified WAV file

Parameters:
ref - The reference to the WAV file in the classpath
Returns:
The Sound read from the WAV file
Throws:
java.io.IOException - Indicates a failure to load the WAV

getWAV

public Audio getWAV(java.io.InputStream in)
             throws java.io.IOException
get the Sound based on a specified WAV file

Parameters:
in - The stream to the WAV to load
Returns:
The Sound read from the WAV file
Throws:
java.io.IOException - Indicates a failure to load the WAV

getWAV

public Audio getWAV(java.lang.String ref,
                    java.lang.String in)
             throws java.io.IOException
get the Sound based on a specified WAV file

Parameters:
ref - The reference to the WAV file in the classpath
in - The stream to the WAV to load
Returns:
The Sound read from the WAV file
Throws:
java.io.IOException - Indicates a failure to load the WAV

init

public void init()
Initialise the sound effects stored. This must be called before anything else will work


isDeferredLoading

public boolean isDeferredLoading()
Check if we're using deferred loading

Returns:
True if we're loading deferred sounds

isMusicOn

public boolean isMusicOn()
Check if music should currently be playing

Returns:
True if music is currently playing

isMusicPlaying

public boolean isMusicPlaying()
Check if the music is currently playing

Returns:
True if the music is playing

musicOn

public boolean musicOn()
Check if music is currently enabled

Returns:
True if music is currently enabled

pauseLoop

public void pauseLoop()
Pause the music loop that is currently playing


poll

public void poll(int delta)
Poll the streaming system

Parameters:
delta - The amount of time passed since last poll (in milliseconds)

restartLoop

public void restartLoop()
Restart the music loop that is currently paused


setCurrentMusicVolume

public void setCurrentMusicVolume(float volume)
Set the music volume of the current playing music. Does NOT affect the global volume

Parameters:
volume - The volume for the current playing music

setDeferredLoading

public void setDeferredLoading(boolean deferred)
True if we should only record the request to load in the intention of loading the sound later

Parameters:
deferred - True if the we should load a token

setMaxSources

public void setMaxSources(int max)
Set the maximum number of concurrent sound effects that will be attempted

Parameters:
max - The maximum number of sound effects/music to mix

setMusicOn

public void setMusicOn(boolean music)
Inidicate whether music should be playing

Parameters:
music - True if music should be played

setMusicPitch

public void setMusicPitch(float pitch)
Set the pitch at which the current music is being played

Parameters:
pitch - The pitch at which the current music is being played

setMusicVolume

public void setMusicVolume(float volume)
Set the music volume

Parameters:
volume - The volume for music

setSoundsOn

public void setSoundsOn(boolean sounds)
Indicate whether sound effects should be played

Parameters:
sounds - True if sound effects should be played

setSoundVolume

public void setSoundVolume(float volume)
Set the sound volume

Parameters:
volume - The volume for sound fx

soundsOn

public boolean soundsOn()
Check if sound effects are currently enabled

Returns:
True if sound effects are currently enabled

soundWorks

public boolean soundWorks()
Check if sound works at all

Returns:
True if sound works at all

stopSoundEffect

public void stopSoundEffect(int id)
Stop a playing sound identified by the ID returned from playing. This utility method should only be used when needing to stop sound effects that may have been played more than once and need to be explicitly stopped.

Parameters:
id - The ID of the underlying OpenAL source as returned from playAsSoundEffect