patch from Keith to improve pulse audio support
[debian/freetts] / debian / patches / pulse-audio-compat.diff
1 Index: freetts-1.2.2/com/sun/speech/freetts/audio/JavaStreamingAudioPlayer.java
2 ===================================================================
3 --- freetts-1.2.2.orig/com/sun/speech/freetts/audio/JavaStreamingAudioPlayer.java
4 +++ freetts-1.2.2/com/sun/speech/freetts/audio/JavaStreamingAudioPlayer.java
5 @@ -7,6 +7,8 @@
6   */
7  package com.sun.speech.freetts.audio;
8  
9 +import java.util.concurrent.Semaphore;
10 +
11  import javax.sound.sampled.AudioFormat;
12  import javax.sound.sampled.AudioSystem;
13  import javax.sound.sampled.DataLine;
14 @@ -94,7 +96,7 @@ public class JavaStreamingAudioPlayer im
15      private long openFailDelayMs;
16      private long totalOpenFailDelayMs;
17  
18 -    private Object openLock = new Object();
19 +    private Semaphore openLock;
20      private Object lineLock = new Object();
21  
22  
23 @@ -193,16 +195,14 @@ public class JavaStreamingAudioPlayer im
24              try {
25                  line = (SourceDataLine) AudioSystem.getLine(info);
26                  line.addLineListener(new JavaStreamLineListener());
27 -                
28 -                synchronized (openLock) {
29 -                    line.open(format, AUDIO_BUFFER_SIZE);
30 -                    try {
31 -                        openLock.wait();
32 -                    } catch (InterruptedException ie) {
33 -                        ie.printStackTrace();
34 -                    }
35 -                    opened = true;
36 -                }                
37 +               openLock = new Semaphore(0);
38 +               line.open(format, AUDIO_BUFFER_SIZE);
39 +               try {
40 +                   openLock.acquire();
41 +                   opened = true;
42 +               } catch (InterruptedException ie) {
43 +                   ie.printStackTrace();
44 +               }
45              } catch (LineUnavailableException lue) {
46                  System.err.println("LINE UNAVAILABLE: " +
47                                     "Format is " + currentFormat);
48 @@ -644,9 +644,7 @@ public class JavaStreamingAudioPlayer im
49           */
50          public void update(LineEvent event) {
51              if (event.getType().equals(LineEvent.Type.OPEN)) {
52 -                synchronized (openLock) {
53 -                    openLock.notifyAll();
54 -                }
55 +               openLock.release();
56              }
57          }
58      }