diff --git a/src/java/com/threerings/openal/ClipBuffer.java b/src/java/com/threerings/openal/ClipBuffer.java index 8e23194e..897043d9 100644 --- a/src/java/com/threerings/openal/ClipBuffer.java +++ b/src/java/com/threerings/openal/ClipBuffer.java @@ -131,7 +131,7 @@ public class ClipBuffer _state = LOADED; _manager.restoreClip(this); } - + // if we're already loaded, this is easy if (_state == LOADED) { if (observer != null) { @@ -182,7 +182,7 @@ public class ClipBuffer _state = UNLOADING; return; } - + // free up our buffer AL10.alDeleteBuffers(_bufferId); _bufferId = null; @@ -255,12 +255,12 @@ public class ClipBuffer /** * Notifies the buffer that a source has been bound to it. - */ + */ protected void sourceBound () { _bound++; } - + /** * Notifies the buffer that a source has been unbound from it. */ @@ -271,15 +271,15 @@ public class ClipBuffer dispose(); } } - + protected SoundManager _manager; protected ClipProvider _provider; protected String _path; protected int _state; protected IntBuffer _bufferId; protected int _size; - protected ObserverList _observers = - new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY); + protected ObserverList _observers = + new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY); protected int _bound; protected static final int UNLOADED = 0; diff --git a/src/java/com/threerings/openal/FileStream.java b/src/java/com/threerings/openal/FileStream.java index b3adf3a8..44f81440 100644 --- a/src/java/com/threerings/openal/FileStream.java +++ b/src/java/com/threerings/openal/FileStream.java @@ -58,19 +58,19 @@ public class FileStream extends Stream _queue.add(new QueuedFile(file, loop)); } - // documentation inherited + @Override protected int getFormat () { return _decoder.getFormat(); } - // documentation inherited + @Override protected int getFrequency () { return _decoder.getFrequency(); } - // documentation inherited + @Override protected int populateBuffer (ByteBuffer buf) throws IOException { diff --git a/src/java/com/threerings/openal/Mp3StreamDecoder.java b/src/java/com/threerings/openal/Mp3StreamDecoder.java index 6daad404..8623a020 100644 --- a/src/java/com/threerings/openal/Mp3StreamDecoder.java +++ b/src/java/com/threerings/openal/Mp3StreamDecoder.java @@ -39,7 +39,7 @@ import javazoom.jl.decoder.SampleBuffer; */ public class Mp3StreamDecoder extends StreamDecoder { - // documentation inherited + @Override public void init (InputStream in) throws IOException { @@ -52,19 +52,19 @@ public class Mp3StreamDecoder extends StreamDecoder _decoder = new Decoder(); } - // documentation inherited + @Override public int getFormat () { return AL10.AL_FORMAT_STEREO16; } - // documentation inherited + @Override public int getFrequency () { return _header.frequency(); } - // documentation inherited + @Override public int read (ByteBuffer buf) throws IOException { diff --git a/src/java/com/threerings/openal/OggStreamDecoder.java b/src/java/com/threerings/openal/OggStreamDecoder.java index d9860377..09d9906b 100644 --- a/src/java/com/threerings/openal/OggStreamDecoder.java +++ b/src/java/com/threerings/openal/OggStreamDecoder.java @@ -43,7 +43,7 @@ import com.jcraft.jorbis.Info; */ public class OggStreamDecoder extends StreamDecoder { - // documentation inherited + @Override public void init (InputStream in) throws IOException { @@ -84,19 +84,19 @@ public class OggStreamDecoder extends StreamDecoder _offsets = new int[_info.channels]; } - // documentation inherited + @Override public int getFormat () { return (_info.channels == 1) ? AL10.AL_FORMAT_MONO16 : AL10.AL_FORMAT_STEREO16; } - // documentation inherited + @Override public int getFrequency () { return _info.rate; } - // documentation inherited + @Override public int read (ByteBuffer buf) throws IOException { diff --git a/src/java/com/threerings/openal/SoundManager.java b/src/java/com/threerings/openal/SoundManager.java index 7ee1ddf6..f8b83972 100644 --- a/src/java/com/threerings/openal/SoundManager.java +++ b/src/java/com/threerings/openal/SoundManager.java @@ -21,14 +21,13 @@ package com.threerings.openal; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; -import java.util.WeakHashMap; - import org.lwjgl.openal.AL; import org.lwjgl.openal.AL10; +import com.google.common.collect.Maps; + import com.samskivert.util.LRUHashMap; import com.samskivert.util.Queue; import com.samskivert.util.RunQueue; @@ -121,7 +120,7 @@ public class SoundManager { return _streams; } - + /** * Updates all of the streams controlled by the manager. This should be called once per frame * by the application. @@ -183,7 +182,7 @@ public class SoundManager }); // create our loading queue - _toLoad = new Queue(); + _toLoad = new Queue(); // start up the background loader thread _loader.setDaemon(true); @@ -250,7 +249,7 @@ public class SoundManager { _clips.put(buffer.getKey(), buffer); } - + /** * Adds a stream to the list maintained by the manager. Called by streams when they are * created. @@ -259,7 +258,7 @@ public class SoundManager { _streams.add(stream); } - + /** * Removes a stream from the list maintained by the manager. Called by streams when they are * disposed. @@ -268,12 +267,13 @@ public class SoundManager { _streams.remove(stream); } - + /** The thread that loads up sound clips in the background. */ protected Thread _loader = new Thread("SoundManager.Loader") { + @Override public void run () { while (true) { - final ClipBuffer buffer = (ClipBuffer)_toLoad.get(); + final ClipBuffer buffer = _toLoad.get(); try { log.debug("Loading " + buffer.getKey() + "."); final Clip clip = buffer.load(); @@ -308,18 +308,18 @@ public class SoundManager protected float _baseGain = 1; /** Contains a mapping of all currently-loading clips. */ - protected HashMap _loading = new HashMap(); + protected HashMap _loading = Maps.newHashMap(); /** 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. */ - protected Queue _toLoad; + protected Queue _toLoad; /** 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. */ protected static SoundManager _soundmgr; diff --git a/src/java/com/threerings/openal/StreamDecoder.java b/src/java/com/threerings/openal/StreamDecoder.java index 329e9eac..01ceadb8 100644 --- a/src/java/com/threerings/openal/StreamDecoder.java +++ b/src/java/com/threerings/openal/StreamDecoder.java @@ -30,6 +30,8 @@ import java.io.InputStream; import java.nio.ByteBuffer; +import com.google.common.collect.Maps; + import static com.threerings.openal.Log.log; /** @@ -40,7 +42,7 @@ public abstract class StreamDecoder /** * Registers a class of {@link StreamDecoder} for the specified file extension. */ - public static void registerExtension (String extension, Class clazz) + public static void registerExtension (String extension, Class clazz) { _extensions.put(extension, clazz); } @@ -58,7 +60,7 @@ public abstract class StreamDecoder return null; } String extension = path.substring(idx+1); - Class clazz = _extensions.get(extension); + Class clazz = _extensions.get(extension); if (clazz == null) { log.warning("No decoder registered for extension [extension=" + extension + ", file=" + path + "]."); @@ -66,7 +68,7 @@ public abstract class StreamDecoder } StreamDecoder decoder; try { - decoder = (StreamDecoder)clazz.newInstance(); + decoder = clazz.newInstance(); } catch (Exception e) { log.warning("Error instantiating decoder [file=" + path + ", error=" + e + "]."); return null; @@ -101,7 +103,8 @@ public abstract class StreamDecoder throws IOException; /** Maps file extensions to decoder classes. */ - protected static HashMap _extensions = new HashMap(); + protected static HashMap> _extensions = + Maps.newHashMap(); static { registerExtension("ogg", OggStreamDecoder.class); registerExtension("mp3", Mp3StreamDecoder.class);