diff --git a/src/engine/client/sound.cpp b/src/engine/client/sound.cpp index 16bf1e8c2..c7cf7c73b 100644 --- a/src/engine/client/sound.cpp +++ b/src/engine/client/sound.cpp @@ -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; diff --git a/src/engine/client/sound.h b/src/engine/client/sound.h index 98ec4304d..086f3f02b 100644 --- a/src/engine/client/sound.h +++ b/src/engine/client/sound.h @@ -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); diff --git a/src/engine/sound.h b/src/engine/sound.h index fbc50f490..b486216d1 100644 --- a/src/engine/sound.h +++ b/src/engine/sound.h @@ -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; diff --git a/src/game/client/components/mapsounds.cpp b/src/game/client/components/mapsounds.cpp index f729ce854..c3d6727c5 100644 --- a/src/game/client/components/mapsounds.cpp +++ b/src/game/client/components/mapsounds.cpp @@ -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;