add FadeInSeconds property

This commit is contained in:
Glenn Maynard
2007-04-06 18:26:09 +00:00
parent 570f17017a
commit 59aaf0dec9
4 changed files with 39 additions and 5 deletions
+2
View File
@@ -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();
+3
View File
@@ -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;
+32 -5
View File
@@ -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;
+2
View File
@@ -27,7 +27,9 @@ private:
StopMode m_StopMode;
int m_iStartFrames;
int m_iLengthFrames;
int m_iFadeInFrames;
int m_iFadeOutFrames;
bool m_bIgnoreFadeInFrames;
};
#endif