- Renamed AsyncSoundPlayer to AltSoundSystem (better represents its purpose).

- Fixed the synchronous sounds playing asynchronously on the alternative sound system.
- Some minor fixes and changes to the alternative sound system.
This commit is contained in:
Agetian
2013-04-10 05:16:46 +00:00
parent afe8c40d87
commit 4f30cd58ec
3 changed files with 15 additions and 13 deletions

2
.gitattributes vendored
View File

@@ -14324,7 +14324,7 @@ src/main/java/forge/quest/io/QuestDataIO.java svneol=native#text/plain
src/main/java/forge/quest/io/ReadPriceList.java svneol=native#text/plain
src/main/java/forge/quest/io/package-info.java svneol=native#text/plain
src/main/java/forge/quest/package-info.java svneol=native#text/plain
src/main/java/forge/sound/AsyncSoundPlayer.java -text
src/main/java/forge/sound/AltSoundSystem.java -text
src/main/java/forge/sound/AudioClip.java -text
src/main/java/forge/sound/EventVisualizer.java -text
src/main/java/forge/sound/IAudioClip.java -text

View File

@@ -22,32 +22,34 @@ import javax.sound.sampled.UnsupportedAudioFileException;
class AsyncSoundRegistry {
static Map<String, Integer> soundsPlayed = new HashMap<String, Integer>();
public static void registerSound(String soundName) {
public synchronized static void registerSound(String soundName) {
if (soundsPlayed.containsKey(soundName)) {
soundsPlayed.put(soundName, soundsPlayed.get(soundName) + 1);
} else {
soundsPlayed.put(soundName, 1);
}
//System.out.println("Register: Count for " + soundName + " = " + soundsPlayed.get(soundName));
}
public static void unregisterSound(String soundName) {
if (soundsPlayed.containsKey(soundName) && soundsPlayed.get(soundName) != 1) {
public synchronized static void unregisterSound(String soundName) {
if (soundsPlayed.containsKey(soundName) && soundsPlayed.get(soundName) > 1) {
soundsPlayed.put(soundName, soundsPlayed.get(soundName) - 1);
} else {
soundsPlayed.remove(soundName);
}
//System.out.println("Unregister: Count for " + soundName + " = " + soundsPlayed.get(soundName));
}
public static boolean isRegistered(String soundName) {
public synchronized static boolean isRegistered(String soundName) {
return soundsPlayed.containsKey(soundName);
}
public static int getNumIterations(String soundName) {
public synchronized static int getNumIterations(String soundName) {
return soundsPlayed.containsKey(soundName) ? soundsPlayed.get(soundName) : 0;
}
}
public class AsyncSoundPlayer extends Thread {
public class AltSoundSystem extends Thread {
private String filename;
private boolean isSync;
@@ -55,13 +57,13 @@ public class AsyncSoundPlayer extends Thread {
private final int EXTERNAL_BUFFER_SIZE = 524288;
private final int MAX_SOUND_ITERATIONS = 5;
public AsyncSoundPlayer(String wavfile, boolean synced) {
public AltSoundSystem(String wavfile, boolean synced) {
filename = wavfile;
isSync = synced;
}
public void run() {
if (isSync && AsyncSoundRegistry.isRegistered(filename)) {
if (isSync && AsyncSoundRegistry.getNumIterations(filename) >= 1) {
return;
}
if (AsyncSoundRegistry.getNumIterations(filename) >= MAX_SOUND_ITERATIONS) {

View File

@@ -72,7 +72,7 @@ public class SoundSystem {
*/
public void play(SoundEffectType type) {
if (isUsingAltSystem()) {
new AsyncSoundPlayer(String.format("%s/%s", IAudioClip.PathToSound, type.getResourceFileName()), false).start();
new AltSoundSystem(String.format("%s/%s", IAudioClip.PathToSound, type.getResourceFileName()), false).start();
} else {
fetchResource(type).play();
}
@@ -83,7 +83,7 @@ public class SoundSystem {
*/
public void play(String resourceFileName) {
if (isUsingAltSystem()) {
new AsyncSoundPlayer(String.format("%s/%s", IAudioClip.PathToSound, resourceFileName), false).start();
new AltSoundSystem(String.format("%s/%s", IAudioClip.PathToSound, resourceFileName), false).start();
} else {
fetchResource(resourceFileName).play();
}
@@ -96,7 +96,7 @@ public class SoundSystem {
*/
public void playSync(String resourceFileName) {
if (isUsingAltSystem()) {
new AsyncSoundPlayer(String.format("%s/%s", IAudioClip.PathToSound, resourceFileName), false).start();
new AltSoundSystem(String.format("%s/%s", IAudioClip.PathToSound, resourceFileName), true).start();
} else {
IAudioClip snd = fetchResource(resourceFileName);
if (snd.isDone()) {
@@ -112,7 +112,7 @@ public class SoundSystem {
*/
public void playSync(SoundEffectType type) {
if (isUsingAltSystem()) {
new AsyncSoundPlayer(String.format("%s/%s", IAudioClip.PathToSound, type.getResourceFileName()), false).start();
new AltSoundSystem(String.format("%s/%s", IAudioClip.PathToSound, type.getResourceFileName()), true).start();
} else {
IAudioClip snd = fetchResource(type);
if (snd.isDone()) {