static void captureAudioFromLine(DataLine line, AudioFormat format) ctex { if (!line instanceof TargetDataLine) fail(getClassName(line)); TargetDataLine tdl = cast line; tdl.open(format); tdl.start(); int total = 0, n; int seconds = 2; int bytesPerSecond = iround(format.getSampleSizeInBits()*format.getChannels()*format.getSampleRate()/8); print("Bytes per second: " + bytesPerSecond); int bytesWanted = seconds*bytesPerSecond; byte[] buf = new byte[1024]; while (total < bytesWanted && (n = tdl.read(buf, 0, min(l(buf), bytesWanted-total))) > 0) { total += n; short[] exp = format.isBigEndian() ? shortArrayFromBytes(buf, 0, n) : shortArrayFromBytes_littleEndian(buf, 0, n); print(structure(subArray(exp, 0, 10))); print("Bytes read from line: " + total + ". min: " + min(exp) + ". max: " + max(exp)); } tdl.close(); }