glsound
Class SoundScape

java.lang.Object
  extended by glsound.SoundScape

public class SoundScape
extends java.lang.Object

SoundScape wraps OpenAL functions to create a sound environment. Can load and play several sounds, set properties of sounds (pitch, position, volume, dropoff), pause all sounds or one sound, control global volume. To run a demo of SoundScape just call the static demo() function:

     SoundScape.demo();
 
The class is static so can be used without instantiation, similar to LWJGL Display, Mouse and Keyboard classes:
     SoundScape.create();      // init sound environment
     ...
     int soundData sd = SoundScape.loadSoundData("a_noise.wav");
     int soundSource ss = SoundScape.makeSoundSource(soundData);
     SoundScape.setSoundPosition(ss, 10, 2, 0);
     SoundScape.play(ss);
     ...
     SoundScape.destroy();
 
Requires the WaveData class to load wav files.

Borrows heavily from Brian Matzon's PlayTest demo (at http://lwjgl.org)


Field Summary
static int SIZE_FLOAT
           
static int SIZE_INT
           
 
Constructor Summary
SoundScape()
          Creates an instance of SoundScape BUT SoundScape is meant to be used as static class.
 
Method Summary
protected static void alExit()
           
static java.nio.FloatBuffer allocFloats(float[] floatarray)
           
static java.nio.IntBuffer allocInts(int howmany)
           
static void create()
          Prepare the SoundScape class for use
static void demo()
          Run a bare-bones demo of SoundScape.
static void destroy()
          Free up allocated sounds and shutdown audio environment.
static void exit(int arg)
           
protected static java.nio.ByteBuffer getData(java.lang.String filename)
          Reads the file into a ByteBuffer
static float getGain(int soundSourceHandle)
           
static boolean isPlaying(int soundSourceHandle)
          return true if this sound is playing
static int loadSoundData(java.lang.String soundFilename)
          Load sound data from a file into a buffer.
static int makeSound(java.lang.String soundFilename)
          
static int makeSoundSource(int soundDataHandle)
          Return integer handle to new sound source.
static void pause(boolean bool)
          Pause or resume all sounds playing in the SoundScape
static void pause(int soundSourceHandle, boolean pause)
          Pause or resume one sound
static void play(int soundSourceHandle)
          Play a sound source
static void setGain(int soundSourceHandle, float gain)
          Set the soundsource volume.
static void setGlobalGain(float gain)
          Set the volume for all sounds.
static void setListenerOrientation(float lookatx, float lookaty, float lookatz, float upx, float upy, float upz)
          Set orientation of the listener.
static void setListenerPosition(float x, float y, float z)
          Set world coordinates of listener.
static void setListenerVelocity(float x, float y, float z)
          Set world coordinates of listener.
static void setLoop(int soundSourceHandle, boolean on)
           
static void setPitch(int soundSourceHandle, float pitch)
           
static void setReferenceDistance(float d)
          Set the reference distance, used by OpenAL to calculate how fast sound drops off.
static void setReferenceDistance(int soundSourceHandle, float distance)
          set the dropoff distance for this sound.
static void setSoundPosition(int soundSourceHandle, float[] xyz)
           
static void setSoundPosition(int soundSourceHandle, float x, float y, float z)
           
static void setVelocity(int soundSourceHandle, float velocity)
          Set velocity of sound 0 - 1
static void stop()
          Stop all sounds playing in the SoundScape
static void stop(int soundSourceHandle)
          Stop playing one sound.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIZE_FLOAT

public static final int SIZE_FLOAT
See Also:
Constant Field Values

SIZE_INT

public static final int SIZE_INT
See Also:
Constant Field Values
Constructor Detail

SoundScape

public SoundScape()
Creates an instance of SoundScape BUT SoundScape is meant to be used as static class. Use SoundScape.create() to init the class.

Method Detail

create

public static void create()
Prepare the SoundScape class for use


destroy

public static void destroy()
Free up allocated sounds and shutdown audio environment.


alExit

protected static void alExit()

exit

public static void exit(int arg)

demo

public static void demo()
Run a bare-bones demo of SoundScape.


