Fix C++ standards library portability issue. (#4261)

Fix C++ standards library portability issue.
Cherry-pick of upstream 2.5 patches: zynaddsubfx/zynaddsubfx@417d49b, zynaddsubfx/zynaddsubfx@edca8ab
Closes #4152
This commit is contained in:
Tres Finocchiaro
2018-03-18 13:36:05 -04:00
committed by GitHub
parent b4e78065e7
commit 6cd5317e09
3 changed files with 23 additions and 4 deletions

View File

@@ -49,5 +49,24 @@ class FFTwrapper
fftwf_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 (std::isnan(__x))
__x = 0;
_Tp __y = __rho * sin(__theta);
if (std::isnan(__y))
__y = 0;
return std::complex<_Tp>(__x, __y);
}
void FFT_cleanup();
#endif

View File

@@ -615,7 +615,7 @@ void PADnoteParameters::applyparameters(bool lockmutex)
newsample.smp[0] = 0.0f;
for(int i = 1; i < spectrumsize; ++i) //randomize the phases
fftfreqs[i] = std::polar(spectrum[i], (float)RND * 6.29f);
fftfreqs[i] = FFTpolar(spectrum[i], (float)RND * 6.29f);
fft->freqs2smps(fftfreqs, newsample.smp); //that's all; here is the only ifft for the whole sample; no windows are used ;-)

View File

@@ -533,7 +533,7 @@ void OscilGen::spectrumadjust()
mag = 1.0f;
break;
}
oscilFFTfreqs[i] = std::polar<fftw_real>(mag, phase);
oscilFFTfreqs[i] = FFTpolar<fftw_real>(mag, phase);
}
}
@@ -629,7 +629,7 @@ void OscilGen::prepare()
int k = i * (j + 1);
if(k >= synth->oscilsize / 2)
break;
oscilFFTfreqs[k] += basefuncFFTfreqs[i] * std::polar<fftw_real>(
oscilFFTfreqs[k] += basefuncFFTfreqs[i] * FFTpolar<fftw_real>(
hmag[j],
hphase[j] * k);
}
@@ -857,7 +857,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