sclass StreamSoundToAPlay { Process process; InputStream in; OutputStream out; int sampleRate = 44100, channels = 2, bits = 16; double duration = yearsToSeconds(1); // max seconds GSWavFile wavStream; long frameCounter = 0; void start { assertOnPATH("aplay"); Process process = Runtime.getRuntime().exec("aplay"); // should probably print those instead drainStreamInNewThread(process.getInputStream()); drainStreamInNewThread(process.getErrorStream()); out = process.getOutputStream(); long numFrames = (long)(duration * sampleRate); wavStream = GSWavFile.newWavFile(out, null, channels, numFrames, bits, sampleRate); } void writeSamples(short[] samples) { double[][] buffer = new double[2][100]; while (frameCounter < numFrames) { // Determine how many frames to write, up to a maximum of the buffer size long remaining = wavFile.getFramesRemaining(); int toWrite = (remaining > 100) ? 100 : (int) remaining; // Fill the buffer, one tone per channel for (int s=0 ; s