comparison audioio/AudioPortAudioTarget.cpp @ 371:dfcc5b355f33

Merge from branch warnfix_no_size_t
author Chris Cannam
date Wed, 18 Jun 2014 13:51:38 +0100
parents 0876ea394902
children 1162c93e7688
comparison
equal deleted inserted replaced
355:e7a3fa8f4eec 371:dfcc5b355f33
216 float *output = (float *)outputBuffer; 216 float *output = (float *)outputBuffer;
217 217
218 assert(nframes <= m_bufferSize); 218 assert(nframes <= m_bufferSize);
219 219
220 static float **tmpbuf = 0; 220 static float **tmpbuf = 0;
221 static size_t tmpbufch = 0; 221 static int tmpbufch = 0;
222 static size_t tmpbufsz = 0; 222 static int tmpbufsz = 0;
223 223
224 size_t sourceChannels = m_source->getSourceChannelCount(); 224 int sourceChannels = m_source->getSourceChannelCount();
225 225
226 // Because we offer pan, we always want at least 2 channels 226 // Because we offer pan, we always want at least 2 channels
227 if (sourceChannels < 2) sourceChannels = 2; 227 if (sourceChannels < 2) sourceChannels = 2;
228 228
229 if (!tmpbuf || tmpbufch != sourceChannels || int(tmpbufsz) < m_bufferSize) { 229 if (!tmpbuf || tmpbufch != sourceChannels || int(tmpbufsz) < m_bufferSize) {
230 230
231 if (tmpbuf) { 231 if (tmpbuf) {
232 for (size_t i = 0; i < tmpbufch; ++i) { 232 for (int i = 0; i < tmpbufch; ++i) {
233 delete[] tmpbuf[i]; 233 delete[] tmpbuf[i];
234 } 234 }
235 delete[] tmpbuf; 235 delete[] tmpbuf;
236 } 236 }
237 237
238 tmpbufch = sourceChannels; 238 tmpbufch = sourceChannels;
239 tmpbufsz = m_bufferSize; 239 tmpbufsz = m_bufferSize;
240 tmpbuf = new float *[tmpbufch]; 240 tmpbuf = new float *[tmpbufch];
241 241
242 for (size_t i = 0; i < tmpbufch; ++i) { 242 for (int i = 0; i < tmpbufch; ++i) {
243 tmpbuf[i] = new float[tmpbufsz]; 243 tmpbuf[i] = new float[tmpbufsz];
244 } 244 }
245 } 245 }
246 246
247 size_t received = m_source->getSourceSamples(nframes, tmpbuf); 247 int received = m_source->getSourceSamples(nframes, tmpbuf);
248 248
249 float peakLeft = 0.0, peakRight = 0.0; 249 float peakLeft = 0.0, peakRight = 0.0;
250 250
251 for (size_t ch = 0; ch < 2; ++ch) { 251 for (int ch = 0; ch < 2; ++ch) {
252 252
253 float peak = 0.0; 253 float peak = 0.0;
254 254
255 if (ch < sourceChannels) { 255 if (ch < sourceChannels) {
256 256
257 // PortAudio samples are interleaved 257 // PortAudio samples are interleaved
258 for (size_t i = 0; i < nframes; ++i) { 258 for (int i = 0; i < nframes; ++i) {
259 if (i < received) { 259 if (i < received) {
260 output[i * 2 + ch] = tmpbuf[ch][i] * m_outputGain; 260 output[i * 2 + ch] = tmpbuf[ch][i] * m_outputGain;
261 float sample = fabsf(output[i * 2 + ch]); 261 float sample = fabsf(output[i * 2 + ch]);
262 if (sample > peak) peak = sample; 262 if (sample > peak) peak = sample;
263 } else { 263 } else {
265 } 265 }
266 } 266 }
267 267
268 } else if (ch == 1 && sourceChannels == 1) { 268 } else if (ch == 1 && sourceChannels == 1) {
269 269
270 for (size_t i = 0; i < nframes; ++i) { 270 for (int i = 0; i < nframes; ++i) {
271 if (i < received) { 271 if (i < received) {
272 output[i * 2 + ch] = tmpbuf[0][i] * m_outputGain; 272 output[i * 2 + ch] = tmpbuf[0][i] * m_outputGain;
273 float sample = fabsf(output[i * 2 + ch]); 273 float sample = fabsf(output[i * 2 + ch]);
274 if (sample > peak) peak = sample; 274 if (sample > peak) peak = sample;
275 } else { 275 } else {
276 output[i * 2 + ch] = 0; 276 output[i * 2 + ch] = 0;
277 } 277 }
278 } 278 }
279 279
280 } else { 280 } else {
281 for (size_t i = 0; i < nframes; ++i) { 281 for (int i = 0; i < nframes; ++i) {
282 output[i * 2 + ch] = 0; 282 output[i * 2 + ch] = 0;
283 } 283 }
284 } 284 }
285 285
286 if (ch == 0) peakLeft = peak; 286 if (ch == 0) peakLeft = peak;