Mercurial > hg > svcore
diff data/model/WaveFileModel.cpp @ 1053:48e4ffa9fb48 cxx11
Minor simplification; could use more
author | Chris Cannam |
---|---|
date | Wed, 11 Mar 2015 11:52:05 +0000 |
parents | 16dc7307d43a |
children | 0fd3661bcfff |
line wrap: on
line diff
--- 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 }