|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectpaulscode.sound.Library
public class Library
The Library class is the class from which all library types are extended.
It provides generic methods for interfacing with the audio libraries
supported by the SoundSystem. Specific libraries should extend this class
and override the necessary methods. For consistant naming conventions, each
sub-class should have the name prefix "Library".
This class may also be used as the "No Sound Library" (i.e. silent mode) if
no other audio libraries are supported by the host machine, or to mute all
sound.
SoundSystem 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 java.util.HashMap<java.lang.String,SoundBuffer> |
bufferMap
Map containing sound file data for easy lookup by filename / identifier. |
protected ListenerData |
listener
Position and orientation of the listener. |
protected java.util.List<Channel> |
normalChannels
Array containing maximum number of non-streaming audio channels. |
protected boolean |
reverseByteOrder
Whether or not the library requires reversal of audio data byte order. |
protected java.util.HashMap<java.lang.String,Source> |
sourceMap
Map containing all created sources for easy look-up by name. |
protected java.util.List<Channel> |
streamingChannels
Array containing maximum number of non-streaming audio channels. |
protected StreamThread |
streamThread
Handles processing for all streaming sources. |
| Constructor Summary | |
|---|---|
Library()
Constructor: Instantiates the source map and listener information. |
|
| Method Summary | |
|---|---|
void |
activate(java.lang.String sourcename)
Activates a previously culled source, so it can be played again. |
void |
checkFadeVolumes()
Makes sure the current volume levels of streaming sources and MIDI are correct. |
void |
cleanup()
Stops all sources, shuts down sound library, and removes references to all instantiated objects. |
void |
copySources(java.util.HashMap<java.lang.String,Source> srcMap)
Creates sources based on the source map provided. |
protected Channel |
createChannel(int type)
Creates a new channel of the specified type (normal or streaming). |
void |
cull(java.lang.String sourcename)
Culls the specified source. |
void |
dequeueSound(java.lang.String sourcename,
java.lang.String filename)
Removes the first occurrence of the specified filename from the specified source's list of sounds to play when previous playback ends. |
void |
dopplerChanged()
Notifies the underlying library that the Doppler parameters have changed. |
protected boolean |
errorCheck(boolean error,
java.lang.String message)
Prints the specified message if error is true. |
protected void |
errorMessage(java.lang.String message)
Prints an error message. |
void |
fadeOut(java.lang.String sourcename,
FilenameURL filenameURL,
long milis)
Fades out the volume of whatever the specified source is currently playing, then begins playing the specified file at the source's previously assigned volume level. |
void |
fadeOutIn(java.lang.String sourcename,
FilenameURL filenameURL,
long milisOut,
long milisIn)
Fades out the volume of whatever the specified source is currently playing, then fades the volume back in playing the specified file. |
int |
feedRawAudioData(Source source,
byte[] buffer)
Feeds raw data through the specified source. |
int |
feedRawAudioData(java.lang.String sourcename,
byte[] buffer)
Feeds raw data through the specified source. |
void |
flush(java.lang.String sourcename)
Clears all previously queued data from a stream. |
java.util.LinkedList<java.lang.String> |
getAllLoadedFilenames()
Returns the filenames of all previously loaded sounds. |
java.util.LinkedList<java.lang.String> |
getAllSourcenames()
Returns the sourcenames of all sources. |
java.lang.String |
getClassName()
Returns the name of the class. |
static java.lang.String |
getDescription()
Returns a longer description of this library type. |
ListenerData |
getListenerData()
Returns information about the listener. |
MidiChannel |
getMidiChannel()
Returns a handle to the MIDI channel, or null if one does not exist. |
float |
getPitch(java.lang.String sourcename)
Returns the pitch of the specified source. |
Source |
getSource(java.lang.String sourcename)
Returns the Source object identified by the specified name. |
java.util.HashMap<java.lang.String,Source> |
getSources()
Returns the sources map. |
static java.lang.String |
getTitle()
Returns the short title of this library type. |
float |
getVolume(java.lang.String sourcename)
Returns the current volume of the specified source, or zero if the specified source was not found. |
protected void |
importantMessage(java.lang.String message)
Prints an important message. |
void |
init()
Initializes the sound library. |
static boolean |
libraryCompatible()
Checks if the no-sound library type is compatible. |
void |
listenerMoved()
Tells all the sources that the listener has moved. |
void |
loadMidi(boolean toLoop,
java.lang.String sourcename,
FilenameURL filenameURL)
Loads the specified MIDI file, and saves the source information about it. |
boolean |
loadSound(FilenameURL filenameURL)
Pre-loads a sound into memory. |
boolean |
loadSound(SoundBuffer buffer,
java.lang.String identifier)
Saves the specified sample data, under the specified identifier. |
protected void |
message(java.lang.String message)
Prints a message. |
boolean |
midiSourcename(java.lang.String sourcename)
Checks if the sourcename matches the midi source. |
float |
millisecondsPlayed(java.lang.String sourcename)
Returns the number of miliseconds since the specified source began playing. |
void |
moveListener(float x,
float y,
float z)
Moves the listener relative to the current position. |
void |
newSource(boolean priority,
boolean toStream,
boolean toLoop,
java.lang.String sourcename,
FilenameURL filenameURL,
float posX,
float posY,
float posZ,
int attModel,
float distOrRoll)
Creates a new source using the specified information. |
void |
pause(java.lang.String sourcename)
Pauses the specified source. |
void |
play(Source source)
Plays the specified source. |
void |
play(java.lang.String sourcename)
Looks up the specified source and plays it. |
protected void |
printStackTrace(java.lang.Exception e)
Prints an exception's error message followed by the stack trace. |
void |
queueSound(java.lang.String sourcename,
FilenameURL filenameURL)
If the specified source is a streaming source or MIDI source, this method queues up the next sound to play when the previous playback ends. |
void |
quickPlay(boolean priority,
boolean toStream,
boolean toLoop,
java.lang.String sourcename,
FilenameURL filenameURL,
float posX,
float posY,
float posZ,
int attModel,
float distOrRoll,
boolean tmp)
Creates and immediately plays a new source that will be removed when it finishes playing. |
void |
rawDataStream(javax.sound.sampled.AudioFormat audioFormat,
boolean priority,
java.lang.String sourcename,
float posX,
float posY,
float posZ,
int attModel,
float distOrRoll)
Opens a direct line for streaming audio data. |
void |
removeSource(java.lang.String sourcename)
Stops and deletes the specified source. |
void |
removeTemporarySources()
Searches for and removes all temporary sources that have finished playing. |
void |
replaySources()
Plays all sources whose 'toPlay' varriable is true but are not currently playing (such as sources which were culled while looping and then reactivated). |
boolean |
reverseByteOrder()
Indicates whether or not this library requires some codecs to reverse-order the audio data they generate. |
void |
rewind(java.lang.String sourcename)
Rewinds the specified source. |
void |
setAttenuation(java.lang.String sourcename,
int model)
Sets the specified source's attenuation model. |
void |
setDistOrRoll(java.lang.String sourcename,
float dr)
Sets the specified source's fade distance or rolloff factor. |
void |
setListenerAngle(float angle)
Changes the listeners orientation to the specified 'angle' radians counterclockwise around the y-Axis. |
void |
setListenerData(ListenerData l)
Changes the listeners position and orientation using the specified listener data. |
void |
setListenerOrientation(float lookX,
float lookY,
float lookZ,
float upX,
float upY,
float upZ)
Changes the listeners orientation using the specified coordinates. |
void |
setListenerPosition(float x,
float y,
float z)
Changes the listener's position. |
void |
setListenerVelocity(float x,
float y,
float z)
Sets the listener's velocity, for use in Doppler effect. |
void |
setLooping(java.lang.String sourcename,
boolean lp)
Sets the specified source's looping parameter. |
void |
setMasterVolume(float value)
Sets the overall volume to the specified value, affecting all sources. |
void |
setMidiChannel(MidiChannel c)
Specifies the MIDI channel to use. |
void |
setPitch(java.lang.String sourcename,
float value)
Manually sets the specified source's pitch. |
void |
setPosition(java.lang.String sourcename,
float x,
float y,
float z)
Changes the specified source's position. |
void |
setPriority(java.lang.String sourcename,
boolean pri)
Sets the specified source's priority factor. |
void |
setTemporary(java.lang.String sourcename,
boolean temporary)
Defines whether or not the source should be removed after it finishes playing. |
void |
setVelocity(java.lang.String sourcename,
float x,
float y,
float z)
Sets the specified source's velocity, for use in Doppler effect. |
void |
setVolume(java.lang.String sourcename,
float value)
Manually sets the specified source's volume. |
void |
stop(java.lang.String sourcename)
Stops the specified source. |
void |
turnListener(float angle)
Turn the listener 'angle' radians counterclockwise around the y-Axis, relative to the current angle. |
void |
unloadMidi()
Unloads the current Midi file. |
void |
unloadSound(java.lang.String filename)
Removes a pre-loaded sound from memory. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected ListenerData listener
protected java.util.HashMap<java.lang.String,SoundBuffer> bufferMap
protected java.util.HashMap<java.lang.String,Source> sourceMap
protected java.util.List<Channel> streamingChannels
protected java.util.List<Channel> normalChannels
protected StreamThread streamThread
protected boolean reverseByteOrder
| Constructor Detail |
|---|
public Library()
throws SoundSystemException
SoundSystemException| Method Detail |
|---|
public void cleanup()
public void init()
throws SoundSystemException
SoundSystemExceptionpublic static boolean libraryCompatible()
protected Channel createChannel(int type)
SoundSystemConfig class.
type - Type of channel.
public boolean loadSound(FilenameURL filenameURL)
filenameURL - Filename/URL of the sound file to load.
public boolean loadSound(SoundBuffer buffer,
java.lang.String identifier)
buffer - the sample data and audio format to save.identifier - What to call the sample.
public java.util.LinkedList<java.lang.String> getAllLoadedFilenames()
public java.util.LinkedList<java.lang.String> getAllSourcenames()
public void unloadSound(java.lang.String filename)
filename - Filename/identifier of the sound file to unload.
public void rawDataStream(javax.sound.sampled.AudioFormat audioFormat,
boolean priority,
java.lang.String sourcename,
float posX,
float posY,
float posZ,
int attModel,
float distOrRoll)
audioFormat - Format that the data will be in.sourcename - A unique identifier for this source. Two sources may not use the same sourcename.posX - X position for this source.posY - Y position for this source.posZ - Z position for this source.attModel - Attenuation model to use.distOrRoll - Either the fading distance or rolloff factor, depending on the value of "attmodel".
public void newSource(boolean priority,
boolean toStream,
boolean toLoop,
java.lang.String sourcename,
FilenameURL filenameURL,
float posX,
float posY,
float posZ,
int attModel,
float distOrRoll)
priority - Setting this to true will prevent other sounds from overriding this one.toStream - Setting this to true will load the sound in pieces rather than all at once.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.posX - X position for this source.posY - Y position for this source.posZ - Z position for this source.attModel - Attenuation model to use.distOrRoll - Either the fading distance or rolloff factor, depending on the value of "attmodel".
public void quickPlay(boolean priority,
boolean toStream,
boolean toLoop,
java.lang.String sourcename,
FilenameURL filenameURL,
float posX,
float posY,
float posZ,
int attModel,
float distOrRoll,
boolean tmp)
priority - Setting this to true will prevent other sounds from overriding this one.toStream - Setting this to true will load the sound in pieces rather than all at once.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 - The filename/URL of the sound file to play at this source.posX - X position for this source.posY - Y position for this source.posZ - Z position for this source.attModel - Attenuation model to use.distOrRoll - Either the fading distance or rolloff factor, depending on the value of "attmodel".
public void setTemporary(java.lang.String sourcename,
boolean temporary)
sourcename - The source's name.temporary - True or False.
public void setPosition(java.lang.String sourcename,
float x,
float y,
float z)
sourcename - The source's name.x - Destination X coordinate.y - Destination Y coordinate.z - Destination Z coordinate.
public void setPriority(java.lang.String sourcename,
boolean pri)
sourcename - The source's name.pri - True or False.
public void setLooping(java.lang.String sourcename,
boolean lp)
sourcename - The source's name.lp - True or False.
public void setAttenuation(java.lang.String sourcename,
int model)
sourcename - The source's name.model - Attenuation model to use.
public void setDistOrRoll(java.lang.String sourcename,
float dr)
sourcename - The source's name.dr - Fade distance or rolloff factor.
public void setVelocity(java.lang.String sourcename,
float x,
float y,
float z)
sourcename - The source's name.x - Velocity along world x-axis.y - Velocity along world y-axis.z - Velocity along world z-axis.
public void setListenerVelocity(float x,
float y,
float z)
x - Velocity along world x-axis.y - Velocity along world y-axis.z - Velocity along world z-axis.public void dopplerChanged()
public float millisecondsPlayed(java.lang.String sourcename)
public int feedRawAudioData(java.lang.String sourcename,
byte[] buffer)
sourcename - Name of the streaming source to play from.buffer - Byte buffer containing raw audio data to stream.
public int feedRawAudioData(Source source,
byte[] buffer)
source - Streaming source to play from.buffer - Byte buffer containing raw audio data to stream.
public void play(java.lang.String sourcename)
sourcename - Name of the source to play.public void play(Source source)
source - The source to play.public void stop(java.lang.String sourcename)
sourcename - The source's name.public void pause(java.lang.String sourcename)
sourcename - The source's name.public void rewind(java.lang.String sourcename)
sourcename - The source's name.public void flush(java.lang.String sourcename)
sourcename - The source's name.public void cull(java.lang.String sourcename)
sourcename - The source's name.public void activate(java.lang.String sourcename)
sourcename - The source's name.public void setMasterVolume(float value)
value - New volume, float value ( 0.0f - 1.0f ).
public void setVolume(java.lang.String sourcename,
float value)
sourcename - The source's name.value - A float value ( 0.0f - 1.0f ).public float getVolume(java.lang.String sourcename)
sourcename - Source to read volume from.
public void setPitch(java.lang.String sourcename,
float value)
sourcename - The source's name.value - A float value ( 0.5f - 2.0f ).public float getPitch(java.lang.String sourcename)
sourcename - The source's name.
public void moveListener(float x,
float y,
float z)
x - X offset.y - Y offset.z - Z offset.
public void setListenerPosition(float x,
float y,
float z)
x - Destination X coordinate.y - Destination Y coordinate.z - Destination Z coordinate.public void turnListener(float angle)
angle - Angle in radians.public void setListenerAngle(float angle)
angle - Angle in radians.
public void setListenerOrientation(float lookX,
float lookY,
float lookZ,
float upX,
float upY,
float upZ)
lookX - X element of the look-at direction.lookY - Y element of the look-at direction.lookZ - Z element of the look-at direction.upX - X element of the up direction.upY - Y element of the up direction.upZ - Z element of the up direction.public void setListenerData(ListenerData l)
l - Listener data to use.public void copySources(java.util.HashMap<java.lang.String,Source> srcMap)
srcMap - Sources to copy.public void removeSource(java.lang.String sourcename)
sourcename - The source's name.public void removeTemporarySources()
public void replaySources()
public void queueSound(java.lang.String sourcename,
FilenameURL filenameURL)
sourcename - Source identifier.filenameURL - Filename/URL of the sound file to play next.
public void dequeueSound(java.lang.String sourcename,
java.lang.String filename)
sourcename - Source identifier.filename - Filename/identifier of the sound file to remove from the queue.
public void fadeOut(java.lang.String sourcename,
FilenameURL filenameURL,
long milis)
sourcename - Name of the source to fade out.filenameURL - Filename/URL of the sound file to play next, or null for none.milis - Number of miliseconds the fadeout should take.
public void fadeOutIn(java.lang.String sourcename,
FilenameURL filenameURL,
long milisOut,
long milisIn)
sourcename - Name of the source to fade out/in.filenameURL - Filename/URL of the sound file to play next, or null for none.milisOut - Number of miliseconds the fadeout should take.milisIn - Number of miliseconds the fadein should take.public void checkFadeVolumes()
public void loadMidi(boolean toLoop,
java.lang.String sourcename,
FilenameURL filenameURL)
toLoop - Midi file should loop or play once.sourcename - Source identifier.filenameURL - Filename/URL of the MIDI file to load.public void unloadMidi()
public boolean midiSourcename(java.lang.String sourcename)
sourcename - Source identifier.
public Source getSource(java.lang.String sourcename)
sourcename - The source's name.
public MidiChannel getMidiChannel()
public void setMidiChannel(MidiChannel c)
c - New MIDI channel.public void listenerMoved()
public java.util.HashMap<java.lang.String,Source> getSources()
public ListenerData getListenerData()
public boolean reverseByteOrder()
public static java.lang.String getTitle()
public static java.lang.String getDescription()
public java.lang.String getClassName()
protected void message(java.lang.String message)
message - Message to print.protected void importantMessage(java.lang.String message)
message - Message to print.
protected boolean errorCheck(boolean error,
java.lang.String message)
error - True or False.message - Message to print if error is true.
protected void errorMessage(java.lang.String message)
message - Message to print.protected void printStackTrace(java.lang.Exception e)
e - Exception containing the information to print.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||