From 924358af4e76335461207c1e5575c294780f1632 Mon Sep 17 00:00:00 2001 From: Nikita Obrekht Date: Mon, 12 Nov 2018 13:29:52 +0200 Subject: [PATCH 1/3] Add ability to use setSoundPosition with streams --- Client/mods/deathmatch/logic/CBassAudio.cpp | 9 +++++---- Client/mods/deathmatch/logic/CBassAudio.h | 2 +- Client/mods/deathmatch/logic/CClientSound.cpp | 10 ++++++---- Client/mods/deathmatch/logic/CClientSound.h | 2 +- .../deathmatch/logic/CStaticFunctionDefinitions.cpp | 6 +----- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Client/mods/deathmatch/logic/CBassAudio.cpp b/Client/mods/deathmatch/logic/CBassAudio.cpp index 19bd61fe49c..24aaa8caf91 100644 --- a/Client/mods/deathmatch/logic/CBassAudio.cpp +++ b/Client/mods/deathmatch/logic/CBassAudio.cpp @@ -22,7 +22,7 @@ void CALLBACK BPMCallback(int handle, float bpm, void* user); void CALLBACK BeatCallback(DWORD chan, double beatpos, void* user); -#define INVALID_FX_HANDLE (-1) // Hope that BASS doesn't use this as a valid Fx handle +#define INVALID_FX_HANDLE (-1) // Hope that BASS doesn't use this as a valid Fx handle namespace { @@ -134,7 +134,7 @@ bool CBassAudio::BeginLoadingMedia(void) // Calc the flags long lFlags = BASS_STREAM_AUTOFREE | BASS_SAMPLE_SOFTWARE; -#if 0 // Everything sounds better in ste-reo +#if 0 // Everything sounds better in ste-reo if ( m_b3D ) lFlags |= BASS_SAMPLE_MONO; #endif @@ -521,7 +521,7 @@ void CBassAudio::SetPaused(bool bPaused) } // Non-streams only -void CBassAudio::SetPlayPosition(double dPosition) +bool CBassAudio::SetPlayPosition(double dPosition) { // Only relevant for non-streams, which are always ready if valid if (m_pSound) @@ -529,8 +529,9 @@ void CBassAudio::SetPlayPosition(double dPosition) // Make sure position is in range QWORD bytePosition = BASS_ChannelSeconds2Bytes(m_pSound, dPosition); QWORD byteLength = BASS_ChannelGetLength(m_pSound, BASS_POS_BYTE); - BASS_ChannelSetPosition(m_pSound, Clamp(0, bytePosition, byteLength - 1), BASS_POS_BYTE); + return BASS_ChannelSetPosition(m_pSound, Clamp(0, bytePosition, byteLength - 1), BASS_POS_BYTE); } + return false; } // Non-streams only diff --git a/Client/mods/deathmatch/logic/CBassAudio.h b/Client/mods/deathmatch/logic/CBassAudio.h index d0f4cd501a0..aed16d478d7 100644 --- a/Client/mods/deathmatch/logic/CBassAudio.h +++ b/Client/mods/deathmatch/logic/CBassAudio.h @@ -54,7 +54,7 @@ class CBassAudio bool BeginLoadingMedia(void); void SetPaused(bool bPaused); - void SetPlayPosition(double dPosition); + bool SetPlayPosition(double dPosition); double GetPlayPosition(void); double GetLength(void); void SetVolume(float fVolume); diff --git a/Client/mods/deathmatch/logic/CClientSound.cpp b/Client/mods/deathmatch/logic/CClientSound.cpp index 8f560f6875b..9a09a5eb122 100644 --- a/Client/mods/deathmatch/logic/CClientSound.cpp +++ b/Client/mods/deathmatch/logic/CClientSound.cpp @@ -293,18 +293,20 @@ void CClientSound::PlayStream(const SString& strURL, bool bLoop, bool bThrottle, // // //////////////////////////////////////////////////////////// -void CClientSound::SetPlayPosition(double dPosition) +bool CClientSound::SetPlayPosition(double dPosition) { if (m_pAudio) { // Use actual audio if active - m_pAudio->SetPlayPosition(dPosition); + return m_pAudio->SetPlayPosition(dPosition); } - else + else if (m_SimulatedPlayPosition.IsValid()) { // Use simulation if not active m_SimulatedPlayPosition.SetPlayPositionNow(dPosition); + return true; } + return false; } double CClientSound::GetPlayPosition(void) @@ -732,4 +734,4 @@ bool CClientSound::SetPan(float fPan) } return false; -} \ No newline at end of file +} diff --git a/Client/mods/deathmatch/logic/CClientSound.h b/Client/mods/deathmatch/logic/CClientSound.h index 4e2ed67b414..3024d3626ac 100644 --- a/Client/mods/deathmatch/logic/CClientSound.h +++ b/Client/mods/deathmatch/logic/CClientSound.h @@ -39,7 +39,7 @@ class CClientSound : public CClientEntity void SetPaused(bool bPaused); bool IsPaused(void); - void SetPlayPosition(double dPosition); + bool SetPlayPosition(double dPosition); double GetPlayPosition(void); double GetLength(bool bAvoidLoad = false); diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index a78cfa35e82..1fe6746c10c 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -7586,11 +7586,7 @@ bool CStaticFunctionDefinitions::StopSound(CClientSound& Sound) bool CStaticFunctionDefinitions::SetSoundPosition(CClientSound& Sound, double dPosition) { - if (Sound.IsSoundStream()) - return false; - - Sound.SetPlayPosition(dPosition); - return true; + return Sound.SetPlayPosition(dPosition); } bool CStaticFunctionDefinitions::SetSoundPosition(CClientPlayer& Player, double dPosition) From d74f251ac874ce915a5aceb8ce6247f358855d26 Mon Sep 17 00:00:00 2001 From: Nikita Obrekht Date: Mon, 12 Nov 2018 13:36:51 +0200 Subject: [PATCH 2/3] Remove extra spaces --- Client/mods/deathmatch/logic/CBassAudio.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/mods/deathmatch/logic/CBassAudio.cpp b/Client/mods/deathmatch/logic/CBassAudio.cpp index 24aaa8caf91..5637c647be2 100644 --- a/Client/mods/deathmatch/logic/CBassAudio.cpp +++ b/Client/mods/deathmatch/logic/CBassAudio.cpp @@ -22,7 +22,7 @@ void CALLBACK BPMCallback(int handle, float bpm, void* user); void CALLBACK BeatCallback(DWORD chan, double beatpos, void* user); -#define INVALID_FX_HANDLE (-1) // Hope that BASS doesn't use this as a valid Fx handle +#define INVALID_FX_HANDLE (-1) // Hope that BASS doesn't use this as a valid Fx handle namespace { @@ -134,7 +134,7 @@ bool CBassAudio::BeginLoadingMedia(void) // Calc the flags long lFlags = BASS_STREAM_AUTOFREE | BASS_SAMPLE_SOFTWARE; -#if 0 // Everything sounds better in ste-reo +#if 0 // Everything sounds better in ste-reo if ( m_b3D ) lFlags |= BASS_SAMPLE_MONO; #endif From 1a67ef8187be9e85fed678a28ebe99e24e44d141 Mon Sep 17 00:00:00 2001 From: Qais Patankar Date: Sun, 10 Feb 2019 14:24:37 +0000 Subject: [PATCH 3/3] fix typo --- Client/mods/deathmatch/logic/CClientSound.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientSound.h b/Client/mods/deathmatch/logic/CClientSound.h index e6b8710c68a..c52859fa3e1 100644 --- a/Client/mods/deathmatch/logic/CClientSound.h +++ b/Client/mods/deathmatch/logic/CClientSound.h @@ -39,8 +39,6 @@ class CClientSound : public CClientEntity void SetPaused(bool bPaused); bool IsPaused(); - bool SetPlayPosition(double dPosition); - double GetPlayPosition(void); bool SetPlayPosition(double dPosition); double GetPlayPosition();