comparison data/fileio/CodedAudioFileReader.cpp @ 1286:40c042780bc9 3.0-integration

A bit more diagnostic info
author Chris Cannam
date Wed, 23 Nov 2016 14:34:27 +0000
parents 757a406dabc4
children 5cc969b236b0
comparison
equal deleted inserted replaced
1285:757a406dabc4 1286:40c042780bc9
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), 51 m_clippedCount(0),
52 m_firstNonzero(0) 52 m_firstNonzero(0),
53 m_lastNonzero(0)
53 { 54 {
54 SVDEBUG << "CodedAudioFileReader:: cache mode: " << cacheMode 55 SVDEBUG << "CodedAudioFileReader:: cache mode: " << cacheMode
55 << " (" << (cacheMode == CacheInTemporaryFile 56 << " (" << (cacheMode == CacheInTemporaryFile
56 ? "CacheInTemporaryFile" : "CacheInMemory") << ")" 57 ? "CacheInTemporaryFile" : "CacheInMemory") << ")"
57 << ", rate: " << targetRate 58 << ", rate: " << targetRate
344 << " frames" << endl; 345 << " frames" << endl;
345 } 346 }
346 SVDEBUG << "CodedAudioFileReader: Signal abs max is " << m_max 347 SVDEBUG << "CodedAudioFileReader: Signal abs max is " << m_max
347 << ", " << m_clippedCount 348 << ", " << m_clippedCount
348 << " samples clipped, first non-zero frame is at " 349 << " samples clipped, first non-zero frame is at "
349 << m_firstNonzero << endl; 350 << m_firstNonzero << ", last at " << m_lastNonzero << endl;
350 if (m_normalised) { 351 if (m_normalised) {
351 SVDEBUG << "CodedAudioFileReader: Normalising, gain is " << m_gain << endl; 352 SVDEBUG << "CodedAudioFileReader: Normalising, gain is " << m_gain << endl;
352 } 353 }
353 } 354 }
354 355
373 CodedAudioFileReader::pushBufferNonResampling(float *buffer, sv_frame_t sz) 374 CodedAudioFileReader::pushBufferNonResampling(float *buffer, sv_frame_t sz)
374 { 375 {
375 float clip = 1.0; 376 float clip = 1.0;
376 sv_frame_t count = sz * m_channelCount; 377 sv_frame_t count = sz * m_channelCount;
377 378
378 if (m_normalised) { 379 for (sv_frame_t j = 0; j < sz; ++j) {
379 for (sv_frame_t i = 0; i < count; ++i) { 380 for (int c = 0; c < m_channelCount; ++c) {
380 float v = fabsf(buffer[i]); 381 sv_frame_t i = j * m_channelCount + c;
381 if (m_firstNonzero == 0 && v != 0.f) {
382 m_firstNonzero = m_frameCount + i;
383 }
384 if (v > m_max) {
385 m_max = v;
386 m_gain = 1.f / m_max;
387 }
388 }
389 } else {
390 for (sv_frame_t i = 0; i < count; ++i) {
391 float v = buffer[i]; 382 float v = buffer[i];
392 if (v > clip) { 383 if (!m_normalised) {
393 buffer[i] = clip; 384 if (v > clip) {
394 ++m_clippedCount; 385 buffer[i] = clip;
395 } else if (v < -clip) { 386 ++m_clippedCount;
396 buffer[i] = -clip; 387 } else if (v < -clip) {
397 ++m_clippedCount; 388 buffer[i] = -clip;
389 ++m_clippedCount;
390 }
398 } 391 }
399 v = fabsf(v); 392 v = fabsf(v);
400 if (m_firstNonzero == 0 && v != 0.f) { 393 if (v != 0.f) {
401 m_firstNonzero = m_frameCount + i; 394 if (m_firstNonzero == 0) {
402 } 395 m_firstNonzero = m_frameCount;
403 if (v > m_max) { 396 }
404 m_max = v; 397 m_lastNonzero = m_frameCount;
405 } 398 if (v > m_max) {
406 } 399 m_max = v;
407 } 400 }
408 401 }
409 m_frameCount += sz; 402 }
403 ++m_frameCount;
404 }
405
406 if (m_max > 0.f) {
407 m_gain = 1.f / m_max; // used when normalising only
408 }
410 409
411 switch (m_cacheMode) { 410 switch (m_cacheMode) {
412 411
413 case CacheInTemporaryFile: 412 case CacheInTemporaryFile:
414 if (sf_writef_float(m_cacheFileWritePtr, buffer, sz) < sz) { 413 if (sf_writef_float(m_cacheFileWritePtr, buffer, sz) < sz) {