Skip to content

Commit

Permalink
Fix C++ standards library portability issue.
Browse files Browse the repository at this point in the history
Signed-off-by: Hans Petter Selasky <[email protected]>
  • Loading branch information
hselasky committed Oct 24, 2014
1 parent 02daa9f commit 417d49b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
19 changes: 19 additions & 0 deletions src/DSP/FFTwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,24 @@ class FFTwrapper
fftw_plan planfftw, planfftw_inv;
};

/*
* The "std::polar" template has no clear definition for the range of
* the input parameters, and some C++ standard library implementations
* don't accept negative amplitude among others. Define our own
* FFTpolar template, which works like we expect it to.
*/
template<class _Tp>
std::complex<_Tp>
FFTpolar(const _Tp& __rho, const _Tp& __theta = _Tp(0))
{
_Tp __x = __rho * cos(__theta);
if (isnan(__x))
__x = 0;
_Tp __y = __rho * sin(__theta);
if (isnan(__y))
__y = 0;
return std::complex<_Tp>(__x, __y);
}

void FFT_cleanup();
#endif
2 changes: 1 addition & 1 deletion src/Params/PADnoteParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ void PADnoteParameters::sampleGenerator(PADnoteParameters::callback cb,

newsample.smp[0] = 0.0f;
for(int i = 1; i < spectrumsize; ++i) //randomize the phases
fftfreqs[i] = std::polar(spectrum[i], (float)RND * 2 * PI);
fftfreqs[i] = FFTpolar(spectrum[i], (float)RND * 2 * PI);
//that's all; here is the only ifft for the whole sample;
//no windows are used ;-)
fft->freqs2smps(fftfreqs, newsample.smp);
Expand Down
6 changes: 3 additions & 3 deletions src/Synth/OscilGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ void OscilGen::spectrumadjust(fft_t *freqs)
mag = 1.0f;
break;
}
freqs[i] = std::polar<fftw_real>(mag, phase);
freqs[i] = FFTpolar<fftw_real>(mag, phase);
}
}

Expand Down Expand Up @@ -766,7 +766,7 @@ void OscilGen::prepare(fft_t *freqs)
int k = i * (j + 1);
if(k >= synth->oscilsize / 2)
break;
freqs[k] += basefuncFFTfreqs[i] * std::polar<fftw_real>(
freqs[k] += basefuncFFTfreqs[i] * FFTpolar<fftw_real>(
hmag[j],
hphase[j] * k);
}
Expand Down Expand Up @@ -981,7 +981,7 @@ short int OscilGen::get(float *smps, float freqHz, int resonance)
const float rnd = PI * powf((Prand - 64.0f) / 64.0f, 2.0f);
for(int i = 1; i < nyquist - 1; ++i) //to Nyquist only for AntiAliasing
outoscilFFTfreqs[i] *=
std::polar<fftw_real>(1.0f, (float)(rnd * i * RND));
FFTpolar<fftw_real>(1.0f, (float)(rnd * i * RND));
}

//Harmonic Amplitude Randomness
Expand Down
5 changes: 3 additions & 2 deletions src/UI/Fl_EQGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Fl_EQGraph.H"
#include "common.H"
#include "../Effects/EffectMgr.h"
#include "../DSP/FFTwrapper.h"
#include "../globals.h"

#include <rtosc/rtosc.h>
Expand Down Expand Up @@ -139,8 +140,8 @@ double Fl_EQGraph::getresponse(int maxy,float freq) const


for(int i = 0; i < MAX_EQ_BANDS*MAX_FILTER_STAGES*2+1; ++i) {
num_res += std::polar<float>(num[i], i*angle);
dem_res += std::polar<float>(dem[i], i*angle);
num_res += FFTpolar<float>(num[i], i*angle);
dem_res += FFTpolar<float>(dem[i], i*angle);
}

float dbresp=20*log(abs(num_res/dem_res))/log(10);
Expand Down

0 comments on commit 417d49b

Please sign in to comment.