Skip to content

Commit efbf598

Browse files
committed
Merge pull request #6 from Audifire/sound
Add sound throttling from ID #0008814
2 parents 7aeb6c5 + 236ca8d commit efbf598

File tree

9 files changed

+31
-20
lines changed

9 files changed

+31
-20
lines changed

MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7282,17 +7282,17 @@ CClientEffect* CStaticFunctionDefinitions::CreateEffect(CResource& Resource, con
72827282
}
72837283

72847284

7285-
CClientSound* CStaticFunctionDefinitions::PlaySound ( CResource* pResource, const SString& strSound, bool bIsURL, bool bLoop )
7285+
CClientSound* CStaticFunctionDefinitions::PlaySound ( CResource* pResource, const SString& strSound, bool bIsURL, bool bLoop, bool bThrottle )
72867286
{
7287-
CClientSound* pSound = m_pSoundManager->PlaySound2D ( strSound, bIsURL, bLoop );
7287+
CClientSound* pSound = m_pSoundManager->PlaySound2D ( strSound, bIsURL, bLoop, bThrottle );
72887288
if ( pSound ) pSound->SetParent ( pResource->GetResourceDynamicEntity() );
72897289
return pSound;
72907290
}
72917291

72927292

7293-
CClientSound* CStaticFunctionDefinitions::PlaySound3D ( CResource* pResource, const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop )
7293+
CClientSound* CStaticFunctionDefinitions::PlaySound3D ( CResource* pResource, const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop, bool bThrottle )
72947294
{
7295-
CClientSound* pSound = m_pSoundManager->PlaySound3D ( strSound, bIsURL, vecPosition, bLoop );
7295+
CClientSound* pSound = m_pSoundManager->PlaySound3D ( strSound, bIsURL, vecPosition, bLoop, bThrottle );
72967296
if ( pSound ) pSound->SetParent ( pResource->GetResourceDynamicEntity() );
72977297
return pSound;
72987298
}

MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,8 @@ class CStaticFunctionDefinitions
632632
static CClientEffect* CreateEffect ( CResource& Resource, const SString& strFxName, const CVector& vecPosition );
633633

634634
// Sound funcs
635-
static CClientSound* PlaySound ( CResource* pResource, const SString& strSound, bool bIsURL, bool bLoop );
636-
static CClientSound* PlaySound3D ( CResource* pResource, const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop );
635+
static CClientSound* PlaySound ( CResource* pResource, const SString& strSound, bool bIsURL, bool bLoop, bool bThrottle );
636+
static CClientSound* PlaySound3D ( CResource* pResource, const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop, bool bThrottle );
637637
static bool StopSound ( CClientSound& Sound );
638638
static bool SetSoundPosition ( CClientSound& Sound, double dPosition );
639639
static bool GetSoundPosition ( CClientSound& Sound, double& dPosition );

MTA10/mods/shared_logic/CBassAudio.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ namespace
6868
}
6969

7070

