Mercurial > jmeCapture
comparison src/com/aurellem/capture/audio/WaveFileWriter.java @ 9:5dfc9e768816
moved files
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 26 Oct 2011 08:54:12 -0700 |
parents | |
children | 8a6b1684f536 |
comparison
equal
deleted
inserted
replaced
8:dde12be02029 | 9:5dfc9e768816 |
---|---|
1 package com.aurellem.capture.audio; | |
2 | |
3 import java.io.ByteArrayInputStream; | |
4 import java.io.File; | |
5 import java.io.IOException; | |
6 import java.nio.ByteBuffer; | |
7 import java.util.Vector; | |
8 | |
9 import javax.sound.sampled.AudioFileFormat; | |
10 import javax.sound.sampled.AudioFormat; | |
11 import javax.sound.sampled.AudioInputStream; | |
12 import javax.sound.sampled.AudioSystem; | |
13 | |
14 public class WaveFileWriter implements SoundProcessor { | |
15 | |
16 public Vector<Byte> fullWaveData = new Vector<Byte>(); | |
17 public File targetFile; | |
18 | |
19 public WaveFileWriter(File targetFile){ | |
20 this.targetFile = targetFile; | |
21 } | |
22 | |
23 public void cleanup() { | |
24 byte[] data = new byte[this.fullWaveData.size()]; | |
25 | |
26 for (int i = 0; i < this.fullWaveData.size(); i++){ | |
27 data[i] = this.fullWaveData.get(i);} | |
28 | |
29 | |
30 ByteArrayInputStream input = new ByteArrayInputStream(data); | |
31 AudioFormat format = new AudioFormat(44100.0f, 32, 1, true, false); | |
32 AudioInputStream audioInput = new AudioInputStream(input, format, data.length / 4 ); | |
33 try {AudioSystem.write(audioInput, AudioFileFormat.Type.WAVE, targetFile);} | |
34 catch (IOException e) {e.printStackTrace();} | |
35 | |
36 } | |
37 | |
38 | |
39 public void process(ByteBuffer audioSamples, int numSamples) { | |
40 for (int i = 0; i<numSamples; i++){ | |
41 Byte b = audioSamples.get(i); | |
42 fullWaveData.add(b); | |
43 } | |
44 } | |
45 | |
46 } |