comparison 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
comparison
equal deleted inserted replaced
30:be37291c62b8 31:b67ffa8aa0b9
15 15
16 public class WaveFileWriter implements SoundProcessor { 16 public class WaveFileWriter implements SoundProcessor {
17 17
18 public File targetFile; 18 public File targetFile;
19 private WaveAudioOutputStream wao; 19 private WaveAudioOutputStream wao;
20 private TDataOutputStream tos;
21 private boolean initialized = false;
22
23 public WaveFileWriter(File targetFile) throws FileNotFoundException{
24 tos = new TNonSeekableDataOutputStream(
25 new FileOutputStream(targetFile));
26
20 27
21 public WaveFileWriter(File targetFile) throws FileNotFoundException{ 28 }
22 wao = new WaveAudioOutputStream(new AudioFormat(44100.0f, 32, 1, true, false), 29
23 AudioSystem.NOT_SPECIFIED, 30 public void init(AudioFormat format){
24 (TDataOutputStream) new TNonSeekableDataOutputStream( 31 wao = new WaveAudioOutputStream(format,AudioSystem.NOT_SPECIFIED, tos);
25 new FileOutputStream(targetFile))); 32 }
33
34 public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) {
35
36 if (!initialized){
37 init(format);
38 initialized = true;
39 }
40
41 byte[] data = new byte[numSamples];
42 audioSamples.get(data, 0, numSamples);
43 try {wao.write(data, 0, numSamples);}
44 catch (IOException e) {e.printStackTrace();}
26 } 45 }
27 46
28 public void cleanup() { 47 public void cleanup() {
29 try {wao.close();} 48 try {wao.close();}
30 catch (IOException e) {e.printStackTrace();} 49 catch (IOException e) {e.printStackTrace();}
31 } 50 }
32 51
33 52
34 public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) {
35 byte[] data = new byte[numSamples];
36 audioSamples.get(data, 0, numSamples);
37 try {wao.write(data, 0, numSamples);}
38 catch (IOException e) {e.printStackTrace();}
39 }
40 } 53 }