changeset 39:4ed2448582cc

* Switch from fftw3 to fftw3f. I think the efficiency improvement is probably worth the lower precision, although I ought to do a few more tests.
author Chris Cannam
date Thu, 15 Jun 2006 12:28:47 +0000
parents 54287e5e7451
children a996c0ef6177
files audioio/AudioCallbackPlaySource.cpp audioio/AudioCallbackPlaySource.h audioio/IntegerTimeStretcher.cpp audioio/IntegerTimeStretcher.h
diffstat 4 files changed, 43 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/audioio/AudioCallbackPlaySource.cpp	Fri May 12 14:40:43 2006 +0000
+++ b/audioio/AudioCallbackPlaySource.cpp	Thu Jun 15 12:28:47 2006 +0000
@@ -602,9 +602,9 @@
 	    //what sort of quality level to use -- or at least to
 	    //allow the user to configure it
 	    (new IntegerTimeStretcher(factor, blockSize, 128),
-	     new double[blockSize * factor]);
+	     new float[blockSize * factor]);
     }
-    m_stretchInputBuffer = new double[blockSize];
+    m_stretchInputBuffer = new float[blockSize];
 }
 
 AudioCallbackPlaySource::TimeStretcherData::~TimeStretcherData()
@@ -625,13 +625,13 @@
     return m_stretcher[channel].first;
 }
 
-double *
+float *
 AudioCallbackPlaySource::TimeStretcherData::getOutputBuffer(size_t channel)
 {
     return m_stretcher[channel].second;
 }
 
