Mercurial > hg > svcore
comparison data/model/WaveFileModel.cpp @ 929:59e7fe1b1003 warnfix_no_size_t
Unsigned removals and warning fixes in data/
author | Chris Cannam |
---|---|
date | Tue, 17 Jun 2014 14:33:42 +0100 |
parents | e802e550a1f2 |
children | df82da55e86a |
comparison
equal
deleted
inserted
replaced
928:6a94bb528e9d | 929:59e7fe1b1003 |
---|---|
33 //#define DEBUG_WAVE_FILE_MODEL 1 | 33 //#define DEBUG_WAVE_FILE_MODEL 1 |
34 | 34 |
35 PowerOfSqrtTwoZoomConstraint | 35 PowerOfSqrtTwoZoomConstraint |
36 WaveFileModel::m_zoomConstraint; | 36 WaveFileModel::m_zoomConstraint; |
37 | 37 |
38 WaveFileModel::WaveFileModel(FileSource source, size_t targetRate) : | 38 WaveFileModel::WaveFileModel(FileSource source, int targetRate) : |
39 m_source(source), | 39 m_source(source), |
40 m_path(source.getLocation()), | 40 m_path(source.getLocation()), |
41 m_myReader(true), | 41 m_myReader(true), |
42 m_startFrame(0), | 42 m_startFrame(0), |
43 m_fillThread(0), | 43 m_fillThread(0), |
124 { | 124 { |
125 WaveFileModel *model = new WaveFileModel(m_source); | 125 WaveFileModel *model = new WaveFileModel(m_source); |
126 return model; | 126 return model; |
127 } | 127 } |
128 | 128 |
129 size_t | 129 int |
130 WaveFileModel::getFrameCount() const | 130 WaveFileModel::getFrameCount() const |
131 { | 131 { |
132 if (!m_reader) return 0; | 132 if (!m_reader) return 0; |
133 return m_reader->getFrameCount(); | 133 return m_reader->getFrameCount(); |
134 } | 134 } |
135 | 135 |
136 size_t | 136 int |
137 WaveFileModel::getChannelCount() const | 137 WaveFileModel::getChannelCount() const |
138 { | 138 { |
139 if (!m_reader) return 0; | 139 if (!m_reader) return 0; |
140 return m_reader->getChannelCount(); | 140 return m_reader->getChannelCount(); |
141 } | 141 } |
142 | 142 |
143 size_t | 143 int |
144 WaveFileModel::getSampleRate() const | 144 WaveFileModel::getSampleRate() const |
145 { | 145 { |
146 if (!m_reader) return 0; | 146 if (!m_reader) return 0; |
147 return m_reader->getSampleRate(); | 147 return m_reader->getSampleRate(); |
148 } | 148 } |
149 | 149 |
150 size_t | 150 int |
151 WaveFileModel::getNativeRate() const | 151 WaveFileModel::getNativeRate() const |
152 { | 152 { |
153 if (!m_reader) return 0; | 153 if (!m_reader) return 0; |
154 size_t rate = m_reader->getNativeRate(); | 154 int rate = m_reader->getNativeRate(); |
155 if (rate == 0) rate = getSampleRate(); | 155 if (rate == 0) rate = getSampleRate(); |
156 return rate; | 156 return rate; |
157 } | 157 } |
158 | 158 |
159 QString | 159 QString |
177 { | 177 { |
178 if (m_reader) return m_reader->getLocation(); | 178 if (m_reader) return m_reader->getLocation(); |
179 return ""; | 179 return ""; |
180 } | 180 } |
181 | 181 |
182 size_t | 182 int |
183 WaveFileModel::getData(int channel, size_t start, size_t count, | 183 WaveFileModel::getData(int channel, int start, int count, |
184 float *buffer) const | 184 float *buffer) const |
185 { | 185 { |
186 // Always read these directly from the file. | 186 // Always read these directly from the file. |
187 // This is used for e.g. audio playback. | 187 // This is used for e.g. audio playback. |
188 // Could be much more efficient (although compiler optimisation will help) | 188 // Could be much more efficient (although compiler optimisation will help) |
192 #endif | 192 #endif |
193 | 193 |
194 if (start >= m_startFrame) { | 194 if (start >= m_startFrame) { |
195 start -= m_startFrame; | 195 start -= m_startFrame; |
196 } else { | 196 } else { |
197 for (size_t i = 0; i < count; ++i) buffer[i] = 0.f; | 197 for (int i = 0; i < count; ++i) buffer[i] = 0.f; |
198 if (count <= m_startFrame - start) { | 198 if (count <= m_startFrame - start) { |
199 return 0; | 199 return 0; |
200 } else { | 200 } else { |
201 count -= (m_startFrame - start); | 201 count -= (m_startFrame - start); |
202 start = 0; | 202 start = 0; |
203 } | 203 } |
204 } | 204 } |
205 | 205 |
206 if (!m_reader || !m_reader->isOK() || count == 0) { | 206 if (!m_reader || !m_reader->isOK() || count == 0) { |
207 for (size_t i = 0; i < count; ++i) buffer[i] = 0.f; | 207 for (int i = 0; i < count; ++i) buffer[i] = 0.f; |
208 return 0; | 208 return 0; |
209 } | 209 } |
210 | 210 |
211 #ifdef DEBUG_WAVE_FILE_MODEL | 211 #ifdef DEBUG_WAVE_FILE_MODEL |
212 // SVDEBUG << "WaveFileModel::getValues(" << channel << ", " | 212 // SVDEBUG << "WaveFileModel::getValues(" << channel << ", " |
216 int channels = getChannelCount(); | 216 int channels = getChannelCount(); |
217 | 217 |
218 SampleBlock frames(count * channels); | 218 SampleBlock frames(count * channels); |
219 m_reader->getInterleavedFrames(start, count, frames); | 219 m_reader->getInterleavedFrames(start, count, frames); |
220 | 220 |
221 size_t i = 0; | 221 int i = 0; |
222 | 222 |
223 int ch0 = channel, ch1 = channel; | 223 int ch0 = channel, ch1 = channel; |
224 if (channel == -1) { | 224 if (channel == -1) { |
225 ch0 = 0; | 225 ch0 = 0; |
226 ch1 = channels - 1; | 226 ch1 = channels - 1; |
230 | 230 |
231 buffer[i] = 0.0; | 231 buffer[i] = 0.0; |
232 | 232 |
233 for (int ch = ch0; ch <= ch1; ++ch) { | 233 for (int ch = ch0; ch <= ch1; ++ch) { |
234 | 234 |
235 size_t index = i * channels + ch; | 235 int index = i * channels + ch; |
236 if (index >= frames.size()) break; | 236 if (index >= (int)frames.size()) break; |
237 | 237 |
238 float sample = frames[index]; | 238 float sample = frames[index]; |
239 buffer[i] += sample; | 239 buffer[i] += sample; |
240 } | 240 } |
241 | 241 |
243 } | 243 } |
244 | 244 |
245 return i; | 245 return i; |
246 } | 246 } |
247 | 247 |
248 size_t | 248 int |
249 WaveFileModel::getData(int channel, size_t start, size_t count, | 249 WaveFileModel::getData(int channel, int start, int count, |
250 double *buffer) const | 250 double *buffer) const |
251 { | 251 { |
252 #ifdef DEBUG_WAVE_FILE_MODEL | 252 #ifdef DEBUG_WAVE_FILE_MODEL |
253 cout << "WaveFileModel::getData(double)[" << this << "]: " << channel << ", " << start << ", " << count << ", " << buffer << endl; | 253 cout << "WaveFileModel::getData(double)[" << this << "]: " << channel << ", " << start << ", " << count << ", " << buffer << endl; |
254 #endif | 254 #endif |
255 | 255 |
256 if (start > m_startFrame) { | 256 if (start > m_startFrame) { |
257 start -= m_startFrame; | 257 start -= m_startFrame; |
258 } else { | 258 } else { |
259 for (size_t i = 0; i < count; ++i) buffer[i] = 0.0; | 259 for (int i = 0; i < count; ++i) buffer[i] = 0.0; |
260 if (count <= m_startFrame - start) { | 260 if (count <= m_startFrame - start) { |
261 return 0; | 261 return 0; |
262 } else { | 262 } else { |
263 count -= (m_startFrame - start); | 263 count -= (m_startFrame - start); |
264 start = 0; | 264 start = 0; |
265 } | 265 } |
266 } | 266 } |
267 | 267 |
268 if (!m_reader || !m_reader->isOK() || count == 0) { | 268 if (!m_reader || !m_reader->isOK() || count == 0) { |
269 for (size_t i = 0; i < count; ++i) buffer[i] = 0.0; | 269 for (int i = 0; i < count; ++i) buffer[i] = 0.0; |
270 return 0; | 270 return 0; |
271 } | 271 } |
272 | 272 |
273 int channels = getChannelCount(); | 273 int channels = getChannelCount(); |
274 | 274 |
275 SampleBlock frames(count * channels); | 275 SampleBlock frames(count * channels); |
276 m_reader->getInterleavedFrames(start, count, frames); | 276 m_reader->getInterleavedFrames(start, count, frames); |
277 | 277 |
278 size_t i = 0; | 278 int i = 0; |
279 | 279 |
280 int ch0 = channel, ch1 = channel; | 280 int ch0 = channel, ch1 = channel; |
281 if (channel == -1) { | 281 if (channel == -1) { |
282 ch0 = 0; | 282 ch0 = 0; |
283 ch1 = channels - 1; | 283 ch1 = channels - 1; |
287 | 287 |
288 buffer[i] = 0.0; | 288 buffer[i] = 0.0; |
289 | 289 |
290 for (int ch = ch0; ch <= ch1; ++ch) { | 290 for (int ch = ch0; ch <= ch1; ++ch) { |
291 | 291 |
292 size_t index = i * channels + ch; | 292 int index = i * channels + ch; |
293 if (index >= frames.size()) break; | 293 if (index >= (int)frames.size()) break; |
294 | 294 |
295 float sample = frames[index]; | 295 float sample = frames[index]; |
296 buffer[i] += sample; | 296 buffer[i] += sample; |
297 } | 297 } |
298 | 298 |
300 } | 300 } |
301 | 301 |
302 return i; | 302 return i; |
303 } | 303 } |
304 | 304 |
305 size_t | 305 int |
306 WaveFileModel::getData(size_t fromchannel, size_t tochannel, | 306 WaveFileModel::getData(int fromchannel, int tochannel, |
307 size_t start, size_t count, | 307 int start, int count, |
308 float **buffer) const | 308 float **buffer) const |
309 { | 309 { |
310 #ifdef DEBUG_WAVE_FILE_MODEL | 310 #ifdef DEBUG_WAVE_FILE_MODEL |
311 cout << "WaveFileModel::getData[" << this << "]: " << fromchannel << "," << tochannel << ", " << start << ", " << count << ", " << buffer << endl; | 311 cout << "WaveFileModel::getData[" << this << "]: " << fromchannel << "," << tochannel << ", " << start << ", " << count << ", " << buffer << endl; |
312 #endif | 312 #endif |
313 | 313 |
314 size_t channels = getChannelCount(); | 314 int channels = getChannelCount(); |
315 | 315 |
316 if (fromchannel > tochannel) { | 316 if (fromchannel > tochannel) { |
317 cerr << "ERROR: WaveFileModel::getData: fromchannel (" | 317 cerr << "ERROR: WaveFileModel::getData: fromchannel (" |
318 << fromchannel << ") > tochannel (" << tochannel << ")" | 318 << fromchannel << ") > tochannel (" << tochannel << ")" |
319 << endl; | 319 << endl; |
329 | 329 |
330 if (fromchannel == tochannel) { | 330 if (fromchannel == tochannel) { |
331 return getData(fromchannel, start, count, buffer[0]); | 331 return getData(fromchannel, start, count, buffer[0]); |
332 } | 332 } |
333 | 333 |
334 size_t reqchannels = (tochannel - fromchannel) + 1; | 334 int reqchannels = (tochannel - fromchannel) + 1; |
335 | 335 |
336 // Always read these directly from the file. | 336 // Always read these directly from the file. |
337 // This is used for e.g. audio playback. | 337 // This is used for e.g. audio playback. |
338 // Could be much more efficient (although compiler optimisation will help) | 338 // Could be much more efficient (although compiler optimisation will help) |
339 | 339 |
340 if (start >= m_startFrame) { | 340 if (start >= m_startFrame) { |
341 start -= m_startFrame; | 341 start -= m_startFrame; |
342 } else { | 342 } else { |
343 for (size_t c = 0; c < reqchannels; ++c) { | 343 for (int c = 0; c < reqchannels; ++c) { |
344 for (size_t i = 0; i < count; ++i) buffer[c][i] = 0.f; | 344 for (int i = 0; i < count; ++i) buffer[c][i] = 0.f; |
345 } | 345 } |
346 if (count <= m_startFrame - start) { | 346 if (count <= m_startFrame - start) { |
347 return 0; | 347 return 0; |
348 } else { | 348 } else { |
349 count -= (m_startFrame - start); | 349 count -= (m_startFrame - start); |
350 start = 0; | 350 start = 0; |
351 } | 351 } |
352 } | 352 } |
353 | 353 |
354 if (!m_reader || !m_reader->isOK() || count == 0) { | 354 if (!m_reader || !m_reader->isOK() || count == 0) { |
355 for (size_t c = 0; c < reqchannels; ++c) { | 355 for (int c = 0; c < reqchannels; ++c) { |
356 for (size_t i = 0; i < count; ++i) buffer[c][i] = 0.f; | 356 for (int i = 0; i < count; ++i) buffer[c][i] = 0.f; |
357 } | 357 } |
358 return 0; | 358 return 0; |
359 } | 359 } |
360 | 360 |
361 SampleBlock frames(count * channels); | 361 SampleBlock frames(count * channels); |
362 m_reader->getInterleavedFrames(start, count, frames); | 362 m_reader->getInterleavedFrames(start, count, frames); |
363 | 363 |
364 size_t i = 0; | 364 int i = 0; |
365 | 365 |
366 int ch0 = fromchannel, ch1 = tochannel; | 366 int index = 0, available = frames.size(); |
367 | |
368 size_t index = 0, available = frames.size(); | |
369 | 367 |
370 while (i < count) { | 368 while (i < count) { |
371 | 369 |
372 if (index >= available) break; | 370 if (index >= available) break; |
373 | 371 |
374 size_t destc = 0; | 372 int destc = 0; |
375 | 373 |
376 for (size_t c = 0; c < channels; ++c) { | 374 for (int c = 0; c < channels; ++c) { |
377 | 375 |
378 if (c >= fromchannel && c <= tochannel) { | 376 if (c >= fromchannel && c <= tochannel) { |
379 buffer[destc][i] = frames[index]; | 377 buffer[destc][i] = frames[index]; |
380 ++destc; | 378 ++destc; |
381 } | 379 } |
387 } | 385 } |
388 | 386 |
389 return i; | 387 return i; |
390 } | 388 } |
391 | 389 |
392 size_t | 390 int |
393 WaveFileModel::getSummaryBlockSize(size_t desired) const | 391 WaveFileModel::getSummaryBlockSize(int desired) const |
394 { | 392 { |
395 int cacheType = 0; | 393 int cacheType = 0; |
396 int power = m_zoomConstraint.getMinCachePower(); | 394 int power = m_zoomConstraint.getMinCachePower(); |
397 size_t roundedBlockSize = m_zoomConstraint.getNearestBlockSize | 395 int roundedBlockSize = m_zoomConstraint.getNearestBlockSize |
398 (desired, cacheType, power, ZoomConstraint::RoundDown); | 396 (desired, cacheType, power, ZoomConstraint::RoundDown); |
399 if (cacheType != 0 && cacheType != 1) { | 397 if (cacheType != 0 && cacheType != 1) { |
400 // We will be reading directly from file, so can satisfy any | 398 // We will be reading directly from file, so can satisfy any |
401 // blocksize requirement | 399 // blocksize requirement |
402 return desired; | 400 return desired; |
404 return roundedBlockSize; | 402 return roundedBlockSize; |
405 } | 403 } |
406 } | 404 } |
407 | 405 |
408 void | 406 void |
409 WaveFileModel::getSummaries(size_t channel, size_t start, size_t count, | 407 WaveFileModel::getSummaries(int channel, int start, int count, |
410 RangeBlock &ranges, size_t &blockSize) const | 408 RangeBlock &ranges, int &blockSize) const |
411 { | 409 { |
412 ranges.clear(); | 410 ranges.clear(); |
413 if (!isOK()) return; | 411 if (!isOK()) return; |
414 ranges.reserve((count / blockSize) + 1); | 412 ranges.reserve((count / blockSize) + 1); |
415 | 413 |
420 start = 0; | 418 start = 0; |
421 } | 419 } |
422 | 420 |
423 int cacheType = 0; | 421 int cacheType = 0; |
424 int power = m_zoomConstraint.getMinCachePower(); | 422 int power = m_zoomConstraint.getMinCachePower(); |
425 size_t roundedBlockSize = m_zoomConstraint.getNearestBlockSize | 423 int roundedBlockSize = m_zoomConstraint.getNearestBlockSize |
426 (blockSize, cacheType, power, ZoomConstraint::RoundDown); | 424 (blockSize, cacheType, power, ZoomConstraint::RoundDown); |
427 | 425 |
428 size_t channels = getChannelCount(); | 426 int channels = getChannelCount(); |
429 | 427 |
430 if (cacheType != 0 && cacheType != 1) { | 428 if (cacheType != 0 && cacheType != 1) { |
431 | 429 |
432 // We need to read directly from the file. We haven't got | 430 // We need to read directly from the file. We haven't got |
433 // this cached. Hope the requested area is small. This is | 431 // this cached. Hope the requested area is small. This is |
447 m_lastDirectReadStart = start; | 445 m_lastDirectReadStart = start; |
448 m_lastDirectReadCount = count; | 446 m_lastDirectReadCount = count; |
449 } | 447 } |
450 | 448 |
451 float max = 0.0, min = 0.0, total = 0.0; | 449 float max = 0.0, min = 0.0, total = 0.0; |
452 size_t i = 0, got = 0; | 450 int i = 0, got = 0; |
453 | 451 |
454 while (i < count) { | 452 while (i < count) { |
455 | 453 |
456 size_t index = i * channels + channel; | 454 int index = i * channels + channel; |
457 if (index >= m_directRead.size()) break; | 455 if (index >= (int)m_directRead.size()) break; |
458 | 456 |
459 float sample = m_directRead[index]; | 457 float sample = m_directRead[index]; |
460 if (sample > max || got == 0) max = sample; | 458 if (sample > max || got == 0) max = sample; |
461 if (sample < min || got == 0) min = sample; | 459 if (sample < min || got == 0) min = sample; |
462 total += fabsf(sample); | 460 total += fabsf(sample); |
485 | 483 |
486 const RangeBlock &cache = m_cache[cacheType]; | 484 const RangeBlock &cache = m_cache[cacheType]; |
487 | 485 |
488 blockSize = roundedBlockSize; | 486 blockSize = roundedBlockSize; |
489 | 487 |
490 size_t cacheBlock, div; | 488 int cacheBlock, div; |
491 | 489 |
492 if (cacheType == 0) { | 490 if (cacheType == 0) { |
493 cacheBlock = (1 << m_zoomConstraint.getMinCachePower()); | 491 cacheBlock = (1 << m_zoomConstraint.getMinCachePower()); |
494 div = (1 << power) / cacheBlock; | 492 div = (1 << power) / cacheBlock; |
495 } else { | 493 } else { |
496 cacheBlock = ((unsigned int)((1 << m_zoomConstraint.getMinCachePower()) * sqrt(2.) + 0.01)); | 494 cacheBlock = ((unsigned int)((1 << m_zoomConstraint.getMinCachePower()) * sqrt(2.) + 0.01)); |
497 div = ((unsigned int)((1 << power) * sqrt(2.) + 0.01)) / cacheBlock; | 495 div = ((unsigned int)((1 << power) * sqrt(2.) + 0.01)) / cacheBlock; |
498 } | 496 } |
499 | 497 |
500 size_t startIndex = start / cacheBlock; | 498 int startIndex = start / cacheBlock; |
501 size_t endIndex = (start + count) / cacheBlock; | 499 int endIndex = (start + count) / cacheBlock; |
502 | 500 |
503 float max = 0.0, min = 0.0, total = 0.0; | 501 float max = 0.0, min = 0.0, total = 0.0; |
504 size_t i = 0, got = 0; | 502 int i = 0, got = 0; |
505 | 503 |
506 #ifdef DEBUG_WAVE_FILE_MODEL | 504 #ifdef DEBUG_WAVE_FILE_MODEL |
507 cerr << "blockSize is " << blockSize << ", cacheBlock " << cacheBlock << ", start " << start << ", count " << count << " (frame count " << getFrameCount() << "), power is " << power << ", div is " << div << ", startIndex " << startIndex << ", endIndex " << endIndex << endl; | 505 cerr << "blockSize is " << blockSize << ", cacheBlock " << cacheBlock << ", start " << start << ", count " << count << " (frame count " << getFrameCount() << "), power is " << power << ", div is " << div << ", startIndex " << startIndex << ", endIndex " << endIndex << endl; |
508 #endif | 506 #endif |
509 | 507 |
510 for (i = 0; i <= endIndex - startIndex; ) { | 508 for (i = 0; i <= endIndex - startIndex; ) { |
511 | 509 |
512 size_t index = (i + startIndex) * channels + channel; | 510 int index = (i + startIndex) * channels + channel; |
513 if (index >= cache.size()) break; | 511 if (index >= (int)cache.size()) break; |
514 | 512 |
515 const Range &range = cache[index]; | 513 const Range &range = cache[index]; |
516 if (range.max() > max || got == 0) max = range.max(); | 514 if (range.max() > max || got == 0) max = range.max(); |
517 if (range.min() < min || got == 0) min = range.min(); | 515 if (range.min() < min || got == 0) min = range.min(); |
518 total += range.absmean(); | 516 total += range.absmean(); |
537 #endif | 535 #endif |
538 return; | 536 return; |
539 } | 537 } |
540 | 538 |
541 WaveFileModel::Range | 539 WaveFileModel::Range |
542 WaveFileModel::getSummary(size_t channel, size_t start, size_t count) const | 540 WaveFileModel::getSummary(int channel, int start, int count) const |
543 { | 541 { |
544 Range range; | 542 Range range; |
545 if (!isOK()) return range; | 543 if (!isOK()) return range; |
546 | 544 |
547 if (start > m_startFrame) start -= m_startFrame; | 545 if (start > m_startFrame) start -= m_startFrame; |
549 else { | 547 else { |
550 count -= (m_startFrame - start); | 548 count -= (m_startFrame - start); |
551 start = 0; | 549 start = 0; |
552 } | 550 } |
553 | 551 |
554 size_t blockSize; | 552 int blockSize; |
555 for (blockSize = 1; blockSize <= count; blockSize *= 2); | 553 for (blockSize = 1; blockSize <= count; blockSize *= 2); |
556 if (blockSize > 1) blockSize /= 2; | 554 if (blockSize > 1) blockSize /= 2; |
557 | 555 |
558 bool first = false; | 556 bool first = false; |
559 | 557 |
560 size_t blockStart = (start / blockSize) * blockSize; | 558 int blockStart = (start / blockSize) * blockSize; |
561 size_t blockEnd = ((start + count) / blockSize) * blockSize; | 559 int blockEnd = ((start + count) / blockSize) * blockSize; |
562 | 560 |
563 if (blockStart < start) blockStart += blockSize; | 561 if (blockStart < start) blockStart += blockSize; |
564 | 562 |
565 if (blockEnd > blockStart) { | 563 if (blockEnd > blockStart) { |
566 RangeBlock ranges; | 564 RangeBlock ranges; |
567 getSummaries(channel, blockStart, blockEnd - blockStart, ranges, blockSize); | 565 getSummaries(channel, blockStart, blockEnd - blockStart, ranges, blockSize); |
568 for (size_t i = 0; i < ranges.size(); ++i) { | 566 for (int i = 0; i < (int)ranges.size(); ++i) { |
569 if (first || ranges[i].min() < range.min()) range.setMin(ranges[i].min()); | 567 if (first || ranges[i].min() < range.min()) range.setMin(ranges[i].min()); |
570 if (first || ranges[i].max() > range.max()) range.setMax(ranges[i].max()); | 568 if (first || ranges[i].max() > range.max()) range.setMax(ranges[i].max()); |
571 if (first || ranges[i].absmean() < range.absmean()) range.setAbsmean(ranges[i].absmean()); | 569 if (first || ranges[i].absmean() < range.absmean()) range.setAbsmean(ranges[i].absmean()); |
572 first = false; | 570 first = false; |
573 } | 571 } |
612 | 610 |
613 void | 611 void |
614 WaveFileModel::fillTimerTimedOut() | 612 WaveFileModel::fillTimerTimedOut() |
615 { | 613 { |
616 if (m_fillThread) { | 614 if (m_fillThread) { |
617 size_t fillExtent = m_fillThread->getFillExtent(); | 615 int fillExtent = m_fillThread->getFillExtent(); |
618 #ifdef DEBUG_WAVE_FILE_MODEL | 616 #ifdef DEBUG_WAVE_FILE_MODEL |
619 SVDEBUG << "WaveFileModel::fillTimerTimedOut: extent = " << fillExtent << endl; | 617 SVDEBUG << "WaveFileModel::fillTimerTimedOut: extent = " << fillExtent << endl; |
620 #endif | 618 #endif |
621 if (fillExtent > m_lastFillExtent) { | 619 if (fillExtent > m_lastFillExtent) { |
622 emit modelChanged(m_lastFillExtent, fillExtent); | 620 emit modelChanged(m_lastFillExtent, fillExtent); |
650 } | 648 } |
651 | 649 |
652 void | 650 void |
653 WaveFileModel::RangeCacheFillThread::run() | 651 WaveFileModel::RangeCacheFillThread::run() |
654 { | 652 { |
655 size_t cacheBlockSize[2]; | 653 int cacheBlockSize[2]; |
656 cacheBlockSize[0] = (1 << m_model.m_zoomConstraint.getMinCachePower()); | 654 cacheBlockSize[0] = (1 << m_model.m_zoomConstraint.getMinCachePower()); |
657 cacheBlockSize[1] = ((unsigned int)((1 << m_model.m_zoomConstraint.getMinCachePower()) * | 655 cacheBlockSize[1] = ((unsigned int)((1 << m_model.m_zoomConstraint.getMinCachePower()) * |
658 sqrt(2.) + 0.01)); | 656 sqrt(2.) + 0.01)); |
659 | 657 |
660 size_t frame = 0; | 658 int frame = 0; |
661 int readBlockSize = 16384; | 659 int readBlockSize = 16384; |
662 SampleBlock block; | 660 SampleBlock block; |
663 | 661 |
664 if (!m_model.isOK()) return; | 662 if (!m_model.isOK()) return; |
665 | 663 |
666 size_t channels = m_model.getChannelCount(); | 664 int channels = m_model.getChannelCount(); |
667 bool updating = m_model.m_reader->isUpdating(); | 665 bool updating = m_model.m_reader->isUpdating(); |
668 | 666 |
669 if (updating) { | 667 if (updating) { |
670 while (channels == 0 && !m_model.m_exiting) { | 668 while (channels == 0 && !m_model.m_exiting) { |
671 // SVDEBUG << "WaveFileModel::fill: Waiting for channels..." << endl; | 669 // SVDEBUG << "WaveFileModel::fill: Waiting for channels..." << endl; |
674 } | 672 } |
675 } | 673 } |
676 | 674 |
677 Range *range = new Range[2 * channels]; | 675 Range *range = new Range[2 * channels]; |
678 float *means = new float[2 * channels]; | 676 float *means = new float[2 * channels]; |
679 size_t count[2]; | 677 int count[2]; |
680 count[0] = count[1] = 0; | 678 count[0] = count[1] = 0; |
681 for (int i = 0; i < 2 * channels; ++i) { | 679 for (int i = 0; i < 2 * channels; ++i) { |
682 means[i] = 0.f; | 680 means[i] = 0.f; |
683 } | 681 } |
684 | 682 |
701 | 699 |
702 // cerr << "block is " << block.size() << endl; | 700 // cerr << "block is " << block.size() << endl; |
703 | 701 |
704 for (int i = 0; i < readBlockSize; ++i) { | 702 for (int i = 0; i < readBlockSize; ++i) { |
705 | 703 |
706 if (channels * i + channels > block.size()) break; | 704 if (channels * i + channels > (int)block.size()) break; |
707 | 705 |
708 for (int ch = 0; ch < channels; ++ch) { | 706 for (int ch = 0; ch < channels; ++ch) { |
709 | 707 |
710 int index = channels * i + ch; | 708 int index = channels * i + ch; |
711 float sample = block[index]; | 709 float sample = block[index]; |
725 } | 723 } |
726 } | 724 } |
727 | 725 |
728 QMutexLocker locker(&m_model.m_mutex); | 726 QMutexLocker locker(&m_model.m_mutex); |
729 | 727 |
730 for (size_t ct = 0; ct < 2; ++ct) { | 728 for (int ct = 0; ct < 2; ++ct) { |
731 | 729 |
732 if (++count[ct] == cacheBlockSize[ct]) { | 730 if (++count[ct] == cacheBlockSize[ct]) { |
733 | 731 |
734 for (size_t ch = 0; ch < size_t(channels); ++ch) { | 732 for (int ch = 0; ch < int(channels); ++ch) { |
735 size_t rangeIndex = ch * 2 + ct; | 733 int rangeIndex = ch * 2 + ct; |
736 means[rangeIndex] /= count[ct]; | 734 means[rangeIndex] /= count[ct]; |
737 range[rangeIndex].setAbsmean(means[rangeIndex]); | 735 range[rangeIndex].setAbsmean(means[rangeIndex]); |
738 m_model.m_cache[ct].push_back(range[rangeIndex]); | 736 m_model.m_cache[ct].push_back(range[rangeIndex]); |
739 range[rangeIndex] = Range(); | 737 range[rangeIndex] = Range(); |
740 means[rangeIndex] = 0.f; | 738 means[rangeIndex] = 0.f; |
764 | 762 |
765 if (!m_model.m_exiting) { | 763 if (!m_model.m_exiting) { |
766 | 764 |
767 QMutexLocker locker(&m_model.m_mutex); | 765 QMutexLocker locker(&m_model.m_mutex); |
768 | 766 |
769 for (size_t ct = 0; ct < 2; ++ct) { | 767 for (int ct = 0; ct < 2; ++ct) { |
770 | 768 |
771 if (count[ct] > 0) { | 769 if (count[ct] > 0) { |
772 | 770 |
773 for (size_t ch = 0; ch < size_t(channels); ++ch) { | 771 for (int ch = 0; ch < int(channels); ++ch) { |
774 size_t rangeIndex = ch * 2 + ct; | 772 int rangeIndex = ch * 2 + ct; |
775 means[rangeIndex] /= count[ct]; | 773 means[rangeIndex] /= count[ct]; |
776 range[rangeIndex].setAbsmean(means[rangeIndex]); | 774 range[rangeIndex].setAbsmean(means[rangeIndex]); |
777 m_model.m_cache[ct].push_back(range[rangeIndex]); | 775 m_model.m_cache[ct].push_back(range[rangeIndex]); |
778 range[rangeIndex] = Range(); | 776 range[rangeIndex] = Range(); |
779 means[rangeIndex] = 0.f; | 777 means[rangeIndex] = 0.f; |
791 delete[] range; | 789 delete[] range; |
792 | 790 |
793 m_fillExtent = m_frameCount; | 791 m_fillExtent = m_frameCount; |
794 | 792 |
795 #ifdef DEBUG_WAVE_FILE_MODEL | 793 #ifdef DEBUG_WAVE_FILE_MODEL |
796 for (size_t ct = 0; ct < 2; ++ct) { | 794 for (int ct = 0; ct < 2; ++ct) { |
797 cerr << "Cache type " << ct << " now contains " << m_model.m_cache[ct].size() << " ranges" << endl; | 795 cerr << "Cache type " << ct << " now contains " << m_model.m_cache[ct].size() << " ranges" << endl; |
798 } | 796 } |
799 #endif | 797 #endif |
800 } | 798 } |
801 | 799 |