Mercurial > vba-clojure
view java/src/com/aurellem/gb/WaveWriter.java @ 546:36e5fa62eb3c
i believe this latest change will correct all A/V synching problems.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 27 Jun 2012 14:08:59 -0500 |
parents | 7ef5c73ea8fa |
children |
line wrap: on
line source
1 package com.aurellem.gb;3 import java.io.File;4 import java.io.FileNotFoundException;5 import java.io.FileOutputStream;6 import java.io.IOException;7 import java.nio.ByteBuffer;9 import javax.sound.sampled.AudioFormat;10 import javax.sound.sampled.AudioSystem;12 import org.tritonus.sampled.file.WaveAudioOutputStream;13 import org.tritonus.share.sampled.file.TDataOutputStream;14 import org.tritonus.share.sampled.file.TNonSeekableDataOutputStream;17 public class WaveWriter {18 public File targetFile;19 private WaveAudioOutputStream wao;20 private TDataOutputStream tos;21 private boolean initialized = false;23 public WaveWriter(File targetFile)24 throws FileNotFoundException{25 tos = new TNonSeekableDataOutputStream26 (new FileOutputStream(targetFile));27 }29 public void init(AudioFormat format){30 wao = new WaveAudioOutputStream31 (format,AudioSystem.NOT_SPECIFIED, tos);32 }34 public void process(byte[] audioSamples,35 AudioFormat format) {36 if (!initialized){37 init(format);38 initialized = true;39 }40 try {wao.write(audioSamples, 0, audioSamples.length);}41 catch (IOException e) {e.printStackTrace();}42 }44 public void cleanup() {45 try {wao.close();}46 catch (IOException e) {e.printStackTrace();}47 }48 }