71-
CBassAudio::CBassAudio ( bool bStream, const SString& strPath, bool bLoop, bool b3D )
71+
CBassAudio::CBassAudio ( bool bStream, const SString& strPath, bool bLoop, bool bThrottle, bool b3D )
7272
: m_bStream ( bStream )
7373
, m_strPath ( strPath )
7474
, m_bLoop ( bLoop )
75+
, m_bThrottle ( bThrottle )
7576
, m_b3D ( b3D )
7677
{
7778
m_fVolume = 1.0f;
@@ -85,7 +86,7 @@ CBassAudio::CBassAudio ( bool bStream, const SString& strPath, bool bLoop, bool
8586
}
8687

8788

88-
CBassAudio::CBassAudio ( void* pBuffer, unsigned int uiBufferLength, bool bLoop, bool b3D ) : m_bStream ( false ), m_pBuffer ( pBuffer ), m_uiBufferLength ( uiBufferLength ), m_bLoop ( bLoop ), m_b3D ( b3D )
89+
CBassAudio::CBassAudio ( void* pBuffer, unsigned int uiBufferLength, bool bLoop, bool b3D ) : m_bStream ( false ), m_pBuffer ( pBuffer ), m_uiBufferLength ( uiBufferLength ), m_bLoop ( bLoop ), m_bThrottle( false), m_b3D ( b3D )
8990
{
9091
m_fVolume = 1.0f;
9192
m_fDefaultFrequency = 44100.0f;
@@ -150,6 +151,9 @@ bool CBassAudio::BeginLoadingMedia ( void )
150151
if ( m_bLoop )
151152
lFlags |= BASS_SAMPLE_LOOP;
152153

154+
if ( m_bThrottle )
155+
lFlags |= BASS_STREAM_RESTRATE;
156+
153157
if ( m_bStream )
154158
{
155159
//

MTA10/mods/shared_logic/CBassAudio.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class CBassAudio
4848
{
4949
public:
5050
ZERO_ON_NEW
51-
CBassAudio ( bool bStream, const SString& strPath, bool bLoop, bool b3D );
51+
CBassAudio ( bool bStream, const SString& strPath, bool bLoop, bool bThrottle, bool b3D );
5252
CBassAudio ( void* pBuffer, unsigned int uiBufferLength, bool bLoop, bool b3D );
5353
~CBassAudio ( void );
5454
void Destroy ( void );
@@ -107,6 +107,7 @@ class CBassAudio
107107
const SString m_strPath;
108108
const bool m_b3D;
109109
const bool m_bLoop;
110+
const bool m_bThrottle;
110111
void* m_pBuffer;
111112
unsigned int m_uiBufferLength;
112113

MTA10/mods/shared_logic/CClientSound.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ bool CClientSound::Create ( void )
113113

114114
// Initial state
115115
if ( !m_pBuffer )
116-
m_pAudio = new CBassAudio ( m_bStream, m_strPath, m_bLoop, m_b3D );
116+
m_pAudio = new CBassAudio ( m_bStream, m_strPath, m_bLoop, m_bThrottle, m_b3D );
117117
else
118118
m_pAudio = new CBassAudio ( m_pBuffer, m_uiBufferLength, m_bLoop, m_b3D );
119119

@@ -286,14 +286,15 @@ bool CClientSound::Play3D ( void* pMemory, unsigned int uiLength, bool bLoop )
286286
}
287287

288288

289-
void CClientSound::PlayStream ( const SString& strURL, bool bLoop, bool b3D )
289+
void CClientSound::PlayStream ( const SString& strURL, bool bLoop, bool bThrottle, bool b3D )
290290
{
291291
assert ( m_strPath.empty () );
292292

293293
m_bStream = true;
294294
m_b3D = b3D;
295295
m_strPath = strURL;
296296
m_bLoop = bLoop;
297+
m_bThrottle = bThrottle;
297298

298299
// Instant distance-stream in if not 3D
299300
if ( !m_b3D )

MTA10/mods/shared_logic/CClientSound.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CClientSound : public CClientEntity
3838
bool Play ( void* pMemory, unsigned int uiLength, bool bLoop );
3939
bool Play3D ( const SString& strPath, bool bLoop );
4040
bool Play3D ( void* pMemory, unsigned int uiLength, bool bLoop );
41-
void PlayStream ( const SString& strURL, bool bLoop, bool b3D = false );
41+
void PlayStream ( const SString& strURL, bool bLoop, bool bThrottle, bool b3D = false );
4242

4343
void SetPaused ( bool bPaused );
4444
bool IsPaused ( void );
@@ -111,6 +111,7 @@ class CClientSound : public CClientEntity
111111
bool m_b3D;
112112
SString m_strPath;
113113
bool m_bLoop;
114+
bool m_bThrottle;
114115
void* m_pBuffer;
115116
unsigned int m_uiBufferLength;
116117

MTA10/mods/shared_logic/CClientSoundManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ void CClientSoundManager::SetDimension ( unsigned short usDimension )
127127
m_usDimension = usDimension;
128128
}
129129

130-
CClientSound* CClientSoundManager::PlaySound2D ( const SString& strSound, bool bIsURL, bool bLoop )
130+
CClientSound* CClientSoundManager::PlaySound2D ( const SString& strSound, bool bIsURL, bool bLoop, bool bThrottle )
131131
{
132132
CClientSound* pSound = new CClientSound ( m_pClientManager, INVALID_ELEMENT_ID );
133133
if ( bIsURL )
134134
{
135-
pSound->PlayStream ( strSound, bLoop );
135+
pSound->PlayStream ( strSound, bLoop, bThrottle );
136136
return pSound;
137137
}
138138
else
@@ -154,13 +154,13 @@ CClientSound* CClientSoundManager::PlaySound2D ( void* pMemory, unsigned int uiL
154154
return NULL;
155155
}
156156

157-
CClientSound* CClientSoundManager::PlaySound3D ( const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop )
157+
CClientSound* CClientSoundManager::PlaySound3D ( const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop, bool bThrottle )
158158
{
159159
CClientSound* pSound = new CClientSound ( m_pClientManager, INVALID_ELEMENT_ID );
160160

161161
if ( bIsURL )
162162
{
163-
pSound->PlayStream ( strSound, bLoop, true );
163+
pSound->PlayStream ( strSound, bLoop, bThrottle, true );
164164
pSound->SetPosition ( vecPosition );
165165
return pSound;
166166
}

MTA10/mods/shared_logic/CClientSoundManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class CClientSoundManager
3131

3232
void SetDimension ( unsigned short usDimension );
3333

34-
CClientSound* PlaySound2D ( const SString& strSound, bool bIsURL, bool bLoop );
34+
CClientSound* PlaySound2D ( const SString& strSound, bool bIsURL, bool bLoop, bool bThrottle );
3535
CClientSound* PlaySound2D ( void* pMemory, unsigned int uiLength, bool bLoop );
36-
CClientSound* PlaySound3D ( const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop );
36+
CClientSound* PlaySound3D ( const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop, bool bThrottle );
3737
CClientSound* PlaySound3D ( void* pMemory, unsigned int uiLength, const CVector& vecPosition, bool bLoop );
3838

3939
CClientSound* PlayGTASFX ( eAudioLookupIndex containerIndex, int iBankIndex, int iAudioIndex, bool bLoop = false );

MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Audio.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ int CLuaFunctionDefs::PlaySound ( lua_State* luaVM )
2323
{
2424
SString strSound = "";
2525
bool bLoop = false;
26+
bool bThrottle = true;
2627
CScriptArgReader argStream ( luaVM );
2728
argStream.ReadString ( strSound );
2829
argStream.ReadBool ( bLoop, false );
30+
argStream.ReadBool ( bThrottle, true );
2931

3032
if ( !argStream.HasErrors() )
3133
{
@@ -46,7 +48,7 @@ int CLuaFunctionDefs::PlaySound ( lua_State* luaVM )
4648
// Fixes #6507 - Caz
4749
if ( pResource )
4850
{
49-
CClientSound* pSound = CStaticFunctionDefinitions::PlaySound ( pResource, strSound, bIsURL, bLoop );
51+
CClientSound* pSound = CStaticFunctionDefinitions::PlaySound ( pResource, strSound, bIsURL, bLoop, bThrottle );
5052
if ( pSound )
5153
{
5254
// call onClientSoundStarted
@@ -74,10 +76,12 @@ int CLuaFunctionDefs::PlaySound3D ( lua_State* luaVM )
7476
SString strSound = "";
7577
CVector vecPosition;
7678
bool bLoop = false;
79+
bool bThrottle = false;
7780
CScriptArgReader argStream ( luaVM );
7881
argStream.ReadString ( strSound );
7982
argStream.ReadVector3D ( vecPosition );
8083
argStream.ReadBool ( bLoop, false );
84+
argStream.ReadBool ( bThrottle, true );
8185

8286
if ( !argStream.HasErrors() )
8387
{
@@ -98,7 +102,7 @@ int CLuaFunctionDefs::PlaySound3D ( lua_State* luaVM )
98102
// Fixes #6507 - Caz
99103
if ( pResource )
100104
{
101-
CClientSound* pSound = CStaticFunctionDefinitions::PlaySound3D ( pResource, strSound, bIsURL, vecPosition, bLoop );
105+
CClientSound* pSound = CStaticFunctionDefinitions::PlaySound3D ( pResource, strSound, bIsURL, vecPosition, bLoop, bThrottle );
102106
if ( pSound )
103107
{
104108
// call onClientSoundStarted

0 commit comments

Comments
 (0)