mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 18:18:18 +00:00
Merge pull request #108 from cinaera/pr_cutoff
Fix sound cutoff for looped sounds and make sound offset threshold depen...
This commit is contained in:
commit
7b4111749a
|
@ -49,7 +49,7 @@ struct CVoice
|
||||||
int m_Age; // increases when reused
|
int m_Age; // increases when reused
|
||||||
int m_Tick;
|
int m_Tick;
|
||||||
int m_Vol; // 0 - 255
|
int m_Vol; // 0 - 255
|
||||||
int m_FalloffDistance; // 0 - inifintee (well int)
|
int m_FalloffDistance; // 0 - inifinitee (well int)
|
||||||
int m_Flags;
|
int m_Flags;
|
||||||
int m_X, m_Y;
|
int m_X, m_Y;
|
||||||
} ;
|
} ;
|
||||||
|
@ -691,16 +691,22 @@ void CSound::SetVoiceTimeOffset(CVoiceHandle Voice, float offset)
|
||||||
if(m_aVoices[VoiceID].m_pSample)
|
if(m_aVoices[VoiceID].m_pSample)
|
||||||
{
|
{
|
||||||
int Tick = 0;
|
int Tick = 0;
|
||||||
|
bool IsLooping = m_aVoices[VoiceID].m_Flags&ISound::FLAG_LOOP;
|
||||||
uint64_t TickOffset = m_aVoices[VoiceID].m_pSample->m_Rate * offset;
|
uint64_t TickOffset = m_aVoices[VoiceID].m_pSample->m_Rate * offset;
|
||||||
if(m_aVoices[VoiceID].m_pSample->m_NumFrames > 0 && m_aVoices[VoiceID].m_Flags&ISound::FLAG_POS)
|
if(m_aVoices[VoiceID].m_pSample->m_NumFrames > 0 && IsLooping)
|
||||||
Tick = TickOffset % m_aVoices[VoiceID].m_pSample->m_NumFrames;
|
Tick = TickOffset % m_aVoices[VoiceID].m_pSample->m_NumFrames;
|
||||||
else
|
else
|
||||||
Tick = clamp(TickOffset, (uint64_t)0, (uint64_t)m_aVoices[VoiceID].m_pSample->m_NumFrames);
|
Tick = clamp(TickOffset, (uint64_t)0, (uint64_t)m_aVoices[VoiceID].m_pSample->m_NumFrames);
|
||||||
|
|
||||||
// at least 200msec off
|
// at least 200msec off, else depend on buffer size
|
||||||
if(abs(m_aVoices[VoiceID].m_Tick-Tick) > 0.2*m_aVoices[VoiceID].m_pSample->m_Rate)
|
float Threshold = max(0.2f * m_aVoices[VoiceID].m_pSample->m_Rate, (float)m_MaxFrames);
|
||||||
|
if(abs(m_aVoices[VoiceID].m_Tick-Tick) > Threshold)
|
||||||
{
|
{
|
||||||
m_aVoices[VoiceID].m_Tick = Tick;
|
// take care of looping (modulo!)
|
||||||
|
if( !(IsLooping && (min(m_aVoices[VoiceID].m_Tick, Tick) + m_aVoices[VoiceID].m_pSample->m_NumFrames - max(m_aVoices[VoiceID].m_Tick, Tick)) <= Threshold))
|
||||||
|
{
|
||||||
|
m_aVoices[VoiceID].m_Tick = Tick;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue