- Set the resource freeing timer to operate in non-repeating mode, since I
previously stopped it every time it fired anyway. - Enforce a maximum queue size for played sounds so that things don't get out of hand. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1908 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: SoundManager.java,v 1.8 2002/11/02 01:49:20 ray Exp $
|
// $Id: SoundManager.java,v 1.9 2002/11/05 21:02:03 ray Exp $
|
||||||
|
|
||||||
package com.threerings.media;
|
package com.threerings.media;
|
||||||
|
|
||||||
@@ -44,9 +44,8 @@ import com.threerings.media.Log;
|
|||||||
// TODO:
|
// TODO:
|
||||||
// - volume for different sound types
|
// - volume for different sound types
|
||||||
// Clip.getControl(FloatControl.Type.VOLUME);
|
// Clip.getControl(FloatControl.Type.VOLUME);
|
||||||
// - either a limit to the queue length, or a way to put items
|
// - maybe a way to put items in the queue with a timestamp,
|
||||||
// in the queue with a timestamp, and if they're processed after that
|
// and if they're processed after that time, we cut them out.
|
||||||
// time, we cut them out.
|
|
||||||
// - looping a sound
|
// - looping a sound
|
||||||
public class SoundManager
|
public class SoundManager
|
||||||
{
|
{
|
||||||
@@ -110,7 +109,7 @@ public class SoundManager
|
|||||||
flushResources(false);
|
flushResources(false);
|
||||||
// and re-start the resource freer timer to do
|
// and re-start the resource freer timer to do
|
||||||
// it again in 3 seconds
|
// it again in 3 seconds
|
||||||
_resourceFreer.start();
|
_resourceFreer.restart();
|
||||||
|
|
||||||
// see if we got the die signal
|
// see if we got the die signal
|
||||||
} else if (o == DIE) {
|
} else if (o == DIE) {
|
||||||
@@ -124,6 +123,8 @@ public class SoundManager
|
|||||||
|
|
||||||
_player.setDaemon(true);
|
_player.setDaemon(true);
|
||||||
_player.start();
|
_player.start();
|
||||||
|
|
||||||
|
_resourceFreer.setRepeats(false);
|
||||||
_resourceFreer.start();
|
_resourceFreer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +177,15 @@ public class SoundManager
|
|||||||
{
|
{
|
||||||
if (_player != null && isEnabled(type)) {
|
if (_player != null && isEnabled(type)) {
|
||||||
// Log.info("Queueing sound [path=" + path + "].");
|
// Log.info("Queueing sound [path=" + path + "].");
|
||||||
_queue.append(path);
|
synchronized (_queue) {
|
||||||
|
if (_queue.size() < MAX_SOUNDS_ENQUEUED) {
|
||||||
|
_queue.append(path);
|
||||||
|
} else {
|
||||||
|
Log.warning("SoundManager not playing sound because " +
|
||||||
|
"too many sounds in queue [path=" + path +
|
||||||
|
", type=" + type + "].");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,11 +448,7 @@ public class SoundManager
|
|||||||
new ActionListener() {
|
new ActionListener() {
|
||||||
public void actionPerformed (ActionEvent e)
|
public void actionPerformed (ActionEvent e)
|
||||||
{
|
{
|
||||||
// stop the timer so we don't queue up loads of FLUSH
|
// request a sweep by the main thread
|
||||||
// requests when the main thread is bogged down.
|
|
||||||
_resourceFreer.stop();
|
|
||||||
|
|
||||||
// and request a sweep by the main thread
|
|
||||||
_queue.append(FLUSH);
|
_queue.append(FLUSH);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -472,6 +477,9 @@ public class SoundManager
|
|||||||
/** Signals to the queue to do different things. */
|
/** Signals to the queue to do different things. */
|
||||||
protected Object FLUSH = new Object(), DIE = new Object();
|
protected Object FLUSH = new Object(), DIE = new Object();
|
||||||
|
|
||||||
|
/** The maximum number of sounds we'll allow to be enqueued. */
|
||||||
|
protected static final int MAX_SOUNDS_ENQUEUED = 25;
|
||||||
|
|
||||||
/** The buffer size in bytes used when reading audio file data. */
|
/** The buffer size in bytes used when reading audio file data. */
|
||||||
protected static final int BUFFER_SIZE = 2048;
|
protected static final int BUFFER_SIZE = 2048;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user