Exploratory house cleaning
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@611 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -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<Observer> _observers =
|
||||
new ObserverList<Observer>(ObserverList.FAST_UNSAFE_NOTIFY);
|
||||
protected int _bound;
|
||||
|
||||
protected static final int UNLOADED = 0;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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<ClipBuffer>();
|
||||
|
||||
// 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<Comparable,ClipBuffer> _loading = new HashMap<Comparable,ClipBuffer>();
|
||||
protected HashMap<Comparable,ClipBuffer> _loading = Maps.newHashMap();
|
||||
|
||||
/** Contains a mapping of all loaded clips. */
|
||||
protected LRUHashMap<Comparable,ClipBuffer> _clips =
|
||||
protected LRUHashMap<Comparable,ClipBuffer> _clips =
|
||||
new LRUHashMap<Comparable,ClipBuffer>(DEFAULT_CACHE_SIZE, _sizer);
|
||||
|
||||
/** Contains a queue of clip buffers waiting to be loaded. */
|
||||
protected Queue _toLoad;
|
||||
protected Queue<ClipBuffer> _toLoad;
|
||||
|
||||
/** The list of active streams. */
|
||||
protected ArrayList<Stream> _streams = new ArrayList<Stream>();
|
||||
|
||||
|
||||
/** 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;
|
||||
|
||||
@@ -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<? extends StreamDecoder> 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<? extends StreamDecoder> 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<String, Class> _extensions = new HashMap<String, Class>();
|
||||
protected static HashMap<String, Class<? extends StreamDecoder>> _extensions =
|
||||
Maps.newHashMap();
|
||||
static {
|
||||
registerExtension("ogg", OggStreamDecoder.class);
|
||||
registerExtension("mp3", Mp3StreamDecoder.class);
|
||||
|
||||
Reference in New Issue
Block a user