diff 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
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/src/com/aurellem/gb/WaveWriter.java	Sat Jun 23 23:10:31 2012 -0500
     1.3 @@ -0,0 +1,48 @@
     1.4 +package com.aurellem.gb;
     1.5 +
     1.6 +import java.io.File;
     1.7 +import java.io.FileNotFoundException;
     1.8 +import java.io.FileOutputStream;
     1.9 +import java.io.IOException;
    1.10 +import java.nio.ByteBuffer;
    1.11 +
    1.12 +import javax.sound.sampled.AudioFormat;
    1.13 +import javax.sound.sampled.AudioSystem;
    1.14 +
    1.15 +import org.tritonus.sampled.file.WaveAudioOutputStream;
    1.16 +import org.tritonus.share.sampled.file.TDataOutputStream;
    1.17 +import org.tritonus.share.sampled.file.TNonSeekableDataOutputStream;
    1.18 +
    1.19 +
    1.20 +public class WaveWriter {
    1.21 +    public  File targetFile;
    1.22 +    private WaveAudioOutputStream wao;
    1.23 +    private TDataOutputStream tos;
    1.24 +    private boolean initialized = false;
    1.25 +	
    1.26 +    public WaveWriter(File targetFile) 
    1.27 +	throws FileNotFoundException{
    1.28 +	tos = new TNonSeekableDataOutputStream
    1.29 +	    (new FileOutputStream(targetFile));
    1.30 +    }
    1.31 +
    1.32 +    public void init(AudioFormat format){
    1.33 +	wao = new WaveAudioOutputStream
    1.34 +	    (format,AudioSystem.NOT_SPECIFIED, tos);
    1.35 +    }
    1.36 +		
    1.37 +    public void process(byte[] audioSamples, 
    1.38 +			AudioFormat format) {
    1.39 +	if (!initialized){
    1.40 +	    init(format);
    1.41 +	    initialized = true;
    1.42 +	}
    1.43 +	try {wao.write(audioSamples, 0, audioSamples.length);}
    1.44 +	catch (IOException e) {e.printStackTrace();}
    1.45 +    }
    1.46 +
    1.47 +    public void cleanup() {
    1.48 +	try {wao.close();}
    1.49 +	catch (IOException e) {e.printStackTrace();}
    1.50 +    }
    1.51 +}
    1.52 \ No newline at end of file