view src/com/aurellem/capture/audio/WaveFileWriter.java @ 24:5f616cc420dd

improved WaveFileWriter using tritonus
author Robert McIntyre <rlm@mit.edu>
date Sun, 30 Oct 2011 04:42:40 -0700
parents b643413c3aba
children 25fcf5fda505
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;
8 import java.util.Vector;
10 import javax.sound.sampled.AudioFormat;
11 import javax.sound.sampled.AudioSystem;
13 import org.tritonus.sampled.file.WaveAudioOutputStream;
14 import org.tritonus.share.sampled.file.TDataOutputStream;
15 import org.tritonus.share.sampled.file.TNonSeekableDataOutputStream;
17 public class WaveFileWriter implements SoundProcessor {
19 public File targetFile;
20 private WaveAudioOutputStream wao;
22 public WaveFileWriter(File targetFile) throws FileNotFoundException{
23 wao = new WaveAudioOutputStream(new AudioFormat(44100.0f, 32, 1, true, false),
24 AudioSystem.NOT_SPECIFIED,
25 (TDataOutputStream) new TNonSeekableDataOutputStream(new FileOutputStream(targetFile)));
26 }
28 public void cleanup() {
29 try {wao.close();}
30 catch (IOException e) {e.printStackTrace();}
31 }
34 public void process(ByteBuffer audioSamples, int numSamples) {
35 byte[] data = new byte[numSamples];
36 audioSamples.get(data, 0, numSamples);
38 try {wao.write(data, 0, numSamples);}
39 catch (IOException e) {e.printStackTrace();}
40 }
41 }