comparison src/com/aurellem/capture/audio/AudioSendRenderer.java @ 29:9f58273090df

added AudioFormat to AudioSendRenderer
author Robert McIntyre <rlm@mit.edu>
date Sun, 30 Oct 2011 10:06:38 -0700
parents 8a6b1684f536
children be37291c62b8
comparison
equal deleted inserted replaced
26:95648b0c12bc 29:9f58273090df
5 import java.util.HashMap; 5 import java.util.HashMap;
6 import java.util.Vector; 6 import java.util.Vector;
7 import java.util.concurrent.CountDownLatch; 7 import java.util.concurrent.CountDownLatch;
8 import java.util.logging.Level; 8 import java.util.logging.Level;
9 import java.util.logging.Logger; 9 import java.util.logging.Logger;
10
11 import javax.sound.sampled.AudioFormat;
10 12
11 import org.lwjgl.LWJGLException; 13 import org.lwjgl.LWJGLException;
12 import org.lwjgl.openal.AL; 14 import org.lwjgl.openal.AL;
13 import org.lwjgl.openal.AL10; 15 import org.lwjgl.openal.AL10;
14 import org.lwjgl.openal.ALCdevice; 16 import org.lwjgl.openal.ALCdevice;
23 public class AudioSendRenderer 25 public class AudioSendRenderer
24 26
25 extends LwjglAudioRenderer implements MultiListener { 27 extends LwjglAudioRenderer implements MultiListener {
26 28
27 private AudioSend audioSend; 29 private AudioSend audioSend;
30 private static final AudioFormat outFormat = new AudioFormat(44100.0f, 32, 1, true, false);
28 31
29 /** 32 /**
30 * Keeps track of all the listeners which have been registered so far. 33 * Keeps track of all the listeners which have been registered so far.
31 * The first element is <code>null</code>, which represents the zeroth 34 * The first element is <code>null</code>, which represents the zeroth
32 * LWJGL listener which is created automatically. 35 * LWJGL listener which is created automatically.
100 * instead to buffers which it makes available via JNI. 103 * instead to buffers which it makes available via JNI.
101 */ 104 */
102 public void initInThread(){ 105 public void initInThread(){
103 try{ 106 try{
104 if (!AL.isCreated()){ 107 if (!AL.isCreated()){
105 AL.create("Multiple Audio Send", 44100, 60, false); 108 AL.create("Multiple Audio Send", (int) outFormat.getSampleRate(), 60, false);
106 } 109 }
107 }catch (OpenALException ex){ 110 }catch (OpenALException ex){
108 logger.log(Level.SEVERE, "Failed to load audio library", ex); 111 logger.log(Level.SEVERE, "Failed to load audio library", ex);
109 System.exit(1); 112 System.exit(1);
110 return; 113 return;
164 } 167 }
165 } 168 }
166 } 169 }
167 170
168 171
169 public final static int BYTES_PER_SAMPLE = 4; 172 //public final static int BYTES_PER_SAMPLE = 4;
170 private ByteBuffer buffer = BufferUtils.createByteBuffer(4096); 173 private ByteBuffer buffer = BufferUtils.createByteBuffer(4096);
171 174
172 public void dispatchAudio(float tpf){ 175 public void dispatchAudio(float tpf){
173 int samplesToGet = (int) (tpf * 44100); 176 int samplesToGet = (int) (tpf * outFormat.getSampleRate());
174 try {latch.await();} 177 try {latch.await();}
175 catch (InterruptedException e) {e.printStackTrace();} 178 catch (InterruptedException e) {e.printStackTrace();}
176 audioSend.step(samplesToGet); 179 audioSend.step(samplesToGet);
177 updateAllListeners(); 180 updateAllListeners();
178 181
179 for (int i = 0; i < this.listeners.size(); i++){ 182 for (int i = 0; i < this.listeners.size(); i++){
180 buffer.clear(); 183 buffer.clear();
181 audioSend.getSamples(buffer, samplesToGet, i); 184 audioSend.getSamples(buffer, samplesToGet, i);
182 SoundProcessor sp = 185 SoundProcessor sp =
183 this.soundProcessorMap.get(this.listeners.get(i)); 186 this.soundProcessorMap.get(this.listeners.get(i));
184 if (null != sp){sp.process(buffer, samplesToGet*BYTES_PER_SAMPLE);} 187 if (null != sp){sp.process(buffer, samplesToGet*outFormat.getFrameSize());}
185 } 188 }
186 189
187 } 190 }
188 191
189 public void update(float tpf){ 192 public void update(float tpf){