Take sample duration into account when enqueuing sound sources

This commit is contained in:
BeaR 2014-10-11 13:55:13 +02:00
parent 66d02de673
commit 96a6d6d85b
4 changed files with 13 additions and 2 deletions

View file

@ -440,6 +440,14 @@ void CSound::UnloadSample(int SampleID)
m_aSamples[SampleID].m_pData = 0x0;
}
float CSound::GetSampleDuration(int SampleID)
{
if(SampleID == -1 || SampleID >= NUM_SAMPLES)
return 0.0f;
return (m_aSamples[SampleID].m_NumFrames/m_aSamples[SampleID].m_Rate);
}
void CSound::SetListenerPos(float x, float y)
{
m_CenterX = (int)x;

View file

@ -30,6 +30,8 @@ public:
virtual int LoadWV(const char *pFilename);
virtual void UnloadSample(int SampleID);
virtual float GetSampleDuration(int SampleID); // in s
virtual void SetListenerPos(float x, float y);
virtual void SetChannel(int ChannelID, float Vol, float Pan);

View file

@ -21,6 +21,8 @@ public:
virtual int LoadWV(const char *pFilename) = 0;
virtual void UnloadSample(int SampleID) = 0;
virtual float GetSampleDuration(int SampleID) = 0; // in s
virtual void SetChannel(int ChannelID, float Volume, float Panning) = 0;
virtual void SetListenerPos(float x, float y) = 0;

View file

@ -80,8 +80,7 @@ void CMapSounds::OnMapLoad()
for(int i = 0; i < pSoundLayer->m_NumSources; i++) {
// dont add sources which are too much delayed
// TODO: use duration of the source sample
if(pSources[i].m_Loop || (Client()->LocalTime()-pSources[i].m_TimeDelay) < 2.0f)
if(pSources[i].m_Loop || (Client()->LocalTime() >= pSources[i].m_TimeDelay + Sound()->GetSampleDuration(pSoundLayer->m_Sound)))
{
CSource source;
source.m_Sound = pSoundLayer->m_Sound;