comparison data/model/AggregateWaveModel.cpp @ 1086:9f4505ac9072

Tidy dense time-value model API a bit; add first simple unit test for FFT model
author Chris Cannam
date Wed, 10 Jun 2015 17:06:02 +0100
parents 0fd3661bcfff
children 4d9816ba0ebe
comparison
equal deleted inserted replaced
1085:bf6f64dabe73 1086:9f4505ac9072
135 } 135 }
136 136
137 if (mixing) delete[] readbuf; 137 if (mixing) delete[] readbuf;
138 return longest; 138 return longest;
139 } 139 }
140 140
141 sv_frame_t 141 sv_frame_t
142 AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count, 142 AggregateWaveModel::getMultiChannelData(int fromchannel, int tochannel,
143 double *buffer) const 143 sv_frame_t start, sv_frame_t count,
144 { 144 float **buffer) const
145 int ch0 = channel, ch1 = channel;
146 bool mixing = false;
147 if (channel == -1) {
148 ch0 = 0;
149 ch1 = getChannelCount()-1;
150 mixing = true;
151 }
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
163 for (int c = ch0; c <= ch1; ++c) {
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 { 145 {
192 sv_frame_t min = count; 146 sv_frame_t min = count;
193 147
194 for (int c = fromchannel; c <= tochannel; ++c) { 148 for (int c = fromchannel; c <= tochannel; ++c) {
195 sv_frame_t here = getData(c, start, count, buffer[c - fromchannel]); 149 sv_frame_t here = getData(c, start, count, buffer[c - fromchannel]);