!7 p-exp { assertOnPATH("aplay"); Process process = Runtime.getRuntime().exec("aplay"); InputStream in = process.getInputStream(); drainStreamInNewThread(in); // just to take care of it OutputStream out = process.getOutputStream(); int sampleRate = 44100; // Samples per second double duration = 5.0; // Seconds // Calculate the number of frames required for specified duration long numFrames = (long)(duration * sampleRate); // Create a wav file with the name specified as the first argument GSWavFile wavFile = GSWavFile.newWavFile(out, null, 2, numFrames, 16, sampleRate); // Create a buffer of 100 frames double[][] buffer = new double[2][100]; long frameCounter = 0; 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