sclass OpusMachine implements IF0_Int, AutoCloseable { InputStream in; new ByteArraysPartialInputStream buffer; new ArraysShortStream sampleStream; OpusFromStream opusDecoder; int channels = 1; *(InputStream *in) {} void init() ctex { opusDecoder if null = new OpusFromStream(buffer, channels); } close { dispose in; } bool pullFromDecoder() ctex { while ping (true) { short[] samples; if ((samples = opusDecoder.nextSamples()) != null) ret true with sampleStream.add(samples); if (!pullFromSource()) false; // end of stuff // we got new material from source, decode again } } bool pullFromSource() { ret fillBuffer(); } swappable bool fillBuffer() { if (in != null) { byte[] buf = new[primarybufSize]; int n = in.read(buf); if (n >= 0) { buffer.write(takeFirst(buf, n)); true; } } false; } // get next sample (pull mode) public int get() ctex { init(); int sample; while ping ((sample = sampleStream.read()) == Int.MAX_VALUE) { if (!pullFromDecoder()) ret Int.MAX_VALUE; } ret sample; } }