Mercurial > jmeCapture
diff src/com/aurellem/capture/WaveFileWriter.java @ 3:a92de00f0414
migrating files
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 25 Oct 2011 11:55:55 -0700 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/com/aurellem/capture/WaveFileWriter.java Tue Oct 25 11:55:55 2011 -0700 1.3 @@ -0,0 +1,46 @@ 1.4 +package com.aurellem.capture; 1.5 + 1.6 +import java.io.ByteArrayInputStream; 1.7 +import java.io.File; 1.8 +import java.io.IOException; 1.9 +import java.nio.ByteBuffer; 1.10 +import java.util.Vector; 1.11 + 1.12 +import javax.sound.sampled.AudioFileFormat; 1.13 +import javax.sound.sampled.AudioFormat; 1.14 +import javax.sound.sampled.AudioInputStream; 1.15 +import javax.sound.sampled.AudioSystem; 1.16 + 1.17 +public class WaveFileWriter implements SoundProcessor { 1.18 + 1.19 + public Vector<Byte> fullWaveData = new Vector<Byte>(); 1.20 + public File targetFile; 1.21 + 1.22 + public WaveFileWriter(File targetFile){ 1.23 + this.targetFile = targetFile; 1.24 + } 1.25 + 1.26 + public void cleanup() { 1.27 + byte[] data = new byte[this.fullWaveData.size()]; 1.28 + 1.29 + for (int i = 0; i < this.fullWaveData.size(); i++){ 1.30 + data[i] = this.fullWaveData.get(i);} 1.31 + 1.32 + 1.33 + ByteArrayInputStream input = new ByteArrayInputStream(data); 1.34 + AudioFormat format = new AudioFormat(44100.0f, 32, 1, true, false); 1.35 + AudioInputStream audioInput = new AudioInputStream(input, format, data.length / 4 ); 1.36 + try {AudioSystem.write(audioInput, AudioFileFormat.Type.WAVE, targetFile);} 1.37 + catch (IOException e) {e.printStackTrace();} 1.38 + 1.39 + } 1.40 + 1.41 + 1.42 + public void process(ByteBuffer audioSamples, int numSamples) { 1.43 + for (int i = 0; i<numSamples; i++){ 1.44 + Byte b = audioSamples.get(i); 1.45 + fullWaveData.add(b); 1.46 + } 1.47 + } 1.48 + 1.49 +}