I'm attempting to create an audio filter using the JavaSound API to read and write the audio files. Currently my code is structured as follows:
ByteArrayOutputStream b_out = new ByteArrayOutputStream();
// Read a frame from the file.
while (audioInputStream.read(audioBytes) != -1) {
//Do stuff here....
b_out.write(outputvalue);
}
// Hook output stream to output file
ByteArrayInputStream b_in = new ByteArrayInputStream(b_out.toByteArray());
AudioInputStream ais = new AudioInputStream(b_in, format, length);
AudioSystem.write(ais, inFileFormat.getType(), outputFile);
This reads the input file as a stream, processes it and writes it to a bytearrayoutputstream, but it waits until the entire file has been processed before writing to disk. Ideally, I would like it to write each sample to disk as it's processed. I've tried several combinations of stream constructs but can't find a way of doing it as AudioSystem.write() takes an input stream. Any ideas?