Rename all the media.SoundManager stuff to variants on SoundPlayer to conflict
less with openal.SoundManager. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@625 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
+5
-78
@@ -57,88 +57,15 @@ import com.threerings.resource.ResourceManager;
|
|||||||
/**
|
/**
|
||||||
* Manages the playing of audio files via the Java Sound APIs.
|
* Manages the playing of audio files via the Java Sound APIs.
|
||||||
*/
|
*/
|
||||||
public class SoundManager extends AbstractSoundManager
|
public class JavaSoundPlayer extends SoundPlayer
|
||||||
{
|
{
|
||||||
/** A pan value indicating that a sound should play from the left only. */
|
|
||||||
public static final float PAN_LEFT = -1f;
|
|
||||||
|
|
||||||
/** A pan value indicating that a sound should play from the right only. */
|
|
||||||
public static final float PAN_RIGHT = 1f;
|
|
||||||
|
|
||||||
/** A pan value indicating that a sound should play from center. */
|
|
||||||
public static final float PAN_CENTER = 0f;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create instances of this for your application to differentiate
|
|
||||||
* between different types of sounds.
|
|
||||||
*/
|
|
||||||
public static class SoundType
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Construct a new SoundType.
|
|
||||||
* Which should be a static variable stashed somewhere for the entire application to share.
|
|
||||||
*
|
|
||||||
* @param strname a short string identifier, preferably without spaces.
|
|
||||||
*/
|
|
||||||
public SoundType (String strname)
|
|
||||||
{
|
|
||||||
_strname = strname;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString ()
|
|
||||||
{
|
|
||||||
return _strname;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String _strname;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A control for sounds.
|
|
||||||
*/
|
|
||||||
public static interface Frob
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Stop playing or looping the sound.
|
|
||||||
* At present, the granularity of this command is limited to the buffer size of the
|
|
||||||
* line spooler, or about 8k of data. Thus, if playing an 11khz sample, it could take
|
|
||||||
* 8/11ths of a second for the sound to actually stop playing.
|
|
||||||
*/
|
|
||||||
public void stop ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the volume of the sound.
|
|
||||||
*/
|
|
||||||
public void setVolume (float vol);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the volume of this sound.
|
|
||||||
*/
|
|
||||||
public float getVolume ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the pan value for the sound. Valid values are
|
|
||||||
* -1 for left-only, 0 is centered, all the way to +1 for right-only.
|
|
||||||
*/
|
|
||||||
public void setPan (float pan);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the pan value of this sound.
|
|
||||||
*/
|
|
||||||
public float getPan ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The default sound type. */
|
|
||||||
public static final SoundType DEFAULT = new SoundType("default");
|
|
||||||
|
|
||||||
/** The default clip cache holds 4 megs. */
|
/** The default clip cache holds 4 megs. */
|
||||||
public static final int DEFAULT_CACHE_SIZE = 4 * 1024 * 1024;
|
public static final int DEFAULT_CACHE_SIZE = 4 * 1024 * 1024;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a sound manager.
|
* Constructs a sound manager.
|
||||||
*/
|
*/
|
||||||
public SoundManager (ResourceManager rmgr)
|
public JavaSoundPlayer (ResourceManager rmgr)
|
||||||
{
|
{
|
||||||
this(rmgr, null, null);
|
this(rmgr, null, null);
|
||||||
}
|
}
|
||||||
@@ -149,7 +76,7 @@ public class SoundManager extends AbstractSoundManager
|
|||||||
* @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 (ResourceManager rmgr, String defaultClipBundle, String defaultClipPath)
|
public JavaSoundPlayer (ResourceManager rmgr, String defaultClipBundle, String defaultClipPath)
|
||||||
{
|
{
|
||||||
this(rmgr, defaultClipBundle, defaultClipPath, DEFAULT_CACHE_SIZE);
|
this(rmgr, defaultClipBundle, defaultClipPath, DEFAULT_CACHE_SIZE);
|
||||||
}
|
}
|
||||||
@@ -161,13 +88,13 @@ public class SoundManager extends AbstractSoundManager
|
|||||||
* clip cannot be located.
|
* clip cannot be located.
|
||||||
* @param cacheSize the number of bytes of sound clips to cache.
|
* @param cacheSize the number of bytes of sound clips to cache.
|
||||||
*/
|
*/
|
||||||
public SoundManager (ResourceManager rmgr, String defaultClipBundle, String defaultClipPath,
|
public JavaSoundPlayer (ResourceManager rmgr, String defaultClipBundle, String defaultClipPath,
|
||||||
int cacheSize)
|
int cacheSize)
|
||||||
{
|
{
|
||||||
this(new SoundLoader(rmgr, defaultClipBundle, defaultClipPath), cacheSize);
|
this(new SoundLoader(rmgr, defaultClipBundle, defaultClipPath), cacheSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SoundManager (SoundLoader loader, int cacheSize)
|
public JavaSoundPlayer (SoundLoader loader, int cacheSize)
|
||||||
{
|
{
|
||||||
// save things off
|
// save things off
|
||||||
_loader = loader;
|
_loader = loader;
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
package com.threerings.media.sound;
|
package com.threerings.media.sound;
|
||||||
|
|
||||||
import com.threerings.media.sound.SoundManager.SoundType;
|
import com.threerings.media.sound.SoundPlayer.SoundType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic set of sound types.
|
* A basic set of sound types.
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public class SoundLoader
|
|||||||
clipin = _rmgr.getResource(path);
|
clipin = _rmgr.getResource(path);
|
||||||
} catch (FileNotFoundException fnfe2) {
|
} catch (FileNotFoundException fnfe2) {
|
||||||
// only play the default sound if we have verbose sound debugging turned on.
|
// only play the default sound if we have verbose sound debugging turned on.
|
||||||
if (SoundManager._verbose.getValue()) {
|
if (JavaSoundPlayer._verbose.getValue()) {
|
||||||
log.warning("Could not locate sound data", "bundle", bundle, "path", path);
|
log.warning("Could not locate sound data", "bundle", bundle, "path", path);
|
||||||
if (_defaultClipPath != null) {
|
if (_defaultClipPath != null) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
+80
-8
@@ -7,11 +7,83 @@ import com.google.common.collect.Sets;
|
|||||||
import com.samskivert.util.Interval;
|
import com.samskivert.util.Interval;
|
||||||
import com.samskivert.util.RunQueue;
|
import com.samskivert.util.RunQueue;
|
||||||
|
|
||||||
import com.threerings.media.sound.SoundManager.Frob;
|
/**
|
||||||
import com.threerings.media.sound.SoundManager.SoundType;
|
* Loads, plays and loops sounds.
|
||||||
|
*/
|
||||||
public abstract class AbstractSoundManager
|
public abstract class SoundPlayer
|
||||||
{
|
{
|
||||||
|
/** A pan value indicating that a sound should play from the left only. */
|
||||||
|
public static final float PAN_LEFT = -1f;
|
||||||
|
|
||||||
|
/** A pan value indicating that a sound should play from the right only. */
|
||||||
|
public static final float PAN_RIGHT = 1f;
|
||||||
|
|
||||||
|
/** A pan value indicating that a sound should play from center. */
|
||||||
|
public static final float PAN_CENTER = 0f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instances of this for your application to differentiate
|
||||||
|
* between different types of sounds.
|
||||||
|
*/
|
||||||
|
public static class SoundType
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Construct a new SoundType.
|
||||||
|
* Which should be a static variable stashed somewhere for the entire application to share.
|
||||||
|
*
|
||||||
|
* @param strname a short string identifier, preferably without spaces.
|
||||||
|
*/
|
||||||
|
public SoundType (String strname)
|
||||||
|
{
|
||||||
|
_strname = strname;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString ()
|
||||||
|
{
|
||||||
|
return _strname;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String _strname;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A control for sounds.
|
||||||
|
*/
|
||||||
|
public static interface Frob
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Stop playing or looping the sound.
|
||||||
|
* At present, the granularity of this command is limited to the buffer size of the
|
||||||
|
* line spooler, or about 8k of data. Thus, if playing an 11khz sample, it could take
|
||||||
|
* 8/11ths of a second for the sound to actually stop playing.
|
||||||
|
*/
|
||||||
|
public void stop ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the volume of the sound.
|
||||||
|
*/
|
||||||
|
public void setVolume (float vol);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the volume of this sound.
|
||||||
|
*/
|
||||||
|
public float getVolume ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the pan value for the sound. Valid values are
|
||||||
|
* -1 for left-only, 0 is centered, all the way to +1 for right-only.
|
||||||
|
*/
|
||||||
|
public void setPan (float pan);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the pan value of this sound.
|
||||||
|
*/
|
||||||
|
public float getPan ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The default sound type. */
|
||||||
|
public static final SoundType DEFAULT = new SoundType("default");
|
||||||
/**
|
/**
|
||||||
* Shut the damn thing off.
|
* Shut the damn thing off.
|
||||||
*/
|
*/
|
||||||
@@ -94,7 +166,7 @@ public abstract class AbstractSoundManager
|
|||||||
*/
|
*/
|
||||||
public boolean play (SoundType type, String pkgPath, String key)
|
public boolean play (SoundType type, String pkgPath, String key)
|
||||||
{
|
{
|
||||||
return play(type, pkgPath, key, 0, SoundManager.PAN_CENTER);
|
return play(type, pkgPath, key, 0, PAN_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,7 +190,7 @@ public abstract class AbstractSoundManager
|
|||||||
*/
|
*/
|
||||||
public boolean play (SoundType type, String pkgPath, String key, int delay)
|
public boolean play (SoundType type, String pkgPath, String key, int delay)
|
||||||
{
|
{
|
||||||
return play(type, pkgPath, key, delay, SoundManager.PAN_CENTER);
|
return play(type, pkgPath, key, delay, PAN_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,7 +231,7 @@ public abstract class AbstractSoundManager
|
|||||||
*/
|
*/
|
||||||
public Frob loop (SoundType type, String pkgPath, String key)
|
public Frob loop (SoundType type, String pkgPath, String key)
|
||||||
{
|
{
|
||||||
return loop(type, pkgPath, key, SoundManager.PAN_CENTER);
|
return loop(type, pkgPath, key, PAN_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -181,7 +253,7 @@ public abstract class AbstractSoundManager
|
|||||||
protected boolean shouldPlay (SoundType type)
|
protected boolean shouldPlay (SoundType type)
|
||||||
{
|
{
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
type = SoundManager.DEFAULT; // let the lazy kids play too
|
type = DEFAULT; // let the lazy kids play too
|
||||||
}
|
}
|
||||||
|
|
||||||
return _clipVol != 0f && isEnabled(type);
|
return _clipVol != 0f && isEnabled(type);
|
||||||
+8
-9
@@ -14,19 +14,18 @@ import com.google.common.collect.Maps;
|
|||||||
import com.samskivert.util.RunQueue;
|
import com.samskivert.util.RunQueue;
|
||||||
|
|
||||||
import com.threerings.media.sound.SoundLoader;
|
import com.threerings.media.sound.SoundLoader;
|
||||||
import com.threerings.media.sound.SoundManager;
|
import com.threerings.media.sound.SoundPlayer;
|
||||||
import com.threerings.media.sound.AbstractSoundManager;
|
|
||||||
|
|
||||||
import static com.threerings.media.Log.log;
|
import static com.threerings.media.Log.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays sounds via OpenAL.
|
* Implements the abstract pieces of {@link SoundPlayer} via OpenAL.
|
||||||
*/
|
*/
|
||||||
public class OpenALSoundManager extends AbstractSoundManager
|
public class OpenALSoundPlayer extends SoundPlayer
|
||||||
implements ClipProvider
|
implements ClipProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
public OpenALSoundManager (SoundLoader loader)
|
public OpenALSoundPlayer (SoundLoader loader)
|
||||||
{
|
{
|
||||||
_loader = loader;
|
_loader = loader;
|
||||||
_alSoundManager = new MediaALSoundManager();
|
_alSoundManager = new MediaALSoundManager();
|
||||||
@@ -75,11 +74,11 @@ public class OpenALSoundManager extends AbstractSoundManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SoundManager.Frob loop (String pkgPath, String key, float pan)
|
protected Frob loop (String pkgPath, String key, float pan)
|
||||||
{
|
{
|
||||||
final Sound sound = _group.getSound(pkgPath + key);
|
final Sound sound = _group.getSound(pkgPath + key);
|
||||||
sound.loop(true);
|
sound.loop(true);
|
||||||
return new SoundManager.Frob(){
|
return new Frob(){
|
||||||
public float getPan () {
|
public float getPan () {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -114,7 +113,7 @@ public class OpenALSoundManager extends AbstractSoundManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class MediaALSoundManager extends com.threerings.openal.SoundManager {
|
protected class MediaALSoundManager extends SoundManager {
|
||||||
protected MediaALSoundManager () {
|
protected MediaALSoundManager () {
|
||||||
super(getSoundQueue());
|
super(getSoundQueue());
|
||||||
}
|
}
|
||||||
@@ -132,7 +131,7 @@ public class OpenALSoundManager extends AbstractSoundManager
|
|||||||
|
|
||||||
protected final SoundLoader _loader;
|
protected final SoundLoader _loader;
|
||||||
protected final SoundGroup _group;
|
protected final SoundGroup _group;
|
||||||
protected final com.threerings.openal.SoundManager _alSoundManager;
|
protected final SoundManager _alSoundManager;
|
||||||
|
|
||||||
/** Number of sounds that can be played simultaneously. */
|
/** Number of sounds that can be played simultaneously. */
|
||||||
protected final int SOURCE_COUNT = 10;
|
protected final int SOURCE_COUNT = 10;
|
||||||
Reference in New Issue
Block a user