view java/src/com/aurellem/gb/WaveWriter.java @ 530:8d3177d19d5f

added full recording function.
author Robert McIntyre <rlm@mit.edu>
date Sun, 24 Jun 2012 16:47:18 -0500
parents 7ef5c73ea8fa
children
line wrap: on
line source
1 package com.aurellem.gb;
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;
9 import javax.sound.sampled.AudioFormat;
10 import javax.sound.sampled.AudioSystem;
12 import org.tritonus.sampled.file.WaveAudioOutputStream;
13 import org.tritonus.share.sampled.file.TDataOutputStream;
14 import org.tritonus.share.sampled.file.TNonSeekableDataOutputStream;
17 public class WaveWriter {
18 public File targetFile;
19 private WaveAudioOutputStream wao;
20 private TDataOutputStream tos;
21 private boolean initialized = false;
23 public WaveWriter(File targetFile)
24 throws FileNotFoundException{
25 tos = new TNonSeekableDataOutputStream
26 (new FileOutputStream(targetFile));
27 }
29 public void init(AudioFormat format){
30 wao = new WaveAudioOutputStream
31 (format,AudioSystem.NOT_SPECIFIED, tos);
32 }
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 }
44 public void cleanup() {
45 try {wao.close();}
46 catch (IOException e) {e.printStackTrace();}
47 }
48 }