add FadeInSeconds property
This commit is contained in:
@@ -44,6 +44,7 @@ RageSoundParams::RageSoundParams():
|
|||||||
{
|
{
|
||||||
m_StartSecond = 0;
|
m_StartSecond = 0;
|
||||||
m_LengthSeconds = -1;
|
m_LengthSeconds = -1;
|
||||||
|
m_fFadeInSeconds = 0;
|
||||||
m_fFadeOutSeconds = 0;
|
m_fFadeOutSeconds = 0;
|
||||||
m_Volume = 1.0f;
|
m_Volume = 1.0f;
|
||||||
m_fPitch = 1.0f;
|
m_fPitch = 1.0f;
|
||||||
@@ -581,6 +582,7 @@ void RageSound::ApplyParams()
|
|||||||
m_pSource->SetProperty( "Speed", m_Param.m_fSpeed );
|
m_pSource->SetProperty( "Speed", m_Param.m_fSpeed );
|
||||||
m_pSource->SetProperty( "StartSecond", m_Param.m_StartSecond );
|
m_pSource->SetProperty( "StartSecond", m_Param.m_StartSecond );
|
||||||
m_pSource->SetProperty( "LengthSeconds", m_Param.m_LengthSeconds );
|
m_pSource->SetProperty( "LengthSeconds", m_Param.m_LengthSeconds );
|
||||||
|
m_pSource->SetProperty( "FadeInSeconds", m_Param.m_fFadeInSeconds );
|
||||||
m_pSource->SetProperty( "FadeSeconds", m_Param.m_fFadeOutSeconds );
|
m_pSource->SetProperty( "FadeSeconds", m_Param.m_fFadeOutSeconds );
|
||||||
|
|
||||||
float fVolume = m_Param.m_Volume * SOUNDMAN->GetMixVolume();
|
float fVolume = m_Param.m_Volume * SOUNDMAN->GetMixVolume();
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ struct RageSoundParams
|
|||||||
float m_StartSecond;
|
float m_StartSecond;
|
||||||
float m_LengthSeconds;
|
float m_LengthSeconds;
|
||||||
|
|
||||||
|
/* Number of seconds to spend fading in. */
|
||||||
|
float m_fFadeInSeconds;
|
||||||
|
|
||||||
/* Number of seconds to spend fading out. */
|
/* Number of seconds to spend fading out. */
|
||||||
float m_fFadeOutSeconds;
|
float m_fFadeOutSeconds;
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,14 @@ RageSoundReader_Extend::RageSoundReader_Extend( RageSoundReader *pSource ):
|
|||||||
m_iStartFrames = 0;
|
m_iStartFrames = 0;
|
||||||
m_iLengthFrames = -1;
|
m_iLengthFrames = -1;
|
||||||
m_iFadeOutFrames = 0;
|
m_iFadeOutFrames = 0;
|
||||||
|
m_iFadeInFrames = 0;
|
||||||
|
m_bIgnoreFadeInFrames = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RageSoundReader_Extend::SetPosition( int iFrame )
|
int RageSoundReader_Extend::SetPosition( int iFrame )
|
||||||
{
|
{
|
||||||
|
m_bIgnoreFadeInFrames = false;
|
||||||
|
|
||||||
m_iPositionFrames = iFrame;
|
m_iPositionFrames = iFrame;
|
||||||
int iRet = m_pSource->SetPosition( max(iFrame, 0) );
|
int iRet = m_pSource->SetPosition( max(iFrame, 0) );
|
||||||
if( iRet < 0 )
|
if( iRet < 0 )
|
||||||
@@ -95,18 +99,30 @@ int RageSoundReader_Extend::Read( float *pBuffer, int iFrames )
|
|||||||
|
|
||||||
if( iFramesRead > 0 )
|
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
|
/* 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 -1, we don't know the length we're playing.
|
||||||
* (m_LengthFrames is the length to play, not the length of the
|
* (m_LengthFrames is the length to play, not the length of the
|
||||||
* source.) If we don't know the length, don't fade. */
|
* source.) If we don't know the length, don't fade. */
|
||||||
if( m_iFadeOutFrames != 0 && m_iLengthFrames != -1 )
|
if( m_iFadeOutFrames != 0 && m_iLengthFrames != -1 )
|
||||||
{
|
{
|
||||||
const int iFinishFadingOutAt = GetEndFrame();
|
iSilencePositionFrames = GetEndFrame();
|
||||||
const int iStartFadingOutAt = iFinishFadingOutAt - m_iFadeOutFrames;
|
iFullVolumePositionFrames = iSilencePositionFrames - m_iFadeOutFrames;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( iSilencePositionFrames != iFullVolumePositionFrames )
|
||||||
|
{
|
||||||
const int iStartSecond = m_iPositionFrames;
|
const int iStartSecond = m_iPositionFrames;
|
||||||
const int iEndSecond = m_iPositionFrames + iFramesRead;
|
const int iEndSecond = m_iPositionFrames + iFramesRead;
|
||||||
const float fStartVolume = SCALE( iStartSecond, iStartFadingOutAt, iFinishFadingOutAt, 1.0f, 0.0f );
|
const float fStartVolume = SCALE( iStartSecond, iFullVolumePositionFrames, iSilencePositionFrames, 1.0f, 0.0f );
|
||||||
const float fEndVolume = SCALE( iEndSecond, iStartFadingOutAt, iFinishFadingOutAt, 1.0f, 0.0f );
|
const float fEndVolume = SCALE( iEndSecond, iFullVolumePositionFrames, iSilencePositionFrames, 1.0f, 0.0f );
|
||||||
RageSoundUtil::Fade( pBuffer, iFramesRead, fStartVolume, fEndVolume );
|
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 )
|
if( iFramesRead == RageSoundReader::END_OF_FILE && m_StopMode == M_LOOP )
|
||||||
{
|
{
|
||||||
this->SetPosition( m_iStartFrames );
|
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;
|
return STREAM_LOOPED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +183,13 @@ bool RageSoundReader_Extend::SetProperty( const RString &sProperty, float fValue
|
|||||||
return true;
|
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() );
|
m_iFadeOutFrames = lrintf( fValue * this->GetSampleRate() );
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ private:
|
|||||||
StopMode m_StopMode;
|
StopMode m_StopMode;
|
||||||
int m_iStartFrames;
|
int m_iStartFrames;
|
||||||
int m_iLengthFrames;
|
int m_iLengthFrames;
|
||||||
|
int m_iFadeInFrames;
|
||||||
int m_iFadeOutFrames;
|
int m_iFadeOutFrames;
|
||||||
|
bool m_bIgnoreFadeInFrames;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user