comparison src/com/aurellem/capture/audio/AudioSendRenderer.java @ 27:5249c8a9603c

changed SoundProcessors to use AudioFormat
author Robert McIntyre <rlm@mit.edu>
date Sun, 30 Oct 2011 08:10:26 -0700
parents 8a6b1684f536
children 7184bc09a92e
comparison
equal deleted inserted replaced
26:95648b0c12bc 27:5249c8a9603c
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 public static final AudioFormat outputFormat = 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)outputFormat.getSampleRate(), 60, false); }
106 }
107 }catch (OpenALException ex){ 109 }catch (OpenALException ex){
108 logger.log(Level.SEVERE, "Failed to load audio library", ex); 110 logger.log(Level.SEVERE, "Failed to load audio library", ex);
109 System.exit(1); 111 System.exit(1);
110 return; 112 return;
111 }catch (LWJGLException ex){ 113 }catch (LWJGLException ex){
164 } 166 }
165 } 167 }
166 } 168 }
167 169
168 170
169 public final static int BYTES_PER_SAMPLE = 4; 171
170 private ByteBuffer buffer = BufferUtils.createByteBuffer(4096); 172 private ByteBuffer buffer = BufferUtils.createByteBuffer(4096);
171 173
172 public void dispatchAudio(float tpf){ 174 public void dispatchAudio(float tpf){
173 int samplesToGet = (int) (tpf * 44100); 175 int samplesToGet = (int) (tpf * outputFormat.getSampleRate());
174 try {latch.await();} 176 try {latch.await();}
175 catch (InterruptedException e) {e.printStackTrace();} 177 catch (InterruptedException e) {e.printStackTrace();}
176 audioSend.step(samplesToGet); 178 audioSend.step(samplesToGet);
177 updateAllListeners(); 179 updateAllListeners();
178 180
179 for (int i = 0; i < this.listeners.size(); i++){ 181 for (int i = 0; i < this.listeners.size(); i++){
180 buffer.clear(); 182 buffer.clear();
181 audioSend.getSamples(buffer, samplesToGet, i); 183 audioSend.getSamples(buffer, samplesToGet, i);
182 SoundProcessor sp = 184 SoundProcessor sp =
183 this.soundProcessorMap.get(this.listeners.get(i)); 185 this.soundProcessorMap.get(this.listeners.get(i));
184 if (null != sp){sp.process(buffer, samplesToGet*BYTES_PER_SAMPLE);} 186 if (null != sp){sp.process(buffer, outputFormat,
187 samplesToGet*outputFormat.getSampleSizeInBits()/8);}
185 } 188 }
186 189
187 } 190 }
188 191
189 public void update(float tpf){ 192 public void update(float tpf){