Skip to content

Commit 417d49b

Browse files
committed
Fix C++ standards library portability issue.
Signed-off-by: Hans Petter Selasky <[email protected]>
1 parent 02daa9f commit 417d49b

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

src/DSP/FFTwrapper.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,24 @@ class FFTwrapper
4848
fftw_plan planfftw, planfftw_inv;
4949
};
5050

51+
/*
52+
* The "std::polar" template has no clear definition for the range of
53+
* the input parameters, and some C++ standard library implementations
54+
* don't accept negative amplitude among others. Define our own
55+
* FFTpolar template, which works like we expect it to.
56+
*/
57+
template<class _Tp>
58+
std::complex<_Tp>
59+
FFTpolar(const _Tp& __rho, const _Tp& __theta = _Tp(0))
60+
{
61+
_Tp __x = __rho * cos(__theta);
62+
if (isnan(__x))
63+
__x = 0;
64+
_Tp __y = __rho * sin(__theta);
65+
if (isnan(__y))
66+
__y = 0;
67+
return std::complex<_Tp>(__x, __y);
68+
}
69+
5170
void FFT_cleanup();
5271
#endif

src/Params/PADnoteParameters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ void PADnoteParameters::sampleGenerator(PADnoteParameters::callback cb,
796796

797797
newsample.smp[0] = 0.0f;
798798
for(int i = 1; i < spectrumsize; ++i) //randomize the phases
799-
fftfreqs[i] = std::polar(spectrum[i], (float)RND * 2 * PI);
799+
fftfreqs[i] = FFTpolar(spectrum[i], (float)RND * 2 * PI);
800800
//that's all; here is the only ifft for the whole sample;
801801
//no windows are used ;-)
802802
fft->freqs2smps(fftfreqs, newsample.smp);

src/Synth/OscilGen.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ void OscilGen::spectrumadjust(fft_t *freqs)
665665
mag = 1.0f;
666666
break;
667667
}
668-
freqs[i] = std::polar<fftw_real>(mag, phase);
668+
freqs[i] = FFTpolar<fftw_real>(mag, phase);
669669
}
670670
}
671671

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

987987
//Harmonic Amplitude Randomness

src/UI/Fl_EQGraph.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Fl_EQGraph.H"
44
#include "common.H"
55
#include "../Effects/EffectMgr.h"
6+
#include "../DSP/FFTwrapper.h"
67
#include "../globals.h"
78

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

140141

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

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

0 commit comments

Comments
 (0)