Widened, demoted logging to debug.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@108 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Michael Bayne
2006-12-30 01:25:57 +00:00
parent c3f4992328
commit 9dadf30d2e
2 changed files with 50 additions and 68 deletions
@@ -53,7 +53,7 @@ public class ClipBuffer
public static Comparable makeKey (ClipProvider provider, String path) public static Comparable makeKey (ClipProvider provider, String path)
{ {
// we'll just use a string, amazing! // we'll just use a string, amazing!
return provider + path; return provider + ":" + path;
} }
/** /**
@@ -34,37 +34,31 @@ import com.samskivert.util.Queue;
import com.samskivert.util.RunQueue; import com.samskivert.util.RunQueue;
/** /**
* An interface to the OpenAL library that provides a number of additional * An interface to the OpenAL library that provides a number of additional services:
* services:
* *
* <ul> * <ul>
* <li> an object oriented interface to the OpenAL system * <li> an object oriented interface to the OpenAL system
* <li> a mechanism for loading a group of sounds and freeing their * <li> a mechanism for loading a group of sounds and freeing their resources all at once
* resources all at once * <li> a mechanism for loading sounds in a background thread and preloading sounds that are likely
* <li> a mechanism for loading sounds in a background thread and * to be needed soon
* preloading sounds that are likely to be needed soon
* </ul> * </ul>
* *
* <p><em>Note:</em> the sound manager is not thread safe (other than * <p><em>Note:</em> the sound manager is not thread safe (other than during its interactions with
* during its interactions with its internal background loading * its internal background loading thread). It assumes that all sound loading and play requests
* thread). It assumes that all sound loading and play requests will be * will be made from a single thread.
* made from a single thread.
*/ */
public class SoundManager public class SoundManager
{ {
/** /**
* Creates, initializes and returns the singleton sound manager * Creates, initializes and returns the singleton sound manager instance.
* instance.
* *
* @param rqueue a queue that the sound manager can use to post short * @param rqueue a queue that the sound manager can use to post short runnables that must be
* runnables that must be executed on the same thread from which all * executed on the same thread from which all other sound methods will be called.
* other sound methods will be called.
*/ */
public static SoundManager createSoundManager (RunQueue rqueue) public static SoundManager createSoundManager (RunQueue rqueue)
{ {
if (_soundmgr != null) { if (_soundmgr != null) {
throw new IllegalStateException( throw new IllegalStateException("A sound manager has already been created.");
"A sound manager has already been created.");
} }
_soundmgr = new SoundManager(rqueue); _soundmgr = new SoundManager(rqueue);
return _soundmgr; return _soundmgr;
@@ -79,9 +73,8 @@ public class SoundManager
} }
/** /**
* Configures the size of our sound cache. If this value is larger * Configures the size of our sound cache. If this value is larger than memory available to the
* than memory available to the underlying sound system, it will be * underlying sound system, it will be reduced when OpenAL first tells us we're out of memory.
* reduced when OpenAL first tells us we're out of memory.
*/ */
public void setCacheSize (int bytes) public void setCacheSize (int bytes)
{ {
@@ -89,9 +82,8 @@ public class SoundManager
} }
/** /**
* Configures the base gain (which must be a value between 0 and 1.0) which * Configures the base gain (which must be a value between 0 and 1.0) which is multiplied to
* is multiplied to the individual gain assigned to sound effects (but not * the individual gain assigned to sound effects (but not music).
* music).
*/ */
public void setBaseGain (float gain) public void setBaseGain (float gain)
{ {
@@ -107,15 +99,13 @@ public class SoundManager
} }
/** /**
* Creates an object that can be used to manage and play a group of * Creates an object that can be used to manage and play a group of sounds. <em>Note:</em> the
* sounds. <em>Note:</em> the sound group <em>must</em> be disposed * sound group <em>must</em> be disposed when it is no longer needed via a call to {@link
* when it is no longer needed via a call to {@link
* SoundGroup#dispose}. * SoundGroup#dispose}.
* *
* @param provider indicates from where the sound group will load its * @param provider indicates from where the sound group will load its sounds.
* sounds. * @param sources indicates the maximum number of simultaneous sounds that can play in this
* @param sources indicates the maximum number of simultaneous sounds * group.
* that can play in this group.
*/ */
public SoundGroup createGroup (ClipProvider provider, int sources) public SoundGroup createGroup (ClipProvider provider, int sources)
{ {
@@ -131,15 +121,15 @@ public class SoundManager
} }
/** /**
* Updates all of the streams controlled by the manager. This should be * Updates all of the streams controlled by the manager. This should be called once per frame
* called once per frame by the application. * by the application.
* *
* @param time the number of seconds elapsed since the last update * @param time the number of seconds elapsed since the last update
*/ */
public void updateStreams (float time) public void updateStreams (float time)
{ {
// iterate backwards through the list so that streams can dispose of // iterate backwards through the list so that streams can dispose of themselves during
// themselves during their update // their update
for (int ii = _streams.size() - 1; ii >= 0; ii--) { for (int ii = _streams.size() - 1; ii >= 0; ii--) {
_streams.get(ii).update(time); _streams.get(ii).update(time);
} }
@@ -164,15 +154,13 @@ public class SoundManager
int errno = AL10.alGetError(); int errno = AL10.alGetError();
if (errno != AL10.AL_NO_ERROR) { if (errno != AL10.AL_NO_ERROR) {
Log.warning("Failed to initialize sound system " + Log.warning("Failed to initialize sound system [errno=" + errno + "].");
"[errno=" + errno + "].");
// don't start the background loading thread // don't start the background loading thread
return; return;
} }
// configure our LRU map with a removal observer // configure our LRU map with a removal observer
_clips.setRemovalObserver( _clips.setRemovalObserver(new LRUHashMap.RemovalObserver<Comparable,ClipBuffer>() {
new LRUHashMap.RemovalObserver<Comparable,ClipBuffer>() {
public void removedFromMap (LRUHashMap<Comparable,ClipBuffer> map, public void removedFromMap (LRUHashMap<Comparable,ClipBuffer> map,
final ClipBuffer item) { final ClipBuffer item) {
_rqueue.postRunnable(new Runnable() { _rqueue.postRunnable(new Runnable() {
@@ -193,10 +181,9 @@ public class SoundManager
} }
/** /**
* Creates a clip buffer for the sound clip loaded via the specified * Creates a clip buffer for the sound clip loaded via the specified provider with the
* provider with the specified path. The clip buffer may come from teh * specified path. The clip buffer may come from teh cache, and it will immediately be queued
* cache, and it will immediately be queued for loading if it is not * for loading if it is not already loaded.
* already loaded.
*/ */
protected ClipBuffer getClip (ClipProvider provider, String path) protected ClipBuffer getClip (ClipProvider provider, String path)
{ {
@@ -222,9 +209,8 @@ public class SoundManager
} }
/** /**
* Queues the supplied clip buffer up for resolution. The {@link Clip} * Queues the supplied clip buffer up for resolution. The {@link Clip} will be loaded into
* will be loaded into memory and then bound into OpenAL on the * memory and then bound into OpenAL on the background thread.
* background thread.
*/ */
protected void queueClipLoad (ClipBuffer buffer) protected void queueClipLoad (ClipBuffer buffer)
{ {
@@ -234,8 +220,8 @@ public class SoundManager
} }
/** /**
* Queues the supplied clip buffer up using our {@link RunQueue} to * Queues the supplied clip buffer up using our {@link RunQueue} to notify its observers that
* notify its observers that it failed to load. * it failed to load.
*/ */
protected void queueClipFailure (final ClipBuffer buffer) protected void queueClipFailure (final ClipBuffer buffer)
{ {
@@ -248,8 +234,8 @@ public class SoundManager
} }
/** /**
* Adds the supplied clip buffer back to the cache after it has been marked * Adds the supplied clip buffer back to the cache after it has been marked for disposal and
* for disposal and subsequently re-requested. * subsequently re-requested.
*/ */
protected void restoreClip (ClipBuffer buffer) protected void restoreClip (ClipBuffer buffer)
{ {
@@ -257,8 +243,8 @@ public class SoundManager
} }
/** /**
* Adds a stream to the list maintained by the manager. Called by streams * Adds a stream to the list maintained by the manager. Called by streams when they are
* when they are created. * created.
*/ */
protected void addStream (Stream stream) protected void addStream (Stream stream)
{ {
@@ -266,8 +252,8 @@ public class SoundManager
} }
/** /**
* Removes a stream from the list maintained by the manager. Called by * Removes a stream from the list maintained by the manager. Called by streams when they are
* streams when they are disposed. * disposed.
*/ */
protected void removeStream (Stream stream) protected void removeStream (Stream stream)
{ {
@@ -280,7 +266,7 @@ public class SoundManager
while (true) { while (true) {
final ClipBuffer buffer = (ClipBuffer)_toLoad.get(); final ClipBuffer buffer = (ClipBuffer)_toLoad.get();
try { try {
Log.info("Loading " + buffer.getKey() + "."); Log.debug("Loading " + buffer.getKey() + ".");
final Clip clip = buffer.load(); final Clip clip = buffer.load();
_rqueue.postRunnable(new Runnable() { _rqueue.postRunnable(new Runnable() {
public void run () { public void run () {
@@ -290,19 +276,17 @@ public class SoundManager
if (buffer.bind(clip)) { if (buffer.bind(clip)) {
_clips.put(ckey, buffer); _clips.put(ckey, buffer);
} else { } else {
// TODO: shrink the cache size if the bind // TODO: shrink the cache size if the bind failed due to
// failed due to OUT_OF_MEMORY // OUT_OF_MEMORY
} }
} }
}); });
} catch (Throwable t) { } catch (Throwable t) {
Log.warning("Failed to load clip " + Log.warning("Failed to load clip [key=" + buffer.getKey() + "].");
"[key=" + buffer.getKey() + "].");
Log.logStackTrace(t); Log.logStackTrace(t);
// let the clip and its observers know that we are a // let the clip and its observers know that we are a miserable failure
// miserable failure
queueClipFailure(buffer); queueClipFailure(buffer);
} }
} }
@@ -312,13 +296,11 @@ public class SoundManager
/** Used to get back from the background thread to our "main" thread. */ /** Used to get back from the background thread to our "main" thread. */
protected RunQueue _rqueue; protected RunQueue _rqueue;
/** A base gain that is multiplied by the individual gain assigned to /** A base gain that is multiplied by the individual gain assigned to sounds. */
* sounds. */
protected float _baseGain = 1; protected float _baseGain = 1;
/** Contains a mapping of all currently-loading clips. */ /** Contains a mapping of all currently-loading clips. */
protected HashMap<Comparable,ClipBuffer> _loading = protected HashMap<Comparable,ClipBuffer> _loading = new HashMap<Comparable,ClipBuffer>();
new HashMap<Comparable,ClipBuffer>();
/** Contains a mapping of all loaded clips. */ /** Contains a mapping of all loaded clips. */
protected LRUHashMap<Comparable,ClipBuffer> _clips = protected LRUHashMap<Comparable,ClipBuffer> _clips =
@@ -330,8 +312,8 @@ public class SoundManager
/** The list of active streams. */ /** The list of active streams. */
protected ArrayList<Stream> _streams = new ArrayList<Stream>(); protected ArrayList<Stream> _streams = new ArrayList<Stream>();
/** The one and only sound manager, here for an exclusive performance /** The one and only sound manager, here for an exclusive performance by special request.
* by special request. Available for all your sound playing needs. */ * Available for all your sound playing needs. */
protected static SoundManager _soundmgr; protected static SoundManager _soundmgr;
/** Used to compute the in-memory size of sound samples. */ /** Used to compute the in-memory size of sound samples. */