Little bit of widening, type safety, and flagging overrides.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@306 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Dave Hoover
2007-10-17 23:34:32 +00:00
parent 8e7997a061
commit 1ebd28a450
6 changed files with 87 additions and 127 deletions
@@ -39,7 +39,7 @@ import javax.sound.midi.Synthesizer;
public class MidiPlayer extends MusicPlayer public class MidiPlayer extends MusicPlayer
implements MetaEventListener implements MetaEventListener
{ {
// documentation inherited @Override // documentation inherited
public void init () public void init ()
throws Exception throws Exception
{ {
@@ -50,13 +50,13 @@ public class MidiPlayer extends MusicPlayer
} }
} }
// documentation inherited @Override // documentation inherited
public void shutdown () public void shutdown ()
{ {
_sequencer.close(); _sequencer.close();
} }
// documentation inherited @Override // documentation inherited
public void start (InputStream stream) public void start (InputStream stream)
throws Exception throws Exception
{ {
@@ -65,14 +65,14 @@ public class MidiPlayer extends MusicPlayer
_sequencer.addMetaEventListener(this); _sequencer.addMetaEventListener(this);
} }
// documentation inherited @Override // documentation inherited
public void stop () public void stop ()
{ {
_sequencer.removeMetaEventListener(this); _sequencer.removeMetaEventListener(this);
_sequencer.stop(); _sequencer.stop();
} }
// documentation inherited @Override // documentation inherited
public void setVolume (float volume) public void setVolume (float volume)
{ {
if (_channels != null) { if (_channels != null) {
@@ -37,7 +37,7 @@ import micromod.resamplers.LinearResampler;
*/ */
public class ModPlayer extends MusicPlayer public class ModPlayer extends MusicPlayer
{ {
// documentation inherited @Override // documentation inherited
public void init () public void init ()
throws Exception throws Exception
{ {
@@ -45,20 +45,19 @@ public class ModPlayer extends MusicPlayer
_device.start(); _device.start();
} }
// documentation inherited @Override // documentation inherited
public void shutdown () public void shutdown ()
{ {
_device.stop(); _device.stop();
} }
// documentation inherited @Override // documentation inherited
public void start (InputStream stream) public void start (InputStream stream)
throws Exception throws Exception
{ {
Module module = ModuleLoader.read(new DataInputStream(stream)); Module module = ModuleLoader.read(new DataInputStream(stream));
final MicroMod mod = new MicroMod( final MicroMod mod = new MicroMod(module, _device, new LinearResampler());
module, _device, new LinearResampler());
_player = new Thread("narya mod player") { _player = new Thread("narya mod player") {
public void run () { public void run () {
@@ -86,13 +85,13 @@ public class ModPlayer extends MusicPlayer
_player.start(); _player.start();
} }
// documentation inherited @Override // documentation inherited
public void stop () public void stop ()
{ {
_player = null; _player = null;
} }
// documentation inherited @Override // documentation inherited
public void setVolume (float vol) public void setVolume (float vol)
{ {
_device.setVolume(vol); _device.setVolume(vol);
@@ -110,17 +109,13 @@ public class ModPlayer extends MusicPlayer
super(new SS16LEAudioFormatConverter(), 44100, 1000); super(new SS16LEAudioFormatConverter(), 44100, 1000);
} }
/** @Override // documentation inherited
* Adjust the volume of the line that we're sending our mod data to.
*/
public void setVolume (float vol) public void setVolume (float vol)
{ {
SoundManager.adjustVolume(sourceDataLine, vol); SoundManager.adjustVolume(sourceDataLine, vol);
} }
/** @Override // documentation inherited
* Access the drain method of the line.
*/
public void drain () public void drain ()
{ {
sourceDataLine.drain(); sourceDataLine.drain();
@@ -43,7 +43,7 @@ import com.threerings.media.Log;
*/ */
public class Mp3Player extends MusicPlayer public class Mp3Player extends MusicPlayer
{ {
// documentation inherited @Override // documentation inherited
public void init () public void init ()
{ {
// TODO: some stuff needs to move here, like setting up the line // TODO: some stuff needs to move here, like setting up the line
@@ -51,12 +51,12 @@ public class Mp3Player extends MusicPlayer
// out (the format might always be known..). // out (the format might always be known..).
} }
// documentation inherited @Override // documentation inherited
public void shutdown () public void shutdown ()
{ {
} }
// documentation inherited @Override // documentation inherited
public void start (final InputStream stream) public void start (final InputStream stream)
throws Exception throws Exception
{ {
@@ -74,15 +74,12 @@ public class Mp3Player extends MusicPlayer
} }
AudioFormat sourceFormat = inStream.getFormat(); AudioFormat sourceFormat = inStream.getFormat();
AudioFormat.Encoding targetEnc = AudioFormat.Encoding targetEnc = AudioFormat.Encoding.PCM_SIGNED;
AudioFormat.Encoding.PCM_SIGNED;
inStream = AudioSystem.getAudioInputStream( inStream = AudioSystem.getAudioInputStream(targetEnc, inStream);
targetEnc, inStream);
AudioFormat format = inStream.getFormat(); AudioFormat format = inStream.getFormat();
DataLine.Info info = new DataLine.Info( DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
SourceDataLine.class, format);
try { try {
_line = (SourceDataLine) AudioSystem.getLine(info); _line = (SourceDataLine) AudioSystem.getLine(info);
@@ -122,13 +119,13 @@ public class Mp3Player extends MusicPlayer
_player.start(); _player.start();
} }
// documentation inherited @Override // documentation inherited
public void stop () public void stop ()
{ {
_player = null; _player = null;
} }
// documentation inherited @Override // documentation inherited
public void setVolume (float volume) public void setVolume (float volume)
{ {
// TODO : line won't be null when we initialize it in the right place // TODO : line won't be null when we initialize it in the right place
@@ -61,8 +61,7 @@ public class MusicManager
} }
/** /**
* Returns a string summarizing our volume settings and disabled sound * Returns a string summarizing our volume settings and disabled sound types.
* types.
*/ */
public String summarizeState () public String summarizeState ()
{ {
@@ -138,7 +137,7 @@ public class MusicManager
MusicKey mkey = new MusicKey(pkgPath, key, -1); MusicKey mkey = new MusicKey(pkgPath, key, -1);
if (!_musicStack.isEmpty()) { if (!_musicStack.isEmpty()) {
MusicKey current = (MusicKey) _musicStack.getFirst(); MusicKey current = _musicStack.getFirst();
// if we're currently playing this song.. // if we're currently playing this song..
if (mkey.equals(current)) { if (mkey.equals(current)) {
@@ -155,7 +154,7 @@ public class MusicManager
} else { } else {
// we aren't currently playing this song. Simply remove. // we aren't currently playing this song. Simply remove.
for (Iterator iter=_musicStack.iterator(); iter.hasNext(); ) { for (Iterator<MusicKey> iter=_musicStack.iterator(); iter.hasNext(); ) {
if (key.equals(iter.next())) { if (key.equals(iter.next())) {
iter.remove(); iter.remove();
return; return;
@@ -165,8 +164,7 @@ public class MusicManager
} }
} }
Log.debug("Sequence stopped that wasn't in the stack anymore " + Log.debug("Sequence stopped that wasn't in the stack anymore [key=" + mkey + "].");
"[key=" + mkey + "].");
} }
/** /**
@@ -178,15 +176,14 @@ public class MusicManager
return; return;
} }
// if the volume is off, we don't actually want to play anything // if the volume is off, we don't actually want to play anything but we want to at least
// but we want to at least decrement any loopers by one // decrement any loopers by one and keep them on the top of the queue
// and keep them on the top of the queue
if (_musicVol == 0f) { if (_musicVol == 0f) {
handleMusicStopped(); handleMusicStopped();
return; return;
} }
MusicKey info = (MusicKey) _musicStack.getFirst(); MusicKey info = _musicStack.getFirst();
Config c = _smgr.getConfig(info); Config c = _smgr.getConfig(info);
String[] names = c.getValue(info.key, (String[])null); String[] names = c.getValue(info.key, (String[])null);
@@ -208,7 +205,7 @@ public class MusicManager
} }
// shutdown the old player if we're switching music types // shutdown the old player if we're switching music types
if (! playerClass.isInstance(_musicPlayer)) { if (!playerClass.isInstance(_musicPlayer)) {
if (_musicPlayer != null) { if (_musicPlayer != null) {
_musicPlayer.shutdown(); _musicPlayer.shutdown();
} }
@@ -219,8 +216,8 @@ public class MusicManager
_musicPlayer.init(_playerListener); _musicPlayer.init(_playerListener);
} catch (Exception e) { } catch (Exception e) {
Log.warning("Unable to instantiate music player [class=" + Log.warning("Unable to instantiate music player [class=" + playerClass +
playerClass + ", e=" + e + "]."); ", e=" + e + "].");
// scrap it, try again with the next song // scrap it, try again with the next song
_musicPlayer = null; _musicPlayer = null;
@@ -271,8 +268,7 @@ public class MusicManager
} }
/** /**
* Stop whatever song is currently playing and deal with the * Stop whatever song is currently playing and deal with the MusicKey associated with it.
* MusicKey associated with it.
*/ */
protected void handleMusicStopped () protected void handleMusicStopped ()
{ {
@@ -281,7 +277,7 @@ public class MusicManager
} }
// see what was playing // see what was playing
MusicKey current = (MusicKey) _musicStack.getFirst(); MusicKey current = _musicStack.getFirst();
// see how many times the song was to loop and act accordingly // see how many times the song was to loop and act accordingly
switch (current.loops) { switch (current.loops) {
@@ -333,7 +329,7 @@ public class MusicManager
protected float _musicVol = 1f; protected float _musicVol = 1f;
/** The stack of songs that we're playing. */ /** The stack of songs that we're playing. */
protected LinkedList _musicStack = new LinkedList(); protected LinkedList<MusicKey> _musicStack = new LinkedList<MusicKey>();
/** The current music player, if any. */ /** The current music player, if any. */
protected MusicPlayer _musicPlayer; protected MusicPlayer _musicPlayer;
@@ -29,14 +29,13 @@ import com.threerings.media.sound.SoundManager.SoundType;
public interface SoundCodes public interface SoundCodes
{ {
/** /**
* Alert sounds are the type of sounds a player would hear when * Alert sounds are the type of sounds a player would hear when getting a puzzle challenge.
* getting a puzzle challenge.
*/ */
public static final SoundType ALERT = new SoundType("alert"); public static final SoundType ALERT = new SoundType("alert");
/** /**
* Feedback sounds are the type of sounds a player would here when * Feedback sounds are the type of sounds a player would here when clicking on buttons or
* clicking on buttons or performing an action. * performing an action.
*/ */
public static final SoundType FEEDBACK = new SoundType("feedback"); public static final SoundType FEEDBACK = new SoundType("feedback");
@@ -82,8 +82,7 @@ public class SoundManager
{ {
/** /**
* Construct a new SoundType. * Construct a new SoundType.
* Which should be a static variable stashed somewhere for the * Which should be a static variable stashed somewhere for the entire application to share.
* entire application to share.
* *
* @param strname a short string identifier, preferably without spaces. * @param strname a short string identifier, preferably without spaces.
*/ */
@@ -92,6 +91,7 @@ public class SoundManager
_strname = strname; _strname = strname;
} }
@Override // documentation inherited
public String toString () public String toString ()
{ {
return _strname; return _strname;
@@ -107,10 +107,9 @@ public class SoundManager
{ {
/** /**
* Stop playing or looping the sound. * Stop playing or looping the sound.
* At present, the granularity of this command is limited to the * At present, the granularity of this command is limited to the buffer size of the
* buffer size of the line spooler, or about 8k of data. Thus, * line spooler, or about 8k of data. Thus, if playing an 11khz sample, it could take
* if playing an 11khz sample, it could take 8/11ths of a second * 8/11ths of a second for the sound to actually stop playing.
* for the sound to actually stop playing.
*/ */
public void stop (); public void stop ();
@@ -154,8 +153,7 @@ public class SoundManager
* @param defaultClipPath The pathname of a sound clip to use as a * @param defaultClipPath The pathname of a sound clip to use as a
* fallback if another sound clip cannot be located. * fallback if another sound clip cannot be located.
*/ */
public SoundManager ( public SoundManager (ResourceManager rmgr, String defaultClipBundle, String defaultClipPath)
ResourceManager rmgr, String defaultClipBundle, String defaultClipPath)
{ {
// save things off // save things off
_rmgr = rmgr; _rmgr = rmgr;
@@ -182,8 +180,7 @@ public class SoundManager
} }
/** /**
* Returns a string summarizing our volume settings and disabled sound * Returns a string summarizing our volume settings and disabled sound types.
* types.
*/ */
public String summarizeState () public String summarizeState ()
{ {
@@ -191,7 +188,7 @@ public class SoundManager
buf.append("clipVol=").append(_clipVol); buf.append("clipVol=").append(_clipVol);
buf.append(", disabled=["); buf.append(", disabled=[");
int ii = 0; int ii = 0;
for (Iterator iter = _disabledTypes.iterator(); iter.hasNext(); ) { for (Iterator<SoundType> iter = _disabledTypes.iterator(); iter.hasNext(); ) {
if (ii++ > 0) { if (ii++ > 0) {
buf.append(", "); buf.append(", ");
} }
@@ -311,16 +308,14 @@ public class SoundManager
* @param delay the delay in milliseconds. * @param delay the delay in milliseconds.
* @param pan a value from -1f (all left) to +1f (all right). * @param pan a value from -1f (all left) to +1f (all right).
*/ */
public void play ( public void play (SoundType type, String pkgPath, String key, int delay, float pan)
SoundType type, String pkgPath, String key, int delay, float pan)
{ {
if (type == null) { if (type == null) {
type = DEFAULT; // let the lazy kids play too type = DEFAULT; // let the lazy kids play too
} }
if ((_clipVol != 0f) && isEnabled(type)) { if ((_clipVol != 0f) && isEnabled(type)) {
final SoundKey skey = new SoundKey(PLAY, pkgPath, key, delay, final SoundKey skey = new SoundKey(PLAY, pkgPath, key, delay, _clipVol, pan);
_clipVol, pan);
if (delay > 0) { if (delay > 0) {
new Interval() { new Interval() {
public void expired () { public void expired () {
@@ -372,8 +367,8 @@ public class SoundManager
} }
} else /* if (_verbose.getValue()) */ { } else /* if (_verbose.getValue()) */ {
Log.warning("SoundManager not playing sound because " + Log.warning("SoundManager not playing sound because too many sounds in queue " +
"too many sounds in queue [key=" + skey + "]."); "[key=" + skey + "].");
} }
} }
@@ -390,8 +385,7 @@ public class SoundManager
} else { } else {
_queue.appendLoud(key); _queue.appendLoud(key);
queued = true; queued = true;
add = okToStartNew && (_freeSpoolers == 0) && add = okToStartNew && (_freeSpoolers == 0) && (_spoolerCount < MAX_SPOOLERS);
(_spoolerCount < MAX_SPOOLERS);
if (add) { if (add) {
_spoolerCount++; _spoolerCount++;
} }
@@ -422,12 +416,12 @@ public class SoundManager
SoundKey key; SoundKey key;
synchronized (_queue) { synchronized (_queue) {
_freeSpoolers++; _freeSpoolers++;
key = (SoundKey) _queue.get(MAX_WAIT_TIME); key = _queue.get(MAX_WAIT_TIME);
_freeSpoolers--; _freeSpoolers--;
if (key == null || key.cmd == DIE) { if (key == null || key.cmd == DIE) {
_spoolerCount--; _spoolerCount--;
// if dieing and there are others to kill, do so // if dying and there are others to kill, do so
if (key != null && _spoolerCount > 0) { if (key != null && _spoolerCount > 0) {
_queue.appendLoud(key); _queue.appendLoud(key);
} }
@@ -464,8 +458,7 @@ public class SoundManager
// copy cached to lock map // copy cached to lock map
_lockedClips.put(key, _clipCache.get(key)); _lockedClips.put(key, _clipCache.get(key));
} catch (Exception e) { } catch (Exception e) {
// don't whine about LOCK failures unless // don't whine about LOCK failures unless we are verbosely logging
// we are verbosely logging
if (_verbose.getValue()) { if (_verbose.getValue()) {
throw e; throw e;
} }
@@ -568,34 +561,28 @@ public class SoundManager
if (sampleSize == AudioSystem.NOT_SPECIFIED) { if (sampleSize == AudioSystem.NOT_SPECIFIED) {
sampleSize = 16; sampleSize = 16;
} }
int drainTime = (int) Math.ceil( int drainTime = (int) Math.ceil((LINEBUF_SIZE * 8 * 1000) / (sampleRate * sampleSize));
(LINEBUF_SIZE * 8 * 1000) / (sampleRate * sampleSize));
// add in a fudge factor of half a second // add in a fudge factor of half a second
drainTime += 500; drainTime += 500;
try { try {
Thread.sleep(drainTime); Thread.sleep(drainTime);
} catch (InterruptedException ie) { } catch (InterruptedException ie) { }
}
} catch (IOException ioe) { } catch (IOException ioe) {
Log.warning("Error loading sound file [key=" + key + Log.warning("Error loading sound file [key=" + key + ", e=" + ioe + "].");
", e=" + ioe + "].");
} catch (UnsupportedAudioFileException uafe) { } catch (UnsupportedAudioFileException uafe) {
Log.warning("Unsupported sound format [key=" + key + Log.warning("Unsupported sound format [key=" + key + ", e=" + uafe + "].");
", e=" + uafe + "].");
} catch (LineUnavailableException lue) { } catch (LineUnavailableException lue) {
String err = "Line not available to play sound [key=" + key.key + String err = "Line not available to play sound [key=" + key.key + ", e=" + lue + "].";
", e=" + lue + "].";
if (_soundSeemsToWork) { if (_soundSeemsToWork) {
Log.warning(err); Log.warning(err);
} else { } else {
// this error comes every goddamned time we play a sound on // this error comes every goddamned time we play a sound on someone with a
// someone with a misconfigured sound card, so let's just keep // misconfigured sound card, so let's just keep it to ourselves
// it to ourselves
Log.debug(err); Log.debug(err);
} }
@@ -616,8 +603,7 @@ public class SoundManager
} }
/** /**
* Called by spooling threads, loads clip data from the resource * Called by spooling threads, loads clip data from the resource manager or the cache.
* manager or the cache.
*/ */
protected byte[] getClipData (SoundKey key) protected byte[] getClipData (SoundKey key)
throws IOException, UnsupportedAudioFileException throws IOException, UnsupportedAudioFileException
@@ -630,13 +616,13 @@ public class SoundManager
_clipCache.clear(); _clipCache.clear();
} }
data = (byte[][]) _clipCache.get(key); data = _clipCache.get(key);
// see if it's in the locked cache (we first look in the regular // see if it's in the locked cache (we first look in the regular
// clip cache so that locked clips that are still cached continue // clip cache so that locked clips that are still cached continue
// to be moved to the head of the LRU queue) // to be moved to the head of the LRU queue)
if (data == null) { if (data == null) {
data = (byte[][]) _lockedClips.get(key); data = _lockedClips.get(key);
} }
if (data == null) { if (data == null) {
@@ -714,8 +700,7 @@ public class SoundManager
try { try {
return new FileInputStream(pick); return new FileInputStream(pick);
} catch (Exception e) { } catch (Exception e) {
Log.warning("Error reading test sound [e=" + e + ", file=" + Log.warning("Error reading test sound [e=" + e + ", file=" + pick + "].");
pick + "].");
} }
} }
return null; return null;
@@ -735,15 +720,13 @@ public class SoundManager
try { try {
clipin = _rmgr.getResource(path); clipin = _rmgr.getResource(path);
} catch (FileNotFoundException fnfe2) { } catch (FileNotFoundException fnfe2) {
// only play the default sound if we have verbose sound // only play the default sound if we have verbose sound debugging turned on.
// debuggin turned on.
if (_verbose.getValue()) { if (_verbose.getValue()) {
Log.warning("Could not locate sound data [bundle=" + Log.warning("Could not locate sound data [bundle=" + bundle +
bundle + ", path=" + path + "]."); ", path=" + path + "].");
if (_defaultClipPath != null) { if (_defaultClipPath != null) {
try { try {
clipin = _rmgr.getResource( clipin = _rmgr.getResource(_defaultClipBundle, _defaultClipPath);
_defaultClipBundle, _defaultClipPath);
} catch (FileNotFoundException fnfe3) { } catch (FileNotFoundException fnfe3) {
try { try {
clipin = _rmgr.getResource(_defaultClipPath); clipin = _rmgr.getResource(_defaultClipPath);
@@ -773,7 +756,7 @@ public class SoundManager
*/ */
protected Config getConfig (SoundKey key) protected Config getConfig (SoundKey key)
{ {
Config c = (Config) _configs.get(key.pkgPath); Config c = _configs.get(key.pkgPath);
if (c == null) { if (c == null) {
String propPath = key.pkgPath + Sounds.PROP_NAME; String propPath = key.pkgPath + Sounds.PROP_NAME;
Properties props = new Properties(); Properties props = new Properties();
@@ -818,11 +801,9 @@ public class SoundManager
*/ */
protected static void adjustVolume (Line line, float vol) protected static void adjustVolume (Line line, float vol)
{ {
FloatControl control = (FloatControl) FloatControl control = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN);
line.getControl(FloatControl.Type.MASTER_GAIN);
// the only problem is that gain is specified in decibals, // the only problem is that gain is specified in decibals, which is a logarithmic scale.
// which is a logarithmic scale.
// Since we want max volume to leave the sample unchanged, our // Since we want max volume to leave the sample unchanged, our
// maximum volume translates into a 0db gain. // maximum volume translates into a 0db gain.
float gain; float gain;
@@ -842,8 +823,7 @@ public class SoundManager
protected static void adjustPan (Line line, float pan) protected static void adjustPan (Line line, float pan)
{ {
try { try {
FloatControl control = FloatControl control = (FloatControl) line.getControl(FloatControl.Type.PAN);
(FloatControl) line.getControl(FloatControl.Type.PAN);
control.setValue(pan); control.setValue(pan);
} catch (Exception e) { } catch (Exception e) {
Log.debug("Cannot set pan on line: " + e); Log.debug("Cannot set pan on line: " + e);
@@ -897,8 +877,7 @@ public class SoundManager
/** /**
* Constructor for a sound effect soundkey. * Constructor for a sound effect soundkey.
*/ */
public SoundKey (byte cmd, String pkgPath, String key, int delay, public SoundKey (byte cmd, String pkgPath, String key, int delay, float volume, float pan)
float volume, float pan)
{ {
this(cmd, pkgPath, key); this(cmd, pkgPath, key);
@@ -950,26 +929,24 @@ public class SoundManager
return (stamp + MAX_SOUND_DELAY < System.currentTimeMillis()); return (stamp + MAX_SOUND_DELAY < System.currentTimeMillis());
} }
// documentation inherited @Override // documentation inherited
public String toString () public String toString ()
{ {
return "SoundKey{cmd=" + cmd + ", pkgPath=" + pkgPath + return "SoundKey{cmd=" + cmd + ", pkgPath=" + pkgPath + ", key=" + key + "}";
", key=" + key + "}";
} }
// documentation inherited @Override // documentation inherited
public int hashCode () public int hashCode ()
{ {
return pkgPath.hashCode() ^ key.hashCode(); return pkgPath.hashCode() ^ key.hashCode();
} }
// documentation inherited @Override // documentation inherited
public boolean equals (Object o) public boolean equals (Object o)
{ {
if (o instanceof SoundKey) { if (o instanceof SoundKey) {
SoundKey that = (SoundKey) o; SoundKey that = (SoundKey) o;
return this.pkgPath.equals(that.pkgPath) && return this.pkgPath.equals(that.pkgPath) && this.key.equals(that.key);
this.key.equals(that.key);
} }
return false; return false;
} }
@@ -982,7 +959,7 @@ public class SoundManager
protected ResourceManager _rmgr; protected ResourceManager _rmgr;
/** The queue of sound clips to be played. */ /** The queue of sound clips to be played. */
protected Queue _queue = new Queue(); protected Queue<SoundKey> _queue = new Queue<SoundKey>();
/** The number of currently active LineSpoolers. */ /** The number of currently active LineSpoolers. */
protected int _spoolerCount, _freeSpoolers; protected int _spoolerCount, _freeSpoolers;
@@ -994,18 +971,18 @@ public class SoundManager
protected float _clipVol = 1f; protected float _clipVol = 1f;
/** The cache of recent audio clips . */ /** The cache of recent audio clips . */
protected LRUHashMap _clipCache = new LRUHashMap(10); protected LRUHashMap<SoundKey,byte[][]> _clipCache = new LRUHashMap<SoundKey,byte[][]>(10);
/** The set of locked audio clips; this is separate from the LRU so /** The set of locked audio clips; this is separate from the LRU so
* that locking clips doesn't booch up an otherwise normal caching * that locking clips doesn't booch up an otherwise normal caching
* agenda. */ * agenda. */
protected HashMap _lockedClips = new HashMap(); protected HashMap<SoundKey,byte[][]> _lockedClips = new HashMap<SoundKey,byte[][]>();
/** A set of soundTypes for which sound is enabled. */ /** A set of soundTypes for which sound is enabled. */
protected HashSet _disabledTypes = new HashSet(); protected HashSet<SoundType> _disabledTypes = new HashSet<SoundType>();
/** A cache of config objects we've created. */ /** A cache of config objects we've created. */
protected LRUHashMap _configs = new LRUHashMap(5); protected LRUHashMap<String,Config> _configs = new LRUHashMap<String,Config>(5);
/** Soundkey command constants. */ /** Soundkey command constants. */
protected static final byte PLAY = 0; protected static final byte PLAY = 0;
@@ -1017,26 +994,22 @@ public class SoundManager
/** A pref that specifies a directory for us to get test sounds from. */ /** A pref that specifies a directory for us to get test sounds from. */
protected static RuntimeAdjust.FileAdjust _testDir = protected static RuntimeAdjust.FileAdjust _testDir =
new RuntimeAdjust.FileAdjust( new RuntimeAdjust.FileAdjust(
"Test sound directory", "narya.media.sound.test_dir", "Test sound directory", "narya.media.sound.test_dir", MediaPrefs.config, true, "");
MediaPrefs.config, true, "");
protected static RuntimeAdjust.BooleanAdjust _verbose = protected static RuntimeAdjust.BooleanAdjust _verbose =
new RuntimeAdjust.BooleanAdjust( new RuntimeAdjust.BooleanAdjust(
"Verbose sound event logging", "narya.media.sound.verbose", "Verbose sound event logging", "narya.media.sound.verbose", MediaPrefs.config, false);
MediaPrefs.config, false);
/** The queue size at which we start to ignore requests to play sounds. */ /** The queue size at which we start to ignore requests to play sounds. */
protected static final int MAX_QUEUE_SIZE = 25; protected static final int MAX_QUEUE_SIZE = 25;
/** The maximum time after which we throw away a sound rather /** The maximum time after which we throw away a sound rather than play it. */
* than play it. */
protected static final long MAX_SOUND_DELAY = 400L; protected static final long MAX_SOUND_DELAY = 400L;
/** The size of the line's buffer. */ /** The size of the line's buffer. */
protected static final int LINEBUF_SIZE = 8 * 1024; protected static final int LINEBUF_SIZE = 8 * 1024;
/** The maximum time a spooler will wait for a stream before /** The maximum time a spooler will wait for a stream before deciding to shut down. */
* deciding to shut down. */
protected static final long MAX_WAIT_TIME = 30000L; protected static final long MAX_WAIT_TIME = 30000L;
/** The maximum number of spoolers we'll allow. This is a lot. */ /** The maximum number of spoolers we'll allow. This is a lot. */