Mercurial > hg > svcore
diff data/model/AggregateWaveModel.cpp @ 1126:39019ce29178 tony-2.0-integration
Merge through to branch for Tony 2.0
author | Chris Cannam |
---|---|
date | Thu, 20 Aug 2015 14:54:21 +0100 |
parents | 5cbf71022679 |
children | 54af1e21705c |
line wrap: on
line diff
--- a/data/model/AggregateWaveModel.cpp Fri Aug 14 18:16:14 2015 +0100 +++ b/data/model/AggregateWaveModel.cpp Thu Aug 20 14:54:21 2015 +0100 @@ -19,6 +19,8 @@ #include <QTextStream> +using namespace std; + PowerOfSqrtTwoZoomConstraint AggregateWaveModel::m_zoomConstraint; @@ -92,111 +94,56 @@ return m_components.begin()->model->getSampleRate(); } -sv_frame_t -AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count, - float *buffer) const +vector<float> +AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count) const { int ch0 = channel, ch1 = channel; - bool mixing = false; if (channel == -1) { ch0 = 0; ch1 = getChannelCount()-1; - mixing = true; } - float *readbuf = buffer; - if (mixing) { - readbuf = new float[count]; - for (sv_frame_t i = 0; i < count; ++i) { - buffer[i] = 0.f; - } - } + vector<float> result(count, 0.f); sv_frame_t longest = 0; for (int c = ch0; c <= ch1; ++c) { - sv_frame_t here = - m_components[c].model->getData(m_components[c].channel, - start, count, - readbuf); - if (here > longest) { - longest = here; + + auto here = m_components[c].model->getData(m_components[c].channel, + start, count); + if (sv_frame_t(here.size()) > longest) { + longest = sv_frame_t(here.size()); } - if (here < count) { - for (sv_frame_t i = here; i < count; ++i) { - readbuf[i] = 0.f; - } - } - if (mixing) { - for (sv_frame_t i = 0; i < count; ++i) { - buffer[i] += readbuf[i]; - } + for (sv_frame_t i = 0; in_range_for(here, i); ++i) { + result[i] += here[i]; } } - if (mixing) delete[] readbuf; - return longest; -} - -sv_frame_t -AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count, - double *buffer) const -{ - int ch0 = channel, ch1 = channel; - bool mixing = false; - if (channel == -1) { - ch0 = 0; - ch1 = getChannelCount()-1; - mixing = true; - } - - double *readbuf = buffer; - if (mixing) { - readbuf = new double[count]; - for (sv_frame_t i = 0; i < count; ++i) { - buffer[i] = 0.0; - } - } - - sv_frame_t longest = 0; - - for (int c = ch0; c <= ch1; ++c) { - sv_frame_t here = - m_components[c].model->getData(m_components[c].channel, - start, count, - readbuf); - if (here > longest) { - longest = here; - } - if (here < count) { - for (sv_frame_t i = here; i < count; ++i) { - readbuf[i] = 0.; - } - } - if (mixing) { - for (sv_frame_t i = 0; i < count; ++i) { - buffer[i] += readbuf[i]; - } - } - } - - if (mixing) delete[] readbuf; - return longest; + result.resize(longest); + return result; } -sv_frame_t -AggregateWaveModel::getData(int fromchannel, int tochannel, - sv_frame_t start, sv_frame_t count, - float **buffer) const +vector<vector<float>> +AggregateWaveModel::getMultiChannelData(int fromchannel, int tochannel, + sv_frame_t start, sv_frame_t count) const { sv_frame_t min = count; + vector<vector<float>> result; + for (int c = fromchannel; c <= tochannel; ++c) { - sv_frame_t here = getData(c, start, count, buffer[c - fromchannel]); - if (here < min) min = here; + auto here = getData(c, start, count); + if (sv_frame_t(here.size()) < min) { + min = sv_frame_t(here.size()); + } + result.push_back(here); + } + + if (min < count) { + for (auto &v : result) v.resize(min); } - return min; + return result; } int