|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.openal.SoundManager
public class SoundManager
An interface to the OpenAL library that provides a number of additional services:
Note: the sound manager is not thread safe (other than during its interactions with its internal background loading thread). It assumes that all sound loading and play requests will be made from a single thread.
| Field Summary | |
|---|---|
protected float |
_baseGain
A base gain that is multiplied by the individual gain assigned to sounds. |
protected LRUHashMap<String,ClipBuffer> |
_clips
Contains a mapping of all loaded clips. |
protected int[] |
_finalizedBuffers
The list of buffers to be deleted. |
protected int[] |
_finalizedSources
The list of sources to be deleted. |
protected List<SoundGroup> |
_groups
The list of active groups. |
protected Listener |
_listener
The listener object. |
protected Thread |
_loader
The thread that loads up sound clips in the background. |
protected HashMap<String,ClipBuffer> |
_loading
Contains a mapping of all currently-loading clips. |
protected RunQueue |
_rqueue
Used to get back from the background thread to our "main" thread. |
protected static LRUHashMap.ItemSizer<ClipBuffer> |
_sizer
Used to compute the in-memory size of sound samples. |
protected static SoundManager |
_soundmgr
The one and only sound manager, here for an exclusive performance by special request. |
protected ArrayList<Stream> |
_streams
The list of active streams. |
protected Queue<ClipBuffer> |
_toLoad
Contains a queue of clip buffers waiting to be loaded. |
protected static int |
DEFAULT_CACHE_SIZE
Default to a cache size of one megabyte. |
| Constructor Summary | |
|---|---|
protected |
SoundManager(RunQueue rqueue)
Creates a sound manager and initializes the OpenAL sound subsystem. |
| Method Summary | |
|---|---|
protected void |
addGroup(SoundGroup group)
Adds a group to the list maintained by the manager. |
protected void |
addStream(Stream stream)
Adds a stream to the list maintained by the manager. |
protected void |
bufferFinalized(int id)
Called when a buffer has been finalized. |
SoundGroup |
createGroup(ClipProvider provider,
int sources)
Creates an object that can be used to manage and play a group of sounds. |
static SoundManager |
createSoundManager(RunQueue rqueue)
Creates, initializes and returns the singleton sound manager instance. |
protected void |
deleteFinalizedObjects()
Deletes all finalized objects. |
float |
getBaseGain()
Returns the base gain used for sound effects (not music). |
protected ClipBuffer |
getClip(ClipProvider provider,
String path)
Creates a clip buffer for the sound clip loaded via the specified provider with the specified path. |
protected ClipBuffer |
getClip(ClipProvider provider,
String path,
ClipBuffer.Observer observer)
Creates a clip buffer for the sound clip loaded via the specified provider with the specified path. |
Listener |
getListener()
Returns a reference to the listener object. |
ArrayList<Stream> |
getStreams()
Returns a reference to the list of active streams. |
boolean |
isInitialized()
Returns true if we were able to initialize the sound system. |
void |
loadClip(ClipProvider provider,
String path)
Loads a clip buffer for the sound clip loaded via the specified provider with the specified path. |
void |
loadClip(ClipProvider provider,
String path,
ClipBuffer.Observer observer)
Loads a clip buffer for the sound clip loaded via the specified provider with the specified path. |
protected void |
queueClipFailure(ClipBuffer buffer)
Queues the supplied clip buffer up using our RunQueue to notify its observers that
it failed to load. |
protected void |
queueClipLoad(ClipBuffer buffer)
Queues the supplied clip buffer up for resolution. |
protected void |
removeGroup(SoundGroup group)
Removes a group from the list maintained by the manager. |
protected void |
removeStream(Stream stream)
Removes a stream from the list maintained by the manager. |
protected void |
restoreClip(ClipBuffer buffer)
Adds the supplied clip buffer back to the cache after it has been marked for disposal and subsequently re-requested. |
void |
setBaseGain(float gain)
Configures the base gain (which must be a value between 0 and 1.0) which is multiplied to the individual gain assigned to sound effects (but not music). |
void |
setCacheSize(int bytes)
Configures the size of our sound cache. |
void |
shutdown()
Shuts down the sound manager. |
protected void |
sourceFinalized(int id)
Called when a source has been finalized. |
void |
updateStreams(float time)
Updates all of the streams controlled by the manager. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Thread _loader
protected RunQueue _rqueue
protected Listener _listener
protected float _baseGain
protected HashMap<String,ClipBuffer> _loading
protected LRUHashMap<String,ClipBuffer> _clips
protected Queue<ClipBuffer> _toLoad
protected ArrayList<Stream> _streams
protected List<SoundGroup> _groups
protected int[] _finalizedSources
protected int[] _finalizedBuffers
protected static SoundManager _soundmgr
protected static LRUHashMap.ItemSizer<ClipBuffer> _sizer
protected static final int DEFAULT_CACHE_SIZE
| Constructor Detail |
|---|
protected SoundManager(RunQueue rqueue)
| Method Detail |
|---|
public static SoundManager createSoundManager(RunQueue rqueue)
rqueue - a queue that the sound manager can use to post short runnables that must be
executed on the same thread from which all other sound methods will be called.public void shutdown()
public boolean isInitialized()
public void setCacheSize(int bytes)
public Listener getListener()
public void setBaseGain(float gain)
public float getBaseGain()
public SoundGroup createGroup(ClipProvider provider,
int sources)
SoundGroup.dispose().
provider - indicates from where the sound group will load its sounds.sources - indicates the maximum number of simultaneous sounds that can play in this
group.public ArrayList<Stream> getStreams()
public void updateStreams(float time)
time - the number of seconds elapsed since the last update
public void loadClip(ClipProvider provider,
String path)
public void loadClip(ClipProvider provider,
String path,
ClipBuffer.Observer observer)
protected ClipBuffer getClip(ClipProvider provider,
String path)
protected ClipBuffer getClip(ClipProvider provider,
String path,
ClipBuffer.Observer observer)
protected void queueClipLoad(ClipBuffer buffer)
Clip will be loaded into
memory and then bound into OpenAL on the background thread.
protected void queueClipFailure(ClipBuffer buffer)
RunQueue to notify its observers that
it failed to load.
protected void restoreClip(ClipBuffer buffer)
protected void addStream(Stream stream)
protected void removeStream(Stream stream)
protected void addGroup(SoundGroup group)
protected void removeGroup(SoundGroup group)
protected void sourceFinalized(int id)
protected void bufferFinalized(int id)
protected void deleteFinalizedObjects()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||