KWhat4 wrote:
..
Post code* rather than..
.vague snippets.
And by 'code' I mean a specific form, an SSCCE.
<
http://www.physci.org/codes/sscce.html>
I am not sure it will help you, but here is a small sound
based tool I wrote to plot the sound traces on-screen,
an oscilloscope.
<
http://www.physci.org/test/oscilloscope/AudioTrace.java>
It's homepage is here..
<
http://www.physci.org/sound/audiotrace.html>
Hopefully this will illustrate my insanity more effectively... I know
its dirty, but the problem is at the very end when i try to read/write
to an audio port. FYI I am using Java 1.5
package com.jargon.client.audio;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.Port;
import javax.sound.sampled.TargetDataLine;
public class Test {
/**
* @param args
* @throws LineUnavailableException
*/
public static void main(String[] args) throws
LineUnavailableException {
AudioFormat objAudioFormat = new AudioFormat(8000.0F, 16, 1, true,
false);
Mixer objTargetMixer = null;
Line objTargetLine = null;
System.out.println("Mixers:");
Mixer.Info[] aMixerInfo = AudioSystem.getMixerInfo();
for (int i = 0; i < aMixerInfo.length; i++) {
/* Possible mixers for this computer
ICH6 [plughw:0,0]
ICH6 [plughw:0,1]
ICH6 [plughw:0,2]
ICH6 [plughw:0,3]
ICH6 [plughw:0,4]
Modem [plughw:1,0]
Port ICH6 [hw:0]
Port Modem [hw:1]
*/
if (aMixerInfo
.getName().equalsIgnoreCase("Port ICH6 [hw:0]")) {
objTargetMixer = AudioSystem.getMixer(aMixerInfo);
}
System.out.println("\t" + aMixerInfo.getName());
}
System.out.println();
//Now try to get a port on our target mixer
System.out.println("Ports:");
Line.Info[] aLineInfo = objTargetMixer.getSourceLineInfo();
for (int i = 0; i < aLineInfo.length; i++) {
/* Possible Port for the Target Mixer for this computer
Capture source port
*/
if (aLineInfo instanceof Port.Info) {
Port.Info objPort = (Port.Info) aLineInfo;
objTargetLine = objTargetMixer.getLine(objPort);
}
System.out.println("\t" + aLineInfo.toString());
}
//So now we have a mixer, we have a port... lets read/write data?
//TODO This is where i bork the process! Note that i have tried all
with no success.
//ClassCastException: com.sun.media.sound.PortMixer$PortMixerPort
//TargetDataLine objInputDataLine = (TargetDataLine)
objTargetMixer.getLine(objTargetLine.getLineInfo());
//TargetDataLine objInputDataLine = (TargetDataLine) objTargetLine;
//TargetDataLine objInputDataLine = (TargetDataLine)
AudioSystem.getLine(objTargetLine.getLineInfo());
//IllegalArgumentException: Line unsupported: interface
TargetDataLine supporting format PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2
bytes/frame, little-endian
//TargetDataLine objInputDataLine = (TargetDataLine)
AudioSystem.getTargetDataLine(objAudioFormat,
objTargetMixer.getMixerInfo());
}
}