comparison data/fft/FFTDataServer.cpp @ 172:a2a8a2b6653a

* Use the Storage Adviser's recommendations for storing FFT cache information
author Chris Cannam
date Tue, 26 Sep 2006 14:12:59 +0000
parents b23eea68357e
children 146eb9e35baa
comparison
equal deleted inserted replaced
171:ebf55cf0d34d 172:a2a8a2b6653a
72 !polar); 72 !polar);
73 73
74 if ((server = findServer(npn))) { 74 if ((server = findServer(npn))) {
75 return server; 75 return server;
76 } 76 }
77
78 StorageAdviser::Criteria criteria =
79 StorageAdviser::Criteria
80 (StorageAdviser::SpeedCritical | StorageAdviser::LongRetentionLikely);
81
82 int cells = fftSize * ((model->getEndFrame() - model->getStartFrame())
83 / windowIncrement + 1);
84 int minimumSize = (cells / 1024) * sizeof(uint16_t); // kb
85 int maximumSize = (cells / 1024) * sizeof(float); // kb
86
87 StorageAdviser::Recommendation recommendation =
88 StorageAdviser::recommend(criteria, minimumSize, maximumSize);
89
90 std::cerr << "Recommendation was: " << recommendation << std::endl;
91 77
92 m_servers[n] = ServerCountPair 78 m_servers[n] = ServerCountPair
93 (new FFTDataServer(n, 79 (new FFTDataServer(n,
94 model, 80 model,
95 channel, 81 channel,
325 m_windower(windowType, windowSize), 311 m_windower(windowType, windowSize),
326 m_windowSize(windowSize), 312 m_windowSize(windowSize),
327 m_windowIncrement(windowIncrement), 313 m_windowIncrement(windowIncrement),
328 m_fftSize(fftSize), 314 m_fftSize(fftSize),
329 m_polar(polar), 315 m_polar(polar),
316 m_memoryCache(false),
317 m_compactCache(false),
330 m_lastUsedCache(-1), 318 m_lastUsedCache(-1),
331 m_fftInput(0), 319 m_fftInput(0),
332 m_exiting(false), 320 m_exiting(false),
333 m_suspended(true), //!!! or false? 321 m_suspended(true), //!!! or false?
334 m_fillThread(0) 322 m_fillThread(0)
346 334
347 int bits = 0; 335 int bits = 0;
348 while (m_cacheWidth) { m_cacheWidth >>= 1; ++bits; } 336 while (m_cacheWidth) { m_cacheWidth >>= 1; ++bits; }
349 m_cacheWidth = 2; 337 m_cacheWidth = 2;
350 while (bits) { m_cacheWidth <<= 1; --bits; } 338 while (bits) { m_cacheWidth <<= 1; --bits; }
339
340 //!!! Need to pass in what this server is intended for
341 // (e.g. playback processing, spectrogram, feature extraction),
342 // or pass in something akin to the storage adviser criteria.
343 // That probably goes alongside the polar argument.
344 // For now we'll assume "spectrogram" criteria for polar ffts,
345 // and "feature extraction" criteria for rectangular ones.
346
347 StorageAdviser::Criteria criteria;
348 if (m_polar) {
349 criteria = StorageAdviser::Criteria
350 (StorageAdviser::SpeedCritical | StorageAdviser::LongRetentionLikely);
351 } else {
352 criteria = StorageAdviser::Criteria(StorageAdviser::PrecisionCritical);
353 }
354
355 int cells = m_width * m_height;
356 int minimumSize = (cells / 1024) * sizeof(uint16_t); // kb
357 int maximumSize = (cells / 1024) * sizeof(float); // kb
358
359 //!!! catch InsufficientDiscSpace
360
361 StorageAdviser::Recommendation recommendation =
362 StorageAdviser::recommend(criteria, minimumSize, maximumSize);
363
364 std::cerr << "Recommendation was: " << recommendation << std::endl;
365
366 m_memoryCache = ((recommendation & StorageAdviser::UseMemory) ||
367 (recommendation & StorageAdviser::PreferMemory));
368
369 m_compactCache = (recommendation & StorageAdviser::ConserveSpace);
351 370
352 #ifdef DEBUG_FFT_SERVER 371 #ifdef DEBUG_FFT_SERVER
353 std::cerr << "Width " << m_width << ", cache width " << m_cacheWidth << " (size " << m_cacheWidth * columnSize << ")" << std::endl; 372 std::cerr << "Width " << m_width << ", cache width " << m_cacheWidth << " (size " << m_cacheWidth * columnSize << ")" << std::endl;
354 #endif 373 #endif
355 374
499 return m_caches[c]; 518 return m_caches[c];
500 } 519 }
501 520
502 QString name = QString("%1-%2").arg(m_fileBaseName).arg(c); 521 QString name = QString("%1-%2").arg(m_fileBaseName).arg(c);
503 522
504 FFTCache *cache = new FFTFileCache(name, MatrixFile::ReadWrite, 523 FFTCache *cache = 0;
505 m_polar ? FFTFileCache::Polar : 524
506 FFTFileCache::Rectangular); 525 if (m_memoryCache) {
526
527 cache = new FFTMemoryCache();
528
529 } else if (m_compactCache) {
530
531 cache = new FFTFileCache(name, MatrixFile::ReadWrite,
532 FFTFileCache::Compact);
533
534 } else {
535
536 cache = new FFTFileCache(name, MatrixFile::ReadWrite,
537 m_polar ? FFTFileCache::Polar :
538 FFTFileCache::Rectangular);
539 }
507 540
508 // FFTCache *cache = new FFTMemoryCache(); 541 // FFTCache *cache = new FFTMemoryCache();
509 542
510 size_t width = m_cacheWidth; 543 size_t width = m_cacheWidth;
511 if (c * m_cacheWidth + width > m_width) { 544 if (c * m_cacheWidth + width > m_width) {