comparison layer/SpectrogramLayer.cpp @ 102:8ce53683d0d7 sv1-v0.9rc2

* I wonder if the fftw_ functions are not as thread-safe as I'd hoped?
author Chris Cannam
date Fri, 12 May 2006 16:51:19 +0000
parents 0f36cdf407a6
children 1348818e7be7
comparison
equal deleted inserted replaced
101:0f36cdf407a6 102:8ce53683d0d7
1326 MatrixFile::ReadOnly); 1326 MatrixFile::ReadOnly);
1327 1327
1328 m_layer.setColourmap(); 1328 m_layer.setColourmap();
1329 //!!! m_layer.m_writeCache->reset(); 1329 //!!! m_layer.m_writeCache->reset();
1330 1330
1331 double *input = (double *)
1332 fftw_malloc(windowSize * sizeof(double));
1333
1334 fftw_complex *output = (fftw_complex *)
1335 fftw_malloc(windowSize * sizeof(fftw_complex));
1336
1337 float *workbuffer = (float *)
1338 fftw_malloc(windowSize * sizeof(float));
1339
1340 fftw_plan plan = fftw_plan_dft_r2c_1d(windowSize, input,
1341 output, FFTW_ESTIMATE);
1342
1343 if (!plan) {
1344 std::cerr << "WARNING: fftw_plan_dft_r2c_1d(" << windowSize << ") failed!" << std::endl;
1345 fftw_free(input);
1346 fftw_free(output);
1347 fftw_free(workbuffer);
1348 continue;
1349 }
1350
1331 // We don't need a lock when writing to or reading from 1351 // We don't need a lock when writing to or reading from
1332 // the pixels in the cache. We do need to ensure we have 1352 // the pixels in the cache. We do need to ensure we have
1333 // the width and height of the cache and the FFT 1353 // the width and height of the cache and the FFT
1334 // parameters known before we unlock, in case they change 1354 // parameters known before we unlock, in case they change
1335 // in the model while we aren't holding a lock. It's safe 1355 // in the model while we aren't holding a lock. It's safe
1337 // happens, because they will continue to match the 1357 // happens, because they will continue to match the
1338 // dimensions of the actual cache (which this thread 1358 // dimensions of the actual cache (which this thread
1339 // manages, not the layer's). 1359 // manages, not the layer's).
1340 m_layer.m_mutex.unlock(); 1360 m_layer.m_mutex.unlock();
1341 1361
1342 double *input = (double *)
1343 fftw_malloc(windowSize * sizeof(double));
1344
1345 fftw_complex *output = (fftw_complex *)
1346 fftw_malloc(windowSize * sizeof(fftw_complex));
1347
1348 float *workbuffer = (float *)
1349 fftw_malloc(windowSize * sizeof(float));
1350
1351 fftw_plan plan = fftw_plan_dft_r2c_1d(windowSize, input,
1352 output, FFTW_ESTIMATE);
1353
1354 Window<double> windower(windowType, windowSize); 1362 Window<double> windower(windowType, windowSize);
1355
1356 if (!plan) {
1357 std::cerr << "WARNING: fftw_plan_dft_r2c_1d(" << windowSize << ") failed!" << std::endl;
1358 fftw_free(input);
1359 fftw_free(output);
1360 fftw_free(workbuffer);
1361 m_layer.m_mutex.lock();
1362 continue;
1363 }
1364 1363
1365 int counter = 0; 1364 int counter = 0;
1366 int updateAt = (end / windowIncrement) / 20; 1365 int updateAt = (end / windowIncrement) / 20;
1367 if (updateAt < 100) updateAt = 100; 1366 if (updateAt < 100) updateAt = 100;
1368 1367