patch from Keith to improve pulse audio support
[debian/freetts] / debian / patches / pulse-audio-compat.diff
diff --git a/debian/patches/pulse-audio-compat.diff b/debian/patches/pulse-audio-compat.diff
new file mode 100644 (file)
index 0000000..5e86d55
--- /dev/null
@@ -0,0 +1,58 @@
+Index: freetts-1.2.2/com/sun/speech/freetts/audio/JavaStreamingAudioPlayer.java
+===================================================================
+--- freetts-1.2.2.orig/com/sun/speech/freetts/audio/JavaStreamingAudioPlayer.java
++++ freetts-1.2.2/com/sun/speech/freetts/audio/JavaStreamingAudioPlayer.java
+@@ -7,6 +7,8 @@
+  */
+ package com.sun.speech.freetts.audio;
++import java.util.concurrent.Semaphore;
++
+ import javax.sound.sampled.AudioFormat;
+ import javax.sound.sampled.AudioSystem;
+ import javax.sound.sampled.DataLine;
+@@ -94,7 +96,7 @@ public class JavaStreamingAudioPlayer im
+     private long openFailDelayMs;
+     private long totalOpenFailDelayMs;
+-    private Object openLock = new Object();
++    private Semaphore openLock;
+     private Object lineLock = new Object();
+@@ -193,16 +195,14 @@ public class JavaStreamingAudioPlayer im
+             try {
+                 line = (SourceDataLine) AudioSystem.getLine(info);
+                 line.addLineListener(new JavaStreamLineListener());
+-                
+-                synchronized (openLock) {
+-                    line.open(format, AUDIO_BUFFER_SIZE);
+-                    try {
+-                        openLock.wait();
+-                    } catch (InterruptedException ie) {
+-                        ie.printStackTrace();
+-                    }
+-                    opened = true;
+-                }                
++              openLock = new Semaphore(0);
++              line.open(format, AUDIO_BUFFER_SIZE);
++              try {
++                  openLock.acquire();
++                  opened = true;
++              } catch (InterruptedException ie) {
++                  ie.printStackTrace();
++              }
+             } catch (LineUnavailableException lue) {
+                 System.err.println("LINE UNAVAILABLE: " +
+                                    "Format is " + currentFormat);
+@@ -644,9 +644,7 @@ public class JavaStreamingAudioPlayer im
+          */
+         public void update(LineEvent event) {
+             if (event.getType().equals(LineEvent.Type.OPEN)) {
+-                synchronized (openLock) {
+-                    openLock.notifyAll();
+-                }
++              openLock.release();
+             }
+         }
+     }