diff --git a/stepmania/src/RageSoundUtil.cpp b/stepmania/src/RageSoundUtil.cpp index a10c3cdba2..fa6a57d380 100644 --- a/stepmania/src/RageSoundUtil.cpp +++ b/stepmania/src/RageSoundUtil.cpp @@ -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. * * Permission is hereby granted, free of charge, to any person obtaining a diff --git a/stepmania/src/RageSoundUtil.h b/stepmania/src/RageSoundUtil.h index 003f40e053..8755c3ccc6 100644 --- a/stepmania/src/RageSoundUtil.h +++ b/stepmania/src/RageSoundUtil.h @@ -9,6 +9,8 @@ namespace RageSoundUtil void Pan( float *pBuffer, int iFrames, float fPos ); void Fade( float *pBuffer, int iFrames, float fStartVolume, float fEndVolume ); 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