Mercurial > hg > svcore
comparison data/fileio/CodedAudioFileReader.cpp @ 1100:5cbf71022679 simple-fft-model
Smooth signal flow through from file to fft model
author | Chris Cannam |
---|---|
date | Mon, 15 Jun 2015 16:02:58 +0100 |
parents | 329ddaf7415d |
children | e86a7ea3dc38 |
comparison
equal
deleted
inserted
replaced
1099:0c351e061945 | 1100:5cbf71022679 |
---|---|
365 throw InsufficientDiscSpace(TempDirectory::getInstance()->getPath()); | 365 throw InsufficientDiscSpace(TempDirectory::getInstance()->getPath()); |
366 } | 366 } |
367 break; | 367 break; |
368 | 368 |
369 case CacheInMemory: | 369 case CacheInMemory: |
370 m_dataLock.lockForWrite(); | 370 m_dataLock.lock(); |
371 m_data.insert(m_data.end(), buffer, buffer + count); | 371 m_data.insert(m_data.end(), buffer, buffer + count); |
372 m_dataLock.unlock(); | 372 m_dataLock.unlock(); |
373 break; | 373 break; |
374 } | 374 } |
375 } | 375 } |
447 case CacheInMemory: | 447 case CacheInMemory: |
448 { | 448 { |
449 if (!isOK()) return {}; | 449 if (!isOK()) return {}; |
450 if (count == 0) return {}; | 450 if (count == 0) return {}; |
451 | 451 |
452 sv_frame_t idx = start * m_channelCount; | 452 sv_frame_t ix0 = start * m_channelCount; |
453 sv_frame_t i = 0; | 453 sv_frame_t ix1 = ix0 + (count * m_channelCount); |
454 sv_frame_t n = count * m_channelCount; | 454 |
455 | 455 // This lock used to be a QReadWriteLock, but it appears that |
456 frames.resize(n); | 456 // its lock mechanism is significantly slower than QMutex so |
457 | 457 // it's not a good idea in cases like this where we don't |
458 m_dataLock.lockForRead(); | 458 // really have threads taking a long time to read concurrently |
459 while (i < n && in_range_for(m_data, idx)) { | 459 m_dataLock.lock(); |
460 frames[i++] = m_data[idx++]; | 460 sv_frame_t n = sv_frame_t(m_data.size()); |
461 } | 461 if (ix1 > n) ix1 = n; |
462 frames = vector<float>(m_data.begin() + ix0, m_data.begin() + ix1); | |
462 m_dataLock.unlock(); | 463 m_dataLock.unlock(); |
463 | |
464 frames.resize(i); | |
465 } | 464 } |
466 } | 465 } |
467 | 466 |
468 if (m_normalised) { | 467 if (m_normalised) { |
469 for (auto &f: frames) f *= m_gain; | 468 for (auto &f: frames) f *= m_gain; |
470 } | 469 } |
471 | 470 |
472 return frames; | 471 return frames; |
473 } | 472 } |
474 | 473 |