add helpers

This commit is contained in:
Glenn Maynard
2007-02-01 03:26:07 +00:00
parent 39f6bd46c3
commit 56c5972fa3
2 changed files with 20 additions and 1 deletions
+18 -1
View File
@@ -83,8 +83,25 @@ void RageSoundUtil::ConvertMonoToStereoInPlace( float *data, int iFrames )
} }
} }
void RageSoundUtil::ConvertNativeInt16ToFloat( const int16_t *pFrom, float *pTo, int iSamples )
{
for( int i = 0; i < iSamples; ++i )
{
pTo[i] = pFrom[i] / 32768.0f;
}
}
void RageSoundUtil::ConvertFloatToNativeInt16( const float *pFrom, int16_t *pTo, int iSamples )
{
for( int i = 0; i < iSamples; ++i )
{
int iOut = lrintf( pFrom[i] * 32768.0f );
pTo[i] = clamp( iOut, -32768, 32767 );
}
}
/* /*
* Copyright (c) 2002-2004 Glenn Maynard * Copyright (c) 2002-2007 Glenn Maynard
* All rights reserved. * All rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
+2
View File
@@ -9,6 +9,8 @@ namespace RageSoundUtil
void Pan( float *pBuffer, int iFrames, float fPos ); void Pan( float *pBuffer, int iFrames, float fPos );
void Fade( float *pBuffer, int iFrames, float fStartVolume, float fEndVolume ); void Fade( float *pBuffer, int iFrames, float fStartVolume, float fEndVolume );
void ConvertMonoToStereoInPlace( float *pBuffer, int iFrames ); void ConvertMonoToStereoInPlace( float *pBuffer, int iFrames );
void ConvertNativeInt16ToFloat( const int16_t *pFrom, float *pTo, int iSamples );
void ConvertFloatToNativeInt16( const float *pFrom, int16_t *pTo, int iSamples );
}; };
#endif #endif