public class Library extends Object
| Modifier and Type | Field and Description |
|---|---|
protected HashMap<String,SoundBuffer> |
bufferMap
Map containing sound file data for easy lookup by filename / identifier.
|
protected ListenerData |
listener
Position and orientation of the listener.
|
protected 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 HashMap<String,Source> |
sourceMap
Map containing all created sources for easy look-up by name.
|
protected List<Channel> |
streamingChannels
Array containing maximum number of non-streaming audio channels.
|
protected StreamThread |
streamThread
Handles processing for all streaming sources.
|
| Constructor and Description |
|---|
Library()
Constructor: Instantiates the source map and listener information.
|
| Modifier and Type | Method and Description |
|---|---|
void |
activate(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(HashMap<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(String sourcename)
Culls the specified source.
|
void |
dequeueSound(String sourcename,
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,
String message)
Prints the specified message if error is true.
|
protected void |
errorMessage(String message)
Prints an error message.
|
void |
fadeOut(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(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(String sourcename,
byte[] buffer)
Feeds raw data through the specified source.
|
void |
flush(String sourcename)
Clears all previously queued data from a stream.
|
LinkedList<String> |
getAllLoadedFilenames()
Returns the filenames of all previously loaded sounds.
|
LinkedList<String> |
getAllSourcenames()
Returns the sourcenames of all sources.
|
String |
getClassName()
Returns the name of the class.
|
static 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(String sourcename)
Returns the pitch of the specified source.
|
Source |
getSource(String sourcename)
Returns the Source object identified by the specified name.
|
HashMap<String,Source> |
getSources()
Returns the sources map.
|
static String |
getTitle()
Returns the short title of this library type.
|
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)
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,
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,
String identifier)
Saves the specified sample data, under the specified identifier.
|
protected void |
message(String message)
Prints a message.
|
boolean |
midiSourcename(String sourcename)
Checks if the sourcename matches the midi source.
|
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 position.
|
void |
newSource(boolean priority,
boolean toStream,
boolean toLoop,
String sourcename,
FilenameURL filenameURL,
float posX,
float posY,
float posZ,
int attModel,
float distOrRoll)
Creates a new source using the specified information.
|
void |
pause(String sourcename)
Pauses the specified source.
|
void |
play(Source source)
Plays the specified source.
|
void |
play(String sourcename)
Looks up the specified source and plays it.
|
protected void |
printStackTrace(Exception e)
Prints an exception's error message followed by the stack trace.
|
void |
queueSound(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,
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(AudioFormat audioFormat,
boolean priority,
String sourcename,
float posX,
float posY,
float posZ,
int attModel,
float distOrRoll)
Opens a direct line for streaming audio data.
|
void |
removeSource(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(String sourcename)
Rewinds the specified source.
|
void |
setAttenuation(String sourcename,
int model)
Sets the specified source's attenuation model.
|
void |
setDistOrRoll(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(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(String sourcename,
float value)
Manually sets the specified source's pitch.
|
void |
setPosition(String sourcename,
float x,
float y,
float z)
Changes the specified source's position.
|
void |
setPriority(String sourcename,
boolean pri)
Sets the specified source's priority factor.
|
void |
setTemporary(String sourcename,
boolean temporary)
Defines whether or not the source 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.
|
void |
stop(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(String filename)
Removes a pre-loaded sound from memory.
|
protected ListenerData listener
protected HashMap<String,SoundBuffer> bufferMap
protected HashMap<String,Source> sourceMap
protected List<Channel> streamingChannels
protected List<Channel> normalChannels
protected StreamThread streamThread
protected boolean reverseByteOrder
public Library()
throws SoundSystemException
SoundSystemExceptionpublic 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, String identifier)
buffer - the sample data and audio format to save.identifier - What to call the sample.public LinkedList<String> getAllLoadedFilenames()
public LinkedList<String> getAllSourcenames()
public void unloadSound(String filename)
filename - Filename/identifier of the sound file to unload.public void rawDataStream(AudioFormat audioFormat, boolean priority, 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,
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,
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(String sourcename, boolean temporary)
sourcename - The source's name.temporary - True or False.public void setPosition(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(String sourcename, boolean pri)
sourcename - The source's name.pri - True or False.public void setLooping(String sourcename, boolean lp)
sourcename - The source's name.lp - True or False.public void setAttenuation(String sourcename, int model)
sourcename - The source's name.model - Attenuation model to use.public void setDistOrRoll(String sourcename, float dr)
sourcename - The source's name.dr - Fade distance or rolloff factor.public void setVelocity(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(String sourcename)
public int feedRawAudioData(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(String sourcename)
sourcename - Name of the source to play.public void play(Source source)
source - The source to play.public void stop(String sourcename)
sourcename - The source's name.public void pause(String sourcename)
sourcename - The source's name.public void rewind(String sourcename)
sourcename - The source's name.public void flush(String sourcename)
sourcename - The source's name.public void cull(String sourcename)
sourcename - The source's name.public void activate(String sourcename)
sourcename - The source's name.public void setMasterVolume(float value)
value - New volume, float value ( 0.0f - 1.0f ).public void setVolume(String sourcename, float value)
sourcename - The source's name.value - A 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 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(HashMap<String,Source> srcMap)
srcMap - Sources to copy.public void removeSource(String sourcename)
sourcename - The source's name.public void removeTemporarySources()
public void replaySources()
public void queueSound(String sourcename, FilenameURL filenameURL)
sourcename - Source identifier.filenameURL - Filename/URL of the sound file to play next.public void dequeueSound(String sourcename, String filename)
sourcename - Source identifier.filename - Filename/identifier of the sound file to remove from the queue.public void fadeOut(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(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,
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(String sourcename)
sourcename - Source identifier.public Source getSource(String sourcename)
sourcename - The source's name.public MidiChannel getMidiChannel()
public void setMidiChannel(MidiChannel c)
c - New MIDI channel.public void listenerMoved()
public HashMap<String,Source> getSources()
public ListenerData getListenerData()
public boolean reverseByteOrder()
public static String getTitle()
public static String getDescription()
public String getClassName()
protected void message(String message)
message - Message to print.protected void importantMessage(String message)
message - Message to print.protected boolean errorCheck(boolean error,
String message)
error - True or False.message - Message to print if error is true.protected void errorMessage(String message)
message - Message to print.protected void printStackTrace(Exception e)
e - Exception containing the information to print.Copyright © 2017. All rights reserved.