[updated] Interpolation, added bounce constructors.
[updated] SoundTest, use volume to start playback.
[fixed] OpenAL crash, issue 551.
[updated] Sound, reversed pan values (now -1 is left, 1 is right... wth Mario!? :p).
float rightVolume = volume;\r
\r
if (pan < 0) {\r
- rightVolume *= (1 - Math.abs(pan));\r
- } else if (pan > 0) {\r
leftVolume *= (1 - Math.abs(pan));\r
+ } else if (pan > 0) {\r
+ rightVolume *= (1 - Math.abs(pan));\r
}\r
\r
soundPool.setVolume((int)soundId, leftVolume, rightVolume);\r
for (int i = 0, n = idleSources.size; i < n; i++) {\r
int sourceID = idleSources.get(i);\r
if (alGetSourcei(sourceID, AL_BUFFER) == bufferID) {\r
- long soundId = sourceToSoundId.remove(sourceID);\r
- soundIdToSource.remove(soundId);\r
-\r
+ if (sourceToSoundId.containsKey(sourceID)) {\r
+ long soundId = sourceToSoundId.remove(sourceID);\r
+ soundIdToSource.remove(soundId);\r
+ }\r
alSourceStop(sourceID);\r
alSourcei(sourceID, AL_BUFFER, 0);\r
}\r
for (int i = 0, n = idleSources.size; i < n; i++) {\r
int sourceID = idleSources.get(i);\r
if (alGetSourcei(sourceID, AL_BUFFER) == bufferID) {\r
- long soundId = sourceToSoundId.remove(sourceID);\r
- soundIdToSource.remove(soundId);\r
-\r
+ if (sourceToSoundId.containsKey(sourceID)) {\r
+ long soundId = sourceToSoundId.remove(sourceID);\r
+ soundIdToSource.remove(soundId);\r
+ }\r
alSourceStop(sourceID);\r
}\r
}\r
if (!soundIdToSource.containsKey(soundId)) return;\r
int sourceId = soundIdToSource.get(soundId);\r
\r
- AL10.alSource3f(sourceId, AL10.AL_POSITION, -pan, 0, 0);\r
+ AL10.alSource3f(sourceId, AL10.AL_POSITION, pan, 0, 0);\r
}\r
\r
public void dispose () {\r
static public final Elastic elasticIn = new ElasticIn(2, 10);\r
static public final Elastic elasticOut = new ElasticOut(2, 10);\r
\r
- //\r
-\r
static public final Interpolation swing = new Swing(1.5f);\r
static public final Interpolation swingIn = new SwingIn(2f);\r
static public final Interpolation swingOut = new SwingOut(2f);\r
\r
- //\r
-\r
static public final Interpolation bounce = new Bounce(4);\r
static public final Interpolation bounceIn = new BounceIn(4);\r
static public final Interpolation bounceOut = new BounceOut(4);\r
public float apply (float a) {\r
if (a <= 0.5f) {\r
a *= 2;\r
- return (float)Math.pow(value, power * (a - 1)) * MathUtils.sin(a * 3.14f / 0.157f) * 1.0955f / 2;\r
+ return (float)Math.pow(value, power * (a - 1)) * MathUtils.sin(a * 20) * 1.0955f / 2;\r
}\r
a = 1 - a;\r
a *= 2;\r
- return 1 - (float)Math.pow(value, power * (a - 1)) * MathUtils.sin((a) * 3.14f / 0.157f) * 1.0955f / 2;\r
+ return 1 - (float)Math.pow(value, power * (a - 1)) * MathUtils.sin((a) * 20) * 1.0955f / 2;\r
}\r
}\r
\r
}\r
\r
public float apply (float a) {\r
- return (float)Math.pow(value, power * (a - 1)) * MathUtils.sin(a * 3.14f / 0.157f) * 1.0955f;\r
+ return (float)Math.pow(value, power * (a - 1)) * MathUtils.sin(a * 20) * 1.0955f;\r
}\r
}\r
\r
\r
public float apply (float a) {\r
a = 1 - a;\r
- return (1 - (float)Math.pow(value, power * (a - 1)) * MathUtils.sin((a) * 3.14f / 0.157f) * 1.0955f);\r
+ return (1 - (float)Math.pow(value, power * (a - 1)) * MathUtils.sin(a * 20) * 1.0955f);\r
}\r
}\r
\r
//\r
\r
static public class Bounce extends BounceOut {\r
+ public Bounce (float[] widths, float[] heights) {\r
+ super(widths, heights);\r
+ }\r
+\r
public Bounce (int bounces) {\r
super(bounces);\r
}\r
static public class BounceOut extends Interpolation {\r
final float[] widths, heights;\r
\r
+ public BounceOut (float[] widths, float[] heights) {\r
+ if (widths.length != heights.length)\r
+ throw new IllegalArgumentException("Must be the same number of widths and heights.");\r
+ this.widths = widths;\r
+ this.heights = heights;\r
+ }\r
+\r
public BounceOut (int bounces) {\r
if (bounces < 2 || bounces > 5) throw new IllegalArgumentException("bounces cannot be < 2 or > 5: " + bounces);\r
widths = new float[bounces];\r
}\r
\r
static public class BounceIn extends BounceOut {\r
+ public BounceIn (float[] widths, float[] heights) {\r
+ super(widths, heights);\r
+ }\r
+\r
public BounceIn (int bounces) {\r
super(bounces);\r
}\r
index = hash2(hashCode);\r
if (!key.equals(keyTable[index])) {\r
index = hash3(hashCode);\r
- if (!key.equals(keyTable[index])) return getStash(key);\r
+ if (!key.equals(keyTable[index])) return getStash(key, null);\r
}\r
}\r
return valueTable[index];\r
}\r
\r
- private V getStash (K key) {\r
+ public V get (K key, V defaultValue) {\r
+ int hashCode = System.identityHashCode(key);\r
+ int index = hashCode & mask;\r
+ if (!key.equals(keyTable[index])) {\r
+ index = hash2(hashCode);\r
+ if (!key.equals(keyTable[index])) {\r
+ index = hash3(hashCode);\r
+ if (!key.equals(keyTable[index])) return getStash(key, defaultValue);\r
+ }\r
+ }\r
+ return valueTable[index];\r
+ }\r
+\r
+ private V getStash (K key, V defaultValue) {\r
K[] keyTable = this.keyTable;\r
for (int i = capacity, n = i + stashSize; i < n; i++)\r
if (keyTable[i] == key) return valueTable[i];\r
- return null;\r
+ return defaultValue;\r
}\r
\r
public V remove (K key) {\r
index = hash2(key);\r
if (keyTable[index] != key) {\r
index = hash3(key);\r
- if (keyTable[index] != key) return getStash(key);\r
+ if (keyTable[index] != key) return getStash(key, null);\r
}\r
}\r
return valueTable[index];\r
}\r
\r
- private V getStash (int key) {\r
+ public V get (int key, V defaultValue) {\r
+ if (key == 0) return zeroValue;\r
+ int index = key & mask;\r
+ if (keyTable[index] != key) {\r
+ index = hash2(key);\r
+ if (keyTable[index] != key) {\r
+ index = hash3(key);\r
+ if (keyTable[index] != key) return getStash(key, defaultValue);\r
+ }\r
+ }\r
+ return valueTable[index];\r
+ }\r
+\r
+ private V getStash (int key, V defaultValue) {\r
int[] keyTable = this.keyTable;\r
for (int i = capacity, n = i + stashSize; i < n; i++)\r
if (keyTable[i] == key) return valueTable[i];\r
- return null;\r
+ return defaultValue;\r
}\r
\r
public V remove (int key) {\r
index = hash2(key);\r
if (keyTable[index] != key) {\r
index = hash3(key);\r
- if (keyTable[index] != key) return getStash(key);\r
+ if (keyTable[index] != key) return getStash(key, null);\r
+ }\r
+ }\r
+ return valueTable[index];\r
+ }\r
+ \r
+ public V get (long key, V defaultValue) {\r
+ if (key == 0) return zeroValue;\r
+ int index = (int)(key & mask);\r
+ if (keyTable[index] != key) {\r
+ index = hash2(key);\r
+ if (keyTable[index] != key) {\r
+ index = hash3(key);\r
+ if (keyTable[index] != key) return getStash(key, defaultValue);\r
}\r
}\r
return valueTable[index];\r
}\r
\r
- private V getStash (long key) {\r
+ private V getStash (long key, V defaultValue) {\r
long[] keyTable = this.keyTable;\r
for (int i = capacity, n = i + stashSize; i < n; i++)\r
if (keyTable[i] == key) return valueTable[i];\r
- return null;\r
+ return defaultValue;\r
}\r
\r
public V remove (long key) {\r
play.setClickListener(new ClickListener() {\r
@Override\r
public void click (Actor actor) {\r
- soundId = sound.play();\r
+ soundId = sound.play(volume.getValue());\r
sound.setPitch(soundId, pitch.getValue());\r
sound.setPan(soundId, pan.getValue(), volume.getValue());\r
}\r