changeset 177:ea894778a6d0

2008-10-09 Omair Majid <omajid@redhat.com> * src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java (getSupportedFormats): Moved stuff around. * src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java (PulseAudioPort): Open the port on construction. (open): Doesnt throw any exceptions, so no throws clause. * src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java (open): Let the mixer know that the line is open. (close): Let the mixer know the the line is closed. * src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java (open): Let the mixer know that the line is open. (close): Let the mixer konw that hte line is closed.
author Omair Majid <omajid@redhat.com>
date Thu, 09 Oct 2008 15:35:27 -0400
parents 5108fc37a890
children d4676ea1be88
files src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java
diffstat 4 files changed, 66 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java	Wed Oct 08 16:06:00 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java	Thu Oct 09 15:35:27 2008 -0400
@@ -136,22 +136,6 @@
 		 * 
 		 */
 		int[] channelSizes = new int[] { 1, 2, 3, 4, 5, 6 };
-		for (int channelSize : channelSizes) {
-			properties = new HashMap<String, Object>();
-			properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_U8");
-
-			int sampleSize = 8; // in bits
-			AudioFormat PA_SAMPLE_U8 = new AudioFormat(Encoding.PCM_UNSIGNED, // encoding
-					AudioSystem.NOT_SPECIFIED, // sample rate
-					sampleSize, // sample size
-					channelSize, // channels
-					sampleSize / 8 * channelSize, // frame size in bytes
-					AudioSystem.NOT_SPECIFIED, // frame rate
-					false, // big endian?
-					properties);
-
-			supportedFormats.add(PA_SAMPLE_U8);
-		}
 
 		for (int channelSize : channelSizes) {
 			properties = new HashMap<String, Object>();
@@ -259,6 +243,23 @@
 			supportedFormats.add(PA_SAMPLE_S32LE);
 		}
 
+		for (int channelSize : channelSizes) {
+			properties = new HashMap<String, Object>();
+			properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_U8");
+
+			int sampleSize = 8; // in bits
+			AudioFormat PA_SAMPLE_U8 = new AudioFormat(Encoding.PCM_UNSIGNED, // encoding
+					AudioSystem.NOT_SPECIFIED, // sample rate
+					sampleSize, // sample size
+					channelSize, // channels
+					sampleSize / 8 * channelSize, // frame size in bytes
+					AudioSystem.NOT_SPECIFIED, // frame rate
+					false, // big endian?
+					properties);
+
+			supportedFormats.add(PA_SAMPLE_U8);
+		}
+
 		return supportedFormats.toArray(new AudioFormat[0]);
 	}
 
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java	Wed Oct 08 16:06:00 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java	Thu Oct 09 15:35:27 2008 -0400
@@ -39,7 +39,6 @@
 
 import javax.sound.sampled.AudioSystem;
 import javax.sound.sampled.LineEvent;
-import javax.sound.sampled.LineUnavailableException;
 import javax.sound.sampled.Port;
 
 public abstract class PulseAudioPort extends PulseAudioLine implements Port,
@@ -79,6 +78,16 @@
 		controls.add(muteControl);
 		isOpen = true;
 
+		/*
+		 * unlike other lines, Ports must either be open or close
+		 * 
+		 * close = no sound. open = sound
+		 * 
+		 * so we set it to be open by default
+		 */
+
+		open();
+
 		// System.out.println("Opened Target Port " + name);
 	}
 
@@ -95,6 +104,8 @@
 	}
 
 	public float getVolume() {
+
+		// FIXME need to query system for volume
 		return this.volume;
 	}
 
@@ -130,7 +141,7 @@
 	public abstract javax.sound.sampled.Line.Info getLineInfo();
 
 	@Override
-	public void open() throws LineUnavailableException {
+	public void open() {
 		native_setVolume(volume);
 		isOpen = true;
 		fireLineEvent(new LineEvent(this, LineEvent.Type.OPEN,
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java	Wed Oct 08 16:06:00 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java	Thu Oct 09 15:35:27 2008 -0400
@@ -41,6 +41,8 @@
 
 public class PulseAudioSourcePort extends PulseAudioPort {
 
+	/* aka mic */
+	
 	static {
 		System.loadLibrary("pulse-java");
 	}
@@ -49,6 +51,21 @@
 		super(name, eventLoop);
 	}
 
+	public void open() {
+		super.open();
+		
+		PulseAudioMixer parent = PulseAudioMixer.getInstance();
+		parent.addSourceLine(this);
+	}
+	
+	public void close() {
+		
+		PulseAudioMixer parent = PulseAudioMixer.getInstance();
+		parent.removeSourceLine(this);
+		
+		super.close();		
+	}
+	
 	public native byte[] native_setVolume(float newValue);
 
 	public synchronized native byte[] native_updateVolumeInfo();
@@ -57,5 +74,7 @@
 	public javax.sound.sampled.Line.Info getLineInfo() {
 		return new Port.Info(Port.class, getName(), false);
 	}
+	
+	
 
 }
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java	Wed Oct 08 16:06:00 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java	Thu Oct 09 15:35:27 2008 -0400
@@ -41,6 +41,8 @@
 
 public class PulseAudioTargetPort extends PulseAudioPort {
 
+	/* aka speaker */
+	
 	static {
 		System.loadLibrary("pulse-java");
 	}
@@ -49,6 +51,21 @@
 		super(name, eventLoop);
 	}
 
+	public void open() {
+		super.open();
+		
+		PulseAudioMixer parent = PulseAudioMixer.getInstance();
+		parent.addTargetLine(this);
+	}
+	
+	public void close() {
+		
+		PulseAudioMixer parent = PulseAudioMixer.getInstance();
+		parent.removeTargetLine(this);
+		
+		super.close();		
+	}
+	
 	public native byte[] native_setVolume(float newValue);
 
 	public synchronized native byte[] native_updateVolumeInfo();