Skip to content

Commit

Permalink
Improve accuracy of CStreamingSound::UpdateFadeOut
Browse files Browse the repository at this point in the history
  • Loading branch information
roblabla committed Feb 17, 2024
1 parent 9e674ed commit db5dad3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions src/zwave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,17 +492,18 @@ CStreamingSound::~CStreamingSound()
//-----------------------------------------------------------------------------
HRESULT CStreamingSound::UpdateFadeOut()
{
if (this->m_dwIsFadingOut == 0)
return 0;

this->m_dwCurFadeoutProgress = this->m_dwCurFadeoutProgress + -1;
if (this->m_dwCurFadeoutProgress < 1)
if (this->m_dwIsFadingOut != 0)
{
this->m_dwIsFadingOut = 0;
this->m_apDSBuffer[0]->Stop();
return 1;
this->m_dwCurFadeoutProgress = this->m_dwCurFadeoutProgress - 1;
if (this->m_dwCurFadeoutProgress <= 0)
{
this->m_dwIsFadingOut = 0;
this->m_apDSBuffer[0]->Stop();
return 1;
}
DWORD vol = ((this->m_dwCurFadeoutProgress * 5000) / this->m_dwTotalFadeout) - 5000;
HRESULT res = this->m_apDSBuffer[0]->SetVolume(vol);
}
this->m_apDSBuffer[0]->SetVolume(((this->m_dwCurFadeoutProgress / this->m_dwTotalFadeout) * 5000) - 5000);
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/zwave.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class CSound
DWORD m_dwNumBuffers;

// th06 extensions for fadeout
DWORD m_dwCurFadeoutProgress;
DWORD m_dwTotalFadeout;
i32 m_dwCurFadeoutProgress;
i32 m_dwTotalFadeout;
DWORD m_dwIsFadingOut;

HRESULT RestoreBuffer(LPDIRECTSOUNDBUFFER pDSB, BOOL *pbWasRestored);
Expand Down

0 comments on commit db5dad3

Please sign in to comment.