public class SoundSystem extends Object
SoundSystemConfig for information
about changing default settings and linking with external pluggins.
| Modifier and Type | Field and Description |
|---|---|
protected String |
className
Name of this class.
|
protected List<CommandObject> |
commandQueue
List of queued commands to perform.
|
protected CommandThread |
commandThread
Processes queued commands in the background.
|
protected SoundSystemLogger |
logger
Processes status messages, warnings, and error messages.
|
Random |
randomNumberGenerator
Generates random numbers.
|
protected Library |
soundLibrary
Handle to the active sound library.
|
| Constructor and Description |
|---|
SoundSystem()
Constructor: Create the sound system using the default library.
|
SoundSystem(Class libraryClass)
Constructor: Create the sound system using the specified library.
|
| Modifier and Type | Method and Description |
|---|---|
void |
activate(String sourcename)
Activates the specified source after it was culled, so it can be played
again.
|
void |
backgroundMusic(String sourcename,
String filename,
boolean toLoop)
Creates a new permanant, streaming, priority source with zero attenuation.
|
void |
backgroundMusic(String sourcename,
URL url,
String identifier,
boolean toLoop)
Creates a new permanant, streaming, priority source with zero attenuation.
|
void |
changeDopplerFactor(float dopplerFactor)
Changes the Doppler factor, for determining Doppler effect scale.
|
void |
changeDopplerVelocity(float dopplerVelocity)
Changes the Doppler velocity, for use in Doppler effect.
|
void |
checkFadeVolumes()
Makes sure the current volume levels of streaming sources and MIDI are
correct.
|
void |
cleanup()
Ends the command thread, shuts down the sound system, and removes references
to all instantiated objects.
|
boolean |
CommandQueue(CommandObject newCommand)
Queues a command.
|
void |
cull(String sourcename)
Culls the specified source.
|
static Class |
currentLibrary()
Returns the currently loaded library, or -1 if none.
|
void |
dequeueSound(String sourcename,
String filename)
Removes the first occurrence of the specified filename/identifier from the
specified source's list of sounds to play when previous playback ends.
|
protected boolean |
errorCheck(boolean error,
String message,
int indent)
Prints the specified message if error is true.
|
protected void |
errorMessage(String message,
int indent)
Prints an error message.
|
void |
fadeOut(String sourcename,
String filename,
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 |
fadeOut(String sourcename,
URL url,
String identifier,
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(String sourcename,
String filename,
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 filename.
|
void |
fadeOutIn(String sourcename,
URL url,
String identifier,
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.
|
void |
feedRawAudioData(String sourcename,
byte[] buffer)
Feeds raw data through the specified source.
|
void |
flush(String sourcename)
Flushes all previously queued audio data from a streaming source.
|
static SoundSystemException |
getLastException()
Returns the last SoundSystemException thrown, or null if none.
|
ListenerData |
getListenerData()
Method for obtaining information about the listener's position and
orientation.
|
float |
getMasterVolume()
Returns the overall volume, affecting all sources.
|
float |
getPitch(String sourcename)
Returns the pitch of the specified source.
|
float |
getVolume(String sourcename)
Returns the current volume of the specified source, or zero if the specified
source was not found.
|
protected void |
importantMessage(String message,
int indent)
Prints an important message.
|
protected void |
init(Class libraryClass)
Loads the message logger, initializes the specified sound library, and
starts the command thread.
|
static boolean |
initialized()
Returns false if a sound library is busy initializing.
|
void |
interruptCommandThread()
Wakes up the Command Thread to process commands.
|
static boolean |
libraryCompatible(Class libraryClass)
Checks if the specified library type is compatible.
|
protected void |
linkDefaultLibrariesAndCodecs()
Links with any default libraries or codecs should be made in this method.
|
void |
loadSound(byte[] data,
AudioFormat format,
String identifier)
Saves raw PCM audio data in the specified audio format, under the specified
identifier.
|
void |
loadSound(String filename)
Pre-loads a sound into memory.
|
void |
loadSound(URL url,
String identifier)
Pre-loads a sound specified by the given URL into memory.
|
protected void |
ManageSources()
This method can be overridden by extended classes to be used for source
management (culling and activating sources based on established rules).
|
protected void |
message(String message,
int indent)
Prints a message.
|
float |
millisecondsPlayed(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 location.
|
boolean |
newLibrary(Class libraryClass)
Switches to the specified library, loosing all sources.
|
void |
newSource(boolean priority,
String sourcename,
String filename,
boolean toLoop,
float x,
float y,
float z,
int attmodel,
float distOrRoll)
Creates a new non-streaming source.
|
void |
newSource(boolean priority,
String sourcename,
URL url,
String identifier,
boolean toLoop,
float x,
float y,
float z,
int attmodel,
float distOrRoll)
Creates a new non-streaming source.
|
void |
newStreamingSource(boolean priority,
String sourcename,
String filename,
boolean toLoop,
float x,
float y,
float z,
int attmodel,
float distOrRoll)
Creates a new streaming source.
|
void |
newStreamingSource(boolean priority,
String sourcename,
URL url,
String identifier,
boolean toLoop,
float x,
float y,
float z,
int attmodel,
float distOrRoll)
Creates a new streaming source.
|
void |
pause(String sourcename)
Pauses the specified source.
|
void |
play(String sourcename)
Plays the specified source.
|
boolean |
playing()
Returns true if anything is currently playing.
|
boolean |
playing(String sourcename)
Returns true if the specified source is playing.
|
void |
queueSound(String sourcename,
String filename)
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 |
queueSound(String sourcename,
URL url,
String identifier)
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.
|
String |
quickPlay(boolean priority,
String filename,
boolean toLoop,
float x,
float y,
float z,
int attmodel,
float distOrRoll)
Creates a temporary source and plays it.
|
String |
quickPlay(boolean priority,
URL url,
String identifier,
boolean toLoop,
float x,
float y,
float z,
int attmodel,
float distOrRoll)
Creates a temporary source and plays it.
|
String |
quickStream(boolean priority,
String filename,
boolean toLoop,
float x,
float y,
float z,
int attmodel,
float distOrRoll)
Creates a temporary source and streams it.
|
String |
quickStream(boolean priority,
URL url,
String identifier,
boolean toLoop,
float x,
float y,
float z,
int attmodel,
float distOrRoll)
Creates a temporary source and streams it.
|
void |
rawDataStream(AudioFormat audioFormat,
boolean priority,
String sourcename,
float x,
float y,
float z,
int attModel,
float distOrRoll)
Opens a direct line for streaming audio data.
|
void |
removeSource(String sourcename)
Removes the specified source and clears up any memory it used.
|
void |
removeTemporarySources()
Searches for and removes any temporary sources that have finished
playing.
|
void |
rewind(String sourcename)
Rewinds the specified source.
|
void |
setAttenuation(String sourcename,
int model)
Changes a source's attenuation model.
|
void |
setDistOrRoll(String sourcename,
float dr)
Changes a source's fade distance or rolloff factor.
|
static void |
setException(SoundSystemException e)
Stores a SoundSystemException which can be retreived later with the
'getLastException' method.
|
void |
setListenerAngle(float angle)
Sets the listener's angle in radians around the y-axis.
|
void |
setListenerOrientation(float lookX,
float lookY,
float lookZ,
float upX,
float upY,
float upZ)
Sets the listener's orientation.
|
void |
setListenerPosition(float x,
float y,
float z)
Moves the listener to the specified location.
|
void |
setListenerVelocity(float x,
float y,
float z)
Sets the listener's velocity, for use in Doppler effect.
|
void |
setLooping(String sourcename,
boolean lp)
Changes a source to looping or non-looping.
|
void |
setMasterVolume(float value)
Sets the overall volume, affecting all sources.
|
void |
setPitch(String sourcename,
float value)
Manually sets the specified source's pitch.
|
void |
setPosition(String sourcename,
float x,
float y,
float z)
Move a source to the specified location.
|
void |
setPriority(String sourcename,
boolean pri)
Set a source's priority factor.
|
void |
setTemporary(String sourcename,
boolean temporary)
Sets a flag for a source indicating whether it should be used or if it
should be removed after it finishes playing.
|
void |
setVelocity(String sourcename,
float x,
float y,
float z)
Sets the specified source's velocity, for use in Doppler effect.
|
void |
setVolume(String sourcename,
float value)
Manually sets the specified source's volume.
|
protected static void |
snooze(long milliseconds)
Sleeps for the specified number of milliseconds.
|
void |
stop(String sourcename)
Stops the specified source.
|
boolean |
switchLibrary(Class libraryClass)
Switches to the specified library, and preserves all sources.
|
void |
turnListener(float angle)
Turns the listener counterclockwise by "angle" radians around the y-axis,
relative to the current angle.
|
void |
unloadSound(String filename)
Removes a pre-loaded sound from memory.
|
protected SoundSystemLogger logger
protected Library soundLibrary
protected List<CommandObject> commandQueue
protected CommandThread commandThread
public Random randomNumberGenerator
protected String className
public SoundSystem()
SoundSystemConfig for
information about sound library types.public SoundSystem(Class libraryClass) throws SoundSystemException
libraryClass - Library to use.
See SoundSystemConfig for
information about chosing a sound library.SoundSystemExceptionprotected void linkDefaultLibrariesAndCodecs()
SoundSystemConfig for
information about linking with sound libraries and codecs.protected void init(Class libraryClass) throws SoundSystemException
libraryClass - Library to initialize.
See SoundSystemConfig for
information about chosing a sound library.SoundSystemExceptionpublic void cleanup()
public void interruptCommandThread()
public void loadSound(String filename)
filename - Filename of the sound file to load.public void loadSound(URL url, String identifier)
url - URL handle to the sound file to load.identifier - Filename/identifier of the file referenced by the URL.public void loadSound(byte[] data,
AudioFormat format,
String identifier)
data - The sample dataformat - Format the sample data is stored inidentifier - What to call the sample.public void unloadSound(String filename)
filename - Filename/identifier of the sound file to unload.public void queueSound(String sourcename, String filename)
sourcename - Source identifier.filename - Name of the sound file to play next.public void queueSound(String sourcename, URL url, String identifier)
sourcename - Source identifier.url - URL handle to the sound file to load.identifier - Filename/identifier of the file referenced by the URL.public void dequeueSound(String sourcename, String filename)
sourcename - Source identifier.filename - Filename/identifier of the sound file to play next.public void fadeOut(String sourcename, String filename, long milis)
sourcename - Name of the source to fade out.filename - Name of a sound file to play next, or null for none.milis - Number of miliseconds the fadeout should take.public void fadeOut(String sourcename, URL url, String identifier, long milis)
sourcename - Name of the source to fade out.url - URL handle to the sound file to play next, or null for none.identifier - Filename/identifier of the file referenced by the URL.milis - Number of miliseconds the fadeout should take.public void fadeOutIn(String sourcename, String filename, long milisOut, long milisIn)
sourcename - Name of the source to fade out/in.filename - Name of a 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 fadeOutIn(String sourcename, URL url, String identifier, long milisOut, long milisIn)
sourcename - Name of the source to fade out/in.url - URL handle to the sound file to play next.identifier - Filename/identifier of the file referenced by the URL.milisOut - Number of miliseconds the fadeout should take.milisIn - Number of miliseconds the fadein should take.public void checkFadeVolumes()
public void backgroundMusic(String sourcename, String filename, boolean toLoop)
sourcename - A unique identifier for this source. Two sources may not use the same sourcename.filename - Filename of the sound file to stream at this source.toLoop - Should this source loop, or play only once.public void backgroundMusic(String sourcename, URL url, String identifier, boolean toLoop)
sourcename - A unique identifier for this source. Two sources may not use the same sourcename.url - URL handle to the sound file to stream at this source.identifier - Filename/identifier of the file referenced by the URL.toLoop - Should this source loop, or play only once.public void newSource(boolean priority,
String sourcename,
String filename,
boolean toLoop,
float x,
float y,
float z,
int attmodel,
float distOrRoll)
SoundSystemConfig for more
information about Attenuation, fade distance, and rolloff factor.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.filename - Filename/identifier of the sound file to play at this source.toLoop - Should this source loop, or play only once.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 "attmodel".public void newSource(boolean priority,
String sourcename,
URL url,
String identifier,
boolean toLoop,
float x,
float y,
float z,
int attmodel,
float distOrRoll)
SoundSystemConfig for more
information about Attenuation, fade distance, and rolloff factor.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.url - URL handle to the sound file to stream at this source.identifier - Filename/identifier of the file referenced by the URL.toLoop - Should this source loop, or play only once.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 "attmodel".public void newStreamingSource(boolean priority,
String sourcename,
String filename,
boolean toLoop,
float x,
float y,
float z,
int attmodel,
float distOrRoll)
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.filename - The filename of the sound file to play at this source.toLoop - Should this source loop, or play only once.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 "attmodel".public void newStreamingSource(boolean priority,
String sourcename,
URL url,
String identifier,
boolean toLoop,
float x,
float y,
float z,
int attmodel,
float distOrRoll)
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.url - URL handle to the sound file to stream at this source.identifier - Filename/identifier of the file referenced by the URL.toLoop - Should this source loop, or play only once.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 "attmodel".public void rawDataStream(AudioFormat audioFormat, boolean priority, String sourcename, float x, float y, float z, int attModel, float distOrRoll)
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 "attmodel".public String quickPlay(boolean priority, String filename, boolean toLoop, float x, float y, float z, int attmodel, float distOrRoll)
priority - Setting this to true will prevent other sounds from overriding this one.filename - Filename/identifier of the sound file to play at this source.toLoop - Should this source loop, or play only once.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 "attmodel".public String quickPlay(boolean priority, URL url, String identifier, boolean toLoop, float x, float y, float z, int attmodel, float distOrRoll)
priority - Setting this to true will prevent other sounds from overriding this one.url - URL handle to the sound file to stream at this source.identifier - Filename/identifier of the file referenced by the URL.toLoop - Should this source loop, or play only once.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 "attmodel".public String quickStream(boolean priority, String filename, boolean toLoop, float x, float y, float z, int attmodel, float distOrRoll)
priority - Setting this to true will prevent other sounds from overriding this one.filename - Filename of the sound file to stream at this source.toLoop - Should this source loop, or play only once.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 "attmodel".public String quickStream(boolean priority, URL url, String identifier, boolean toLoop, float x, float y, float z, int attmodel, float distOrRoll)
priority - Setting this to true will prevent other sounds from overriding this one.url - URL handle to the sound file to stream at this source.identifier - Filename/identifier of the file referenced by the URL.toLoop - Should this source loop, or play only once.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 "attmodel".public void setPosition(String sourcename, float x, float y, float z)
sourcename - Identifier for the source.x - destination X coordinate.y - destination Y coordinate.z - destination Z coordinate.public void setVolume(String sourcename, float value)
sourcename - Source to move.value - New volume, float value ( 0.0f - 1.0f ).public float getVolume(String sourcename)
sourcename - Source to read volume from.public void setPitch(String sourcename, float value)
sourcename - The source's name.value - A float value ( 0.5f - 2.0f ).public float getPitch(String sourcename)
sourcename - The source's name.public void setPriority(String sourcename, boolean pri)
sourcename - Identifier for the source.pri - Setting this to true makes this source a priority source.public void setLooping(String sourcename, boolean lp)
sourcename - Identifier for the source.lp - This source should loop.public void setAttenuation(String sourcename, int model)
SoundSystemConfig for more
information about Attenuation.sourcename - Identifier for the source.model - Attenuation model to use.public void setDistOrRoll(String sourcename, float dr)
SoundSystemConfig for more
information about fade distance and rolloff.sourcename - Identifier for the source.dr - Either the fading distance or rolloff factor, depending on the attenuation model used.public void changeDopplerFactor(float dopplerFactor)
SoundSystemConfig for more
information about Doppler effect.dopplerFactor - New value for Doppler factor.public void changeDopplerVelocity(float dopplerVelocity)
SoundSystemConfig for more
information about Doppler effect.dopplerVelocity - New value for Doppler velocity.public void setVelocity(String sourcename, float x, float y, float z)
SoundSystemConfig for more
information about Doppler effect.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)
SoundSystemConfig for more
information about Doppler effect.x - Velocity along world x-axis.y - Velocity along world y-axis.z - Velocity along world z-axis.public float millisecondsPlayed(String sourcename)
public void feedRawAudioData(String sourcename, byte[] buffer)
sourcename - Name of the streaming source to play from.buffer - Byte buffer containing raw audio data to stream.public void play(String sourcename)
sourcename - Identifier for the source.public void pause(String sourcename)
sourcename - Identifier for the source.public void stop(String sourcename)
sourcename - Identifier for the source.public void rewind(String sourcename)
sourcename - Identifier for the source.public void flush(String sourcename)
sourcename - Identifier for the source.public void cull(String sourcename)
sourcename - Identifier for the source.public void activate(String sourcename)
sourcename - Identifier for the source.public void setTemporary(String sourcename, boolean temporary)
sourcename - Identifier for the source.temporary - True = temporary, False = permanant.public void removeSource(String sourcename)
sourcename - Identifier for the source.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 - radian offset.public void setListenerAngle(float angle)
angle - radians.public void setListenerOrientation(float lookX,
float lookY,
float lookZ,
float upX,
float upY,
float upZ)
lookX - X coordinate of the (normalized) look-at vector.lookY - Y coordinate of the (normalized) look-at vector.lookZ - Z coordinate of the (normalized) look-at vector.upX - X coordinate of the (normalized) up-direction vector.upY - Y coordinate of the (normalized) up-direction vector.upZ - Z coordinate of the (normalized) up-direction vector.public void setMasterVolume(float value)
value - New volume, float value ( 0.0f - 1.0f ).public float getMasterVolume()
public ListenerData getListenerData()
ListenerData object.public boolean switchLibrary(Class libraryClass) throws SoundSystemException
libraryClass - Library to use.SoundSystemConfig for
information about chosing a sound library.SoundSystemExceptionpublic boolean newLibrary(Class libraryClass) throws SoundSystemException
libraryClass - Library to use.
See SoundSystemConfig for
information about chosing a sound library.SoundSystemExceptionprotected void ManageSources()
public boolean CommandQueue(CommandObject newCommand)
CommandObject for more information
about commands.newCommand - Command to queue, or null to execute commands.public void removeTemporarySources()
public boolean playing(String sourcename)
sourcename - Unique identifier of the source to check.public boolean playing()
public static boolean libraryCompatible(Class libraryClass)
libraryClass - Libary type to check.public static Class currentLibrary()
public static boolean initialized()
public static SoundSystemException getLastException()
public static void setException(SoundSystemException e)
e - Exception to store.protected static void snooze(long milliseconds)
protected void message(String message, int indent)
message - Message to print.indent - Number of tabs to indent the message.protected void importantMessage(String message, int indent)
message - Message to print.indent - Number of tabs to indent the message.protected boolean errorCheck(boolean error,
String message,
int indent)
error - True or False.message - Message to print if error is true.indent - Number of tabs to indent the message.protected void errorMessage(String message, int indent)
message - Message to print.indent - Number of tabs to indent the message.Copyright © 2017. All rights reserved.