Mercurial > jmeCapture
comparison src/com/aurellem/capture/audio/AudioSendRenderer.java @ 38:adeb88787645
fixed all problems for 16 bit mono output
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 31 Oct 2011 07:43:44 -0700 |
parents | 2a525e937d86 |
children | 784a3f4e6202 |
comparison
equal
deleted
inserted
replaced
37:094a92b556a2 | 38:adeb88787645 |
---|---|
25 public class AudioSendRenderer | 25 public class AudioSendRenderer |
26 | 26 |
27 extends LwjglAudioRenderer implements MultiListener { | 27 extends LwjglAudioRenderer implements MultiListener { |
28 | 28 |
29 private AudioSend audioSend; | 29 private AudioSend audioSend; |
30 private static final AudioFormat outFormat = new AudioFormat(44100.0f, 32, 1, true, false); | 30 private AudioFormat outFormat;// = new AudioFormat(44100.0f, 32, 1, true, false); |
31 | 31 |
32 /** | 32 /** |
33 * 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. |
34 * The first element is <code>null</code>, which represents the zeroth | 34 * The first element is <code>null</code>, which represents the zeroth |
35 * LWJGL listener which is created automatically. | 35 * LWJGL listener which is created automatically. |
104 * instead to buffers which it makes available via JNI. | 104 * instead to buffers which it makes available via JNI. |
105 */ | 105 */ |
106 public void initInThread(){ | 106 public void initInThread(){ |
107 try{ | 107 try{ |
108 if (!AL.isCreated()){ | 108 if (!AL.isCreated()){ |
109 AL.create("Multiple Audio Send", (int) outFormat.getSampleRate(), 60, false); | 109 AL.create("Multiple Audio Send", 44100, 60, false); |
110 } | 110 } |
111 }catch (OpenALException ex){ | 111 }catch (OpenALException ex){ |
112 logger.log(Level.SEVERE, "Failed to load audio library", ex); | 112 logger.log(Level.SEVERE, "Failed to load audio library", ex); |
113 System.exit(1); | 113 System.exit(1); |
114 return; | 114 return; |
132 deviceIDField.setAccessible(false);} | 132 deviceIDField.setAccessible(false);} |
133 catch (SecurityException e) {e.printStackTrace();} | 133 catch (SecurityException e) {e.printStackTrace();} |
134 catch (NoSuchFieldException e) {e.printStackTrace();} | 134 catch (NoSuchFieldException e) {e.printStackTrace();} |
135 | 135 |
136 this.audioSend = new AudioSend(this.deviceID); | 136 this.audioSend = new AudioSend(this.deviceID); |
137 this.outFormat = audioSend.getAudioFormat(); | |
138 initBuffer(); | |
139 System.out.println(outFormat); | |
137 | 140 |
138 // The LWJGL context must be established as the master context before | 141 // The LWJGL context must be established as the master context before |
139 // any other listeners can be created on this device. | 142 // any other listeners can be created on this device. |
140 audioSend.initDevice(); | 143 audioSend.initDevice(); |
141 // Now, everything is initialized, and it is safe to add more listeners. | 144 // Now, everything is initialized, and it is safe to add more listeners. |
169 } | 172 } |
170 } | 173 } |
171 | 174 |
172 | 175 |
173 //public final static int BYTES_PER_SAMPLE = 4; | 176 //public final static int BYTES_PER_SAMPLE = 4; |
174 private ByteBuffer buffer = BufferUtils.createByteBuffer(4096); | 177 |
175 | 178 |
176 private byte[] debug0 = new byte[4096]; | 179 private ByteBuffer buffer;; |
177 private byte[] debug1 = new byte[4096]; | 180 private byte[] debug0; |
178 | 181 private byte[] debug1; |
179 | 182 |
183 public static final int MIN_FRAMERATE = 10; | |
184 | |
185 private void initBuffer(){ | |
186 int bufferSize = (int)(this.outFormat.getSampleRate() / ((float)MIN_FRAMERATE)) * | |
187 this.outFormat.getFrameSize(); | |
188 this.buffer = BufferUtils.createByteBuffer(bufferSize); | |
189 debug0 = new byte[4096]; | |
190 debug1 = new byte[4096]; | |
191 | |
192 } | |
193 /* | |
194 | |
195 */ | |
180 public void dispatchAudio(float tpf){ | 196 public void dispatchAudio(float tpf){ |
181 | 197 |
182 int samplesToGet = (int) (tpf * outFormat.getSampleRate()); | 198 int samplesToGet = (int) (tpf * outFormat.getSampleRate()); |
199 System.out.println("want " + samplesToGet + " samples"); | |
183 try {latch.await();} | 200 try {latch.await();} |
184 catch (InterruptedException e) {e.printStackTrace();} | 201 catch (InterruptedException e) {e.printStackTrace();} |
185 audioSend.step(samplesToGet); | 202 audioSend.step(samplesToGet); |
186 updateAllListeners(); | 203 updateAllListeners(); |
187 | 204 |