mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Take sample duration into account when enqueuing sound sources
This commit is contained in:
parent
66d02de673
commit
96a6d6d85b
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue