Prevent buffer copy #14

Closed
Skydust wants to merge 1 commits from dev into r/direct-stream-record
2 changed files with 14 additions and 4 deletions
Showing only changes of commit 6b4293ef84 - Show all commits

View File

@@ -1 +1 @@
version=4.1
version=4.2

View File

@@ -152,10 +152,20 @@ public class RecordState {
}
public void rawToWave(ByteArrayOutputStream input, File wavFile) throws IOException {
// Transform output to input stream with pipes
PipedInputStream pis = new PipedInputStream();
final PipedOutputStream out = new PipedOutputStream(pis);
new Thread(() -> {
try {
input.writeTo(out);
} catch (IOException e) {
throw new RuntimeException(e);
}
}).start();
AudioFormat format = getAudioFormat();
byte[] audioData = input.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(audioData);
AudioInputStream audioInputStream = new AudioInputStream(bais, format, audioData.length / format.getFrameSize());
AudioInputStream audioInputStream = new AudioInputStream(pis, format, input.size() / format.getFrameSize());
AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, wavFile);