Mercurial > jmeCapture
diff src/com/aurellem/capture/audio/WaveFileWriter.java @ 31:b67ffa8aa0b9
fixed click problem
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 30 Oct 2011 10:17:09 -0700 |
parents | be37291c62b8 |
children | c4bfbf5d090e |
line wrap: on
line diff
1.1 --- a/src/com/aurellem/capture/audio/WaveFileWriter.java Sun Oct 30 10:11:21 2011 -0700 1.2 +++ b/src/com/aurellem/capture/audio/WaveFileWriter.java Sun Oct 30 10:17:09 2011 -0700 1.3 @@ -17,12 +17,31 @@ 1.4 1.5 public File targetFile; 1.6 private WaveAudioOutputStream wao; 1.7 + private TDataOutputStream tos; 1.8 + private boolean initialized = false; 1.9 + 1.10 + public WaveFileWriter(File targetFile) throws FileNotFoundException{ 1.11 + tos = new TNonSeekableDataOutputStream( 1.12 + new FileOutputStream(targetFile)); 1.13 + 1.14 1.15 - public WaveFileWriter(File targetFile) throws FileNotFoundException{ 1.16 - wao = new WaveAudioOutputStream(new AudioFormat(44100.0f, 32, 1, true, false), 1.17 - AudioSystem.NOT_SPECIFIED, 1.18 - (TDataOutputStream) new TNonSeekableDataOutputStream( 1.19 - new FileOutputStream(targetFile))); 1.20 + } 1.21 + 1.22 + public void init(AudioFormat format){ 1.23 + wao = new WaveAudioOutputStream(format,AudioSystem.NOT_SPECIFIED, tos); 1.24 + } 1.25 + 1.26 + public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) { 1.27 + 1.28 + if (!initialized){ 1.29 + init(format); 1.30 + initialized = true; 1.31 + } 1.32 + 1.33 + byte[] data = new byte[numSamples]; 1.34 + audioSamples.get(data, 0, numSamples); 1.35 + try {wao.write(data, 0, numSamples);} 1.36 + catch (IOException e) {e.printStackTrace();} 1.37 } 1.38 1.39 public void cleanup() { 1.40 @@ -31,10 +50,4 @@ 1.41 } 1.42 1.43 1.44 - public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) { 1.45 - byte[] data = new byte[numSamples]; 1.46 - audioSamples.get(data, 0, numSamples); 1.47 - try {wao.write(data, 0, numSamples);} 1.48 - catch (IOException e) {e.printStackTrace();} 1.49 - } 1.50 }