view src/com/aurellem/capture/audio/WaveFileWriter.java @ 25:25fcf5fda505

removed warnings
author Robert McIntyre <rlm@mit.edu>
date Sun, 30 Oct 2011 04:43:05 -0700
parents 5f616cc420dd
children 95648b0c12bc
line wrap: on
line source
1 package com.aurellem.capture.audio;
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;
16 public class WaveFileWriter implements SoundProcessor {
18 public File targetFile;
19 private WaveAudioOutputStream wao;
21 public WaveFileWriter(File targetFile) throws FileNotFoundException{
22 wao = new WaveAudioOutputStream(new AudioFormat(44100.0f, 32, 1, true, false),
23 AudioSystem.NOT_SPECIFIED,
24 (TDataOutputStream) new TNonSeekableDataOutputStream(new FileOutputStream(targetFile)));
25 }
27 public void cleanup() {
28 try {wao.close();}
29 catch (IOException e) {e.printStackTrace();}
30 }
33 public void process(ByteBuffer audioSamples, int numSamples) {
34 byte[] data = new byte[numSamples];
35 audioSamples.get(data, 0, numSamples);
37 try {wao.write(data, 0, numSamples);}
38 catch (IOException e) {e.printStackTrace();}
39 }
40 }