-double *
+float *
 AudioCallbackPlaySource::TimeStretcherData::getInputBuffer()
 {
     return m_stretchInputBuffer;
@@ -721,7 +721,7 @@
     if (m_slowdownCounter == 0) {
 
 	size_t got = 0;
-	double *ib = timeStretcher->getInputBuffer();
+	float *ib = timeStretcher->getInputBuffer();
 
 	for (size_t ch = 0; ch < getTargetChannelCount(); ++ch) {
 
@@ -753,7 +753,7 @@
 
     for (size_t ch = 0; ch < getTargetChannelCount(); ++ch) {
 
-	double *ob = timeStretcher->getOutputBuffer(ch);
+	float *ob = timeStretcher->getOutputBuffer(ch);
 
 #ifdef DEBUG_AUDIO_PLAY_SOURCE
 	std::cerr << "AudioCallbackPlaySource::getSamples: Copying from (" << (m_slowdownCounter * count) << "," << count << ") to buffer" << std::endl;
--- a/audioio/AudioCallbackPlaySource.h	Fri May 12 14:40:43 2006 +0000
+++ b/audioio/AudioCallbackPlaySource.h	Thu Jun 15 12:28:47 2006 +0000
@@ -252,8 +252,8 @@
 
 	size_t getFactor() const { return m_factor; }
 	IntegerTimeStretcher *getStretcher(size_t channel);
-	double *getOutputBuffer(size_t channel);
-	double *getInputBuffer();
+	float *getOutputBuffer(size_t channel);
+	float *getInputBuffer();
 	
 	void run(size_t channel);
 
@@ -261,9 +261,9 @@
 	TimeStretcherData(const TimeStretcherData &); // not provided
 	TimeStretcherData &operator=(const TimeStretcherData &); // not provided
 
-	typedef std::pair<IntegerTimeStretcher *, double *> StretcherBuffer;
+	typedef std::pair<IntegerTimeStretcher *, float *> StretcherBuffer;
 	std::map<size_t, StretcherBuffer> m_stretcher;
-	double *m_stretchInputBuffer;
+	float *m_stretchInputBuffer;
 	size_t m_factor;
 	size_t m_blockSize;
     };
--- a/audioio/IntegerTimeStretcher.cpp	Fri May 12 14:40:43 2006 +0000
+++ b/audioio/IntegerTimeStretcher.cpp	Thu Jun 15 12:28:47 2006 +0000
@@ -32,16 +32,16 @@
     m_inbuf(m_wlen),
     m_outbuf(maxProcessInputBlockSize * ratio)
 {
-    m_window = new Window<double>(windowType, m_wlen),
+    m_window = new Window<float>(windowType, m_wlen),
 
-    m_time = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * m_wlen);
-    m_freq = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * m_wlen);
-    m_dbuf = (double *)fftw_malloc(sizeof(double) * m_wlen);
+    m_time = (fftwf_complex *)fftwf_malloc(sizeof(fftwf_complex) * m_wlen);
+    m_freq = (fftwf_complex *)fftwf_malloc(sizeof(fftwf_complex) * m_wlen);
+    m_dbuf = (float *)fftwf_malloc(sizeof(float) * m_wlen);
 
-    m_plan = fftw_plan_dft_1d(m_wlen, m_time, m_freq, FFTW_FORWARD, FFTW_ESTIMATE);
-    m_iplan = fftw_plan_dft_c2r_1d(m_wlen, m_freq, m_dbuf, FFTW_ESTIMATE);
+    m_plan = fftwf_plan_dft_1d(m_wlen, m_time, m_freq, FFTW_FORWARD, FFTW_ESTIMATE);
+    m_iplan = fftwf_plan_dft_c2r_1d(m_wlen, m_freq, m_dbuf, FFTW_ESTIMATE);
 
-    m_mashbuf = new double[m_wlen];
+    m_mashbuf = new float[m_wlen];
     for (int i = 0; i < m_wlen; ++i) {
 	m_mashbuf[i] = 0.0;
     }
@@ -51,12 +51,12 @@
 {
     std::cerr << "IntegerTimeStretcher::~IntegerTimeStretcher" << std::endl;
 
-    fftw_destroy_plan(m_plan);
-    fftw_destroy_plan(m_iplan);
+    fftwf_destroy_plan(m_plan);
+    fftwf_destroy_plan(m_iplan);
 
-    fftw_free(m_time);
-    fftw_free(m_freq);
-    fftw_free(m_dbuf);
+    fftwf_free(m_time);
+    fftwf_free(m_freq);
+    fftwf_free(m_dbuf);
 
     delete m_window;
     delete m_mashbuf;
@@ -69,7 +69,7 @@
 }
 
 void
-IntegerTimeStretcher::process(double *input, double *output, size_t samples)
+IntegerTimeStretcher::process(float *input, float *output, size_t samples)
 {
     // We need to add samples from input to our internal buffer.  When
     // we have m_windowSize samples in the buffer, we can process it,
@@ -163,7 +163,7 @@
 }
 
 void
-IntegerTimeStretcher::processBlock(double *buf, double *out)
+IntegerTimeStretcher::processBlock(float *buf, float *out)
 {
     size_t i;
 
@@ -177,7 +177,7 @@
     m_window->cut(buf);
 
     for (i = 0; i < m_wlen/2; ++i) {
-	double temp = buf[i];
+	float temp = buf[i];
 	buf[i] = buf[i + m_wlen/2];
 	buf[i + m_wlen/2] = temp;
     }
@@ -187,27 +187,27 @@
 	m_time[i][1] = 0.0;
     }
 
-    fftw_execute(m_plan); // m_time -> m_freq
+    fftwf_execute(m_plan); // m_time -> m_freq
 
     for (i = 0; i < m_wlen; ++i) {
 	
-	double mag = sqrt(m_freq[i][0] * m_freq[i][0] +
+	float mag = sqrtf(m_freq[i][0] * m_freq[i][0] +
 			  m_freq[i][1] * m_freq[i][1]);
 		
-	double phase = atan2(m_freq[i][1], m_freq[i][0]);
+	float phase = atan2f(m_freq[i][1], m_freq[i][0]);
 	
 	phase = phase * m_ratio;
 	
-	double real = mag * cos(phase);
-	double imag = mag * sin(phase);
+	float real = mag * cosf(phase);
+	float imag = mag * sinf(phase);
 	m_freq[i][0] = real;
 	m_freq[i][1] = imag;
     }
     
-    fftw_execute(m_iplan); // m_freq -> in, inverse fft
+    fftwf_execute(m_iplan); // m_freq -> in, inverse fft
     
     for (i = 0; i < m_wlen/2; ++i) {
-	double temp = buf[i] / m_wlen;
+	float temp = buf[i] / m_wlen;
 	buf[i] = buf[i + m_wlen/2] / m_wlen;
 	buf[i + m_wlen/2] = temp;
     }
--- a/audioio/IntegerTimeStretcher.h	Fri May 12 14:40:43 2006 +0000
+++ b/audioio/IntegerTimeStretcher.h	Thu Jun 15 12:28:47 2006 +0000
@@ -41,7 +41,7 @@
 			 WindowType windowType = HanningWindow);
     virtual ~IntegerTimeStretcher();
 
-    void process(double *input, double *output, size_t samples);
+    void process(float *input, float *output, size_t samples);
 
     /**
      * Get the hop size for input.  Smaller values may produce better
@@ -68,24 +68,24 @@
     size_t getProcessingLatency() const;
 
 protected:
-    void processBlock(double *in, double *out);
+    void processBlock(float *in, float *out);
 
     size_t m_ratio;
     size_t m_n1;
     size_t m_n2;
     size_t m_wlen;
-    Window<double> *m_window;
+    Window<float> *m_window;
 
-    fftw_complex *m_time;
-    fftw_complex *m_freq;
-    double *m_dbuf;
+    fftwf_complex *m_time;
+    fftwf_complex *m_freq;
+    float *m_dbuf;
 
-    fftw_plan m_plan;
-    fftw_plan m_iplan;
+    fftwf_plan m_plan;
+    fftwf_plan m_iplan;
     
-    RingBuffer<double> m_inbuf;
-    RingBuffer<double> m_outbuf;
-    double *m_mashbuf;
+    RingBuffer<float> m_inbuf;
+    RingBuffer<float> m_outbuf;
+    float *m_mashbuf;
 };
 
 #endif