title: Can't select microphone TargetDataLine. Seems, I can use only input that is default for my OS system
body: <p>I'm trying to read audio input from different microphones. I found very wired behavior. It seems, that whatever microphone I choose, I can grab sound only for microphone that is default for system. I know this, because sum of signals from both 'microphones' is similar, what I hit default system microphone. What am I doing wrong?</p>
  <pre><code>
  import java.util.LinkedList;
  import java.util.List;
  
  import javax.sound.sampled.*;
  
  public class AudioTest {
  
      public static void main(String[] args) throws LineUnavailableException {
  
          AudioFormat format = new AudioFormat(8000.0f, 16, 1, true, true);
  
          // list all microphones
          List&lt;Line.Info&gt; micList = enumerateMicrophones();
  
          // assign microphone1
          TargetDataLine microphone1 = (TargetDataLine) AudioSystem.getLine(micList.get(1));
          
          // assign microphone2
          TargetDataLine microphone2 = (TargetDataLine) AudioSystem.getLine(micList.get(2));
          
          // read sound from microphone1
          byte[] data1 = new byte[1000];
          microphone1.open(format);
          microphone1.start();
          microphone1.read(data1, 0, 1000);
  
          // read sound from microphone2
          byte[] data2 = new byte[1000];
          microphone2.open(format);
          microphone2.start();
          microphone2.read(data2, 0, 1000);
  
          // Print sum (bigger for laud sounds). 
          // Similar values means - both microphones are in fact the same     
          System.out.println(&quot;Mic1: &quot; + calcSum(data1));
          System.out.println(&quot;Mic2: &quot; + calcSum(data2));
      }
      
      static long calcSum(byte[] data) {
          long sum = 0;
          for(byte bt: data) {
              sum += Math.abs(bt);
          }
          return sum;
      }
  
      public static List&lt;Line.Info&gt; enumerateMicrophones() {
          List&lt;Line.Info&gt; out = new LinkedList&lt;Line.Info&gt;();
          Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
          for (Mixer.Info info : mixerInfos) {
              Mixer m = AudioSystem.getMixer(info);
              Line.Info[] lineInfos = m.getTargetLineInfo();
              for (Info lineInfo : lineInfos) {
                  if (lineInfo.getLineClass().equals(TargetDataLine.class)) {
                      out.add(lineInfo);
                      System.out.println(&quot;Mixer: &quot; + info.toString() + &quot;          Line: &quot; + lineInfo.toString());
                  }
              }
          }
          return out;
      }
  
  }
  </code></pre>
  <p>The mixers/lines printed are:</p>
  <blockquote>
  <p><code>Mixer: PulseAudio Mixer, version 0.02          Line: interface TargetDataLine supporting 42 audio formats, and buffers of 0 to 1000000 bytes</code></p>
  <p><code>Mixer: default [default], version 4.15.0-108-generic          Line: interface TargetDataLine supporting 512 audio formats, and buffers of at least 32 bytes</code></p>
  <p><code>Mixer: PCH [plughw:0,0], version 4.15.0-108-generic          Line: interface TargetDataLine supporting 24 audio formats, and buffers of at least 32 bytes</code></p>
  </blockquote>
  <p>Sometimes I have one more device:</p>
  <blockquote>
  <p><code>Mixer: Device [plughw:1,0], version 4.15.0-108-generic          Line: interface TargetDataLine supporting 4 audio formats, and buffers of at least 32 bytes</code></p>
  </blockquote>
  <p>Sometimes not. Wired</p>
  <p>What my operating system Ubuntu sees:</p>
  <blockquote>
  <p><code>#arecord -l</code></p>
  <p><code>**** List of CAPTURE Hardware Devices ****</code></p>
  <p><code>card 0: PCH [HDA Intel PCH], device 0: ALC269VC Analog [ALC269VC Analog]</code></p>
  <p><code>  Subdevices: 1/1</code></p>
  <p><code>  Subdevice #0: subdevice #0</code></p>
  <p><code>card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]</code></p>
  <p><code>  Subdevices: 1/1</code></p>
  <p><code>  Subdevice #0: subdevice #0</code></p>
  </blockquote>
  <p>I have one microphone connected by USB, and one build into laptop.</p>