# HG changeset patch # User Chris Cannam # Date 1426074725 0 # Node ID 48e4ffa9fb4841cbbed91d8d304604a4552c5539 # Parent e603b44510c38da3246ffa936b76c97db92c9445 Minor simplification; could use more diff -r e603b44510c3 -r 48e4ffa9fb48 data/fileio/WavFileReader.cpp --- a/data/fileio/WavFileReader.cpp Wed Mar 11 11:03:22 2015 +0000 +++ b/data/fileio/WavFileReader.cpp Wed Mar 11 11:52:05 2015 +0000 @@ -140,8 +140,6 @@ count = m_fileInfo.frames - start; } - sf_count_t readCount = 0; - if (start != m_lastStart || count != m_lastCount) { if (sf_seek(m_file, start, SEEK_SET) < 0) { @@ -151,10 +149,14 @@ sv_frame_t n = count * m_fileInfo.channels; m_buffer.resize(n); + sf_count_t readCount = 0; + if ((readCount = sf_readf_float(m_file, m_buffer.data(), count)) < 0) { return SampleBlock(); } + m_buffer.resize(readCount * m_fileInfo.channels); + m_lastStart = start; m_lastCount = readCount; } diff -r e603b44510c3 -r 48e4ffa9fb48 data/model/RangeSummarisableTimeValueModel.h --- a/data/model/RangeSummarisableTimeValueModel.h Wed Mar 11 11:03:22 2015 +0000 +++ b/data/model/RangeSummarisableTimeValueModel.h Wed Mar 11 11:52:05 2015 +0000 @@ -41,21 +41,33 @@ { public: Range() : - m_min(0.f), m_max(0.f), m_absmean(0.f) { } + m_new(true), m_min(0.f), m_max(0.f), m_absmean(0.f) { } Range(const Range &r) : - m_min(r.m_min), m_max(r.m_max), m_absmean(r.m_absmean) { } + m_new(true), m_min(r.m_min), m_max(r.m_max), m_absmean(r.m_absmean) { } Range(float min, float max, float absmean) : - m_min(min), m_max(max), m_absmean(absmean) { } + m_new(true), m_min(min), m_max(max), m_absmean(absmean) { } float min() const { return m_min; } float max() const { return m_max; } float absmean() const { return m_absmean; } - void setMin(float min) { m_min = min; } - void setMax(float max) { m_max = max; } + void setMin(float min) { m_min = min; m_new = false; } + void setMax(float max) { m_max = max; m_new = false; } void setAbsmean(float absmean) { m_absmean = absmean; } + void sample(float s) { + if (m_new) { + m_min = s; + m_max = s; + m_new = false; + } else { + if (s < m_min) m_min = s; + if (s > m_max) m_max = s; + } + } + private: + bool m_new; float m_min; float m_max; float m_absmean; diff -r e603b44510c3 -r 48e4ffa9fb48 data/model/WaveFileModel.cpp --- a/data/model/WaveFileModel.cpp Wed Mar 11 11:03:22 2015 +0000 +++ b/data/model/WaveFileModel.cpp Wed Mar 11 11:52:05 2015 +0000 @@ -667,7 +667,7 @@ sqrt(2.) + 0.01)); sv_frame_t frame = 0; - sv_frame_t readBlockSize = 16384; + const sv_frame_t readBlockSize = 16384; SampleBlock block; if (!m_model.isOK()) return; @@ -719,17 +719,10 @@ sv_frame_t index = channels * i + ch; float sample = block[index]; - for (int ct = 0; ct < 2; ++ct) { // cache type + for (int cacheType = 0; cacheType < 2; ++cacheType) { // cache type - sv_frame_t rangeIndex = ch * 2 + ct; - - if (sample > range[rangeIndex].max() || count[ct] == 0) { - range[rangeIndex].setMax(sample); - } - if (sample < range[rangeIndex].min() || count[ct] == 0) { - range[rangeIndex].setMin(sample); - } - + sv_frame_t rangeIndex = ch * 2 + cacheType; + range[rangeIndex].sample(sample); means[rangeIndex] += fabsf(sample); } } @@ -737,20 +730,20 @@ //!!! this looks like a ludicrous way to do synchronisation QMutexLocker locker(&m_model.m_mutex); - for (int ct = 0; ct < 2; ++ct) { + for (int cacheType = 0; cacheType < 2; ++cacheType) { - if (++count[ct] == cacheBlockSize[ct]) { + if (++count[cacheType] == cacheBlockSize[cacheType]) { for (int ch = 0; ch < int(channels); ++ch) { - int rangeIndex = ch * 2 + ct; - means[rangeIndex] = means[rangeIndex] / float(count[ct]); + int rangeIndex = ch * 2 + cacheType; + means[rangeIndex] = means[rangeIndex] / float(count[cacheType]); range[rangeIndex].setAbsmean(means[rangeIndex]); - m_model.m_cache[ct].push_back(range[rangeIndex]); + m_model.m_cache[cacheType].push_back(range[rangeIndex]); range[rangeIndex] = Range(); means[rangeIndex] = 0.f; } - count[ct] = 0; + count[cacheType] = 0; } } @@ -776,24 +769,24 @@ QMutexLocker locker(&m_model.m_mutex); - for (int ct = 0; ct < 2; ++ct) { + for (int cacheType = 0; cacheType < 2; ++cacheType) { - if (count[ct] > 0) { + if (count[cacheType] > 0) { for (int ch = 0; ch < int(channels); ++ch) { - int rangeIndex = ch * 2 + ct; - means[rangeIndex] = means[rangeIndex] / float(count[ct]); + int rangeIndex = ch * 2 + cacheType; + means[rangeIndex] = means[rangeIndex] / float(count[cacheType]); range[rangeIndex].setAbsmean(means[rangeIndex]); - m_model.m_cache[ct].push_back(range[rangeIndex]); + m_model.m_cache[cacheType].push_back(range[rangeIndex]); range[rangeIndex] = Range(); means[rangeIndex] = 0.f; } - count[ct] = 0; + count[cacheType] = 0; } - const Range &rr = *m_model.m_cache[ct].begin(); - MUNLOCK(&rr, m_model.m_cache[ct].capacity() * sizeof(Range)); + const Range &rr = *m_model.m_cache[cacheType].begin(); + MUNLOCK(&rr, m_model.m_cache[cacheType].capacity() * sizeof(Range)); } } @@ -803,8 +796,8 @@ m_fillExtent = m_frameCount; #ifdef DEBUG_WAVE_FILE_MODEL - for (int ct = 0; ct < 2; ++ct) { - cerr << "Cache type " << ct << " now contains " << m_model.m_cache[ct].size() << " ranges" << endl; + for (int cacheType = 0; cacheType < 2; ++cacheType) { + cerr << "Cache type " << cacheType << " now contains " << m_model.m_cache[cacheType].size() << " ranges" << endl; } #endif }