Mercurial > hg > svcore
comparison data/fft/FFTDataServer.cpp @ 334:aa8dbac62024
* Pass StorageAdviser::Criteria into FFTModel constructor etc
author | Chris Cannam |
---|---|
date | Sun, 11 Nov 2007 20:31:12 +0000 |
parents | 5877d68815c7 |
children | 02d2ad95ea52 94fc0591ea43 |
comparison
equal
deleted
inserted
replaced
333:1afaf98dbf11 | 334:aa8dbac62024 |
---|---|
50 WindowType windowType, | 50 WindowType windowType, |
51 size_t windowSize, | 51 size_t windowSize, |
52 size_t windowIncrement, | 52 size_t windowIncrement, |
53 size_t fftSize, | 53 size_t fftSize, |
54 bool polar, | 54 bool polar, |
55 StorageAdviser::Criteria criteria, | |
55 size_t fillFromColumn) | 56 size_t fillFromColumn) |
56 { | 57 { |
57 QString n = generateFileBasename(model, | 58 QString n = generateFileBasename(model, |
58 channel, | 59 channel, |
59 windowType, | 60 windowType, |
89 windowType, | 90 windowType, |
90 windowSize, | 91 windowSize, |
91 windowIncrement, | 92 windowIncrement, |
92 fftSize, | 93 fftSize, |
93 polar, | 94 polar, |
95 criteria, | |
94 fillFromColumn); | 96 fillFromColumn); |
95 } catch (InsufficientDiscSpace) { | 97 } catch (InsufficientDiscSpace) { |
96 delete server; | 98 delete server; |
97 server = 0; | 99 server = 0; |
98 } | 100 } |
110 WindowType windowType, | 112 WindowType windowType, |
111 size_t windowSize, | 113 size_t windowSize, |
112 size_t windowIncrement, | 114 size_t windowIncrement, |
113 size_t fftSize, | 115 size_t fftSize, |
114 bool polar, | 116 bool polar, |
117 StorageAdviser::Criteria criteria, | |
115 size_t fillFromColumn) | 118 size_t fillFromColumn) |
116 { | 119 { |
117 // Fuzzy matching: | 120 // Fuzzy matching: |
118 // | 121 // |
119 // -- if we're asked for polar and have non-polar, use it (and | 122 // -- if we're asked for polar and have non-polar, use it (and |
215 windowType, | 218 windowType, |
216 windowSize, | 219 windowSize, |
217 windowIncrement, | 220 windowIncrement, |
218 fftSize, | 221 fftSize, |
219 polar, | 222 polar, |
223 criteria, | |
220 fillFromColumn); | 224 fillFromColumn); |
221 } | 225 } |
222 | 226 |
223 FFTDataServer * | 227 FFTDataServer * |
224 FFTDataServer::findServer(QString n) | 228 FFTDataServer::findServer(QString n) |
477 WindowType windowType, | 481 WindowType windowType, |
478 size_t windowSize, | 482 size_t windowSize, |
479 size_t windowIncrement, | 483 size_t windowIncrement, |
480 size_t fftSize, | 484 size_t fftSize, |
481 bool polar, | 485 bool polar, |
486 StorageAdviser::Criteria criteria, | |
482 size_t fillFromColumn) : | 487 size_t fillFromColumn) : |
483 m_fileBaseName(fileBaseName), | 488 m_fileBaseName(fileBaseName), |
484 m_model(model), | 489 m_model(model), |
485 m_channel(channel), | 490 m_channel(channel), |
486 m_windower(windowType, windowSize), | 491 m_windower(windowType, windowSize), |
524 int bits = 0; | 529 int bits = 0; |
525 while (m_cacheWidth) { m_cacheWidth >>= 1; ++bits; } | 530 while (m_cacheWidth) { m_cacheWidth >>= 1; ++bits; } |
526 m_cacheWidth = 2; | 531 m_cacheWidth = 2; |
527 while (bits) { m_cacheWidth <<= 1; --bits; } | 532 while (bits) { m_cacheWidth <<= 1; --bits; } |
528 | 533 |
529 //!!! Need to pass in what this server is intended for | 534 if (criteria == StorageAdviser::NoCriteria) { |
530 // (e.g. playback processing, spectrogram, feature extraction), | 535 |
531 // or pass in something akin to the storage adviser criteria. | 536 // assume "spectrogram" criteria for polar ffts, and "feature |
532 // That probably goes alongside the polar argument. | 537 // extraction" criteria for rectangular ones. |
533 // For now we'll assume "spectrogram" criteria for polar ffts, | 538 |
534 // and "feature extraction" criteria for rectangular ones. | 539 if (m_polar) { |
535 | 540 criteria = StorageAdviser::Criteria |
536 StorageAdviser::Criteria criteria; | 541 (StorageAdviser::SpeedCritical | |
537 if (m_polar) { | 542 StorageAdviser::LongRetentionLikely); |
538 criteria = StorageAdviser::Criteria | 543 } else { |
539 (StorageAdviser::SpeedCritical | | 544 criteria = StorageAdviser::Criteria |
540 StorageAdviser::LongRetentionLikely); | 545 (StorageAdviser::PrecisionCritical); |
541 } else { | 546 } |
542 criteria = StorageAdviser::Criteria | |
543 (StorageAdviser::PrecisionCritical); | |
544 } | 547 } |
545 | 548 |
546 int cells = m_width * m_height; | 549 int cells = m_width * m_height; |
547 int minimumSize = (cells / 1024) * sizeof(uint16_t); // kb | 550 int minimumSize = (cells / 1024) * sizeof(uint16_t); // kb |
548 int maximumSize = (cells / 1024) * sizeof(float); // kb | 551 int maximumSize = (cells / 1024) * sizeof(float); // kb |
552 | |
553 // We don't have a compact rectangular representation, and compact | |
554 // of course is never precision-critical | |
555 bool canCompact = true; | |
556 if ((criteria & StorageAdviser::PrecisionCritical) || !m_polar) { | |
557 canCompact = false; | |
558 minimumSize = maximumSize; // don't use compact | |
559 } | |
549 | 560 |
550 StorageAdviser::Recommendation recommendation; | 561 StorageAdviser::Recommendation recommendation; |
551 | 562 |
552 try { | 563 try { |
553 | 564 |
572 | 583 |
573 std::cerr << "Recommendation was: " << recommendation << std::endl; | 584 std::cerr << "Recommendation was: " << recommendation << std::endl; |
574 | 585 |
575 m_memoryCache = false; | 586 m_memoryCache = false; |
576 | 587 |
577 if (recommendation & StorageAdviser::UseMemory) { | 588 if ((recommendation & StorageAdviser::UseMemory) || |
578 | 589 (recommendation & StorageAdviser::PreferMemory)) { |
579 // can't use disc, must use memory | |
580 | |
581 m_memoryCache = true; | 590 m_memoryCache = true; |
582 | 591 } |
583 } else if (recommendation & StorageAdviser::PreferMemory) { | 592 |
584 | 593 m_compactCache = canCompact && |
585 // if memory is recommended, we use it if we're using polar | 594 (recommendation & StorageAdviser::ConserveSpace); |
586 // coordinates; but we don't have a native rectangular memory | 595 |
587 // cache, so we might as well use disc if we want rectangular | 596 std::cerr << "FFTDataServer: memory cache = " << m_memoryCache << ", compact cache = " << m_compactCache << std::endl; |
588 // coordinates rather than have all the bother of converting | |
589 // every time | |
590 | |
591 if (m_polar) m_memoryCache = true; | |
592 } | |
593 | |
594 m_compactCache = (recommendation & StorageAdviser::ConserveSpace); | |
595 | 597 |
596 #ifdef DEBUG_FFT_SERVER | 598 #ifdef DEBUG_FFT_SERVER |
597 std::cerr << "Width " << m_width << ", cache width " << m_cacheWidth << " (size " << m_cacheWidth * columnSize << ")" << std::endl; | 599 std::cerr << "Width " << m_width << ", cache width " << m_cacheWidth << " (size " << m_cacheWidth * columnSize << ")" << std::endl; |
598 #endif | 600 #endif |
599 | 601 |
614 | 616 |
615 m_workbuffer = (float *) | 617 m_workbuffer = (float *) |
616 fftf_malloc((fftSize+2) * sizeof(float)); | 618 fftf_malloc((fftSize+2) * sizeof(float)); |
617 | 619 |
618 m_fftPlan = fftf_plan_dft_r2c_1d(m_fftSize, | 620 m_fftPlan = fftf_plan_dft_r2c_1d(m_fftSize, |
619 m_fftInput, | 621 m_fftInput, |
620 m_fftOutput, | 622 m_fftOutput, |
621 FFTW_MEASURE); | 623 FFTW_MEASURE); |
622 | 624 |
623 if (!m_fftPlan) { | 625 if (!m_fftPlan) { |
624 std::cerr << "ERROR: fftf_plan_dft_r2c_1d(" << m_windowSize << ") failed!" << std::endl; | 626 std::cerr << "ERROR: fftf_plan_dft_r2c_1d(" << m_windowSize << ") failed!" << std::endl; |
625 throw(0); | 627 throw(0); |
626 } | 628 } |
786 | 788 |
787 if (m_memoryCache) { | 789 if (m_memoryCache) { |
788 | 790 |
789 cache = new FFTMemoryCache | 791 cache = new FFTMemoryCache |
790 (m_compactCache ? FFTMemoryCache::Compact : | 792 (m_compactCache ? FFTMemoryCache::Compact : |
791 FFTMemoryCache::Polar); | 793 // FFTMemoryCache::Polar); |
794 m_polar ? FFTMemoryCache::Polar : | |
795 FFTMemoryCache::Rectangular); | |
792 | 796 |
793 } else if (m_compactCache) { | 797 } else if (m_compactCache) { |
794 | 798 |
795 cache = new FFTFileCache | 799 cache = new FFTFileCache |
796 (name, | 800 (name, |