Clean up math functions

- Remove checking for standard functions from the build system
- Prefix all invocations with std::
- Replace suffixed functions with unprefixed versions
- Include <cmath> in all files that use it and remove the global include

e.g. floorf(x) -> std::floor(x)
This commit is contained in:
Martin Natano
2023-04-19 19:31:40 +02:00
parent f39ed52dbf
commit b68ca517e6
111 changed files with 1831 additions and 1785 deletions
+15 -14
View File
@@ -12,6 +12,7 @@
#include "RageMath.h"
#include "RageThreads.h"
#include <cmath>
#include <numeric>
/* Filter length. This must be a power of 2. */
@@ -23,14 +24,14 @@ namespace
{
if( f == 0 )
return 1;
return sinf(f)/f;
return std::sin(f) / f;
}
/* Modified Bessel function I0. From Abramowitz and Stegun "Handbook of Mathematical
* Functions", "Modified Bessel Functions I and K". */
float BesselI0( float fX )
{
float fAbsX = fabsf( fX );
float fAbsX = std::abs( fX );
if( fAbsX < 3.75f )
{
float y = fX / 3.75f;
@@ -41,16 +42,16 @@ namespace
else
{
float y = 3.75f/fAbsX;
float fRet = (exp(fAbsX)/sqrt(fAbsX)) *
float fRet = (std::exp(fAbsX)/std::sqrt(fAbsX)) *
(+0.39894228f+y*(+0.01328592f+y*(+0.00225319f+y*(-0.00157565f+y*(0.00916281f+
y*(-0.02057706f+y*(+0.02635537f+y*(-0.01647633f+y*+0.00392377f))))))));
return fRet;
}
}
/*
/*
* Kaiser window:
*
*
* K(n) = I0( B*sqrt(1-(n/p)^2) )
* -----------------------
* I0(B)
@@ -63,8 +64,8 @@ namespace
float p = (iLen-1)/2.0f;
for( int n = 0; n < iLen; ++n )
{
float fN1 = fabsf((n-p)/p);
float fNum = fBeta * sqrtf( std::max(1-fN1*fN1, 0.0f) );
float fN1 = std::abs((n-p)/p);
float fNum = fBeta * std::sqrt( std::max(1.0f - fN1*fN1, 0.0f) );
fNum = BesselI0( fNum );
float fVal = fNum/fDenom;
pBuf[n] *= fVal;
@@ -216,7 +217,7 @@ private:
* input first output sample (before decimation)
* sample second output sample
* third output sample
*
*
* 0 0
* 0 1 0
* 1592 2 1 0
@@ -290,7 +291,7 @@ int PolyphaseFilter::RunPolyphaseFilter(
float *pOutOrig = pOut;
const float *pInEnd = pIn + iSamplesIn*iSampleStride;
const float *pOutEnd = pOut + iSamplesOut*iSampleStride;
int iFilled = State.m_iFilled;
int iPolyIndex = State.m_iPolyIndex;
while( pOut != pOutEnd )
@@ -394,7 +395,7 @@ namespace PolyphaseFilterCache
typedef std::map<std::pair<int, float>, PolyphaseFilter*> FilterMap;
static RageMutex PolyphaseFiltersLock("PolyphaseFiltersLock");
static FilterMap g_mapPolyphaseFilters;
const PolyphaseFilter *MakePolyphaseFilter( int iUpFactor, float fCutoffFrequency )
{
PolyphaseFiltersLock.Lock();
@@ -452,7 +453,7 @@ public:
* too much filtering, by not having a LPF that's high enough. */
RageSoundResampler_Polyphase( int iUpFactor, int iMinDownFactor, int iMaxDownFactor )
{
/* Cache filters between iMinDownFactor and iMaxDownFactor. Do them in
/* Cache filters between iMinDownFactor and iMaxDownFactor. Do them in
* iFilterIncrement increments; we'll round down to the closest match
* when filtering. This will only cause the low-pass filter to be rounded;
* the conversion ratio will always be exact. */
@@ -527,7 +528,7 @@ private:
float fCutoffFrequency = GetCutoffFrequency( iDownFactor );
return PolyphaseFilterCache::FindNearestPolyphaseFilter( m_iUpFactor, fCutoffFrequency );
}
const PolyphaseFilter *m_pPolyphase;
PolyphaseFilter::State *m_pState;
int m_iUpFactor;
@@ -620,7 +621,7 @@ void RageSoundReader_Resample_Good::ReopenResampler()
}
if( m_fRate != -1 )
iDownFactor = lrintf( m_fRate * iDownFactor );
iDownFactor = std::lrint( m_fRate * iDownFactor );
for( size_t iChannel = 0; iChannel < m_apResamplers.size(); ++iChannel )
m_apResamplers[iChannel]->SetDownFactor( iDownFactor );
@@ -696,7 +697,7 @@ void RageSoundReader_Resample_Good::SetRate( float fRatio )
int iDownFactor, iUpFactor;
GetFactors( iDownFactor, iUpFactor );
if( m_fRate != -1 )
iDownFactor = lrintf( m_fRate * iDownFactor );
iDownFactor = std::lrint( m_fRate * iDownFactor );
/* Set m_fRate to the actual rate, after quantization by iUpFactor. */
m_fRate = float(iDownFactor) / iUpFactor;