title: How do I make my Java program stop capturing audio as soon as a certain frequency has been read?
body: <p>I'm creating a guitar tuner in Java on the netbeans IDE and I want my program to stop capturing live audio as soon as a certain frequency has been read. This code below starts the audio capture but stops instantly. I want it to stop as soon as it reaches the frequency of the Low E string for example.
  I've used this website for help so far: <a href="https://docs.oracle.com/javase/tutorial/sound/capturing.html" rel="nofollow noreferrer">https://docs.oracle.com/javase/tutorial/sound/capturing.html</a></p>
  <pre><code>//libraries
  import static java.awt.SystemColor.info;
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import static java.lang.System.in;
  import javax.sound.sampled.AudioFormat;
  import javax.sound.sampled.AudioSystem;
  import javax.sound.sampled.DataLine.Info;
  import javax.sound.sampled.DataLine;
  import javax.sound.sampled.LineUnavailableException;
  import javax.sound.sampled.TargetDataLine;
  
  
  public class AudioInputPractice {
  
  /**
   * @param args the command line arguments
   * @throws javax.sound.sampled.LineUnavailableException
   */
  public int read(byte[] b, int off, int len) throws IOException{
              return in.read(b, off, len);
          }
  
  public static void main(String[] args){
      
      System.out.println(&quot;Starting sound test...&quot;);
      
     
      //audio 
      try
      {
          TargetDataLine line;
          AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100, 16, 2, 4, 4100, false);
        
          DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
          if (!AudioSystem.isLineSupported(info)) {System.err.println(&quot;Line not Supported&quot;);}
          line = (TargetDataLine)AudioSystem.getLine(info);
          line.open();
          
          
    
      
      ByteArrayOutputStream out= new ByteArrayOutputStream();
      int numBytesRead;
      byte[] data = new byte[line.getBufferSize() / 5];
      
      System.out.println(&quot;Starting recording...&quot;);
      
      line.start();
      
      numBytesRead = line.read(data, 0 , data.length);
      out.write(data, 0, numBytesRead);
      }
      catch (LineUnavailableException ex) 
      {
          System.out.println(&quot;Error&quot;);
      }
      
      
      
      }
  }
  </code></pre>