Mercurial > jmeCapture
comparison src/com/aurellem/capture/audio/AudioSendRenderer.java @ 39:784a3f4e6202
updating capture-video
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 03 Nov 2011 16:00:46 -0700 |
parents | adeb88787645 |
children | 2f129118e2d6 |
comparison
equal
deleted
inserted
replaced
38:adeb88787645 | 39:784a3f4e6202 |
---|---|
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(); | 137 this.outFormat = audioSend.getAudioFormat(); |
138 initBuffer(); | 138 initBuffer(); |
139 System.out.println(outFormat); | 139 |
140 | |
141 // The LWJGL context must be established as the master context before | 140 // The LWJGL context must be established as the master context before |
142 // any other listeners can be created on this device. | 141 // any other listeners can be created on this device. |
143 audioSend.initDevice(); | 142 audioSend.initDevice(); |
144 // Now, everything is initialized, and it is safe to add more listeners. | 143 // Now, everything is initialized, and it is safe to add more listeners. |
145 latch.countDown(); | 144 latch.countDown(); |
171 } | 170 } |
172 } | 171 } |
173 } | 172 } |
174 | 173 |
175 | 174 |
176 //public final static int BYTES_PER_SAMPLE = 4; | |
177 | |
178 | |
179 private ByteBuffer buffer;; | 175 private ByteBuffer buffer;; |
180 private byte[] debug0; | 176 |
181 private byte[] debug1; | |
182 | |
183 public static final int MIN_FRAMERATE = 10; | 177 public static final int MIN_FRAMERATE = 10; |
184 | 178 |
185 private void initBuffer(){ | 179 private void initBuffer(){ |
186 int bufferSize = (int)(this.outFormat.getSampleRate() / ((float)MIN_FRAMERATE)) * | 180 int bufferSize = (int)(this.outFormat.getSampleRate() / ((float)MIN_FRAMERATE)) * |
187 this.outFormat.getFrameSize(); | 181 this.outFormat.getFrameSize(); |
188 this.buffer = BufferUtils.createByteBuffer(bufferSize); | 182 this.buffer = BufferUtils.createByteBuffer(bufferSize); |
189 debug0 = new byte[4096]; | |
190 debug1 = new byte[4096]; | |
191 | |
192 } | 183 } |
193 /* | 184 /* |
194 | 185 |
195 */ | 186 */ |
196 public void dispatchAudio(float tpf){ | 187 public void dispatchAudio(float tpf){ |
197 | 188 |
198 int samplesToGet = (int) (tpf * outFormat.getSampleRate()); | 189 int samplesToGet = (int) (tpf * outFormat.getSampleRate()); |
199 System.out.println("want " + samplesToGet + " samples"); | |
200 try {latch.await();} | 190 try {latch.await();} |
201 catch (InterruptedException e) {e.printStackTrace();} | 191 catch (InterruptedException e) {e.printStackTrace();} |
202 audioSend.step(samplesToGet); | 192 audioSend.step(samplesToGet); |
203 updateAllListeners(); | 193 updateAllListeners(); |
204 | 194 |
205 for (int i = 0; i < this.listeners.size(); i++){ | 195 for (int i = 0; i < this.listeners.size(); i++){ |
206 buffer.clear(); | 196 buffer.clear(); |
207 audioSend.getSamples(buffer, samplesToGet, i); | 197 audioSend.getSamples(buffer, samplesToGet, i); |
208 if (i == 0 ) buffer.get(debug0); | |
209 if (i == 1 ) buffer.get(debug1); | |
210 SoundProcessor sp = | 198 SoundProcessor sp = |
211 this.soundProcessorMap.get(this.listeners.get(i)); | 199 this.soundProcessorMap.get(this.listeners.get(i)); |
212 if (null != sp){sp.process(buffer, samplesToGet*outFormat.getFrameSize(), outFormat);} | 200 if (null != sp){sp.process(buffer, samplesToGet*outFormat.getFrameSize(), outFormat);} |
213 } | 201 } |
214 | 202 |
215 for (int i = 0; i < samplesToGet; i++){ | |
216 if (debug1[i] != debug0[i]){ | |
217 System.out.println("inconsistency detected @ sample " + i); | |
218 System.out.println("main : " + debug0[i]); | |
219 System.out.println("aux : " + debug1[i]); | |
220 | |
221 break; | |
222 } | |
223 | |
224 } | |
225 | |
226 } | 203 } |
227 | 204 |
228 public void update(float tpf){ | 205 public void update(float tpf){ |
229 super.update(tpf); | 206 super.update(tpf); |
230 dispatchAudio(tpf); | 207 dispatchAudio(tpf); |