comparison data/fileio/CodedAudioFileReader.cpp @ 1285:757a406dabc4 3.0-integration

More diagnostic output
author Chris Cannam
date Wed, 23 Nov 2016 13:57:36 +0000
parents 56c06dc0937c
children 40c042780bc9
comparison
equal deleted inserted replaced
1284:16a8e97179d7 1285:757a406dabc4
45 m_resampler(0), 45 m_resampler(0),
46 m_resampleBuffer(0), 46 m_resampleBuffer(0),
47 m_fileFrameCount(0), 47 m_fileFrameCount(0),
48 m_normalised(normalised), 48 m_normalised(normalised),
49 m_max(0.f), 49 m_max(0.f),
50 m_gain(1.f) 50 m_gain(1.f),
51 m_clippedCount(0),
52 m_firstNonzero(0)
51 { 53 {
52 SVDEBUG << "CodedAudioFileReader:: cache mode: " << cacheMode 54 SVDEBUG << "CodedAudioFileReader:: cache mode: " << cacheMode
53 << " (" << (cacheMode == CacheInTemporaryFile 55 << " (" << (cacheMode == CacheInTemporaryFile
54 ? "CacheInTemporaryFile" : "CacheInMemory") << ")" 56 ? "CacheInTemporaryFile" : "CacheInMemory") << ")"
55 << ", rate: " << targetRate 57 << ", rate: " << targetRate
332 // I know, I know, we already allocated it... 334 // I know, I know, we already allocated it...
333 StorageAdviser::notifyPlannedAllocation 335 StorageAdviser::notifyPlannedAllocation
334 (StorageAdviser::MemoryAllocation, 336 (StorageAdviser::MemoryAllocation,
335 (m_data.size() * sizeof(float)) / 1024); 337 (m_data.size() * sizeof(float)) / 1024);
336 } 338 }
339
340 SVDEBUG << "CodedAudioFileReader: File decodes to " << m_fileFrameCount
341 << " frames" << endl;
342 if (m_fileFrameCount != m_frameCount) {
343 SVDEBUG << "CodedAudioFileReader: Resampled to " << m_frameCount
344 << " frames" << endl;
345 }
346 SVDEBUG << "CodedAudioFileReader: Signal abs max is " << m_max
347 << ", " << m_clippedCount
348 << " samples clipped, first non-zero frame is at "
349 << m_firstNonzero << endl;
350 if (m_normalised) {
351 SVDEBUG << "CodedAudioFileReader: Normalising, gain is " << m_gain << endl;
352 }
337 } 353 }
338 354
339 void 355 void
340 CodedAudioFileReader::pushBuffer(float *buffer, sv_frame_t sz, bool final) 356 CodedAudioFileReader::pushBuffer(float *buffer, sv_frame_t sz, bool final)
341 { 357 {
360 sv_frame_t count = sz * m_channelCount; 376 sv_frame_t count = sz * m_channelCount;
361 377
362 if (m_normalised) { 378 if (m_normalised) {
363 for (sv_frame_t i = 0; i < count; ++i) { 379 for (sv_frame_t i = 0; i < count; ++i) {
364 float v = fabsf(buffer[i]); 380 float v = fabsf(buffer[i]);
381 if (m_firstNonzero == 0 && v != 0.f) {
382 m_firstNonzero = m_frameCount + i;
383 }
365 if (v > m_max) { 384 if (v > m_max) {
366 m_max = v; 385 m_max = v;
367 m_gain = 1.f / m_max; 386 m_gain = 1.f / m_max;
368 } 387 }
369 } 388 }
370 } else { 389 } else {
371 for (sv_frame_t i = 0; i < count; ++i) { 390 for (sv_frame_t i = 0; i < count; ++i) {
372 if (buffer[i] > clip) buffer[i] = clip; 391 float v = buffer[i];
373 } 392 if (v > clip) {
374 for (sv_frame_t i = 0; i < count; ++i) { 393 buffer[i] = clip;
375 if (buffer[i] < -clip) buffer[i] = -clip; 394 ++m_clippedCount;
395 } else if (v < -clip) {
396 buffer[i] = -clip;
397 ++m_clippedCount;
398 }
399 v = fabsf(v);
400 if (m_firstNonzero == 0 && v != 0.f) {
401 m_firstNonzero = m_frameCount + i;
402 }
403 if (v > m_max) {
404 m_max = v;
405 }
376 } 406 }
377 } 407 }
378 408
379 m_frameCount += sz; 409 m_frameCount += sz;
380 410
388 } 418 }
389 break; 419 break;
390 420
391 case CacheInMemory: 421 case CacheInMemory:
392 m_dataLock.lock(); 422 m_dataLock.lock();
423 /*
424 if (m_data.size() < 5120) {
425 for (int i = 0; i < count && i < 5120; ++i) {
426 if (i % 8 == 0) cerr << i << ": ";
427 cerr << buffer[i] << " ";
428 if (i % 8 == 7) cerr << endl;
429 }
430 }
431 cerr << endl;
432 */
393 m_data.insert(m_data.end(), buffer, buffer + count); 433 m_data.insert(m_data.end(), buffer, buffer + count);
394 m_dataLock.unlock(); 434 m_dataLock.unlock();
395 break; 435 break;
396 } 436 }
397 } 437 }