Mercurial > vba-clojure
comparison java/src/com/aurellem/gb/WaveWriter.java @ 524:7ef5c73ea8fa
working on recording sound. almost have it, but there is still unexplained popping sounds.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 23 Jun 2012 23:10:31 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
523:d00096b6bf17 | 524:7ef5c73ea8fa |
---|---|
1 package com.aurellem.gb; | |
2 | |
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; | |
8 | |
9 import javax.sound.sampled.AudioFormat; | |
10 import javax.sound.sampled.AudioSystem; | |
11 | |
12 import org.tritonus.sampled.file.WaveAudioOutputStream; | |
13 import org.tritonus.share.sampled.file.TDataOutputStream; | |
14 import org.tritonus.share.sampled.file.TNonSeekableDataOutputStream; | |
15 | |
16 | |
17 public class WaveWriter { | |
18 public File targetFile; | |
19 private WaveAudioOutputStream wao; | |
20 private TDataOutputStream tos; | |
21 private boolean initialized = false; | |
22 | |
23 public WaveWriter(File targetFile) | |
24 throws FileNotFoundException{ | |
25 tos = new TNonSeekableDataOutputStream | |
26 (new FileOutputStream(targetFile)); | |
27 } | |
28 | |
29 public void init(AudioFormat format){ | |
30 wao = new WaveAudioOutputStream | |
31 (format,AudioSystem.NOT_SPECIFIED, tos); | |
32 } | |
33 | |
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 } | |
43 | |
44 public void cleanup() { | |
45 try {wao.close();} | |
46 catch (IOException e) {e.printStackTrace();} | |
47 } | |
48 } |