pause

public static void pause(boolean bool)
Pause or resume all sounds playing in the SoundScape


stop

public static void stop()
Stop all sounds playing in the SoundScape


setGlobalGain

public static void setGlobalGain(float gain)
Set the volume for all sounds. Use this to adjust ambient volume level for entire sound scape.

Parameters:
gain - float: 0 - 1

setReferenceDistance

public static void setReferenceDistance(float d)
Set the reference distance, used by OpenAL to calculate how fast sound drops off. This distance should be proportional to the size of your scene, ie. a scene that is hundreds of units wide might have a reference distance of 10 for a "small" sound, or 100 for a "big" sound that fills the whole space.

See Also:
makeSoundSource().

setListenerPosition

public static void setListenerPosition(float x,
                                       float y,
                                       float z)
Set world coordinates of listener.


setListenerVelocity

public static void setListenerVelocity(float x,
                                       float y,
                                       float z)
Set world coordinates of listener.


setListenerOrientation

public static void setListenerOrientation(float lookatx,
                                          float lookaty,
                                          float lookatz,
                                          float upx,
                                          float upy,
                                          float upz)
Set orientation of the listener. first 3 elements are "at", second 3 are "up"


pause

public static void pause(int soundSourceHandle,
                         boolean pause)
Pause or resume one sound


play

public static void play(int soundSourceHandle)
Play a sound source


stop

public static void stop(int soundSourceHandle)
Stop playing one sound.


getGain

public static float getGain(int soundSourceHandle)

setVelocity

public static void setVelocity(int soundSourceHandle,
                               float velocity)
Set velocity of sound 0 - 1


setPitch

public static void setPitch(int soundSourceHandle,
                            float pitch)
Parameters:
soundSourceHandle - set pitch of this sound source
pitch -

setGain

public static void setGain(int soundSourceHandle,
                           float gain)
Set the soundsource volume. Gain range is 0.0 or above. A value of 1.0 means unattenuated/unchanged. Each division by 2 equals an attenuation of -6dB. Each multiplication by 2 equals an amplification of +6dB. A value of 0.0 turns sound off.

Parameters:
soundSourceHandle -
gain -

setSoundPosition

public static void setSoundPosition(int soundSourceHandle,
                                    float x,
                                    float y,
                                    float z)

setSoundPosition

public static void setSoundPosition(int soundSourceHandle,
                                    float[] xyz)

setReferenceDistance

public static void setReferenceDistance(int soundSourceHandle,
                                        float distance)
set the dropoff distance for this sound. this number controls how far the sound travels. The distance parameter should be proportional to the units of distance used in the scene.

Parameters:
soundSourceHandle -
distance -

setLoop

public static void setLoop(int soundSourceHandle,
                           boolean on)

isPlaying

public static boolean isPlaying(int soundSourceHandle)
return true if this sound is playing

Parameters:
soundSourceHandle -
Returns:
true if sound is playing

getData

protected static java.nio.ByteBuffer getData(java.lang.String filename)
Reads the file into a ByteBuffer

Parameters:
filename - Name of file to load
Returns:
ByteBuffer containing file data

makeSoundSource

public static int makeSoundSource(int soundDataHandle)
Return integer handle to new sound source. Expects a handle to a loaded sound data buffer (see loadSoundData()). Multiple sound sources can share the same data buffer. Each sound source can have a position, pitch, velocity that will affect the way the sound plays.

Returns:

loadSoundData

public static int loadSoundData(java.lang.String soundFilename)
Load sound data from a file into a buffer. Returns a handle that is passed to makeSoundSource() to create a sound in the environment. Multiple sound sources can be bound to one data buffer.

Parameters:
soundFilename - name of file to load (.wav)
Returns:
numeric handle to the sound data buffer

makeSound

public static int makeSound(java.lang.String soundFilename)

Parameters:
soundFilename - name of file to load (.wav)
Returns:
numeric handle to the sound data buffer

allocInts

public static java.nio.IntBuffer allocInts(int howmany)

allocFloats

public static java.nio.FloatBuffer allocFloats(float[] floatarray)