|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.media.sound.SoundPlayer
com.threerings.media.sound.JavaSoundPlayer
public class JavaSoundPlayer
Manages the playing of audio files via the Java Sound APIs.
| Nested Class Summary | |
|---|---|
protected static class |
JavaSoundPlayer.SoundKey
A key for tracking sounds. |
| Nested classes/interfaces inherited from class com.threerings.media.sound.SoundPlayer |
|---|
SoundPlayer.Frob, SoundPlayer.SoundType |
| Field Summary | |
|---|---|
protected RunQueue |
_callbackQueue
The queue where callbacks for keys being processed are dispatched. |
protected LRUHashMap<JavaSoundPlayer.SoundKey,byte[][]> |
_clipCache
The cache of recent audio clips . |
protected int |
_freeSpoolers
The number of currently active LineSpoolers. |
protected SoundLoader |
_loader
Does our package based sound loading. |
protected HashMap<JavaSoundPlayer.SoundKey,byte[][]> |
_lockedClips
The set of locked audio clips; this is separate from the LRU so that locking clips doesn't booch up an otherwise normal caching agenda. |
protected Queue<JavaSoundPlayer.SoundKey> |
_queue
The queue of sound clips to be played. |
protected boolean |
_soundSeemsToWork
If we every play a sound successfully, this is set to true. |
protected int |
_spoolerCount
The number of currently active LineSpoolers. |
protected static RuntimeAdjust.FileAdjust |
_testDir
A pref that specifies a directory for us to get test sounds from. |
protected static RuntimeAdjust.BooleanAdjust |
_verbose
|
static int |
DEFAULT_CACHE_SIZE
The default clip cache holds 4 megs. |
protected static byte |
DIE
|
protected static int |
LINEBUF_SIZE
The size of the line's buffer. |
protected static byte |
LOCK
|
protected static byte |
LOOP
|
protected static int |
MAX_QUEUE_SIZE
The queue size at which we start to ignore requests to play sounds. |
protected static long |
MAX_SOUND_DELAY
The maximum time after which we throw away a sound rather than play it. |
protected static int |
MAX_SPOOLERS
The maximum number of spoolers we'll allow. |
protected static long |
MAX_WAIT_TIME
The maximum time a spooler will wait for a stream before deciding to shut down. |
protected static byte |
PLAY
Soundkey command constants. |
protected static byte |
UNLOCK
|
| Fields inherited from class com.threerings.media.sound.SoundPlayer |
|---|
_clipVol, _disabledTypes, _enabledObservers, DEFAULT, PAN_CENTER, PAN_LEFT, PAN_RIGHT |
| Constructor Summary | |
|---|---|
JavaSoundPlayer(ResourceManager rmgr)
Constructs a sound manager. |
|
JavaSoundPlayer(ResourceManager rmgr,
String defaultClipBundle,
String defaultClipPath)
Constructs a sound manager with the default clip cache size. |
|
JavaSoundPlayer(ResourceManager rmgr,
String defaultClipBundle,
String defaultClipPath,
int cacheSize)
Constructs a sound manager. |
|
JavaSoundPlayer(SoundLoader loader,
int cacheSize)
|
|
| Method Summary | |
|---|---|
protected void |
addToPlayQueue(JavaSoundPlayer.SoundKey skey)
Add the sound clip key to the queue to be played. |
protected static void |
adjustPan(Line line,
float pan)
Set the pan value for the specified line. |
protected static void |
adjustVolume(Line line,
float vol)
Use the gain control to implement volume. |
protected boolean |
enqueue(JavaSoundPlayer.SoundKey key,
boolean okToStartNew)
Enqueue a new SoundKey. |
protected byte[] |
getClipData(JavaSoundPlayer.SoundKey key)
Called by spooling threads, loads clip data from the resource manager or the cache. |
RunQueue |
getSoundQueue()
Gets the run queue on which sound should be played. |
protected InputStream |
getTestClip(JavaSoundPlayer.SoundKey key)
|
protected boolean |
isTesting()
|
void |
lock(String pkgPath,
String... keys)
Optionally lock each of these keys prior to playing, to guarantee that it will be quickly available for playing. |
protected SoundPlayer.Frob |
loop(String pkgPath,
String key,
float pan)
Loop the specified sound, stopping as quickly as possible when stop is called. |
protected SoundPlayer.Frob |
loop(String pkgPath,
String key,
float pan,
byte cmd)
Loop the specified sound. |
protected void |
play(String pkgPath,
String key,
float pan)
Play the specified sound after the specified delay. |
protected void |
playSound(JavaSoundPlayer.SoundKey key)
On a spooling thread, |
protected void |
processKey(JavaSoundPlayer.SoundKey key)
Process the requested command in the specified SoundKey. |
void |
setSoundQueue(RunQueue queue)
Sets the run queue on which sound should be played. |
static AudioInputStream |
setupAudioStream(byte[] data)
Sets up an audio stream from the given byte array, and gets it to convert itself to PCM data for writing to our output line (if it isn't already that) |
static AudioInputStream |
setupAudioStream(InputStream in)
Sets up an audio stream from the given byte array, and gets it to convert itself to PCM data for writing to our output line (if it isn't already that) |
void |
shutdown()
Shut the damn thing off. |
protected void |
spoolerRun()
This is the primary run method of the sound-playing threads. |
void |
unlock(String pkgPath,
String... keys)
Unlock the specified sounds so that its resources can be freed. |
| Methods inherited from class com.threerings.media.sound.SoundPlayer |
|---|
addSoundEnabledObserver, getClipVolume, isEnabled, loop, loop, play, play, play, play, removeSoundEnabledObserver, setClipVolume, setEnabled, shouldPlay, summarizeState |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_CACHE_SIZE
protected SoundLoader _loader
protected RunQueue _callbackQueue
protected Queue<JavaSoundPlayer.SoundKey> _queue
protected int _spoolerCount
protected int _freeSpoolers
protected boolean _soundSeemsToWork
protected LRUHashMap<JavaSoundPlayer.SoundKey,byte[][]> _clipCache
protected HashMap<JavaSoundPlayer.SoundKey,byte[][]> _lockedClips
protected static final byte PLAY
protected static final byte LOCK
protected static final byte UNLOCK
protected static final byte DIE
protected static final byte LOOP
protected static RuntimeAdjust.FileAdjust _testDir
protected static RuntimeAdjust.BooleanAdjust _verbose
protected static final int MAX_QUEUE_SIZE
protected static final long MAX_SOUND_DELAY
protected static final int LINEBUF_SIZE
protected static final long MAX_WAIT_TIME
protected static final int MAX_SPOOLERS
| Constructor Detail |
|---|
public JavaSoundPlayer(ResourceManager rmgr)
public JavaSoundPlayer(ResourceManager rmgr,
String defaultClipBundle,
String defaultClipPath)
defaultClipPath - The pathname of a sound clip to use as a
fallback if another sound clip cannot be located.
public JavaSoundPlayer(ResourceManager rmgr,
String defaultClipBundle,
String defaultClipPath,
int cacheSize)
defaultClipPath - The pathname of a sound clip to use as a fallback if another sound
clip cannot be located.cacheSize - the number of bytes of sound clips to cache.
public JavaSoundPlayer(SoundLoader loader,
int cacheSize)
| Method Detail |
|---|
public void shutdown()
SoundPlayer
shutdown in class SoundPlayerpublic void setSoundQueue(RunQueue queue)
public RunQueue getSoundQueue()
SoundPlayerRunQueue.AWT.
getSoundQueue in class SoundPlayer
public void lock(String pkgPath,
String... keys)
SoundPlayer
lock in class SoundPlayer
public void unlock(String pkgPath,
String... keys)
SoundPlayer
unlock in class SoundPlayer
protected void play(String pkgPath,
String key,
float pan)
SoundPlayer
play in class SoundPlayerpan - a value from -1f (all left) to +1f (all right).
protected SoundPlayer.Frob loop(String pkgPath,
String key,
float pan)
SoundPlayer
loop in class SoundPlayer
protected SoundPlayer.Frob loop(String pkgPath,
String key,
float pan,
byte cmd)
protected void addToPlayQueue(JavaSoundPlayer.SoundKey skey)
protected boolean enqueue(JavaSoundPlayer.SoundKey key,
boolean okToStartNew)
protected void spoolerRun()
protected void processKey(JavaSoundPlayer.SoundKey key)
throws Exception
Exception
public static AudioInputStream setupAudioStream(byte[] data)
throws UnsupportedAudioFileException,
IOException
UnsupportedAudioFileException
IOException
public static AudioInputStream setupAudioStream(InputStream in)
throws UnsupportedAudioFileException,
IOException
UnsupportedAudioFileException
IOExceptionprotected void playSound(JavaSoundPlayer.SoundKey key)
protected boolean isTesting()
protected byte[] getClipData(JavaSoundPlayer.SoundKey key)
throws IOException,
UnsupportedAudioFileException
IOException
UnsupportedAudioFileExceptionprotected InputStream getTestClip(JavaSoundPlayer.SoundKey key)
protected static void adjustVolume(Line line,
float vol)
protected static void adjustPan(Line line,
float pan)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||