annotate java/src/com/aurellem/gb/WaveWriter.java @ 596:747d47d96d2f

determined that I cannot shorten the long B sequeuce during bootstrap.
author Robert McIntyre <rlm@mit.edu>
date Sun, 02 Sep 2012 06:36:57 -0500
parents 7ef5c73ea8fa
children
rev   line source
rlm@524 1 package com.aurellem.gb;
rlm@524 2
rlm@524 3 import java.io.File;
rlm@524 4 import java.io.FileNotFoundException;
rlm@524 5 import java.io.FileOutputStream;
rlm@524 6 import java.io.IOException;
rlm@524 7 import java.nio.ByteBuffer;
rlm@524 8
rlm@524 9 import javax.sound.sampled.AudioFormat;
rlm@524 10 import javax.sound.sampled.AudioSystem;
rlm@524 11
rlm@524 12 import org.tritonus.sampled.file.WaveAudioOutputStream;
rlm@524 13 import org.tritonus.share.sampled.file.TDataOutputStream;
rlm@524 14 import org.tritonus.share.sampled.file.TNonSeekableDataOutputStream;
rlm@524 15
rlm@524 16
rlm@524 17 public class WaveWriter {
rlm@524 18 public File targetFile;
rlm@524 19 private WaveAudioOutputStream wao;
rlm@524 20 private TDataOutputStream tos;
rlm@524 21 private boolean initialized = false;
rlm@524 22
rlm@524 23 public WaveWriter(File targetFile)
rlm@524 24 throws FileNotFoundException{
rlm@524 25 tos = new TNonSeekableDataOutputStream
rlm@524 26 (new FileOutputStream(targetFile));
rlm@524 27 }
rlm@524 28
rlm@524 29 public void init(AudioFormat format){
rlm@524 30 wao = new WaveAudioOutputStream
rlm@524 31 (format,AudioSystem.NOT_SPECIFIED, tos);
rlm@524 32 }
rlm@524 33
rlm@524 34 public void process(byte[] audioSamples,
rlm@524 35 AudioFormat format) {
rlm@524 36 if (!initialized){
rlm@524 37 init(format);
rlm@524 38 initialized = true;
rlm@524 39 }
rlm@524 40 try {wao.write(audioSamples, 0, audioSamples.length);}
rlm@524 41 catch (IOException e) {e.printStackTrace();}
rlm@524 42 }
rlm@524 43
rlm@524 44 public void cleanup() {
rlm@524 45 try {wao.close();}
rlm@524 46 catch (IOException e) {e.printStackTrace();}
rlm@524 47 }
rlm@524 48 }