From fc326344122436b759f36830eda1e462692e0802 Mon Sep 17 00:00:00 2001 From: Charlie Groves Date: Thu, 14 Aug 2008 00:50:17 +0000 Subject: [PATCH] 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 --- ...SoundManager.java => JavaSoundPlayer.java} | 83 ++--------------- .../threerings/media/sound/SoundCodes.java | 2 +- .../threerings/media/sound/SoundLoader.java | 2 +- ...ractSoundManager.java => SoundPlayer.java} | 88 +++++++++++++++++-- ...undManager.java => OpenALSoundPlayer.java} | 17 ++-- 5 files changed, 95 insertions(+), 97 deletions(-) rename src/java/com/threerings/media/sound/{SoundManager.java => JavaSoundPlayer.java} (91%) rename src/java/com/threerings/media/sound/{AbstractSoundManager.java => SoundPlayer.java} (69%) rename src/java/com/threerings/openal/{OpenALSoundManager.java => OpenALSoundPlayer.java} (85%) diff --git a/src/java/com/threerings/media/sound/SoundManager.java b/src/java/com/threerings/media/sound/JavaSoundPlayer.java similarity index 91% rename from src/java/com/threerings/media/sound/SoundManager.java rename to src/java/com/threerings/media/sound/JavaSoundPlayer.java index 5fe2ab42..53abcc4a 100644 --- a/src/java/com/threerings/media/sound/SoundManager.java +++ b/src/java/com/threerings/media/sound/JavaSoundPlayer.java @@ -57,88 +57,15 @@ import com.threerings.resource.ResourceManager; /** * 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. */ public static final int DEFAULT_CACHE_SIZE = 4 * 1024 * 1024; /** * Constructs a sound manager. */ - public SoundManager (ResourceManager rmgr) + public JavaSoundPlayer (ResourceManager rmgr) { 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 * 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); } @@ -161,13 +88,13 @@ public class SoundManager extends AbstractSoundManager * clip cannot be located. * @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) { this(new SoundLoader(rmgr, defaultClipBundle, defaultClipPath), cacheSize); } - public SoundManager (SoundLoader loader, int cacheSize) + public JavaSoundPlayer (SoundLoader loader, int cacheSize) { // save things off _loader = loader; diff --git a/src/java/com/threerings/media/sound/SoundCodes.java b/src/java/com/threerings/media/sound/SoundCodes.java index 20a84872..80c2a8c2 100644 --- a/src/java/com/threerings/media/sound/SoundCodes.java +++ b/src/java/com/threerings/media/sound/SoundCodes.java @@ -21,7 +21,7 @@ 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. diff --git a/src/java/com/threerings/media/sound/SoundLoader.java b/src/java/com/threerings/media/sound/SoundLoader.java index 95fc0173..dccbd011 100644 --- a/src/java/com/threerings/media/sound/SoundLoader.java +++ b/src/java/com/threerings/media/sound/SoundLoader.java @@ -91,7 +91,7 @@ public class SoundLoader clipin = _rmgr.getResource(path); } catch (FileNotFoundException fnfe2) { // 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); if (_defaultClipPath != null) { try { diff --git a/src/java/com/threerings/media/sound/AbstractSoundManager.java b/src/java/com/threerings/media/sound/SoundPlayer.java similarity index 69% rename from src/java/com/threerings/media/sound/AbstractSoundManager.java rename to src/java/com/threerings/media/sound/SoundPlayer.java index 19f40aca..0d9787f4 100644 --- a/src/java/com/threerings/media/sound/AbstractSoundManager.java +++ b/src/java/com/threerings/media/sound/SoundPlayer.java @@ -7,11 +7,83 @@ import com.google.common.collect.Sets; import com.samskivert.util.Interval; import com.samskivert.util.RunQueue; -import com.threerings.media.sound.SoundManager.Frob; -import com.threerings.media.sound.SoundManager.SoundType; - -public abstract class AbstractSoundManager +/** + * Loads, plays and loops sounds. + */ +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. */ @@ -94,7 +166,7 @@ public abstract class AbstractSoundManager */ 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) { - 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) { - 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) { 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); diff --git a/src/java/com/threerings/openal/OpenALSoundManager.java b/src/java/com/threerings/openal/OpenALSoundPlayer.java similarity index 85% rename from src/java/com/threerings/openal/OpenALSoundManager.java rename to src/java/com/threerings/openal/OpenALSoundPlayer.java index 1696333b..19f6df4b 100644 --- a/src/java/com/threerings/openal/OpenALSoundManager.java +++ b/src/java/com/threerings/openal/OpenALSoundPlayer.java @@ -14,19 +14,18 @@ import com.google.common.collect.Maps; import com.samskivert.util.RunQueue; import com.threerings.media.sound.SoundLoader; -import com.threerings.media.sound.SoundManager; -import com.threerings.media.sound.AbstractSoundManager; +import com.threerings.media.sound.SoundPlayer; 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 { - public OpenALSoundManager (SoundLoader loader) + public OpenALSoundPlayer (SoundLoader loader) { _loader = loader; _alSoundManager = new MediaALSoundManager(); @@ -75,11 +74,11 @@ public class OpenALSoundManager extends AbstractSoundManager } @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); sound.loop(true); - return new SoundManager.Frob(){ + return new Frob(){ public float getPan () { 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 () { super(getSoundQueue()); } @@ -132,7 +131,7 @@ public class OpenALSoundManager extends AbstractSoundManager protected final SoundLoader _loader; protected final SoundGroup _group; - protected final com.threerings.openal.SoundManager _alSoundManager; + protected final SoundManager _alSoundManager; /** Number of sounds that can be played simultaneously. */ protected final int SOURCE_COUNT = 10;