Mercurial > hg > svcore
comparison 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 |
comparison
equal
deleted
inserted
replaced
1119:e22bfe8ca248 | 1126:39019ce29178 |
---|---|
17 | 17 |
18 #include <iostream> | 18 #include <iostream> |
19 | 19 |
20 #include <QTextStream> | 20 #include <QTextStream> |
21 | 21 |
22 using namespace std; | |
23 | |
22 PowerOfSqrtTwoZoomConstraint | 24 PowerOfSqrtTwoZoomConstraint |
23 AggregateWaveModel::m_zoomConstraint; | 25 AggregateWaveModel::m_zoomConstraint; |
24 | 26 |
25 AggregateWaveModel::AggregateWaveModel(ChannelSpecList channelSpecs) : | 27 AggregateWaveModel::AggregateWaveModel(ChannelSpecList channelSpecs) : |
26 m_components(channelSpecs) | 28 m_components(channelSpecs) |
90 { | 92 { |
91 if (m_components.empty()) return 0; | 93 if (m_components.empty()) return 0; |
92 return m_components.begin()->model->getSampleRate(); | 94 return m_components.begin()->model->getSampleRate(); |
93 } | 95 } |
94 | 96 |
95 sv_frame_t | 97 vector<float> |
96 AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count, | 98 AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count) const |
97 float *buffer) const | |
98 { | 99 { |
99 int ch0 = channel, ch1 = channel; | 100 int ch0 = channel, ch1 = channel; |
100 bool mixing = false; | |
101 if (channel == -1) { | 101 if (channel == -1) { |
102 ch0 = 0; | 102 ch0 = 0; |
103 ch1 = getChannelCount()-1; | 103 ch1 = getChannelCount()-1; |
104 mixing = true; | 104 } |
105 } | 105 |
106 | 106 vector<float> result(count, 0.f); |
107 float *readbuf = buffer; | |
108 if (mixing) { | |
109 readbuf = new float[count]; | |
110 for (sv_frame_t i = 0; i < count; ++i) { | |
111 buffer[i] = 0.f; | |
112 } | |
113 } | |
114 | 107 |
115 sv_frame_t longest = 0; | 108 sv_frame_t longest = 0; |
116 | 109 |
117 for (int c = ch0; c <= ch1; ++c) { | 110 for (int c = ch0; c <= ch1; ++c) { |
118 sv_frame_t here = | 111 |
119 m_components[c].model->getData(m_components[c].channel, | 112 auto here = m_components[c].model->getData(m_components[c].channel, |
120 start, count, | 113 start, count); |
121 readbuf); | 114 if (sv_frame_t(here.size()) > longest) { |
122 if (here > longest) { | 115 longest = sv_frame_t(here.size()); |
123 longest = here; | 116 } |
124 } | 117 for (sv_frame_t i = 0; in_range_for(here, i); ++i) { |
125 if (here < count) { | 118 result[i] += here[i]; |
126 for (sv_frame_t i = here; i < count; ++i) { | 119 } |
127 readbuf[i] = 0.f; | 120 } |
128 } | 121 |
129 } | 122 result.resize(longest); |
130 if (mixing) { | 123 return result; |
131 for (sv_frame_t i = 0; i < count; ++i) { | 124 } |
132 buffer[i] += readbuf[i]; | 125 |
133 } | 126 vector<vector<float>> |
134 } | 127 AggregateWaveModel::getMultiChannelData(int fromchannel, int tochannel, |
135 } | 128 sv_frame_t start, sv_frame_t count) const |
136 | 129 { |
137 if (mixing) delete[] readbuf; | 130 sv_frame_t min = count; |
138 return longest; | 131 |
139 } | 132 vector<vector<float>> result; |
140 | 133 |
141 sv_frame_t | 134 for (int c = fromchannel; c <= tochannel; ++c) { |
142 AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count, | 135 auto here = getData(c, start, count); |
143 double *buffer) const | 136 if (sv_frame_t(here.size()) < min) { |
144 { | 137 min = sv_frame_t(here.size()); |
145 int ch0 = channel, ch1 = channel; | 138 } |
146 bool mixing = false; | 139 result.push_back(here); |
147 if (channel == -1) { | 140 } |
148 ch0 = 0; | 141 |
149 ch1 = getChannelCount()-1; | 142 if (min < count) { |
150 mixing = true; | 143 for (auto &v : result) v.resize(min); |
151 } | 144 } |
152 | |
153 double *readbuf = buffer; | |
154 if (mixing) { | |
155 readbuf = new double[count]; | |
156 for (sv_frame_t i = 0; i < count; ++i) { | |
157 buffer[i] = 0.0; | |
158 } | |
159 } | |
160 | |
161 sv_frame_t longest = 0; | |
162 | 145 |
163 for (int c = ch0; c <= ch1; ++c) { | 146 return result; |
164 sv_frame_t here = | |
165 m_components[c].model->getData(m_components[c].channel, | |
166 start, count, | |
167 readbuf); | |
168 if (here > longest) { | |
169 longest = here; | |
170 } | |
171 if (here < count) { | |
172 for (sv_frame_t i = here; i < count; ++i) { | |
173 readbuf[i] = 0.; | |
174 } | |
175 } | |
176 if (mixing) { | |
177 for (sv_frame_t i = 0; i < count; ++i) { | |
178 buffer[i] += readbuf[i]; | |
179 } | |
180 } | |
181 } | |
182 | |
183 if (mixing) delete[] readbuf; | |
184 return longest; | |
185 } | |
186 | |
187 sv_frame_t | |
188 AggregateWaveModel::getData(int fromchannel, int tochannel, | |
189 sv_frame_t start, sv_frame_t count, | |
190 float **buffer) const | |
191 { | |
192 sv_frame_t min = count; | |
193 | |
194 for (int c = fromchannel; c <= tochannel; ++c) { | |
195 sv_frame_t here = getData(c, start, count, buffer[c - fromchannel]); | |
196 if (here < min) min = here; | |
197 } | |
198 | |
199 return min; | |
200 } | 147 } |
201 | 148 |
202 int | 149 int |
203 AggregateWaveModel::getSummaryBlockSize(int desired) const | 150 AggregateWaveModel::getSummaryBlockSize(int desired) const |
204 { | 151 { |