!7 // Source: AudioLoop from jsresources.org import javax.sound.sampled.*; static boolean DEBUG; static int DEFAULT_INTERNAL_BUFSIZ = 40960; static int DEFAULT_EXTERNAL_BUFSIZ = 40960; p { S strMixerName = null; float fFrameRate = 44100.0F; int nInternalBufferSize = DEFAULT_INTERNAL_BUFSIZ; int nExternalBufferSize = DEFAULT_EXTERNAL_BUFSIZ; AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, fFrameRate, 16, 2, 4, fFrameRate, false); if (DEBUG) { print("AudioLoop.main(): audio format: " + audioFormat); } new AudioLoop(audioFormat, nInternalBufferSize, nExternalBufferSize, strMixerName).start(); } sclass AudioLoop extends Thread { TargetDataLine m_targetLine; SourceDataLine m_sourceLine; volatile bool recording; int externalBufferSize; *(AudioFormat format, int nInternalBufferSize, int *externalBufferSize, String strMixerName) throws LineUnavailableException { Mixer mixer = strMixerName == null ? null : AudioSystem.getMixer(javaSound_getMixerInfo(strMixerName)); DataLine.Info targetInfo = new DataLine.Info(TargetDataLine.class, format, nInternalBufferSize); DataLine.Info sourceInfo = new DataLine.Info(SourceDataLine.class, format, nInternalBufferSize); if (mixer != null) { m_targetLine = (TargetDataLine) mixer.getLine(targetInfo); m_sourceLine = (SourceDataLine) mixer.getLine(sourceInfo); } else { m_targetLine = (TargetDataLine) AudioSystem.getLine(targetInfo); m_sourceLine = (SourceDataLine) AudioSystem.getLine(sourceInfo); } m_targetLine.open(format, nInternalBufferSize); m_sourceLine.open(format, nInternalBufferSize); } public void start() { m_targetLine.start(); m_sourceLine.start(); super.start(); } public void run() { byte[] abBuffer = new byte[externalBufferSize]; int nBufferSize = abBuffer.length; recording = true; while (recording) { if (DEBUG) { print("Trying to read: " + nBufferSize); } int nBytesRead = m_targetLine.read(abBuffer, 0, nBufferSize); if (DEBUG) { print("Read: " + nBytesRead); } m_sourceLine.write(abBuffer, 0, nBytesRead); } } }