sinterface Capturer { void stop(); byte[] getPCM(); AudioFormat format(); } static Capturer captureAudioFromLine2(DataLine line, final AudioFormat format) ctex { if (!line instanceof TargetDataLine) fail(getClassName(line)); final TargetDataLine tdl = cast line; tdl.open(format); tdl.start(); ret new Capturer { volatile bool stopped; new ByteArrayOutputStream baos; public void stop() { stopped = true; } { thread "Audio Capture" { try { int total = 0, n; byte[] buf = new byte[1024]; while (!stopped && licensed() && (n = tdl.read(buf, 0, l(buf))) > 0) { total += n; baos.write(buf, 0, n); //print("Bytes read from line: " + total); } } finally { tdl.close(); } } } public byte[] getPCM() { ret baos.toByteArray(); } public AudioFormat format() { ret format; } }; }