add RageSoundLoadParams, to specify load-time params

allow loading pitch shifter
add pitch and speed params
This commit is contained in:
Glenn Maynard
2006-11-30 07:28:26 +00:00
parent bd639a7547
commit 458be5efa4
2 changed files with 36 additions and 5 deletions
+24 -4
View File
@@ -29,6 +29,7 @@
#include "arch/ArchHooks/ArchHooks.h"
#include "RageSoundUtil.h"
#include "RageSoundReader_PitchChange.h"
#include "RageSoundReader_Preload.h"
#include "RageSoundReader_Resample_Good.h"
#include "RageSoundReader_FileReader.h"
@@ -46,11 +47,18 @@ RageSoundParams::RageSoundParams():
m_Volume = 1.0f;
m_Balance = 0; // center
m_fRate = 1.0f;
m_fPitch = 1.0f;
m_fSpeed = 1.0f;
m_bAccurateSync = false;
StopMode = M_AUTO;
m_bIsCriticalSound = false;
}
RageSoundLoadParams::RageSoundLoadParams()
{
m_bSupportRateChanging = false;
}
RageSound::RageSound():
m_Mutex( "RageSound" )
{
@@ -164,10 +172,16 @@ bool RageSound::Load( RString sSoundFilePath )
return Load( sSoundFilePath, false );
}
bool RageSound::Load( RString sSoundFilePath, bool bPrecache )
bool RageSound::Load( RString sSoundFilePath, bool bPrecache, const RageSoundLoadParams *pParams )
{
LOG->Trace( "RageSound::LoadSound( '%s', %d )", sSoundFilePath.c_str(), bPrecache );
if( pParams == NULL )
{
static const RageSoundLoadParams Defaults;
pParams = &Defaults;
}
/* If this sound is already preloaded and held by SOUNDMAN, just make a copy
* of that. Since RageSoundReader_Preload is refcounted, this is cheap. */
RageSoundReader *pSound = SOUNDMAN->GetLoadedSound( sSoundFilePath );
@@ -206,6 +220,12 @@ bool RageSound::Load( RString sSoundFilePath, bool bPrecache )
}
}
if( pParams->m_bSupportRateChanging )
{
RageSoundReader_PitchChange *pRate = new RageSoundReader_PitchChange( m_pSource );
m_pSource = pRate;
}
m_sFilePath = sSoundFilePath;
m_Mutex.SetName( ssprintf("RageSound (%s)", Basename(sSoundFilePath).c_str() ) );
@@ -227,8 +247,6 @@ void RageSound::LoadSoundReader( RageSoundReader *pSound )
pSound = Resample;
}
pSound->SetProperty( "Speed", 1.5f );
m_pSource = pSound;
}
@@ -760,6 +778,7 @@ RageTimer RageSound::GetStartTime() const
void RageSound::SetParams( const RageSoundParams &p )
{
m_Param = p;
ApplyParams();
}
void RageSound::ApplyParams()
@@ -767,7 +786,8 @@ void RageSound::ApplyParams()
if( m_pSource == NULL )
return;
m_pSource->SetProperty( "Speed", m_Param.m_fRate );
m_pSource->SetProperty( "Pitch", m_Param.m_fPitch );
m_pSource->SetProperty( "Speed", m_Param.m_fSpeed );
}
RageSoundParams::StopMode_t RageSound::GetStopMode() const
+12 -1
View File
@@ -48,6 +48,8 @@ struct RageSoundParams
/* Number of samples input and output when changing speed. Currently,
* this is either 1/1, 5/4 or 4/5. */
float m_fRate;
float m_fPitch;
float m_fSpeed;
/* If enabled, file seeking will prefer accuracy over speed. */
bool m_bAccurateSync;
@@ -72,6 +74,15 @@ struct RageSoundParams
bool m_bIsCriticalSound; // "is a sound that should be played even during attract"
};
struct RageSoundLoadParams
{
RageSoundLoadParams();
/* If true, speed and pitch changes will be supported for this sound, at a
* small memory penalty if not used. */
bool m_bSupportRateChanging;
};
class RageSound: public RageSoundBase
{
public:
@@ -95,7 +106,7 @@ public:
* they can be ignored most of the time, so we continue to work if a file
* is broken or missing.
*/
bool Load( RString sFile, bool bPrecache );
bool Load( RString sFile, bool bPrecache, const RageSoundLoadParams *pParams = NULL );
/*
* Using this version means the "don't care" about caching. Currently,