diff --git a/Mage.Client/src/main/java/mage/client/util/audio/LinePool.java b/Mage.Client/src/main/java/mage/client/util/audio/LinePool.java index bd4ddb3dc3d..8145f756bbf 100644 --- a/Mage.Client/src/main/java/mage/client/util/audio/LinePool.java +++ b/Mage.Client/src/main/java/mage/client/util/audio/LinePool.java @@ -10,17 +10,20 @@ import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.LineEvent; +import javax.sound.sampled.LineEvent.Type; import javax.sound.sampled.LineListener; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.Mixer; -import javax.sound.sampled.Mixer.Info; import javax.sound.sampled.SourceDataLine; -import javax.sound.sampled.LineEvent.Type; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import mage.utils.ThreadUtils; public class LinePool { + private final Logger log = LoggerFactory.getLogger(getClass()); private static final int LINE_CLEANUP_INTERVAL = 30000; AudioFormat format; Set freeLines = new HashSet<>(); @@ -64,6 +67,7 @@ public class LinePool { for (SourceDataLine sourceDataLine : freeLines) { if (sourceDataLine.isOpen()) { sourceDataLine.close(); + log.debug("Closed line {}", sourceDataLine); } } } @@ -74,6 +78,8 @@ public class LinePool { public void playSound(final MageClip mageClip) { final SourceDataLine line; synchronized (LinePool.this) { + log.debug("Playing {}", mageClip.getFilename()); + logLineStats(); if (activeLines.size() > 0) { line = activeLines.iterator().next(); } else if (freeLines.size() > 0) { @@ -81,11 +87,13 @@ public class LinePool { } else { // no lines available, queue sound to play it when a line is available queue.add(mageClip); + log.debug("Sound {} queued.", mageClip.getFilename()); return; } freeLines.remove(line); activeLines.remove(line); busyLines.add(line); + logLineStats(); } ThreadUtils.threadPool.submit(new Runnable() { @@ -99,18 +107,25 @@ public class LinePool { @Override public void update(LineEvent event) { + log.debug("Event: {}", event); if (event.getType() != Type.STOP) { return; } synchronized (LinePool.this) { + log.debug("Before stop on line {}", line); + logLineStats(); busyLines.remove(line); if (activeLines.size() < LinePool.this.alwaysActive) { activeLines.add(line); } else { freeLines.add(line); } + log.debug("After stop on line {}", line); + logLineStats(); if (queue.size() > 0) { - playSound(queue.poll()); + MageClip queuedSound = queue.poll(); + log.debug("Playing queued sound {}", queuedSound); + playSound(queuedSound); } } } @@ -122,10 +137,16 @@ public class LinePool { } } byte[] buffer = mageClip.getBuffer(); + log.debug("Before write to line {}", line); line.write(buffer, 0, buffer.length); line.drain(); line.stop(); + log.debug("Line completed: {}", line); } }); } + + private void logLineStats() { + log.debug("Free lines: {} Active: {} Busy: {}", freeLines.size(), activeLines.size(), busyLines.size()); + } } diff --git a/Mage.Client/src/main/java/mage/client/util/audio/MageClip.java b/Mage.Client/src/main/java/mage/client/util/audio/MageClip.java index 41b5bb40c49..c5fb0d04c69 100644 --- a/Mage.Client/src/main/java/mage/client/util/audio/MageClip.java +++ b/Mage.Client/src/main/java/mage/client/util/audio/MageClip.java @@ -75,4 +75,8 @@ public class MageClip { return buf; } + public String getFilename() { + return filename; + } + } diff --git a/Mage.Client/src/main/resources/log4j.properties b/Mage.Client/src/main/resources/log4j.properties index af6182a5d18..3ab8d112d79 100644 --- a/Mage.Client/src/main/resources/log4j.properties +++ b/Mage.Client/src/main/resources/log4j.properties @@ -11,6 +11,7 @@ log4j.logger.com.j256.ormlite=warn #log4j.logger.mage.client.remote.CallbackClientImpl=debug #log4j.logger.mage.client.game.FeedbackPanel=debug #log4j.logger.mage.client.game.FeedbackPanel=warn +#log4j.logger.mage.client.util.audio=debug #console log log4j.appender.console=org.apache.log4j.ConsoleAppender