Class SoundScape

java.lang.Object
  |
  +--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), pause all sounds or one sound. 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 int allocateSoundData()
          Return integer handle to allocated sound data buffer.
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 deleteSoundData(int soundDataHandle)
          Delete the sound data buffer with the given handle
static void deleteSoundSource(int soundSourceHandle)
          Delete the sound source with the given handle
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 boolean isPlaying(int soundSourceHandle)
           
static int loadSoundData(java.lang.String soundFilename)
          Load sound data from a file into a buffer.
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)
           
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 setSoundPosition(int soundSourceHandle, float[] xyz)
           
static void setSoundPosition(int soundSourceHandle, float x, float y, float z)
           
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.


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


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.


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)

setSoundPosition

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

setSoundPosition

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

setLoop

public static void setLoop(int soundSourceHandle,
                           boolean on)

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

alExit

protected static void alExit()

exit

public static void exit(int arg)

allocateSoundData

public static int allocateSoundData()
Return integer handle to allocated sound data buffer.

Returns:

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:

deleteSoundData

public static void deleteSoundData(int soundDataHandle)
Delete the sound data buffer with the given handle


deleteSoundSource

public static void deleteSoundSource(int soundSourceHandle)
Delete the sound source with the given handle


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

isPlaying

public static boolean isPlaying(int soundSourceHandle)
Parameters:
soundSourceHandle - test if this sound is playing
Returns:
true if sound is playing

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 should have a reference distance of 100 or so. A scene that is 5 units wide could use a ref distance of 3. Used in 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"


allocInts

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

allocFloats

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