paulscode.sound.libraries
Class SourceJavaSound

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

public class SourceJavaSound
extends Source

The SourceJavaSound class provides an interface to the JavaSound library. For more information about the Java Sound API, please visit http://java.sun.com/products/java-media/sound/

SoundSystem LibraryJavaSound 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 may not falsely claim to be the author of this library or any unmodified portion of it.
2) You may not copyright this library or a modified version of it and then sue me for copyright infringement.
3) 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.
4) 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
5) 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.
6) 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
protected  ChannelJavaSound channelJavaSound
          The source's basic Channel type-cast to a ChannelJavaSound.
 ListenerData listener
          Handle to the listener information.
 
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
SourceJavaSound(ListenerData listener, 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.
SourceJavaSound(ListenerData listener, 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.
SourceJavaSound(ListenerData listener, Source old, SoundBuffer soundBuffer)
          Constructor: Creates a new source matching the specified source.
 
Method Summary
 void calculateGain()
          Calculates the gain for this source based on its attenuation model and distance from the listener.
 void calculatePan()
          Calculates the panning for this source based on its position in relation to the listener.
 void calculatePitch()
          Calculates the pitch for this source based on its position in relation to the listener.
 void changeSource(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.
 void listenerMoved()
          Called every time the listener's position or orientation changes.
 float min(float a, float b)
           
 void play(Channel c)
          Plays the source on the specified channel.
 void positionChanged()
          Updates the pan and 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 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, checkFadeOut, cull, dequeueSound, errorCheck, errorMessage, fadeOut, fadeOutIn, feedRawAudioData, flush, getClassName, getDistanceFromListener, getPitch, getSoundSequenceQueueSize, importantMessage, incrementSoundSequence, message, millisecondsPlayed, pause, paused, playing, printStackTrace, queueSound, readBuffersFromNextSoundInSequence, reverseByteOrder, rewind, setLooping, setPriority, setTemporary, stop, stopped, stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

channelJavaSound

protected ChannelJavaSound channelJavaSound
The source's basic Channel type-cast to a ChannelJavaSound.


listener

public ListenerData listener
Handle to the listener information.

Constructor Detail

SourceJavaSound

public SourceJavaSound(ListenerData listener,
                       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:
listener - Handle to information about the listener.
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 - Sound buffer to use if creating a new normal source.
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.

SourceJavaSound

public SourceJavaSound(ListenerData listener,
                       Source old,
                       SoundBuffer soundBuffer)
Constructor: Creates a new source matching the specified source.

Parameters:
listener - Handle to information about the listener.
old - Source to copy information from.
soundBuffer - Sound buffer to use if creating a new normal source.

SourceJavaSound

public SourceJavaSound(ListenerData listener,
                       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:
listener - Handle to information about the listener.
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(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.

Overrides:
changeSource in class Source
Parameters:
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 - Sound buffer to use if creating a new normal source.
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.

listenerMoved

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

Overrides:
listenerMoved in class Source

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.

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()
Updates the pan and gain.

Overrides:
positionChanged in class Source

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 ).

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.

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.

calculateGain

public void calculateGain()
Calculates the gain for this source based on its attenuation model and distance from the listener.


calculatePan

public void calculatePan()
Calculates the panning for this source based on its position in relation to the listener.


calculatePitch

public void calculatePitch()
Calculates the pitch for this source based on its position in relation to the listener.


min

public float min(float a,
                 float b)