comparison src/com/aurellem/capture/audio/WaveFileWriter.java @ 27:5249c8a9603c

changed SoundProcessors to use AudioFormat
author Robert McIntyre <rlm@mit.edu>
date Sun, 30 Oct 2011 08:10:26 -0700
parents 95648b0c12bc
children
comparison
equal deleted inserted replaced
26:95648b0c12bc 27:5249c8a9603c
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 20 private boolean initialized = false;
21 private FileOutputStream fos;
22
21 public WaveFileWriter(File targetFile) throws FileNotFoundException{ 23 public WaveFileWriter(File targetFile) throws FileNotFoundException{
22 wao = new WaveAudioOutputStream(new AudioFormat(44100.0f, 32, 1, true, false), 24 this.fos = new FileOutputStream(targetFile);
23 AudioSystem.NOT_SPECIFIED,
24 (TDataOutputStream) new TNonSeekableDataOutputStream(
25 new FileOutputStream(targetFile)));
26 } 25 }
27 26
28 public void cleanup() { 27 public void cleanup() {
29 try {wao.close();} 28 try {wao.close();}
30 catch (IOException e) {e.printStackTrace();} 29 catch (IOException e) {e.printStackTrace();}
31 } 30 }
32 31
33 32 private void initiaize(AudioFormat format){
34 public void process(ByteBuffer audioSamples, int numSamples) { 33 wao = new WaveAudioOutputStream(format,
34 (long)AudioSystem.NOT_SPECIFIED,
35 (TDataOutputStream) new TNonSeekableDataOutputStream(
36 fos));
37 }
38
39 public void process(ByteBuffer audioSamples, AudioFormat format, int numSamples) {
40
41 if (!initialized){initiaize(format);}
42
35 byte[] data = new byte[numSamples]; 43 byte[] data = new byte[numSamples];
36 audioSamples.get(data, 0, numSamples); 44 audioSamples.get(data, 0, numSamples);
37 try {wao.write(data, 0, numSamples);} 45 try {wao.write(data, 0, numSamples);}
38 catch (IOException e) {e.printStackTrace();} 46 catch (IOException e) {e.printStackTrace();}
39 } 47 }