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
+28 -27
View File
@@ -7,6 +7,7 @@
#include "RageSoundReader_Resample_Good.h"
#include "test_misc.h"
#include <cmath>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -22,7 +23,7 @@ void ReadData( RageSoundReader *pReader,
int got = pReader->Read( pBuf, iFrames );
ASSERT_M( got == iFrames, ssprintf("%i, %i", got, iFrames) );
}
void find( const char *haystack, int hs, const char *needle, int ns )
{
for( int i = 0; i <= hs-ns; ++i )
@@ -79,7 +80,7 @@ void dump( const int16_t *buf, int samples )
void dump( const float *buf, int samples )
{
for( int i = 0; i < samples; ++i )
printf( "0x%04lx,", lrintf(buf[i]*32768) );
printf( "0x%04lx,", std::lrint(buf[i]*32768) );
printf( "\n" );
}
@@ -87,7 +88,7 @@ bool compare( const float *m1, const int16_t *m2, int iSamples )
{
for( int i = 0; i < iSamples; ++i )
{
int16_t iSample1 = lrintf(m1[i]*32768);
int16_t iSample1 = std::lrint(m1[i]*32768);
if( iSample1 != m2[i] )
return false;
}
@@ -104,10 +105,10 @@ void compare_buffers( const int16_t *expect, const int16_t *got, int frames,
NumInaccurateSamplesAtStart = 0;
NumInaccurateSamples = 0;
for( int i = 0; i < frames; ++i )
{
int diff = abs( expect[i] - got[i] );
int diff = std::abs( expect[i] - got[i] );
if( diff > 200 )
{
printf("%i\n", diff);
@@ -126,8 +127,8 @@ bool compare_buffers( const int16_t *expect, const int16_t *got, int frames, int
{
/*
* Compare each channel separately. Try to figure out if
* the data is exactly the same,
*
* the data is exactly the same,
*
* 2: either the source or dest data starts out around 0 and converges quickly
* on the other; this happens with resamplers after a seek, since they're missing
* data before the seeked position (could be fixed)
@@ -140,10 +141,10 @@ bool compare_buffers( const int16_t *expect, const int16_t *got, int frames, int
* converges.
*
* Determine if data is identical, but offset.
*
*
*/
int NumInaccurateSamples;
int NumInaccurateSamplesAtStart;
@@ -166,10 +167,10 @@ bool test_read( RageSoundReader *snd, float *expected_data, int frames )
// (const int16_t *) buf,
// bytes/2,
// 2 );
bool bMatches = true;
for( int i = 0; i < samples; ++i )
if( fabsf(buf[i] - expected_data[i]) > 0.00001f )
if( std::abs(buf[i] - expected_data[i]) > 0.00001f )
bMatches = false;
if( bMatches )
return true;
@@ -205,7 +206,7 @@ RageSoundReader *ApplyFilters( RageSoundReader *s, int filters )
delete r;
}
}
if( filters & FILTER_RESAMPLE_FAST )
{
RageSoundReader_Resample_Good *r = new RageSoundReader_Resample_Good( s, 10000 );
@@ -242,7 +243,7 @@ int FramesOfSilence( const float *data, int frames, int iChannels )
while( SilentFrames < frames )
{
for( int c = 0; c < iChannels; ++c )
if( fabsf(*data++) > (1/65536.0f) )
if( std::abs(*data++) > (1/65536.0f) )
return SilentFrames;
++SilentFrames;
}
@@ -331,7 +332,7 @@ bool RunTests( RageSoundReader *snd, const TestFile &tf )
{
/* Find out how many frames of silence we have. */
int SilentFrames = FramesOfSilence( sdata, one_second_frames, snd->GetNumChannels() );
const float *InitialData = sdata + SilentFrames*snd->GetNumChannels();
const int InitialDataSize = one_second_frames - SilentFrames;
@@ -340,14 +341,14 @@ bool RunTests( RageSoundReader *snd, const TestFile &tf )
LOG->Warn( "Not enough (%i<%i) data to check after %i frames of silence", InitialDataSize, sizeof(tf.initial), SilentFrames );
return false;
}
bool bFailed = false;
if( SilentFrames != tf.SilentFrames )
{
LOG->Trace( "Expected %i silence, got %i (%i too high)", tf.SilentFrames, SilentFrames, SilentFrames-tf.SilentFrames );
bFailed = true;
}
bool Identical = !compare( InitialData, tf.initial, sizeof(tf.initial) );
if( !Identical )
{
@@ -356,7 +357,7 @@ bool RunTests( RageSoundReader *snd, const TestFile &tf )
LOG->Trace(" ");
bFailed = true;
}
if( bFailed )
{
LOG->Trace("Got data:");
@@ -401,7 +402,7 @@ bool RunTests( RageSoundReader *snd, const TestFile &tf )
bAll42=false;
}
if( bAllNull || bAll42 )
{
LOG->Warn( "'%s': sanity check failed (%i %i)", fn, bAllNull, bAll42 );
@@ -418,7 +419,7 @@ bool RunTests( RageSoundReader *snd, const TestFile &tf )
break;
ASSERT( got >= 0 );
}
/* Now, make sure reading after an EOF returns another EOF. */
if( !must_be_eof(snd) )
{
@@ -436,7 +437,7 @@ bool RunTests( RageSoundReader *snd, const TestFile &tf )
{
const char *szMode = i == 0? "accurate":"fast";
snd->SetProperty( "AccurateSync", i == 0? true:false );
/* SetPosition(0) must always reset properly. */
int iRet = snd->SetPosition(0);
if( iRet != 1 )
@@ -467,7 +468,7 @@ bool RunTests( RageSoundReader *snd, const TestFile &tf )
return false;
}
}
/* Seek to 1ms and make sure it gives us the correct data. */
snd->SetProperty( "AccurateSync", true );
int iFrame = snd->GetSampleRate() * 1 / 1000; // 1ms
@@ -488,12 +489,12 @@ bool RunTests( RageSoundReader *snd, const TestFile &tf )
bool test_file( const TestFile &tf, int filters )
{
const char *fn = tf.fn;
LOG->Trace("Testing: %s", fn );
RString error;
RageSoundReader *s = SoundReader_FileReader::OpenFile( fn, error );
s = ApplyFilters( s, filters );
if( s == NULL )
{
LOG->Trace( "File '%s' failed to open: %s", fn, error.c_str() );
@@ -509,15 +510,15 @@ bool test_file( const TestFile &tf, int filters )
/*
* Check SetPosition consistency:
*
*
* Reopen the file from scratch, seek to 100ms, read some data, do some
* operations that would result in the internal TOC being filled (seek
* to the end), then re-read the data at 100ms and make sure it's the same.
*/
snd = SoundReader_FileReader::OpenFile( fn, error );
snd = ApplyFilters( snd, filters );
if( snd == NULL )
{
LOG->Trace( "File '%s' failed to open: %s", fn, error.c_str() );
@@ -572,7 +573,7 @@ int main( int argc, char *argv[] )
{ "test BASS 44100 stereo VBR (XING, LAME, ID3V1, ID3V2).wav", 622, {0xffff,0x0000,0xffff,0x0000}, {0xef6c,0x0cb8,0xef10,0x0bd2} },
{ NULL, 0, {0,0,0,0}, {0,0,0,0} }
};
for( int i = 0; files[i].fn; ++i )
{
if( !test_file( files[i], 0 ) )
+1 -1
View File
@@ -116,7 +116,7 @@ int q = 0;
/* b == f */
// if( fabsf(b-f) > 0.001 )
// if( std::abs(b-f) > 0.001 )
// {
// LOG->Warn( "%f != %f", b, f );
// return;
+5 -5
View File
@@ -206,7 +206,7 @@ static bool cmp( const float *p1, const float *p2, size_t size )
const float epsilon = 0.000001;
++size;
while( --size )
if( fabs(*p1++ - *p2++) >= epsilon )
if( std::abs(*p1++ - *p2++) >= epsilon )
return false;
return true;
}
@@ -219,13 +219,13 @@ static bool CheckAlignedRead()
T *pDestBuf = NEW( T, size );
T *pRefBuf = NEW( T, size );
bool ret = true;
for( int i = 0; i < 8; ++i )
{
RandBuffer( pSrcBuf, size-i );
Vector::FastSoundRead( pDestBuf, pSrcBuf, size-i );
ScalarRead( pRefBuf, pSrcBuf, size-i );
if( !(ret = cmp(pRefBuf, pDestBuf, size-i)) )
{
fprintf( stderr, "%d: \n", i );
@@ -248,7 +248,7 @@ static bool CheckMisalignedRead()
T *pDestBuf = NEW( T, size );
T *pRefBuf = NEW( T, size );
bool ret = true;
for( int j = 0; j < 8; ++j )
{
for( int i = 0; i < 8; ++i )
@@ -256,7 +256,7 @@ static bool CheckMisalignedRead()
RandBuffer( pSrcBuf, size-i );
Vector::FastSoundRead( pDestBuf+j, pSrcBuf, size-i-j );
ScalarRead( pRefBuf+j, pSrcBuf, size-i-j );
if( !(ret = cmp(pRefBuf+j, pDestBuf+j, size-i-j)) )
{
fprintf( stderr, "%d, %d: \n", j, i );