diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index 7d6b37c99d..e0ec4f2ade 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -44,6 +44,7 @@ RageSoundParams::RageSoundParams(): { m_StartSecond = 0; m_LengthSeconds = -1; + m_fFadeInSeconds = 0; m_fFadeOutSeconds = 0; m_Volume = 1.0f; m_fPitch = 1.0f; @@ -581,6 +582,7 @@ void RageSound::ApplyParams() m_pSource->SetProperty( "Speed", m_Param.m_fSpeed ); m_pSource->SetProperty( "StartSecond", m_Param.m_StartSecond ); m_pSource->SetProperty( "LengthSeconds", m_Param.m_LengthSeconds ); + m_pSource->SetProperty( "FadeInSeconds", m_Param.m_fFadeInSeconds ); m_pSource->SetProperty( "FadeSeconds", m_Param.m_fFadeOutSeconds ); float fVolume = m_Param.m_Volume * SOUNDMAN->GetMixVolume(); diff --git a/stepmania/src/RageSound.h b/stepmania/src/RageSound.h index 352dcaf9ef..7beebd1c9d 100644 --- a/stepmania/src/RageSound.h +++ b/stepmania/src/RageSound.h @@ -32,6 +32,9 @@ struct RageSoundParams float m_StartSecond; float m_LengthSeconds; + /* Number of seconds to spend fading in. */ + float m_fFadeInSeconds; + /* Number of seconds to spend fading out. */ float m_fFadeOutSeconds; diff --git a/stepmania/src/RageSoundReader_Extend.cpp b/stepmania/src/RageSoundReader_Extend.cpp index 8a31ea1727..73f2d0cb45 100644 --- a/stepmania/src/RageSoundReader_Extend.cpp +++ b/stepmania/src/RageSoundReader_Extend.cpp @@ -21,10 +21,14 @@ RageSoundReader_Extend::RageSoundReader_Extend( RageSoundReader *pSource ): m_iStartFrames = 0; m_iLengthFrames = -1; m_iFadeOutFrames = 0; + m_iFadeInFrames = 0; + m_bIgnoreFadeInFrames = false; } int RageSoundReader_Extend::SetPosition( int iFrame ) { + m_bIgnoreFadeInFrames = false; + m_iPositionFrames = iFrame; int iRet = m_pSource->SetPosition( max(iFrame, 0) ); if( iRet < 0 ) @@ -95,18 +99,30 @@ int RageSoundReader_Extend::Read( float *pBuffer, int iFrames ) if( iFramesRead > 0 ) { + int iFullVolumePositionFrames = 0; + int iSilencePositionFrames = 0; + if( m_iFadeInFrames != 0 && !m_bIgnoreFadeInFrames ) + { + iSilencePositionFrames = 0; + iFullVolumePositionFrames = m_iFadeInFrames; + } + /* We want to fade when there's m_iFadeFrames frames left, but if * m_LengthFrames is -1, we don't know the length we're playing. * (m_LengthFrames is the length to play, not the length of the * source.) If we don't know the length, don't fade. */ if( m_iFadeOutFrames != 0 && m_iLengthFrames != -1 ) { - const int iFinishFadingOutAt = GetEndFrame(); - const int iStartFadingOutAt = iFinishFadingOutAt - m_iFadeOutFrames; + iSilencePositionFrames = GetEndFrame(); + iFullVolumePositionFrames = iSilencePositionFrames - m_iFadeOutFrames; + } + + if( iSilencePositionFrames != iFullVolumePositionFrames ) + { const int iStartSecond = m_iPositionFrames; const int iEndSecond = m_iPositionFrames + iFramesRead; - const float fStartVolume = SCALE( iStartSecond, iStartFadingOutAt, iFinishFadingOutAt, 1.0f, 0.0f ); - const float fEndVolume = SCALE( iEndSecond, iStartFadingOutAt, iFinishFadingOutAt, 1.0f, 0.0f ); + const float fStartVolume = SCALE( iStartSecond, iFullVolumePositionFrames, iSilencePositionFrames, 1.0f, 0.0f ); + const float fEndVolume = SCALE( iEndSecond, iFullVolumePositionFrames, iSilencePositionFrames, 1.0f, 0.0f ); RageSoundUtil::Fade( pBuffer, iFramesRead, fStartVolume, fEndVolume ); } @@ -116,6 +132,11 @@ int RageSoundReader_Extend::Read( float *pBuffer, int iFrames ) if( iFramesRead == RageSoundReader::END_OF_FILE && m_StopMode == M_LOOP ) { this->SetPosition( m_iStartFrames ); + + /* If we're not fading out at the end, then only fade in once. Ignore + * m_iFadeInFrames until seeked, so we only fade in once. */ + if( m_iFadeOutFrames == 0 ) + m_bIgnoreFadeInFrames = true; return STREAM_LOOPED; } @@ -162,7 +183,13 @@ bool RageSoundReader_Extend::SetProperty( const RString &sProperty, float fValue return true; } - if( sProperty == "FadeSeconds" ) + if( sProperty == "FadeInSeconds" ) + { + m_iFadeInFrames = lrintf( fValue * this->GetSampleRate() ); + return true; + } + + if( sProperty == "FadeSeconds" || sProperty == "FadeOutSeconds" ) { m_iFadeOutFrames = lrintf( fValue * this->GetSampleRate() ); return true; diff --git a/stepmania/src/RageSoundReader_Extend.h b/stepmania/src/RageSoundReader_Extend.h index baff95f49a..73d6972cb5 100644 --- a/stepmania/src/RageSoundReader_Extend.h +++ b/stepmania/src/RageSoundReader_Extend.h @@ -27,7 +27,9 @@ private: StopMode m_StopMode; int m_iStartFrames; int m_iLengthFrames; + int m_iFadeInFrames; int m_iFadeOutFrames; + bool m_bIgnoreFadeInFrames; }; #endif