This discussion is archived
1 Reply Latest reply: Feb 14, 2011 11:42 AM by captfoss RSS

where is source data coming from?

839200 Newbie
Currently Being Moderated
Hi,
I've cobbled togeher a working app (based on some examples found on the net). The application works well, but I have one specific question as to why it works!

The application takes data from the mic on my pc and saves it to a file. I can play back this file through standard media player and it obviously has worked as I can hear the recording again.

I'm using a TargetDataLine to record the audio to a file. I get this from an appripriate mixer. To do this, I have the following method to provide me with an appropriate mixer:

<pre>
private Mixer getMixerSupportingDataLine(DataLine.Info dataLineInfo) {
          Info[] mixerInfoArray = AudioSystem.getMixerInfo();

          for (int i=0; mixerInfoArray!=null && i<mixerInfoArray.length; i++) {
               Mixer.Info mixerInfo = (Mixer.Info)mixerInfoArray;
               Mixer mixer=AudioSystem.getMixer(mixerInfo);
               if (mixer.isLineSupported(dataLineInfo)) {
                    System.out.println("mixer info="+mixerInfo.getName());
                    return mixer;
               }
          }
          return null;
     }
</pre>

Now the parameter I pass into this method comes form the following code:

<pre>
audioFormat = getAudioFormat();
DataLine.Info dataLineInfo =
new DataLine.Info(
TargetDataLine.class,
audioFormat);

private AudioFormat getAudioFormat(){
     float sampleRate = 8000.0F;
     int sampleSizeInBits = 16;
     int channels = 1;
     boolean signed = true;
     boolean bigEndian = false;
     return new AudioFormat(sampleRate,
     sampleSizeInBits,
     channels,
     signed,
     bigEndian);
     }
</pre>
So I have a mixer that I know supports the kind of TargetDataLine that I want. So I get a targetDataLine from the mixer:

<pre>
targetDataLine = (TargetDataLine)mixer.getLine(dataLineInfo);
</pre>

I can then open the line and read data from it, save it to a file, and all is fine.


So my question is this:

Nowhere in my code do I specify where the data (that ends up in my TargetDataLine) is coming from. I've not specified that it should come from a mic, or line-in, or any other physical device. It just magically reads data from my mic.

When I query my mixer to see its sources:
<pre>
System.out.println(" capturing and mixer has this many source lines:"+mixer.getSourceLineInfo().length);
System.out.println(" mixer info"+mixer.getMixerInfo());
System.out.println(" source lines open"+mixer.getSourceLines().length);
System.out.println(" mixer open:"+mixer.isOpen());
System.out.println(" mixer controls:"+mixer.getControls().length);
</pre>
I see that there are no sources!
<pre>
mixer info=Microsoft Sound Mapper
capturing and mixer has this many source lines:0
mixer infoMicrosoft Sound Mapper, version Unknown Version
source lines open0
mixer open:true
mixer controls:0
</pre>
I really want to understand this, as it seems fundamental. If the mixer has no source lines, how is it getting data from the mic?! Surely there must be a way to query the mixer to find the data source.

Can anyone help me understand this fundamental point?

Many thanks,
Martin

Edited by: user4621888 on 12-Feb-2011 08:57

Edited by: user4621888 on 12-Feb-2011 09:10
  • 1. Re: where is source data coming from?
    captfoss Pro
    Currently Being Moderated
    user4621888 wrote:
    So my question is this:

    Nowhere in my code do I specify where the data (that ends up in my TargetDataLine) is coming from. I've not specified that it should come from a mic, or line-in, or any other physical device. It just magically reads data from my mic.
    Ok.
    I see that there are no sources!
    Source and Target lines are what the user uses to write and read data from the line (respectively)... For example, the port that's actually associated with the microphone will have zero source lines, because you're not allowed to write to the microphone...but it gets data from the microphone, behind the scenes.

    So, fundamentally, just remember that just because you can't write to it doesn't mean it doesn't take in data. It often times means it's hard coded to read a specific stream of data.

    In this case, the stream of data is probably the default recording device specified in Windows...

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points