reading sound card output?

Discussion in 'Java' started by mail.flacco@gmail.com, Sep 24, 2007.

  1. Guest

    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.
    , Sep 24, 2007
    #1
    1. Advertising

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


    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
    Andrew Thompson, Sep 25, 2007
    #2
    1. Advertising

  3. Guest

    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
    , Sep 28, 2007
    #3
  4. Guest

    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
    }
    }
    }
    , Sep 28, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. terry

    Second sound card

    terry, Jan 19, 2004, in forum: Java
    Replies:
    1
    Views:
    332
    Andrew Thompson
    Jan 19, 2004
  2. Replies:
    0
    Views:
    490
  3. Nick

    Sound card input

    Nick, Dec 7, 2003, in forum: C++
    Replies:
    1
    Views:
    386
    Hongzheng Wang
    Dec 8, 2003
  4. Replies:
    4
    Views:
    342
    Niklas Norrthon
    Dec 1, 2005
  5. Alex Hall
    Replies:
    1
    Views:
    459
    Gregory Ewing
    May 17, 2010
Loading...

Share This Page