Mercurial > jmeCapture
comparison src/com/aurellem/capture/audio/WaveFileWriter.java @ 68:302d5e9ad120
adjust format
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 19 Jul 2012 12:28:55 -0500 |
parents | d799a0278cc9 |
children |
comparison
equal
deleted
inserted
replaced
67:30cea3f0f30a | 68:302d5e9ad120 |
---|---|
19 * @author Robert McIntyre | 19 * @author Robert McIntyre |
20 */ | 20 */ |
21 | 21 |
22 public class WaveFileWriter implements SoundProcessor { | 22 public class WaveFileWriter implements SoundProcessor { |
23 | 23 |
24 public File targetFile; | 24 public File targetFile; |
25 private WaveAudioOutputStream wao; | 25 private WaveAudioOutputStream wao; |
26 private TDataOutputStream tos; | 26 private TDataOutputStream tos; |
27 private boolean initialized = false; | 27 private boolean initialized = false; |
28 | 28 |
29 public WaveFileWriter(File targetFile) throws FileNotFoundException{ | 29 public WaveFileWriter(File targetFile) |
30 tos = new TNonSeekableDataOutputStream( | 30 throws FileNotFoundException{ |
31 new FileOutputStream(targetFile)); | 31 tos = new TNonSeekableDataOutputStream |
32 } | 32 (new FileOutputStream(targetFile)); |
33 } | |
33 | 34 |
34 public void init(AudioFormat format){ | 35 public void init(AudioFormat format){ |
35 wao = new WaveAudioOutputStream(format,AudioSystem.NOT_SPECIFIED, tos); | 36 wao = new WaveAudioOutputStream(format,AudioSystem.NOT_SPECIFIED, tos); |
37 } | |
38 | |
39 public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) { | |
40 audioSamples.clear(); | |
41 if (!initialized){ | |
42 init(format); | |
43 initialized = true; | |
36 } | 44 } |
37 | 45 |
38 public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) { | 46 byte[] data = new byte[numSamples]; |
39 audioSamples.clear(); | 47 audioSamples.get(data, 0, numSamples); |
40 if (!initialized){ | 48 try {wao.write(data, 0, numSamples);} |
41 init(format); | 49 catch (IOException e) {e.printStackTrace();} |
42 initialized = true; | 50 } |
43 } | |
44 | |
45 byte[] data = new byte[numSamples]; | |
46 audioSamples.get(data, 0, numSamples); | |
47 try {wao.write(data, 0, numSamples);} | |
48 catch (IOException e) {e.printStackTrace();} | |
49 } | |
50 | 51 |
51 public void cleanup() { | 52 public void cleanup() { |
52 try {wao.close();} | 53 try {wao.close();} |
53 catch (IOException e) {e.printStackTrace();} | 54 catch (IOException e) {e.printStackTrace();} |
54 } | 55 } |
55 | 56 |
56 | 57 |
57 } | 58 } |