From 9dadf30d2e8ac39848474dce3431b649d11fb1b2 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 30 Dec 2006 01:25:57 +0000 Subject: [PATCH] Widened, demoted logging to debug. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@108 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../com/threerings/openal/ClipBuffer.java | 2 +- .../com/threerings/openal/SoundManager.java | 116 ++++++++---------- 2 files changed, 50 insertions(+), 68 deletions(-) diff --git a/src/java/com/threerings/openal/ClipBuffer.java b/src/java/com/threerings/openal/ClipBuffer.java index f78cebe7..13d117d8 100644 --- a/src/java/com/threerings/openal/ClipBuffer.java +++ b/src/java/com/threerings/openal/ClipBuffer.java @@ -53,7 +53,7 @@ public class ClipBuffer public static Comparable makeKey (ClipProvider provider, String path) { // we'll just use a string, amazing! - return provider + path; + return provider + ":" + path; } /** diff --git a/src/java/com/threerings/openal/SoundManager.java b/src/java/com/threerings/openal/SoundManager.java index d7841264..e9625fe1 100644 --- a/src/java/com/threerings/openal/SoundManager.java +++ b/src/java/com/threerings/openal/SoundManager.java @@ -34,37 +34,31 @@ import com.samskivert.util.Queue; import com.samskivert.util.RunQueue; /** - * An interface to the OpenAL library that provides a number of additional - * services: + * 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. + *

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. */ public class SoundManager { /** - * Creates, initializes and returns the singleton sound manager - * instance. + * Creates, initializes and returns the singleton sound manager instance. * - * @param 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. + * @param 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 static SoundManager createSoundManager (RunQueue rqueue) { if (_soundmgr != null) { - throw new IllegalStateException( - "A sound manager has already been created."); + throw new IllegalStateException("A sound manager has already been created."); } _soundmgr = new SoundManager(rqueue); return _soundmgr; @@ -79,9 +73,8 @@ public class SoundManager } /** - * Configures the size of our sound cache. If this value is larger - * than memory available to the underlying sound system, it will be - * reduced when OpenAL first tells us we're out of memory. + * Configures the size of our sound cache. If this value is larger than memory available to the + * underlying sound system, it will be reduced when OpenAL first tells us we're out of memory. */ 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 - * is multiplied to the individual gain assigned to sound effects (but not - * music). + * 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). */ 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 - * sounds. Note: the sound group must be disposed - * when it is no longer needed via a call to {@link + * Creates an object that can be used to manage and play a group of sounds. Note: the + * sound group must be disposed when it is no longer needed via a call to {@link * SoundGroup#dispose}. * - * @param provider indicates from where the sound group will load its - * sounds. - * @param sources indicates the maximum number of simultaneous sounds - * that can play in this group. + * @param provider indicates from where the sound group will load its sounds. + * @param sources indicates the maximum number of simultaneous sounds that can play in this + * group. */ 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 - * called once per frame by the application. + * Updates all of the streams controlled by the manager. This should be called once per frame + * by the application. * * @param time the number of seconds elapsed since the last update */ public void updateStreams (float time) { - // iterate backwards through the list so that streams can dispose of - // themselves during their update + // iterate backwards through the list so that streams can dispose of themselves during + // their update for (int ii = _streams.size() - 1; ii >= 0; ii--) { _streams.get(ii).update(time); } @@ -164,15 +154,13 @@ public class SoundManager int errno = AL10.alGetError(); if (errno != AL10.AL_NO_ERROR) { - Log.warning("Failed to initialize sound system " + - "[errno=" + errno + "]."); + Log.warning("Failed to initialize sound system [errno=" + errno + "]."); // don't start the background loading thread return; } // configure our LRU map with a removal observer - _clips.setRemovalObserver( - new LRUHashMap.RemovalObserver() { + _clips.setRemovalObserver(new LRUHashMap.RemovalObserver() { public void removedFromMap (LRUHashMap map, final ClipBuffer item) { _rqueue.postRunnable(new Runnable() { @@ -193,10 +181,9 @@ public class SoundManager } /** - * Creates a clip buffer for the sound clip loaded via the specified - * provider with the specified path. The clip buffer may come from teh - * cache, and it will immediately be queued for loading if it is not - * already loaded. + * Creates a clip buffer for the sound clip loaded via the specified provider with the + * specified path. The clip buffer may come from teh cache, and it will immediately be queued + * for loading if it is not already loaded. */ 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} - * will be loaded into memory and then bound into OpenAL on the - * background thread. + * Queues the supplied clip buffer up for resolution. The {@link Clip} will be loaded into + * memory and then bound into OpenAL on the background thread. */ protected void queueClipLoad (ClipBuffer buffer) { @@ -234,8 +220,8 @@ public class SoundManager } /** - * Queues the supplied clip buffer up using our {@link RunQueue} to - * notify its observers that it failed to load. + * Queues the supplied clip buffer up using our {@link RunQueue} to notify its observers that + * it failed to load. */ 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 - * for disposal and subsequently re-requested. + * Adds the supplied clip buffer back to the cache after it has been marked for disposal and + * subsequently re-requested. */ 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 - * when they are created. + * Adds a stream to the list maintained by the manager. Called by streams when they are + * created. */ protected void addStream (Stream stream) { @@ -266,8 +252,8 @@ public class SoundManager } /** - * Removes a stream from the list maintained by the manager. Called by - * streams when they are disposed. + * Removes a stream from the list maintained by the manager. Called by streams when they are + * disposed. */ protected void removeStream (Stream stream) { @@ -280,7 +266,7 @@ public class SoundManager while (true) { final ClipBuffer buffer = (ClipBuffer)_toLoad.get(); try { - Log.info("Loading " + buffer.getKey() + "."); + Log.debug("Loading " + buffer.getKey() + "."); final Clip clip = buffer.load(); _rqueue.postRunnable(new Runnable() { public void run () { @@ -290,19 +276,17 @@ public class SoundManager if (buffer.bind(clip)) { _clips.put(ckey, buffer); } else { - // TODO: shrink the cache size if the bind - // failed due to OUT_OF_MEMORY + // TODO: shrink the cache size if the bind failed due to + // OUT_OF_MEMORY } } }); } catch (Throwable t) { - Log.warning("Failed to load clip " + - "[key=" + buffer.getKey() + "]."); + Log.warning("Failed to load clip [key=" + buffer.getKey() + "]."); Log.logStackTrace(t); - // let the clip and its observers know that we are a - // miserable failure + // let the clip and its observers know that we are a miserable failure queueClipFailure(buffer); } } @@ -312,16 +296,14 @@ public class SoundManager /** Used to get back from the background thread to our "main" thread. */ protected RunQueue _rqueue; - /** A base gain that is multiplied by the individual gain assigned to - * sounds. */ + /** A base gain that is multiplied by the individual gain assigned to sounds. */ protected float _baseGain = 1; /** Contains a mapping of all currently-loading clips. */ - protected HashMap _loading = - new HashMap(); + protected HashMap _loading = new HashMap(); /** Contains a mapping of all loaded clips. */ - protected LRUHashMap _clips = + protected LRUHashMap _clips = new LRUHashMap(DEFAULT_CACHE_SIZE, _sizer); /** Contains a queue of clip buffers waiting to be loaded. */ @@ -330,8 +312,8 @@ public class SoundManager /** The list of active streams. */ protected ArrayList _streams = new ArrayList(); - /** The one and only sound manager, here for an exclusive performance - * by special request. Available for all your sound playing needs. */ + /** The one and only sound manager, here for an exclusive performance by special request. + * Available for all your sound playing needs. */ protected static SoundManager _soundmgr; /** Used to compute the in-memory size of sound samples. */