scope playAudioFromSampleMakingFunction. svoid playAudioFromSampleMakingFunction(int bufSize, VF1 sampleMaker) { new AudioLoop(bufsize, sampleMaker).start(); } sclass #AudioLoop extends Thread { SourceDataLine out; new Flag stopFlag; byte[] buf; VF1 sampleMaker; *(AudioFormat format, int bufSize, VF1 *sampleMaker) { out = javaSound_outputLine(javaSound_cdQuality(), internalBufferSize); buf = new byte[internalBufferSize]; } public void start { out.start°; super.start°; } void stopPlaying { out.close°; stopFlag.raise°; } // "stop()" was taken public void run° { short[] pair = new short[2]; while (licensed() && !stopFlag.isUp()) { for (int i = 0; i < l(buf); i += 4) { nextSamples(pair); buf[i] = (byte) pair[0]; buf[i+1] = (byte) (pair[0] >> 8); buf[i+2] = (byte) pair[1]; buf[i+3] = (byte) (pair[1] >> 8); } //print("Writing " + l(buf) + " bytes"); int n = out.write(buf, 0, l(buf)); if (n != l(buf)) print("huh: " + n + " of " + l(buf)); } } }