Use global constant for pi instead of define. Calculate sinus transform in envelope transform only if amount more than zero.

This commit is contained in:
xenakios 2018-03-26 15:40:30 +03:00
parent 52ebb38415
commit 8421269565
4 changed files with 11 additions and 12 deletions

View File

@ -94,7 +94,7 @@ void FFT::smp2freq()
void FFT::freq2smp() void FFT::freq2smp()
{ {
REALTYPE inv_2p15_2pi=1.0f/16384.0f*(float)M_PI; REALTYPE inv_2p15_2pi=1.0f/16384.0f*(float)c_PI;
for (int i=1;i<nsamples/2;i++) for (int i=1;i<nsamples/2;i++)
{ {
unsigned int rand = m_randdist(m_randgen); unsigned int rand = m_randdist(m_randgen);
@ -120,16 +120,16 @@ void FFT::applywindow(FFTWindow type)
for (int i=0;i<nsamples;i++) window.data[i]=0.707f; for (int i=0;i<nsamples;i++) window.data[i]=0.707f;
break; break;
case W_HAMMING: case W_HAMMING:
for (int i=0;i<nsamples;i++) window.data[i]=(float)(0.53836-0.46164*cos(2.0*M_PI*i/(nsamples+1.0))); for (int i=0;i<nsamples;i++) window.data[i]=(float)(0.53836-0.46164*cos(2.0*c_PI*i/(nsamples+1.0)));
break; break;
case W_HANN: case W_HANN:
for (int i=0;i<nsamples;i++) window.data[i]=(float)(0.5*(1.0-cos(2*M_PI*i/(nsamples-1.0)))); for (int i=0;i<nsamples;i++) window.data[i]=(float)(0.5*(1.0-cos(2*c_PI*i/(nsamples-1.0))));
break; break;
case W_BLACKMAN: case W_BLACKMAN:
for (int i=0;i<nsamples;i++) window.data[i]=(float)(0.42-0.5*cos(2*M_PI*i/(nsamples-1.0))+0.08*cos(4*M_PI*i/(nsamples-1.0))); for (int i=0;i<nsamples;i++) window.data[i]=(float)(0.42-0.5*cos(2*c_PI*i/(nsamples-1.0))+0.08*cos(4*c_PI*i/(nsamples-1.0)));
break; break;
case W_BLACKMAN_HARRIS: case W_BLACKMAN_HARRIS:
for (int i=0;i<nsamples;i++) window.data[i]=(float)(0.35875-0.48829*cos(2*M_PI*i/(nsamples-1.0))+0.14128*cos(4*M_PI*i/(nsamples-1.0))-0.01168*cos(6*M_PI*i/(nsamples-1.0))); for (int i=0;i<nsamples;i++) window.data[i]=(float)(0.35875-0.48829*cos(2*c_PI*i/(nsamples-1.0))+0.14128*cos(4*c_PI*i/(nsamples-1.0))-0.01168*cos(6*c_PI*i/(nsamples-1.0)));
break; break;
}; };
@ -305,7 +305,7 @@ REALTYPE Stretch::process(REALTYPE *smps,int nsmps)
outfft->freq2smp(); outfft->freq2smp();
//make the output buffer //make the output buffer
REALTYPE tmp=(float)(1.0/(float) bufsize*M_PI); REALTYPE tmp=(float)(1.0/(float) bufsize*c_PI);
REALTYPE hinv_sqrt2=0.853553390593f;//(1.0+1.0/sqrt(2))*0.5; REALTYPE hinv_sqrt2=0.853553390593f;//(1.0+1.0/sqrt(2))*0.5;
REALTYPE ampfactor=2.0f; REALTYPE ampfactor=2.0f;

View File

@ -61,9 +61,7 @@ inline String formatted(Args... args)
#define NULL 0 #define NULL 0
#endif #endif
#ifndef M_PI const double c_PI = 3.14159265359;
#define M_PI 3.14159265359
#endif
const int g_maxnumoutchans = 32; const int g_maxnumoutchans = 32;

View File

@ -843,7 +843,7 @@ void SpectralVisualizer::setState(const ProcessParameters & pars, int nfreqs, do
for (int j = 0; j < numharmonics; ++j) for (int j = 0; j < numharmonics; ++j)
{ {
double oscgain = 1.0 - (1.0 / numharmonics)*j; double oscgain = 1.0 - (1.0 / numharmonics)*j;
m_insamples[i] += scaler * oscgain * sin(2 * 3.141592653 / samplerate * i* (hz + hz * j)); m_insamples[i] += scaler * oscgain * sin(2 * c_PI / samplerate * i* (hz + hz * j));
} }
} }
} }

View File

@ -596,8 +596,9 @@ public:
double center_v = m_minvalue + (m_maxvalue - m_minvalue) / 2.0; double center_v = m_minvalue + (m_maxvalue - m_minvalue) / 2.0;
double diff = center_v - v; double diff = center_v - v;
double scaled = center_v - m_transform_y_scale * diff; double scaled = center_v - m_transform_y_scale * diff;
double shifted = scaled + m_transform_y_shift + m_transform_y_sinus* double shifted = scaled + m_transform_y_shift;
sin(2*3.141592653*(x-m_transform_x_shift)*m_transform_y_sinus_freq); if (m_transform_y_sinus>0.0)
shifted+=m_transform_y_sinus * sin(2*c_PI*(x-m_transform_x_shift)*m_transform_y_sinus_freq);
double tiltline = m_transform_y_tilt-(2.0*m_transform_y_tilt*x); double tiltline = m_transform_y_tilt-(2.0*m_transform_y_tilt*x);
double tilted = shifted+tiltline; double tilted = shifted+tiltline;
if (m_transform_y_random_amount > 0.0) if (m_transform_y_random_amount > 0.0)