diff src/com/aurellem/capture/audio/WaveFileWriter.java @ 27:5249c8a9603c

changed SoundProcessors to use AudioFormat
author Robert McIntyre <rlm@mit.edu>
date Sun, 30 Oct 2011 08:10:26 -0700
parents 95648b0c12bc
children
line wrap: on
line diff
     1.1 --- a/src/com/aurellem/capture/audio/WaveFileWriter.java	Sun Oct 30 04:43:39 2011 -0700
     1.2 +++ b/src/com/aurellem/capture/audio/WaveFileWriter.java	Sun Oct 30 08:10:26 2011 -0700
     1.3 @@ -17,12 +17,11 @@
     1.4  
     1.5  	public File targetFile;
     1.6  	private WaveAudioOutputStream wao;
     1.7 -
     1.8 +	private boolean initialized = false;
     1.9 +	private FileOutputStream fos;
    1.10 +	
    1.11  	public WaveFileWriter(File targetFile) throws FileNotFoundException{
    1.12 -		wao = new WaveAudioOutputStream(new AudioFormat(44100.0f, 32, 1, true, false),
    1.13 -				AudioSystem.NOT_SPECIFIED, 
    1.14 -				(TDataOutputStream) new TNonSeekableDataOutputStream(
    1.15 -						new FileOutputStream(targetFile)));
    1.16 +		this.fos = new FileOutputStream(targetFile);
    1.17  	}
    1.18  
    1.19  	public void cleanup() {
    1.20 @@ -30,8 +29,17 @@
    1.21  		catch (IOException e) {e.printStackTrace();}
    1.22  	}
    1.23  
    1.24 -
    1.25 -	public void process(ByteBuffer audioSamples, int numSamples) {
    1.26 +	private void initiaize(AudioFormat format){
    1.27 +		wao = new WaveAudioOutputStream(format,
    1.28 +				(long)AudioSystem.NOT_SPECIFIED, 
    1.29 +				(TDataOutputStream) new TNonSeekableDataOutputStream(
    1.30 +						fos));
    1.31 +	}
    1.32 +	
    1.33 +	public void process(ByteBuffer audioSamples, AudioFormat format, int numSamples) {
    1.34 +		
    1.35 +		if (!initialized){initiaize(format);}	
    1.36 +		
    1.37  		byte[] data = new byte[numSamples];
    1.38  		audioSamples.get(data, 0, numSamples);
    1.39  		try {wao.write(data, 0, numSamples);}