comparison data/fft/FFTDataServer.cpp @ 203:11e107062a2b

* Fix apparent (but not actual) failure to save session file * Fix doofusness in FFT model (N/2 vs N/2+1) -- need to review use of this model in spectrogram
author Chris Cannam
date Fri, 08 Dec 2006 18:17:29 +0000
parents 91fdc752e540
children 05154c7bb90b
comparison
equal deleted inserted replaced
202:91fdc752e540 203:11e107062a2b
342 342
343 size_t start = m_model->getStartFrame(); 343 size_t start = m_model->getStartFrame();
344 size_t end = m_model->getEndFrame(); 344 size_t end = m_model->getEndFrame();
345 345
346 m_width = (end - start) / m_windowIncrement + 1; 346 m_width = (end - start) / m_windowIncrement + 1;
347 m_height = m_fftSize / 2; 347 m_height = m_fftSize / 2 + 1; // DC == 0, Nyquist == fftsize/2
348 348
349 size_t maxCacheSize = 20 * 1024 * 1024; 349 size_t maxCacheSize = 20 * 1024 * 1024;
350 size_t columnSize = m_height * sizeof(fftsample) * 2 + sizeof(fftsample); 350 size_t columnSize = m_height * sizeof(fftsample) * 2 + sizeof(fftsample);
351 if (m_width * columnSize < maxCacheSize * 2) m_cacheWidth = m_width; 351 if (m_width * columnSize < maxCacheSize * 2) m_cacheWidth = m_width;
352 else m_cacheWidth = maxCacheSize / columnSize; 352 else m_cacheWidth = maxCacheSize / columnSize;
399 399
400 m_fftInput = (fftsample *) 400 m_fftInput = (fftsample *)
401 fftwf_malloc(fftSize * sizeof(fftsample)); 401 fftwf_malloc(fftSize * sizeof(fftsample));
402 402
403 m_fftOutput = (fftwf_complex *) 403 m_fftOutput = (fftwf_complex *)
404 fftwf_malloc(fftSize * sizeof(fftwf_complex)); 404 fftwf_malloc((fftSize/2 + 1) * sizeof(fftwf_complex));
405 405
406 m_workbuffer = (float *) 406 m_workbuffer = (float *)
407 fftwf_malloc(fftSize * sizeof(float)); 407 fftwf_malloc((fftSize+2) * sizeof(float));
408 408
409 m_fftPlan = fftwf_plan_dft_r2c_1d(m_fftSize, 409 m_fftPlan = fftwf_plan_dft_r2c_1d(m_fftSize,
410 m_fftInput, 410 m_fftInput,
411 m_fftOutput, 411 m_fftOutput,
412 FFTW_ESTIMATE); 412 FFTW_ESTIMATE);
782 782
783 fftwf_execute(m_fftPlan); 783 fftwf_execute(m_fftPlan);
784 784
785 fftsample factor = 0.0; 785 fftsample factor = 0.0;
786 786
787 for (size_t i = 0; i < m_fftSize/2; ++i) { 787 for (size_t i = 0; i <= m_fftSize/2; ++i) {
788 788
789 fftsample mag = sqrtf(m_fftOutput[i][0] * m_fftOutput[i][0] + 789 fftsample mag = sqrtf(m_fftOutput[i][0] * m_fftOutput[i][0] +
790 m_fftOutput[i][1] * m_fftOutput[i][1]); 790 m_fftOutput[i][1] * m_fftOutput[i][1]);
791 mag /= m_windowSize / 2; 791 mag /= m_windowSize / 2;
792 792
794 794
795 fftsample phase = atan2f(m_fftOutput[i][1], m_fftOutput[i][0]); 795 fftsample phase = atan2f(m_fftOutput[i][1], m_fftOutput[i][0]);
796 phase = princargf(phase); 796 phase = princargf(phase);
797 797
798 m_workbuffer[i] = mag; 798 m_workbuffer[i] = mag;
799 m_workbuffer[i + m_fftSize/2] = phase; 799 m_workbuffer[i + m_fftSize/2+1] = phase;
800 } 800 }
801 801
802 cache->setColumnAt(col, 802 cache->setColumnAt(col,
803 m_workbuffer, 803 m_workbuffer,
804 m_workbuffer + m_fftSize/2, 804 m_workbuffer + m_fftSize/2+1,
805 factor); 805 factor);
806 806
807 if (m_suspended) { 807 if (m_suspended) {
808 // std::cerr << "FFTDataServer::fillColumn(" << x << "): calling resume" << std::endl; 808 // std::cerr << "FFTDataServer::fillColumn(" << x << "): calling resume" << std::endl;
809 // resume(); 809 // resume();