!7 static int DEFAULT_INTERNAL_BUFSIZ = 40960, DEFAULT_EXTERNAL_BUFSIZ = 40960; p { temp WAVDecoder decoder = new(newFileInputStream(loadLibrary(#1400093))); new L chunks; while licensed { short[] buf = new short[4096]; int n = decoder.readStereoSamples(buf); if (n <= 0) break; chunks.add(subArray(buf, 0, n)); } short[] samples = concatShortArrays(chunks); new AudioLoop(javaSound_cdQuality(), DEFAULT_INTERNAL_BUFSIZ, DEFAULT_EXTERNAL_BUFSIZ, samples).start(); } sclass AudioLoop extends Thread { TargetDataLine in; SourceDataLine out; new Flag stopFlag; int externalBufferSize; byte[] buf; short[] samples; *(AudioFormat format, int internalBufferSize, int *externalBufferSize, short[] *samples) { out = javaSound_outputLine(format, internalBufferSize); buf = new byte[internalBufferSize]; } public void start { out.start°; super.start°; } void stopPlaying { out.close°; stopFlag.raise°; } // "stop()" was taken int sampleIndex = 0; void nextSamples(short[] pair) { pair[0] = samples[sampleIndex]; pair[1] = samples[sampleIndex+1]; sampleIndex = (sampleIndex+2) % l(samples); } 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)); } } }