* Default to using double-precision FFTs only when linking against FFTW,

to avoid having to -lfftw3 -lfftw3f
This commit is contained in:
Chris Cannam
2007-11-27 14:12:04 +00:00
parent 653bf4017a
commit 09dadc239a
6 changed files with 227 additions and 160 deletions

View File

@@ -52,6 +52,24 @@ public:
// Remove this define to make float FFTs be carried out using fftwf_*
// functions instead of converting to doubles and using fftw_*.
#define FFTW_DOUBLE_ONLY 1
#ifdef FFTW_DOUBLE_ONLY
#define fftwf_complex fftw_complex
#define fftwf_plan fftw_plan
#define fftwf_plan_dft_r2c_1d fftw_plan_dft_r2c_1d
#define fftwf_plan_dft_c2r_1d fftw_plan_dft_c2r_1d
#define fftwf_destroy_plan fftw_destroy_plan
#define fftwf_free fftw_free
#define fftwf_execute fftw_execute
#define atan2f atan2
#define sqrtf sqrt
#define cosf cos
#define sinf sin
#endif
class D_FFTW : public FFTImpl
{
public:
@@ -90,7 +108,11 @@ public:
if (m_extantf++ == 0) load = true;
m_extantMutex.unlock();
if (load) loadWisdom('f');
#ifdef FFTW_DOUBLE_ONLY
m_fbuf = (double *)fftw_malloc(m_size * sizeof(double));
#else
m_fbuf = (float *)fftw_malloc(m_size * sizeof(float));
#endif
m_fpacked = (fftwf_complex *)fftw_malloc
((m_size/2 + 1) * sizeof(fftwf_complex));
m_fplanf = fftwf_plan_dft_r2c_1d
@@ -120,6 +142,10 @@ public:
void wisdom(bool save, char type) {
#ifdef FFTW_DOUBLE_ONLY
if (type == 'f') return;
#endif
const char *home = getenv("HOME");
if (!home) return;
@@ -131,13 +157,18 @@ public:
if (save) {
switch (type) {
#ifndef FFTW_DOUBLE_ONLY
case 'f': fftwf_export_wisdom_to_file(f); break;
case 'd': fftw_export_wisdom_to_file(f); break;
default: break;
}
} else {
switch (type) {
#ifndef FFTW_DOUBLE_ONLY
case 'f': fftwf_import_wisdom_from_file(f); break;
#endif
case 'd': fftw_import_wisdom_from_file(f); break;
default: break;
}
}
@@ -283,15 +314,19 @@ public:
}
private:
unsigned int m_size;
fftwf_plan m_fplanf;
fftwf_plan m_fplani;
#ifdef FFTW_DOUBLE_ONLY
double *m_fbuf;
#else
float *m_fbuf;
#endif
fftwf_complex *m_fpacked;
fftw_plan m_dplanf;
fftw_plan m_dplani;
float *m_fbuf;
fftwf_complex *m_fpacked;
double *m_dbuf;
fftw_complex *m_dpacked;
unsigned int m_size;
static unsigned int m_extantf;
static unsigned int m_extantd;
static Mutex m_extantMutex;
@@ -306,6 +341,7 @@ D_FFTW::m_extantd = 0;
Mutex
D_FFTW::m_extantMutex;
#endif
class D_Cross : public FFTImpl
{

View File

@@ -385,6 +385,13 @@ RubberBandPitchShifter::runImpl(unsigned long insamples)
// std::cout << "out chunk: " << chunk << std::endl;
m_outputBuffer[c]->read(m_output[c], chunk);
}
static int minr = -1;
int avail = m_outputBuffer[0]->getReadSpace();
if (minr == -1 || (avail >= 0 && avail < minr)) {
std::cerr << "RubberBandPitchShifter::runImpl: new min remaining " << avail << " from " << minr << std::endl;
minr = avail;
}
}
void

View File

@@ -268,6 +268,8 @@ int main(int argc, char **argv)
int frame = 0;
int percent = 0;
sf_seek(sndfile, 0, SEEK_SET);
if (!realtime) {
if (!quiet) {
@@ -278,7 +280,6 @@ int main(int argc, char **argv)
int count = -1;
if (sf_seek(sndfile, frame, SEEK_SET) < 0) break;
if ((count = sf_readf_float(sndfile, fbuf, ibs)) <= 0) break;
for (size_t c = 0; c < channels; ++c) {
@@ -306,6 +307,8 @@ int main(int argc, char **argv)
if (!quiet) {
cerr << "\rCalculating profile..." << endl;
}
sf_seek(sndfile, 0, SEEK_SET);
}
frame = 0;
@@ -321,7 +324,6 @@ int main(int argc, char **argv)
int count = -1;
if (sf_seek(sndfile, frame, SEEK_SET) < 0) break;
if ((count = sf_readf_float(sndfile, fbuf, ibs)) < 0) break;
countIn += count;
@@ -446,7 +448,7 @@ int main(int argc, char **argv)
struct timeval etv;
(void)gettimeofday(&etv, 0);
etv.tv_sec -= tv.tv_sec;
if (etv.tv_usec < tv.tv_usec) {
etv.tv_usec += 1000000;