reading sound card output?

M

mail.flacco

I'd like to build an oscilloscope in java that monitors the sound
card, so if I'm playing something in winamp or itunes I can look at
the freq domain info.

I've been having a lot of trouble reading from the soundcard though. I
can't get a targetline for a mixer that lets me read off the
soundcard, and likewise I haven't seen any ports that look like they
could be used.

Port.info gives me a microphone, line in and cd player as my audio
input options, and the speakers as an output. I'd like to read what's
being sent out!

I've looked at several example programs:

1) http://www.developer.com/java/other/article.php/1579071#Discussion and Sample Programs
- Records sound from microphone, then plays it back. If I could read
off the sound card, I'd be golden. However, changing the mixer from
"sound capture something or other" gives me audio format errors,
despite the fact that targetlineinfo on the other mixers tells me lots
of formats are supported.

2) http://www.physci.org/sound/audiotrace.html - Doesn't work
unfortunately.

Thanks guys.
 
A

Andrew Thompson


Do you mean "doesn't work" in terms of getting a 'flat line'
trace for all available channels?

What's the line info.?

Had you seen the original thread* relating to that code?

* Detailing the problems we faced in accessing the soundcard.

Actually, now I think about it, had you seen the audiotrace
code, as opposed to simply the executable?

What OS and version are you using?
(I was worried that MS new 'media regime' might cause
problems for accessing the sound lines.)

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200709/1
 
M

mail.flacco

I read the other threads about your project and tried running
audiotrace from exe and from source.

I hadn't hooked up my mike, and when I spoke into it I saw it on lines
1 and 2! Nothing playing on the speakers though appeared on the lines
even with show all lines on. I'm using xp pro 64. Perhaps it's my
soundcard. Here's what a list of mixers looks like:

Available Mixers:
Primary Sound Driver
Realtek HD Audio output
Primary Sound Capture Driver
Realtek HD Audio Input
Realtek HD Digital input
Java Sound Audio Engine
Port Realtek HD Audio output
Port Realtek HD Digital input
Port Realtek HD Audio Input

Here's AudioTrace's mixer info:
Mixer 0: Primary Sound Driver, version Unknown Version
Mixer 1: Realtek HD Audio output, version Unknown Version
Mixer 2: Primary Sound Capture Driver, version Unknown Version
Line 2/0: interface TargetDataLine supporting 8 audio formats, and
buffers of at least 32 bytes
frmt.: PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-
endian
Mixer 3: Realtek HD Audio Input, version Unknown Version
Line 3/0: interface TargetDataLine supporting 8 audio formats, and
buffers of at least 32 bytes
frmt.: PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-
endian
Mixer 4: Realtek HD Digital input, version Unknown Version
Line 4/0: interface TargetDataLine supporting 8 audio formats, and
buffers of at least 32 bytes
frmt.: PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-
endian
Mixer 5: Java Sound Audio Engine, version 1.0
Mixer 6: Port Realtek HD Audio output, version 5.10
Line 6/0: SPEAKER target port
Note: Is a Data line, but not a TDL
Mixer 7: Port Realtek HD Digital input, version 5.10
Mixer 8: Port Realtek HD Audio Input, version 5.10
Line 8/0: Recording Control target port
Note: Is a Data line, but not a TDL

Here's a more detailed examination of the Realtek HD Audio Input and
Audio Output mixers with line info and controls:
Found mixer: Port Realtek HD Audio Input
Port Mixer
Source Line Supported:
COMPACT_DISC, source
Available controls:
CD Volume Control containing Mute Controls.
Mute Control with current value: false
MICROPHONE, source
Available controls:
Mic Volume Control containing Mute Controls.
Mute Control with current value: false
LINE_IN, source
Available controls:
Line Volume Control containing Mute Controls.
Mute Control with current value: false
Stereo Mix, source
Available controls:
Stereo Mix Control containing Mute Controls.
Mute Control with current value: true
Target Line Supported:
Recording Control, taget
Available controls:
Volume with current value: 0.37421227 (range: 0.0 - 1.0)
Balance with current value: -3.2120983E-8 (range: -1.0 - 1.0)
Mute Control with current value: false
CD Volume Control containing Mute Controls.
Mute Control with current value: false
Mic Volume Control containing Mute Controls.
Mute Control with current value: false
Line Volume Control containing Mute Controls.
Mute Control with current value: false
Stereo Mix Control containing Mute Controls.
Mute Control with current value: true
 
M

mail.flacco

I realized I omitted some info: I'm only getting 3 lines showing up on
your program.

Also, I wrote the following program to see if I could get a valid
speaker port and record from it. The port was valid, but I can't
record. I assume that's because as a port the speaker is play only,
not record.

//////////////////////////////
import javax.sound.sampled.*;
import java.io.*;

public class Test {
public static void main(String args[])
{
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
AudioFormat audioFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
44100.0F, 16, 2, 4, 44100.0F, false);

Port.Info portInfo = new Port.Info(TargetDataLine.class,
Port.Info.SPEAKER.getName(), false);
DataLine.Info dataLineInfo = new
DataLine.Info(portInfo.getLineClass(),
audioFormat);
Mixer mixer = AudioSystem.getMixer(mixerInfo[3]);

TargetDataLine targetDataLine = null;
try {
targetDataLine = (TargetDataLine)mixer.getLine(dataLineInfo);
targetDataLine.open(audioFormat);
} catch ( Exception e) { System.out.println("E: "+e); }
int numBytesAvailable = targetDataLine.available();


BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
String exitQ = null;

targetDataLine.start();
while(true) {
byte tempBuffer[] = new byte[10000];

targetDataLine.read(tempBuffer, 0, tempBuffer.length);
System.out.println(tempBuffer.toString());
System.out.println("# bytes available = "+numBytesAvailable);


try {
exitQ = br.readLine();
} catch (IOException ioe) {
System.out.println("IO error trying read exit code!");
System.exit(1);
}
if (exitQ.charAt(0)=='e') { System.out.println("Goodbye");
System.exit(1); } //type e to exit
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top