diff src/com/aurellem/capture/audio/WaveFileWriter.java @ 68:302d5e9ad120

adjust format
author Robert McIntyre <rlm@mit.edu>
date Thu, 19 Jul 2012 12:28:55 -0500
parents d799a0278cc9
children
line wrap: on
line diff
     1.1 --- a/src/com/aurellem/capture/audio/WaveFileWriter.java	Tue Feb 28 11:17:04 2012 -0600
     1.2 +++ b/src/com/aurellem/capture/audio/WaveFileWriter.java	Thu Jul 19 12:28:55 2012 -0500
     1.3 @@ -21,37 +21,38 @@
     1.4  
     1.5  public class WaveFileWriter implements SoundProcessor {
     1.6  
     1.7 -	public File targetFile;
     1.8 -	private WaveAudioOutputStream wao;
     1.9 -	private TDataOutputStream tos;
    1.10 -	private boolean initialized = false;
    1.11 +    public File targetFile;
    1.12 +    private WaveAudioOutputStream wao;
    1.13 +    private TDataOutputStream tos;
    1.14 +    private boolean initialized = false;
    1.15  	
    1.16 -	public WaveFileWriter(File targetFile) throws FileNotFoundException{
    1.17 -		tos = new TNonSeekableDataOutputStream(
    1.18 -				new FileOutputStream(targetFile));
    1.19 -	}
    1.20 +    public WaveFileWriter(File targetFile) 
    1.21 +	throws FileNotFoundException{
    1.22 +	tos = new TNonSeekableDataOutputStream
    1.23 +	    (new FileOutputStream(targetFile));
    1.24 +    }
    1.25  
    1.26 -	public void init(AudioFormat format){
    1.27 -		wao = new WaveAudioOutputStream(format,AudioSystem.NOT_SPECIFIED, tos);
    1.28 +    public void init(AudioFormat format){
    1.29 +	wao = new WaveAudioOutputStream(format,AudioSystem.NOT_SPECIFIED, tos);
    1.30 +    }
    1.31 +		
    1.32 +    public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) {
    1.33 +	audioSamples.clear();
    1.34 +	if (!initialized){
    1.35 +	    init(format);
    1.36 +	    initialized = true;
    1.37  	}
    1.38  		
    1.39 -	public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) {
    1.40 -		audioSamples.clear();
    1.41 -		if (!initialized){
    1.42 -			init(format);
    1.43 -			initialized = true;
    1.44 -		}
    1.45 -		
    1.46 -		byte[] data = new byte[numSamples];
    1.47 -		audioSamples.get(data, 0, numSamples);
    1.48 -		try {wao.write(data, 0, numSamples);}
    1.49 -		catch (IOException e) {e.printStackTrace();}
    1.50 -	}
    1.51 +	byte[] data = new byte[numSamples];
    1.52 +	audioSamples.get(data, 0, numSamples);
    1.53 +	try {wao.write(data, 0, numSamples);}
    1.54 +	catch (IOException e) {e.printStackTrace();}
    1.55 +    }
    1.56  
    1.57 -	public void cleanup() {
    1.58 -		try {wao.close();}
    1.59 -		catch (IOException e) {e.printStackTrace();}
    1.60 -	}
    1.61 +    public void cleanup() {
    1.62 +	try {wao.close();}
    1.63 +	catch (IOException e) {e.printStackTrace();}
    1.64 +    }
    1.65  
    1.66  
    1.67  }