paulscode.sound.libraries
Class SourceJOAL

java.lang.Object
  extended by paulscode.sound.Source
      extended by paulscode.sound.libraries.SourceJOAL

public class SourceJOAL
extends Source

The SourceJOAL class provides an interface to the JOAL binding of OpenAL.

This software is based on or using the JOAL Library available from http://joal.dev.java.net/


JOAL License:
Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-Redistribution of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-Redistribution in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of Sun Microsystems, Inc. or the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
This software is provided "AS IS," without a warranty of any kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
You acknowledge that this software is not designed or intended for use in the design, construction, operation or maintenance of any nuclear facility.


SoundSystem LibraryJOAL License:

You are free to use this library for any purpose, commercial or otherwise. You may modify this library or source code, and distribute it any way you like, provided the following conditions are met:
1) You must abide by the conditions of the aforementioned JOAL License.
2) You may not falsely claim to be the author of this library or any unmodified portion of it.
3) You may not copyright this library or a modified version of it and then sue me for copyright infringement.
4) If you modify the source code, you must clearly document the changes made before redistributing the modified source code, so other users know it is not the original code.
5) You are not required to give me credit for this library in any derived work, but if you do, you must also mention my website: http://www.paulscode.com
6) I the author will not be responsible for any damages (physical, financial, or otherwise) caused by the use if this library or any part of it.
7) I the author do not guarantee, warrant, or make any representations, either expressed or implied, regarding the use of this library or any part of it.

Author: Paul Lamb
http://www.paulscode.com


Field Summary
 
Fields inherited from class paulscode.sound.Source
attModel, channel, codec, distanceFromListener, distOrRoll, fadeInGain, fadeInMilis, fadeOutGain, fadeOutMilis, filenameURL, gain, lastFadeCheck, libraryType, nextBuffers, nextCodec, pitch, position, preLoad, priority, rawDataFormat, rawDataStream, soundBuffer, soundSequenceLock, soundSequenceQueue, sourcename, sourceVolume, temporary, toLoop, toPlay, toStream, velocity
 
Constructor Summary
SourceJOAL(Vector3D listenerPosition, javax.sound.sampled.AudioFormat audioFormat, boolean priority, java.lang.String sourcename, float x, float y, float z, int attModel, float distOrRoll)
          Constructor: Creates a new streaming source that will be directly fed with raw audio data.
SourceJOAL(Vector3D listenerPosition, int[] myBuffer, boolean priority, boolean toStream, boolean toLoop, java.lang.String sourcename, FilenameURL filenameURL, SoundBuffer soundBuffer, float x, float y, float z, int attModel, float distOrRoll, boolean temporary)
          Constructor: Creates a new source using the specified parameters.
SourceJOAL(Vector3D listenerPosition, int[] myBuffer, Source old, SoundBuffer soundBuffer)
          Constructor: Creates a new source matching the specified source.
 
Method Summary
 void changeSource(Vector3D listenerPosition, int[] myBuffer, boolean priority, boolean toStream, boolean toLoop, java.lang.String sourcename, FilenameURL filenameURL, SoundBuffer soundBuffer, float x, float y, float z, int attModel, float distOrRoll, boolean temporary)
          Changes the peripheral information about the source using the specified parameters.
 void cleanup()
          Shuts the source down and removes references to all instantiated objects.
 boolean incrementSoundSequence()
          Removes the next filename from the sound sequence queue and assigns it to this source.
 void listenerMoved()
          Called every time the listener's position or orientation changes.
 void play(Channel c)
          Plays the source on the specified channel.
 void positionChanged()
          Recalculates the distance from the listner and the gain.
 boolean preLoad()
          Queues up the initial stream-buffers for the stream.
 void setAttenuation(int model)
          Sets this source's attenuation model.
 void setDistOrRoll(float dr)
          Sets this source's fade distance or rolloff factor, depending on the attenuation model.
 void setLooping(boolean lp)
          Sets whether this source should loop or only play once.
 void setPitch(float value)
          Manually sets this source's pitch.
 void setPosition(float x, float y, float z)
          Moves the source to the specified position.
 void setVelocity(float x, float y, float z)
          Sets this source's velocity, for use in Doppler effect.
 
Methods inherited from class paulscode.sound.Source
activate, active, changeSource, checkFadeOut, cull, dequeueSound, errorCheck, errorMessage, fadeOut, fadeOutIn, feedRawAudioData, flush, getClassName, getDistanceFromListener, getPitch, getSoundSequenceQueueSize, importantMessage, message, millisecondsPlayed, pause, paused, playing, printStackTrace, queueSound, readBuffersFromNextSoundInSequence, reverseByteOrder, rewind, setPriority, setTemporary, stop, stopped, stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SourceJOAL

public SourceJOAL(Vector3D listenerPosition,
                  int[] myBuffer,
                  boolean priority,
                  boolean toStream,
                  boolean toLoop,
                  java.lang.String sourcename,
                  FilenameURL filenameURL,
                  SoundBuffer soundBuffer,
                  float x,
                  float y,
                  float z,
                  int attModel,
                  float distOrRoll,
                  boolean temporary)
Constructor: Creates a new source using the specified parameters.

