mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
- 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:
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -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/ReadPriceList.java svneol=native#text/plain
|
||||||
src/main/java/forge/quest/io/package-info.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/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/AudioClip.java -text
|
||||||
src/main/java/forge/sound/EventVisualizer.java -text
|
src/main/java/forge/sound/EventVisualizer.java -text
|
||||||
src/main/java/forge/sound/IAudioClip.java -text
|
src/main/java/forge/sound/IAudioClip.java -text
|
||||||
|
|||||||
@@ -22,32 +22,34 @@ import javax.sound.sampled.UnsupportedAudioFileException;
|
|||||||
class AsyncSoundRegistry {
|
class AsyncSoundRegistry {
|
||||||
static Map<String, Integer> soundsPlayed = new HashMap<String, Integer>();
|
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)) {
|
if (soundsPlayed.containsKey(soundName)) {
|
||||||
soundsPlayed.put(soundName, soundsPlayed.get(soundName) + 1);
|
soundsPlayed.put(soundName, soundsPlayed.get(soundName) + 1);
|
||||||
} else {
|
} else {
|
||||||
soundsPlayed.put(soundName, 1);
|
soundsPlayed.put(soundName, 1);
|
||||||
}
|
}
|
||||||
|
//System.out.println("Register: Count for " + soundName + " = " + soundsPlayed.get(soundName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unregisterSound(String soundName) {
|
public synchronized static void unregisterSound(String soundName) {
|
||||||
if (soundsPlayed.containsKey(soundName) && soundsPlayed.get(soundName) != 1) {
|
if (soundsPlayed.containsKey(soundName) && soundsPlayed.get(soundName) > 1) {
|
||||||
soundsPlayed.put(soundName, soundsPlayed.get(soundName) - 1);
|
soundsPlayed.put(soundName, soundsPlayed.get(soundName) - 1);
|
||||||
} else {
|
} else {
|
||||||
soundsPlayed.remove(soundName);
|
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);
|
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;
|
return soundsPlayed.containsKey(soundName) ? soundsPlayed.get(soundName) : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AsyncSoundPlayer extends Thread {
|
public class AltSoundSystem extends Thread {
|
||||||
|
|
||||||
private String filename;
|
private String filename;
|
||||||
private boolean isSync;
|
private boolean isSync;
|
||||||
@@ -55,13 +57,13 @@ public class AsyncSoundPlayer extends Thread {
|
|||||||
private final int EXTERNAL_BUFFER_SIZE = 524288;
|
private final int EXTERNAL_BUFFER_SIZE = 524288;
|
||||||
private final int MAX_SOUND_ITERATIONS = 5;
|
private final int MAX_SOUND_ITERATIONS = 5;
|
||||||
|
|
||||||
public AsyncSoundPlayer(String wavfile, boolean synced) {
|
public AltSoundSystem(String wavfile, boolean synced) {
|
||||||
filename = wavfile;
|
filename = wavfile;
|
||||||
isSync = synced;
|
isSync = synced;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
if (isSync && AsyncSoundRegistry.isRegistered(filename)) {
|
if (isSync && AsyncSoundRegistry.getNumIterations(filename) >= 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (AsyncSoundRegistry.getNumIterations(filename) >= MAX_SOUND_ITERATIONS) {
|
if (AsyncSoundRegistry.getNumIterations(filename) >= MAX_SOUND_ITERATIONS) {
|
||||||
@@ -72,7 +72,7 @@ public class SoundSystem {
|
|||||||
*/
|
*/
|
||||||
public void play(SoundEffectType type) {
|
public void play(SoundEffectType type) {
|
||||||
if (isUsingAltSystem()) {
|
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 {
|
} else {
|
||||||
fetchResource(type).play();
|
fetchResource(type).play();
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ public class SoundSystem {
|
|||||||
*/
|
*/
|
||||||
public void play(String resourceFileName) {
|
public void play(String resourceFileName) {
|
||||||
if (isUsingAltSystem()) {
|
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 {
|
} else {
|
||||||
fetchResource(resourceFileName).play();
|
fetchResource(resourceFileName).play();
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ public class SoundSystem {
|
|||||||
*/
|
*/
|
||||||
public void playSync(String resourceFileName) {
|
public void playSync(String resourceFileName) {
|
||||||
if (isUsingAltSystem()) {
|
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 {
|
} else {
|
||||||
IAudioClip snd = fetchResource(resourceFileName);
|
IAudioClip snd = fetchResource(resourceFileName);
|
||||||
if (snd.isDone()) {
|
if (snd.isDone()) {
|
||||||
@@ -112,7 +112,7 @@ public class SoundSystem {
|
|||||||
*/
|
*/
|
||||||
public void playSync(SoundEffectType type) {
|
public void playSync(SoundEffectType type) {
|
||||||
if (isUsingAltSystem()) {
|
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 {
|
} else {
|
||||||
IAudioClip snd = fetchResource(type);
|
IAudioClip snd = fetchResource(type);
|
||||||
if (snd.isDone()) {
|
if (snd.isDone()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user