From cd30b42cd8eb99f78de28a6bc7d089adc42f967e Mon Sep 17 00:00:00 2001 From: Charlie Groves Date: Mon, 23 Jun 2008 22:00:22 +0000 Subject: [PATCH] Allow the size of the sound cache to be set in the sound manager's constructor. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@549 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../threerings/media/sound/SoundManager.java | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/java/com/threerings/media/sound/SoundManager.java b/src/java/com/threerings/media/sound/SoundManager.java index ac13dc60..e215671e 100644 --- a/src/java/com/threerings/media/sound/SoundManager.java +++ b/src/java/com/threerings/media/sound/SoundManager.java @@ -135,10 +135,13 @@ public class SoundManager */ 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. */ @@ -148,18 +151,39 @@ public class SoundManager } /** - * Constructs a sound manager. + * Constructs a sound manager with the default clip cache size. * - * @param defaultClipBundle * @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) + { + this(rmgr, defaultClipBundle, defaultClipPath, DEFAULT_CACHE_SIZE); + } + + /** + * Constructs a sound manager. + * + * @param defaultClipPath The pathname of a sound clip to use as a + * fallback if another sound clip cannot be located. + * @param cacheSize the number of bytes of sound clips to cache. + */ + public SoundManager (ResourceManager rmgr, String defaultClipBundle, String defaultClipPath, int cacheSize) { // save things off _rmgr = rmgr; _defaultClipBundle = defaultClipBundle; _defaultClipPath = defaultClipPath; + _clipCache = + new LRUHashMap(cacheSize, new LRUHashMap.ItemSizer() { + public int computeSize (byte[][] value) { + int total = 0; + for (byte[] bs : value) { + total += bs.length; + } + return total; + } + }); } /** @@ -1011,16 +1035,7 @@ public class SoundManager protected float _clipVol = 1f; /** The cache of recent audio clips . */ - protected LRUHashMap _clipCache = - new LRUHashMap(4 * 1024 * 1024, new LRUHashMap.ItemSizer() { - public int computeSize (byte[][] value) { - int total = 0; - for (byte[] bs : value) { - total += bs.length; - } - return total; - } - }); + protected LRUHashMap _clipCache; /** The set of locked audio clips; this is separate from the LRU so * that locking clips doesn't booch up an otherwise normal caching