Parameters:
listenerPosition - Handle to the Vector3D containing the listener's 3D coordinates.
myBuffer - OpenAL sound-buffer identifier to use for a new normal source.
priority - Setting this to true will prevent other sounds from overriding this one.
toStream - Setting this to true will create a streaming source.
toLoop - Should this source loop, or play only once.
sourcename - A unique identifier for this source. Two sources may not use the same sourcename.
filenameURL - Filename/URL of the sound file to play at this source.
soundBuffer - Buffer containing audio data, or null if not loaded yet.
x - X position for this source.
y - Y position for this source.
z - Z position for this source.
attModel - Attenuation model to use.
distOrRoll - Either the fading distance or rolloff factor, depending on the value of 'att'.
temporary - Whether or not to remove this source after it finishes playing.

SourceJOAL

public SourceJOAL(Vector3D listenerPosition,
                  int[] myBuffer,
                  Source old,
                  SoundBuffer soundBuffer)
Constructor: Creates a new source matching the specified source.

Parameters:
listenerPosition - Handle to the Vector3D containing the listener's 3D coordinates.
myBuffer - OpenAL sound-buffer identifier to use for a new normal source.
old - Source to copy information from.
soundBuffer - Buffer containing audio data, or null if not loaded yet.

SourceJOAL

public SourceJOAL(Vector3D listenerPosition,
                  javax.sound.sampled.AudioFormat audioFormat,
                  boolean priority,
                  java.lang.String sourcename,
                  float x,
                  float y,
                  float z,
                  int attModel,
                  float distOrRoll)
Constructor: Creates a new streaming source that will be directly fed with raw audio data.

Parameters:
listenerPosition - Handle to the Vector3D containing the listener's 3D coordinates.
audioFormat - Format that the data will be in.
priority - Setting this to true will prevent other sounds from overriding this one.
sourcename - A unique identifier for this source. Two sources may not use the same sourcename.
x - X position for this source.
y - Y position for this source.
z - Z position for this source.
attModel - Attenuation model to use.
distOrRoll - Either the fading distance or rolloff factor, depending on the value of 'att'.
Method Detail

cleanup

public void cleanup()
Shuts the source down and removes references to all instantiated objects.

Overrides:
cleanup in class Source

changeSource

public void changeSource(Vector3D listenerPosition,
                         int[] myBuffer,
                         boolean priority,
                         boolean toStream,
                         boolean toLoop,
                         java.lang.String sourcename,
                         FilenameURL filenameURL,
                         SoundBuffer soundBuffer,
                         float x,
                         float y,
                         float z,
                         int attModel,
                         float distOrRoll,
                         boolean temporary)
Changes the peripheral information about the source using the specified parameters.

Parameters:
listenerPosition - Handle to the Vector3D containing the listener's 3D coordinates.
myBuffer - OpenAL sound-buffer identifier to use for a new normal source.
priority - Setting this to true will prevent other sounds from overriding this one.
toStream - Setting this to true will create a streaming source.
toLoop - Should this source loop, or play only once.
sourcename - A unique identifier for this source. Two sources may not use the same sourcename.
filenameURL - Filename/URL of the sound file to play at this source.
soundBuffer - Buffer containing audio data, or null if not loaded yet.
x - X position for this source.
y - Y position for this source.
z - Z position for this source.
attModel - Attenuation model to use.
distOrRoll - Either the fading distance or rolloff factor, depending on the value of 'att'.
temporary - Whether or not to remove this source after it finishes playing.

incrementSoundSequence

public boolean incrementSoundSequence()
Removes the next filename from the sound sequence queue and assigns it to this source. This method has no effect on non-streaming sources. This method is used internally by SoundSystem, and it is unlikely that the user will ever need to use it.

Overrides:
incrementSoundSequence in class Source
Returns:
True if there was something in the queue.

listenerMoved

public void listenerMoved()
Called every time the listener's position or orientation changes.

Overrides:
listenerMoved in class Source

setPosition

public void setPosition(float x,
                        float y,
                        float z)
Moves the source to the specified position.

Overrides:
setPosition in class Source
Parameters:
x - X coordinate to move to.
y - Y coordinate to move to.
z - Z coordinate to move to.

positionChanged

public void positionChanged()
Recalculates the distance from the listner and the gain.

Overrides:
positionChanged in class Source

setLooping

public void setLooping(boolean lp)
Sets whether this source should loop or only play once.

Overrides:
setLooping in class Source
Parameters:
lp - True or false.

setAttenuation

public void setAttenuation(int model)
Sets this source's attenuation model.

Overrides:
setAttenuation in class Source
Parameters:
model - Attenuation model to use.

setDistOrRoll

public void setDistOrRoll(float dr)
Sets this source's fade distance or rolloff factor, depending on the attenuation model.

Overrides:
setDistOrRoll in class Source
Parameters:
dr - New value for fade distance or rolloff factor.

setVelocity

public void setVelocity(float x,
                        float y,
                        float z)
Sets this source's velocity, for use in Doppler effect.

Overrides:
setVelocity in class Source
Parameters:
x - Velocity along world x-axis.
y - Velocity along world y-axis.
z - Velocity along world z-axis.

setPitch

public void setPitch(float value)
Manually sets this source's pitch.

Overrides:
setPitch in class Source
Parameters:
value - A float value ( 0.5f - 2.0f ).

play

public void play(Channel c)
Plays the source on the specified channel.

Overrides:
play in class Source
Parameters:
c - Channel to play on.

preLoad

public boolean preLoad()
Queues up the initial stream-buffers for the stream.

Overrides:
preLoad in class Source
Returns:
False if the end of the stream was reached.