changeset 83:3f9cc08fdbc0

Moved more methods to DataLine
author iivan@town.yyz.redhat.com
date Fri, 15 Aug 2008 16:57:00 -0400
parents 10aa02b5a832
children dc7a6d1c130e
files src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java
diffstat 4 files changed, 54 insertions(+), 105 deletions(-) [+]
line wrap: on
line diff
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java	Fri Aug 15 16:39:53 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java	Fri Aug 15 16:57:00 2008 -0400
@@ -10,6 +10,7 @@
 import javax.sound.sampled.LineEvent;
 import javax.sound.sampled.LineListener;
 import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.AudioFormat.Encoding;
 
 public abstract class PulseAudioDataLine implements Line {
 
@@ -19,6 +20,7 @@
 	protected String streamName = "Java Stream";
 	
 	protected boolean isOpen = false;
+	private boolean isPaused = false;
 	protected AudioFormat[] supportedFormats = null;
 	protected AudioFormat currentFormat = null;
 	protected AudioFormat defaultFormat = null;
@@ -88,11 +90,27 @@
 		}
 	}
 	
+	public void open(AudioFormat format) throws LineUnavailableException {
+		open(format, DEFAULT_BUFFER_SIZE);
+
+	}
+	
+	public void open() throws LineUnavailableException {
+		// pick a random format
+		if (defaultFormat == null) {
+			defaultFormat = new AudioFormat(Encoding.PCM_UNSIGNED, 44100, 8, 2,
+					2, AudioSystem.NOT_SPECIFIED, false);
+		}
+
+		open(defaultFormat, DEFAULT_BUFFER_SIZE);
+	}
+
+	
 	public void close() {
 		assert (isOpen);
 
 		synchronized (eventLoop.threadLock) {
-			stream.drain();
+			//drain();
 			stream.disconnect();
 		}
 
@@ -105,6 +123,35 @@
 
 	}
 	
+	public void start() {
+		if (isPaused) {
+			stream.cork(false);
+			isPaused = false;
+		}
+
+		/*
+		 * for(LineListener l :listeners) { l.update(new LineEvent(this,
+		 * LineEvent.Type.START, 0)); }
+		 */
+
+	}
+
+	public void stop() {
+		synchronized (eventLoop.threadLock) {
+			stream.cork(true);
+		}
+		isPaused = true;
+
+	}
+	
+	public void addLineListener(LineListener listener) {
+		this.lineListeners.add(listener);
+	}
+
+	public void removeLineListener(LineListener listener) {
+		this.lineListeners.remove(listener);
+	}
+	
 	private void fireLineEvent(LineEvent e) {
 		for (LineListener lineListener : lineListeners) {
 			lineListener.update(e);
@@ -112,6 +159,11 @@
 	}
 
 	abstract void connectLine();
+	abstract void drain();
+	
+	public boolean isOpen() {
+		return isOpen;
+	}
 
 	
 
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java	Fri Aug 15 16:39:53 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java	Fri Aug 15 16:57:00 2008 -0400
@@ -304,7 +304,7 @@
 
 		} else {
 			formats = getSupportedFormats();
-			defaultFormat = new AudioFormat(Encoding.PCM_UNSIGNED, 22050, 8, 2,
+			defaultFormat = new AudioFormat(Encoding.PCM_UNSIGNED, 44100, 8, 2,
 					2, AudioSystem.NOT_SPECIFIED, false);
 		}
 
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java	Fri Aug 15 16:39:53 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java	Fri Aug 15 16:57:00 2008 -0400
@@ -52,10 +52,6 @@
 public class PulseAudioSourceDataLine extends PulseAudioDataLine implements SourceDataLine {
 
 
-	private boolean isPaused = false;
-
-
-
 	private Control[] controls = null;
 	private PulseAudioStreamMuteControl muteControl;
 	private PulseAudioStreamVolumeControl volumeControl;
@@ -111,20 +107,6 @@
 		stream.connectForPlayback(null);
 	}
 
-	public void open(AudioFormat format) throws LineUnavailableException {
-		open(format, DEFAULT_BUFFER_SIZE);
-
-	}
-
-	public void open() throws LineUnavailableException {
-		// pick a random format
-		if (defaultFormat == null) {
-			defaultFormat = new AudioFormat(Encoding.PCM_UNSIGNED, 22050, 8, 2,
-					2, AudioSystem.NOT_SPECIFIED, false);
-		}
-
-		open(defaultFormat, DEFAULT_BUFFER_SIZE);
-	}
 
 	@Override
 	public int write(byte[] data, int offset, int length) {
@@ -178,38 +160,6 @@
 		return sizeWritten;
 	}
 
-	public void start() {
-		if (isPaused) {
-			stream.cork(false);
-			isPaused = false;
-		}
-
-		/*
-		 * for(LineListener l :listeners) { l.update(new LineEvent(this,
-		 * LineEvent.Type.START, 0)); }
-		 */
-
-	}
-
-	public void stop() {
-		synchronized (eventLoop.threadLock) {
-			stream.cork(true);
-		}
-		isPaused = true;
-
-	}
-
-	public void addLineListener(LineListener listener) {
-		this.lineListeners.add(listener);
-	}
-
-	public void removeLineListener(LineListener listener) {
-		this.lineListeners.remove(listener);
-	}
-
-	public boolean isOpen() {
-		return isOpen;
-	}
 
 	public int available() {
 		synchronized (eventLoop.threadLock) {
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java	Fri Aug 15 16:39:53 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java	Fri Aug 15 16:57:00 2008 -0400
@@ -41,7 +41,6 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import javax.sound.sampled.*;
-import javax.sound.sampled.AudioFormat.Encoding;
 import javax.sound.sampled.Control.Type;
 
 
@@ -83,21 +82,6 @@
 		stream.connectForRecording(null);
 	}
 
-	public void open(AudioFormat format) throws LineUnavailableException {
-		open(format, DEFAULT_BUFFER_SIZE);
-
-	}
-
-	public void open() throws LineUnavailableException {
-		// pick a random format
-		if (defaultFormat == null) {
-			defaultFormat = new AudioFormat(Encoding.PCM_UNSIGNED, 22050, 8, 2,
-					2, AudioSystem.NOT_SPECIFIED, false);
-		}
-
-		open(defaultFormat, DEFAULT_BUFFER_SIZE);
-	}
-
 
 	@Override
 	public int read(byte[] data, int offset, int length) {
@@ -144,32 +128,7 @@
 	
 	}
 
-	private native void readFromStream(byte[] b, int off, int len);
 
-	public void start() {
-		if (isPaused) {
-			resumeStream();
-			isPaused = false;
-		} /*else {
-			startStream();
-		}*/
-
-		/*for (LineListener l : listeners) {
-			l.update(new LineEvent(this, LineEvent.Type.START, 0));
-		}*/
-	}
-
-	public void stop() {
-		//pauseStream();
-		isPaused = true;
-
-	}
-
-	private native void startStream();
-
-	private native void pauseStream();
-
-	private native void resumeStream();
 
 	@Override
 	public void drain() {
@@ -183,18 +142,6 @@
 
 	}
 
-	public void addLineListener(LineListener listener) {
-		lineListeners.add(listener);
-	}
-
-	public void removeLineListener(LineListener listener) {
-		lineListeners.remove(listener);
-	}
-
-	public boolean isOpen() {
-		return isOpen;
-	}
-
 	public int available() {
 		synchronized (eventLoop.threadLock) {
 			return native_get_readable_size();