mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 14:08:19 +00:00
Use sound lock when setting/getting current time of sample
The lock needs to be owned when accessing the sound voices. Calling `IsPlaying` is redundant, as the loops effectively check whether the sample is playing.
This commit is contained in:
parent
7a84a746e0
commit
87191a380e
|
@ -631,19 +631,17 @@ float CSound::GetSampleCurrentTime(int SampleID)
|
||||||
if(SampleID == -1 || SampleID >= NUM_SAMPLES)
|
if(SampleID == -1 || SampleID >= NUM_SAMPLES)
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
|
|
||||||
|
const CLockScope LockScope(m_SoundLock);
|
||||||
CSample *pSample = &m_aSamples[SampleID];
|
CSample *pSample = &m_aSamples[SampleID];
|
||||||
if(IsPlaying(SampleID))
|
|
||||||
{
|
|
||||||
for(auto &Voice : m_aVoices)
|
for(auto &Voice : m_aVoices)
|
||||||
{
|
{
|
||||||
if(Voice.m_pSample == pSample)
|
if(Voice.m_pSample == pSample)
|
||||||
{
|
{
|
||||||
return (Voice.m_Tick / (float)pSample->m_Rate);
|
return Voice.m_Tick / (float)pSample->m_Rate;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (pSample->m_PausedAt / (float)pSample->m_Rate);
|
return pSample->m_PausedAt / (float)pSample->m_Rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSound::SetSampleCurrentTime(int SampleID, float Time)
|
void CSound::SetSampleCurrentTime(int SampleID, float Time)
|
||||||
|
@ -651,22 +649,19 @@ void CSound::SetSampleCurrentTime(int SampleID, float Time)
|
||||||
if(SampleID == -1 || SampleID >= NUM_SAMPLES)
|
if(SampleID == -1 || SampleID >= NUM_SAMPLES)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const CLockScope LockScope(m_SoundLock);
|
||||||
CSample *pSample = &m_aSamples[SampleID];
|
CSample *pSample = &m_aSamples[SampleID];
|
||||||
if(IsPlaying(SampleID))
|
|
||||||
{
|
|
||||||
for(auto &Voice : m_aVoices)
|
for(auto &Voice : m_aVoices)
|
||||||
{
|
{
|
||||||
if(Voice.m_pSample == pSample)
|
if(Voice.m_pSample == pSample)
|
||||||
{
|
{
|
||||||
Voice.m_Tick = pSample->m_NumFrames * Time;
|
Voice.m_Tick = pSample->m_NumFrames * Time;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pSample->m_PausedAt = pSample->m_NumFrames * Time;
|
pSample->m_PausedAt = pSample->m_NumFrames * Time;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CSound::SetChannel(int ChannelID, float Vol, float Pan)
|
void CSound::SetChannel(int ChannelID, float Vol, float Pan)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue