OpenBarnyard
 
Loading...
Searching...
No Matches
ASoundManager Class Reference

#include <ASoundManager.h>

Inheritance diagram for ASoundManager:

Classes

struct  CameraData
 
struct  Category
 
struct  ChannelRef
 
struct  ChannelRefLegacy
 
class  Cue
 
struct  EventParameters
 
struct  S2
 
struct  S4
 
class  SoundEvent
 
struct  SoundEventListSortResults
 
struct  SoundEventManager
 
struct  SoundEventSortResults
 
struct  StreamRef
 

Public Types

enum  SOUNDEVENT : TUINT {
  SOUNDEVENT_PlayAudio , SOUNDEVENT_PlayStream , SOUNDEVENT_StopAudio , SOUNDEVENT_UpdateChannelVolume ,
  SOUNDEVENT_UpdateChannelFrequency , SOUNDEVENT_UNUSED1 , SOUNDEVENT_UpdateChannelPosition , SOUNDEVENT_UNUSED2 ,
  SOUNDEVENT_UNUSED3 , SOUNDEVENT_NUMOF
}
 
using ThisClass = ASoundManager
 
using BaseClass = Toshi::TTask
 
using SoundEventList = Toshi::T2DListNodeWrapper<Toshi::T2SortedList<SoundEvent, Toshi::T2DList<SoundEvent>, SoundEventSortResults>>
 
using PauseListener = Toshi::TListener<Toshi::TSystemManager, TBOOL, ASoundManager>
 

Public Member Functions

virtual Toshi::TClass * GetClass () override
 
 ASoundManager ()
 
 ~ASoundManager ()
 
virtual TBOOL Reset () override
 
virtual TBOOL OnCreate () override
 
virtual TBOOL OnUpdate (TFLOAT a_fDeltaTime) override
 
virtual void OnDestroy () override
 
TINT PlayCue (ASoundId a_iSound)
 
TINT PlayCueEx (ASoundId a_iSound, TFLOAT a_fVolume, TBOOL a_bFlag, TFLOAT a_fDelay, TINT a_iTrack)
 
void StopCue (TINT &a_rCueIndex)
 
void StopCueAsync (TINT &a_rCueIndex, TFLOAT a_fDelay)
 
void PauseAllCues (TBOOL a_bPause)
 
TINT GetAvailableCueIndex ()
 
TBOOL IsCuePlaying (TINT a_iCueIndex)
 
void CancelCueEvents (Cue *a_pCue, SOUNDEVENT a_eEventType)
 
AWaveBankFindWaveBank (const Toshi::TPString8 &a_rcName)
 
TBOOL LoadWaveBanksInfo (const TCHAR *a_szFileName)
 
TBOOL LoadWaveBankSamples (const Toshi::TPString8 &a_rcName, AWaveBank::LOADFLAGS a_eLoadFlags, TINT a_iBufferSize)
 
ASoundBankFindSoundBank (const Toshi::TPString8 &a_rcName)
 
TBOOL LoadSoundBank (const Toshi::TPString8 &a_rcName, TBOOL a_bSimpleSound, TBOOL a_bLoadImmediately)
 
void LoadSoundBankSamples (const Toshi::TPString8 &a_rcName)
 

Static Public Member Functions

static Toshi::TObject * CreateTObject ()
 
static Toshi::TObject * CreateTObjectInPlace (void *a_pPtr)
 
static void InitialiseClass ()
 
static void DeinitialiseClass ()
 
static TFORCEINLINE Toshi::TClass * GetClassStatic ()
 

Public Attributes

friend AWaveBank
 

Static Public Attributes

static constexpr Toshi::TClass * PARENTCLASS = & Toshi::TTask::ms_oClass
 
static Toshi::TClass ms_oClass = Toshi::TClass( "ASoundManager", ASoundManager::PARENTCLASS, ASoundManager::CreateTObject, ASoundManager::CreateTObjectInPlace, ASoundManager::InitialiseClass, ASoundManager::DeinitialiseClass, 0, 1, sizeof( ASoundManager ), alignof( ASoundManager ) )
 
static constexpr const TCHARSOUNDS_BASE_DIRECTORY = "Data/Sound/"
 
static constexpr TUINT MAX_NUM_CATEGORIES = 16
 
static TBOOL ms_bShouldUpdateLoadingScreen = false
 

Detailed Description

Definition at line 20 of file ASoundManager.h.

Member Typedef Documentation

◆ BaseClass

using ASoundManager::BaseClass = Toshi::TTask

Definition at line 24 of file ASoundManager.h.

◆ PauseListener

using ASoundManager::PauseListener = Toshi::TListener<Toshi::TSystemManager, TBOOL, ASoundManager>

Definition at line 243 of file ASoundManager.h.

◆ SoundEventList

using ASoundManager::SoundEventList = Toshi::T2DListNodeWrapper<Toshi::T2SortedList<SoundEvent, Toshi::T2DList<SoundEvent>, SoundEventSortResults>>

Definition at line 153 of file ASoundManager.h.

◆ ThisClass

Definition at line 24 of file ASoundManager.h.

Member Enumeration Documentation

◆ SOUNDEVENT

Enumerator
SOUNDEVENT_PlayAudio 
SOUNDEVENT_PlayStream 
SOUNDEVENT_StopAudio 
SOUNDEVENT_UpdateChannelVolume 
SOUNDEVENT_UpdateChannelFrequency 
SOUNDEVENT_UNUSED1 
SOUNDEVENT_UpdateChannelPosition 
SOUNDEVENT_UNUSED2 
SOUNDEVENT_UNUSED3 
SOUNDEVENT_NUMOF 

Definition at line 44 of file ASoundManager.h.

Constructor & Destructor Documentation

◆ ASoundManager()

ASoundManager::ASoundManager ( )

Definition at line 31 of file ASoundManager.cpp.

33{
34 TIMPLEMENT();
35 m_iLastAvailableSoundExSlot = -1;
36 m_fCurrentTime = 0.0f;
37
38 m_bMuted = TFALSE;
39 m_bUseMinHardwareChannels = TTRUE;
40 m_iMinHWChannels = 32;
41 m_iNumChannels = 32;
42 m_iGlobalFrequency = 22050;
43
44 ms_pFileSystem = TFileManager::GetSingleton()->FindFileSystem( "local" );
45
46 // Set event handlers
47 m_oEventManager.SetEventHandler( SOUNDEVENT_PlayAudio, &ASoundManager::EventHandler_PlaySound );
48 m_oEventManager.SetEventHandler( SOUNDEVENT_PlayStream, &ASoundManager::EventHandler_PlayStream );
49 m_oEventManager.SetEventHandler( SOUNDEVENT_StopAudio, &ASoundManager::EventHandler_StopAudio );
50}
#define TIMPLEMENT()
Definition Defines.h:136
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
#define MAX_NUM_STREAMS
#define MAX_NUM_SOUND_EVENTS
TFileSystem * FindFileSystem(const TString8 &name)
static TFORCEINLINE TFileManager * GetSingleton()
Definition TSingleton.h:49
@ POOL_Sound
Definition AMemory.h:37
static Toshi::T2Allocator * GetAllocator(POOL a_ePool)
Definition AMemory.cpp:31

◆ ~ASoundManager()

ASoundManager::~ASoundManager ( )

Definition at line 52 of file ASoundManager.cpp.

53{
54 TIMPLEMENT();
55
56 m_FreeListS2.Clear();
57
58 FSOUND_Close();
59 m_PauseListener.Disconnect();
60 Reset();
61}
virtual TBOOL Reset() override

Member Function Documentation

◆ CancelCueEvents()

void ASoundManager::CancelCueEvents ( Cue * a_pCue,
SOUNDEVENT a_eEventType )

Definition at line 453 of file ASoundManager.cpp.

454{
455 TVALIDPTR( a_pCue );
456
457 for ( auto it = a_pCue->oEventList->Begin(); it != a_pCue->oEventList->End(); )
458 {
459 auto itNext = it.Next();
460
461 if ( it->eEventType == a_eEventType )
462 {
463 a_pCue->oEventList->Erase( it );
464 m_SoundEventPool.DeleteObject( it );
465 }
466
467 it = itNext;
468 }
469}
#define TVALIDPTR(PTR)
Definition Defines.h:139

◆ CreateTObject()

Toshi::TObject * ASoundManager::CreateTObject ( )
static

Definition at line 26 of file ASoundManager.cpp.

◆ CreateTObjectInPlace()

Toshi::TObject * ASoundManager::CreateTObjectInPlace ( void * a_pPtr)
static

Definition at line 26 of file ASoundManager.cpp.

◆ DeinitialiseClass()

void ASoundManager::DeinitialiseClass ( )
static

Definition at line 26 of file ASoundManager.cpp.

◆ FindSoundBank()

ASoundBank * ASoundManager::FindSoundBank ( const Toshi::TPString8 & a_rcName)

Definition at line 1073 of file ASoundManager.cpp.

1074{
1075 T2_FOREACH( m_SoundBanks, it )
1076 {
1077 if ( it->m_strName == a_rcName )
1078 return it;
1079 }
1080
1081 return TNULL;
1082}
#define T2_FOREACH(vecName, iteratorName)
Definition T2Iterator.h:4
#define TNULL
Definition Typedefs.h:23

◆ FindWaveBank()

AWaveBank * ASoundManager::FindWaveBank ( const Toshi::TPString8 & a_rcName)

Definition at line 471 of file ASoundManager.cpp.

472{
473 auto pFoundNode = ms_WaveBanks.Find( a_rcName );
474
475 return ( ms_WaveBanks.IsValid( pFoundNode ) ) ? pFoundNode->GetSecond() : TNULL;
476}

◆ GetAvailableCueIndex()

TINT ASoundManager::GetAvailableCueIndex ( )

Definition at line 352 of file ASoundManager.cpp.

353{
354 TINT iSlot;
355
356 for ( iSlot = m_iLastAvailableSoundExSlot + 1;; iSlot++ )
357 {
358 if ( iSlot == 128 )
359 iSlot = 0;
360
361 if ( iSlot == m_iLastAvailableSoundExSlot )
362 return -1;
363
364 if ( m_aCues[ iSlot ].fStartTime <= 0.0 )
365 {
366 if ( iSlot == -1 )
367 return iSlot;
368
369 if ( !m_aCues[ iSlot ].bUsed )
370 break;
371 }
372 }
373
374 m_iLastAvailableSoundExSlot = iSlot;
375 return iSlot;
376}
int TINT
Definition Typedefs.h:7

◆ GetClass()

Toshi::TClass * ASoundManager::GetClass ( )
overridevirtual

Definition at line 26 of file ASoundManager.cpp.

◆ GetClassStatic()

static TFORCEINLINE Toshi::TClass * ASoundManager::GetClassStatic ( )
inlinestatic

Definition at line 24 of file ASoundManager.h.

◆ InitialiseClass()

void ASoundManager::InitialiseClass ( )
static

Definition at line 26 of file ASoundManager.cpp.

◆ IsCuePlaying()

TBOOL ASoundManager::IsCuePlaying ( TINT a_iCueIndex)

Definition at line 378 of file ASoundManager.cpp.

379{
380 TASSERT( a_iCueIndex < ASOUNDMANAGER_MAX_NUM_CUE );
381
382 if ( a_iCueIndex == -1 )
383 return TFALSE;
384
385 Cue* pCue = &m_aCues[ a_iCueIndex ];
386
387 if ( pCue->fStartTime2 > 0.0f || !pCue->oEventList->IsEmpty() )
388 return TTRUE;
389
390 if ( pCue->IsUsed() && pCue->pSound != TNULL )
391 {
392 ASound* pSound = pCue->pSound;
393
394 if ( pSound->m_iFlags & 16 )
395 {
396 // Stream
397 T2_FOREACH( pCue->oChannelRefs, channel )
398 {
399 if ( !( channel->iFlags & 0x20 ) || FSOUND_IsPlaying( channel->iFMODChannelHandle ) )
400 {
401 return TTRUE;
402 }
403 }
404 }
405 else
406 {
407 // Loaded data
408 T2_FOREACH( pCue->oChannelRefs, channel )
409 {
410 if ( FSOUND_IsPlaying( channel->iFMODChannelHandle ) )
411 {
412 return TTRUE;
413 }
414 }
415 }
416 }
417
418 return TFALSE;
419}
#define TASSERT(X,...)
Definition Defines.h:138
#define ASOUNDMANAGER_MAX_NUM_CUE

◆ LoadSoundBank()

TBOOL ASoundManager::LoadSoundBank ( const Toshi::TPString8 & a_rcName,
TBOOL a_bSimpleSound,
TBOOL a_bLoadImmediately )

Definition at line 1084 of file ASoundManager.cpp.

1085{
1086 if ( a_rcName.GetPooledString() && !a_rcName.GetPooledString()->GetString8().IsEmpty() )
1087 {
1088 if ( FindSoundBank( a_rcName ) == TNULL )
1089 {
1090 return LoadSoundBankImpl( a_rcName, a_bSoundEx, a_bLoadImmediately );
1091 }
1092 }
1093
1094 return TFALSE;
1095}
ASoundBank * FindSoundBank(const Toshi::TPString8 &a_rcName)

◆ LoadSoundBankSamples()

void ASoundManager::LoadSoundBankSamples ( const Toshi::TPString8 & a_rcName)

Definition at line 1097 of file ASoundManager.cpp.

1098{
1099 if ( ASoundBank* pSoundBank = FindSoundBank( a_rcName ) )
1100 {
1101 pSoundBank->Load();
1102 }
1103}

◆ LoadWaveBankSamples()

TBOOL ASoundManager::LoadWaveBankSamples ( const Toshi::TPString8 & a_rcName,
AWaveBank::LOADFLAGS a_eLoadFlags,
TINT a_iBufferSize )

Definition at line 1058 of file ASoundManager.cpp.

1059{
1060 if ( a_rcName.GetPooledString() && !a_rcName.GetPooledString()->GetString8().IsEmpty() )
1061 {
1062 AWaveBank* pWaveBank = FindWaveBank( a_rcName );
1063
1064 if ( pWaveBank )
1065 {
1066 return pWaveBank->Load( a_eLoadFlags, a_iBufferSize ) == AWaveBank::LOADRESULT_OK;
1067 }
1068 }
1069
1070 return TFALSE;
1071}
AWaveBank * FindWaveBank(const Toshi::TPString8 &a_rcName)
virtual LOADRESULT Load(LOADFLAGS a_uiFlags, TINT a_iBufferSize)=0
@ LOADRESULT_OK
Definition AWaveBank.h:23

◆ LoadWaveBanksInfo()

TBOOL ASoundManager::LoadWaveBanksInfo ( const TCHAR * a_szFileName)

Definition at line 1012 of file ASoundManager.cpp.

1013{
1014 TBOOL bOpened = AAssetLoader::Load(
1015 "Data/Assets/lib_wavebank.trb",
1017 TTRUE
1018 );
1019
1020 if ( !bOpened ) return TFALSE;
1021
1022 const PBProperties* pProperties =
1024 TVALIDPTR( pProperties );
1025
1026 auto pWaveBanksVal = pProperties->GetProperty( "Wavebanks" );
1027 TVALIDPTR( pWaveBanksVal );
1028
1029 auto pWaveBanks = pWaveBanksVal->GetArray();
1030
1031 for ( TUINT i = 0; i < pWaveBanks->GetSize(); i++ )
1032 {
1033 TPString8 strWaveBankName = pWaveBanks->GetValue( i )->GetTPString8();
1034
1035 if ( FindWaveBank( strWaveBankName ) == TNULL )
1036 {
1037 LoadWaveBankFromAsset( strWaveBankName.GetString(), 0 );
1038 }
1039 }
1040
1041 auto pCategoriesVal = pProperties->GetProperty( "Categories" );
1042 TVALIDPTR( pCategoriesVal );
1043
1044 auto pCategories = pCategoriesVal->GetArray();
1045
1046 for ( TUINT i = 0; i < pCategories->GetSize(); i++ )
1047 {
1048 TPString8 strCategoryName = pCategories->GetValue( i )->GetTPString8();
1049
1050 m_CategoryIndices.Insert( strCategoryName, m_CategoryIndices.Size() );
1051 }
1052
1054
1055 return TTRUE;
1056}
unsigned int TUINT
Definition Typedefs.h:8
bool TBOOL
Definition Typedefs.h:6
@ AAssetType_WaveBank
Definition AAssetLoader.h:9
static constexpr const TCHAR * TRB_SECTION_NAME
const PBPropertyValue * GetProperty(const TCHAR *a_szName) const
TFORCEINLINE const TCHAR * GetString() const
Definition TPString8.h:167
static TBOOL Load(const TCHAR *a_szFileName, AAssetType a_eAssetType, TBOOL a_bStream)
static void Close(AAssetType a_eAssetType)
static T * CastSymbol(const TCHAR *a_szFileName, const TCHAR *a_szSymbolName, AAssetType a_eAssetType)

◆ OnCreate()

TBOOL ASoundManager::OnCreate ( )
overridevirtual

Definition at line 69 of file ASoundManager.cpp.

70{
71 Initialise();
72 m_PauseListener.Connect(
74 this,
75 []( ASoundManager* a_pSndMngr, TSystemManager* a_pSysMngr, TBOOL* a_pPaused ) {
76 a_pSndMngr->PauseAllCues( *a_pPaused );
77 return TTRUE;
78 },
79 0
80 );
81
82 m_pS4 = new ( AMemory::GetMemBlock( AMemory::POOL_Sound ) ) S4[ 32 ];
83
84 for ( TINT i = 0; i < 32; i++ )
85 {
86 m_FreeListS4.PushBack( &m_pS4[ i ] );
87 }
88
89 for ( TINT i = 0; i < TARRAYSIZE( m_aS2 ); i++ )
90 {
91 m_FreeListS2.PushBack( &m_aS2[ i ] );
92 }
93
94 return TTRUE;
95}
#define TARRAYSIZE(ARRAY)
Definition Defines.h:70
TSystemManager g_oSystemManager
Definition TSystem.cpp:15
TEmitter< TSystemManager, TBOOL > & GetPauseEmitter()
Definition TSystem.h:140
static Toshi::TMemory::MemBlock * GetMemBlock(POOL a_ePool)
Definition AMemory.cpp:38

◆ OnDestroy()

void ASoundManager::OnDestroy ( )
overridevirtual

Definition at line 231 of file ASoundManager.cpp.

232{
233 m_UnkList1.Clear();
234 m_FreeListS4.Clear();
235 delete[] m_pS4;
236 m_pS4 = TNULL;
237 m_PauseListener.Disconnect();
238}

◆ OnUpdate()

TBOOL ASoundManager::OnUpdate ( TFLOAT a_fDeltaTime)
overridevirtual

Definition at line 97 of file ASoundManager.cpp.

98{
99 TIMPLEMENT();
100 m_fCurrentTime += a_fDeltaTime;
101
102 if ( !g_oSystemManager.IsPaused() )
103 {
104 if ( ARootTask::GetSingleton()->IsPaused() && ms_iNumPauses <= 0 )
105 {
107 }
108 else if ( !ARootTask::GetSingleton()->IsPaused() && ms_iNumPauses > 0 )
109 {
111 }
112 }
113
114 TTODO( "FUN_005db310" );
115
116 // Run the event loop
117 while ( !m_QueuedSortedEventLists.IsEmpty() )
118 {
119 SoundEventList& eventList = *m_QueuedSortedEventLists.Front();
120 ASoundManager::SoundEvent* pEarliestEvent = eventList->Front();
121
122 // Skip the list if it's too early to execute it's earliest event
123 if ( pEarliestEvent->fStartTime > m_fCurrentTime )
124 break;
125
126 // Handle events in the list
127 while ( TTRUE )
128 {
129 pEarliestEvent->Remove();
130 m_oEventManager.ExecuteEvent( pEarliestEvent->eEventType, this, pEarliestEvent );
131
132 // Deallocate the event object
133 m_SoundEventPool.DeleteObject( pEarliestEvent );
134
135 if ( !eventList.IsLinked() )
136 break;
137
138 // Check if the list is over
139 if ( eventList->IsEmpty() )
140 {
141 // Unlink the list since it's not used anymore
142 eventList.Remove();
143 break;
144 }
145
146 // Certainly, there are some more events
147 // Let's check if they need to be processed
148 pEarliestEvent = eventList->Front();
149
150 if ( pEarliestEvent->fStartTime > m_fCurrentTime )
151 {
152 // Seems that the other events in the list are not to be executed yet,
153 // so let's reinsert the list to preserve correct order and move on to
154 // the next list.
155
156 m_QueuedSortedEventLists.ReInsert( eventList );
157 break;
158 }
159 }
160 }
161
162 // Update streams
163 for ( auto pStream = m_StreamRefs.Begin(); pStream != m_StreamRefs.End(); )
164 {
165 if ( ( pStream->pUnknown && UpdateStreamActivity( pStream ) ) ||
166 ( pStream->pCue && UpdateStreamCue( pStream ) ) )
167 {
168 auto itNext = m_StreamRefs.Erase( pStream );
169 m_StreamRefPool.DeleteObject( pStream );
170
171 pStream = itNext;
172 }
173 else
174 {
175 pStream = pStream.Next();
176 }
177 }
178
179 // Reset cues that has finished playing
180 for ( TINT i = 0; i < ASOUNDMANAGER_MAX_NUM_CUE; i++ )
181 {
182 TFLOAT fCueStartTime = m_aCues[ i ].fStartTime;
183
184 if ( fCueStartTime > 0.0f && !IsCuePlaying( i ) )
185 {
186 m_aCues[ i ].Reset();
187 }
188 }
189
190 // ...
191
192 // Update sound attributes based on the current camera position
193 // TODO: replace TTRUE with some flag from the AQuestManager
194 if ( ARootTask::GetSingleton()->IsGameSystemCreated() && TTRUE )
195 {
196 ACamera* pCamera = ACameraManager::GetSingleton()->GetCurrentCamera();
197
198 // Get the position
199 m_oCameraData.Position = pCamera->GetMatrix().AsBasisVector4( BASISVECTOR_TRANSLATION );
200
201 // Get the forward vector
202 m_oCameraData.Forward = pCamera->GetMatrix().AsBasisVector4( BASISVECTOR_FORWARD );
203 m_oCameraData.Forward.w = 1.0f;
204
205 // Get the up vector
206 m_oCameraData.Up = pCamera->GetMatrix().AsBasisVector4( BASISVECTOR_UP );
207 m_oCameraData.Up.w = 1.0f;
208
209 // Invert up axis as it needs to be
210 m_oCameraData.Up.x = -m_oCameraData.Up.x;
211 m_oCameraData.Up.y = -m_oCameraData.Up.y;
212 m_oCameraData.Up.z = -m_oCameraData.Up.z;
213
214 TFLOAT aPosition[ 3 ];
215 aPosition[ 0 ] = m_oCameraData.Position.x;
216 aPosition[ 1 ] = m_oCameraData.Position.y;
217 aPosition[ 2 ] = m_oCameraData.Position.z;
218
219 TFLOAT aVelocity[ 3 ];
220 aVelocity[ 0 ] = m_oCameraData.Velocity.x;
221 aVelocity[ 1 ] = m_oCameraData.Velocity.y;
222 aVelocity[ 2 ] = m_oCameraData.Velocity.z;
223
224 FSOUND_3D_Listener_SetAttributes( aPosition, aVelocity, m_oCameraData.Forward.x, m_oCameraData.Forward.y, -m_oCameraData.Forward.z, m_oCameraData.Up.x, m_oCameraData.Up.y, -m_oCameraData.Up.z );
225 }
226
227 FSOUND_Update();
228 return TTRUE;
229}
@ BASISVECTOR_TRANSLATION
Definition TMatrix44.h:28
@ BASISVECTOR_UP
Definition TMatrix44.h:26
@ BASISVECTOR_FORWARD
Definition TMatrix44.h:27
#define TTODO(DESC)
Definition Defines.h:134
float TFLOAT
Definition Typedefs.h:4
TBOOL IsPaused() const
Definition TSystem.h:160
Toshi::TMatrix44 & GetMatrix()
Definition ACamera.cpp:58
Toshi::T2DListNodeWrapper< Toshi::T2SortedList< SoundEvent, Toshi::T2DList< SoundEvent >, SoundEventSortResults > > SoundEventList
TBOOL IsCuePlaying(TINT a_iCueIndex)
void PauseAllCues(TBOOL a_bPause)

◆ PauseAllCues()

void ASoundManager::PauseAllCues ( TBOOL a_bPause)

Definition at line 966 of file ASoundManager.cpp.

967{
968 if ( a_bPause )
969 {
970 // Don't count number of pauses
971 if ( ms_iNumPauses != 0 ) return;
972
973 // Pause cues
974 for ( TINT i = 0; i < ASOUNDMANAGER_MAX_NUM_CUE; i++ )
975 {
976 Cue* pCue = &m_aCues[ i ];
977
978 if ( !pCue->pSound || !m_aCategories[ pCue->pSound->m_uiCategoryIndex ].bPausable )
979 continue;
980
981 T2_FOREACH( pCue->oChannelRefs, channel )
982 {
983 if ( !( channel->iFlags & 1 ) )
984 {
985 FSOUND_SetPaused( channel->iFMODChannelHandle, TTRUE );
986 }
987 }
988 }
989
990 ms_iNumPauses += 1;
991 }
992 else if ( ms_iNumPauses > 0 && --ms_iNumPauses == 0 )
993 {
994 // Unpause cues
995 for ( TINT i = 0; i < ASOUNDMANAGER_MAX_NUM_CUE; i++ )
996 {
997 Cue* pCue = &m_aCues[ i ];
998
999 if ( !pCue->pSound ) continue;
1000
1001 T2_FOREACH( pCue->oChannelRefs, channel )
1002 {
1003 if ( !( channel->iFlags & 1 ) )
1004 {
1005 FSOUND_SetPaused( channel->iFMODChannelHandle, TFALSE );
1006 }
1007 }
1008 }
1009 }
1010}

◆ PlayCue()

TINT ASoundManager::PlayCue ( ASoundId a_iSound)

Definition at line 240 of file ASoundManager.cpp.

241{
242 return PlayCueEx( a_iSound, 1.0f, TFALSE, 0.0f, -1 );
243}
TINT PlayCueEx(ASoundId a_iSound, TFLOAT a_fVolume, TBOOL a_bFlag, TFLOAT a_fDelay, TINT a_iTrack)

◆ PlayCueEx()

TINT ASoundManager::PlayCueEx ( ASoundId a_iSound,
TFLOAT a_fVolume,
TBOOL a_bFlag,
TFLOAT a_fDelay,
TINT a_iTrack )

Definition at line 245 of file ASoundManager.cpp.

246{
247 if ( a_iSound == ASOUNDID_INVALID )
248 return -1;
249
250 // Look if the sound is stored to be played
251 auto pFoundNode = m_SoundIdToSound.Find( a_iSound );
252
253 if ( !m_SoundIdToSound.IsValid( pFoundNode ) )
254 return -1;
255
256 // The sound is found, can use it
257 ASound* pSound = pFoundNode->GetSecond();
258
259 // Check if no waves are stored in the sound
260 if ( pSound->m_vecSamples.Size() == 0 )
261 return -1;
262
263 TINT iCueIndex = GetAvailableCueIndex();
264
265 // Check if we can use some cue to play the sound
266 if ( iCueIndex == -1 )
267 return -1;
268
269 Cue* pCue = &m_aCues[ iCueIndex ];
270 pCue->fStartTime = m_fCurrentTime;
271
272 // Add this cue to a category
273 m_aCategories[ pSound->m_uiCategoryIndex ].PlayingCues.PushBack( pCue );
274
275 TINT iFlags = pSound->m_iFlags;
276
277 if ( a_bFlag )
278 {
279 iFlags |= 1;
280 pCue->fStartTime2 = m_fCurrentTime;
281 }
282
283 // Setup basic settings on the cue
284 pCue->fVolume = ( a_fVolume > 1.0f ) ? 1.0f : a_fVolume;
285 pCue->pSound = pSound;
286 pCue->fFrequency = 1.0f;
287 pCue->vecLoopStarts.Copy( pSound->m_vecLoopStarts );
288
289 TINT iSoundNumTracks = pSound->m_vecTracks.Size();
290
291 if ( a_iTrack == -1 )
292 {
293 // Play all the tracks of this sound
294
295 if ( iSoundNumTracks > 0 )
296 {
297 TINT iFirstWaveIndex = 0;
298
299 for ( TINT iTrack = 0; iTrack < iSoundNumTracks; iTrack++ )
300 {
301 if ( pSound->m_TrackLoop.GetBit( iTrack ) != 0 )
302 iFlags |= 2;
303 else
304 iFlags &= ~2;
305
306 CreatePlaySoundEvent(
307 pCue,
308 iTrack,
309 iFirstWaveIndex,
310 pSound->m_vecTracks[ iTrack ] + iFirstWaveIndex,
311 iFlags,
312 a_fDelay,
313 -1.0f
314 );
315
316 iFirstWaveIndex += pSound->m_vecTracks[ iTrack ];
317 }
318 }
319 }
320 else
321 {
322 // Play only the specified track
323
324 TINT iFirstWaveIndex = pSound->GetFirstWaveForTrack( a_iTrack );
325
326 if ( pSound->m_TrackLoop.GetBit( a_iTrack ) != 0 )
327 iFlags |= 2;
328 else
329 iFlags &= ~2;
330
331 CreatePlaySoundEvent(
332 pCue,
333 a_iTrack,
334 iFirstWaveIndex,
335 pSound->m_vecTracks[ a_iTrack ] + iFirstWaveIndex,
336 iFlags,
337 a_fDelay,
338 -1.0f
339 );
340 }
341
342 pCue->bUsed = TTRUE;
343
344 return iCueIndex;
345}
#define ASOUNDID_INVALID
Definition ASoundLegacy.h:3
TINT GetFirstWaveForTrack(TINT a_iTrack) const
Definition ASound.cpp:17
TINT GetAvailableCueIndex()

◆ Reset()

TBOOL ASoundManager::Reset ( )
overridevirtual

Definition at line 63 of file ASoundManager.cpp.

64{
65 TIMPLEMENT();
66 return TTRUE;
67}

◆ StopCue()

void ASoundManager::StopCue ( TINT & a_rCueIndex)

Definition at line 347 of file ASoundManager.cpp.

348{
349 StopCueAsync( a_rCueIndex, 0.0f );
350}
void StopCueAsync(TINT &a_rCueIndex, TFLOAT a_fDelay)

◆ StopCueAsync()

void ASoundManager::StopCueAsync ( TINT & a_rCueIndex,
TFLOAT a_fDelay )

Definition at line 421 of file ASoundManager.cpp.

422{
423 if ( a_rCueIndex == -1 )
424 return;
425
426 TASSERT( a_rCueIndex >= 0 && a_rCueIndex < ASOUNDMANAGER_MAX_NUM_CUE );
427 Cue* pCue = &m_aCues[ a_rCueIndex ];
428 a_rCueIndex = -1;
429
430 if ( pCue->IsUsed() )
431 {
432 if ( a_fDelay != 0.0f && pCue->oChannelRefs.Size() == 0 )
433 {
434 // No need to remove events or wait for async stop
435 pCue->Reset();
436 }
437 else if ( !pCue->HasEventOfType( SOUNDEVENT_StopAudio ) )
438 {
440
441 T2_FOREACH( pCue->oChannelRefs, channel )
442 {
443 if ( channel->iFMODChannelHandle == -1 )
444 continue;
445
446 // Stop audio for every valid channel
447 CreateSoundEvent( SOUNDEVENT_StopAudio, a_fDelay, pCue, channel->pSample, channel, 0, -1 );
448 }
449 }
450 }
451}
void CancelCueEvents(Cue *a_pCue, SOUNDEVENT a_eEventType)

Member Data Documentation

◆ AWaveBank

friend ASoundManager::AWaveBank

Definition at line 248 of file ASoundManager.h.

◆ MAX_NUM_CATEGORIES

TUINT ASoundManager::MAX_NUM_CATEGORIES = 16
staticconstexpr

Definition at line 246 of file ASoundManager.h.

◆ ms_bShouldUpdateLoadingScreen

TBOOL ASoundManager::ms_bShouldUpdateLoadingScreen = false
inlinestatic

Definition at line 376 of file ASoundManager.h.

◆ ms_oClass

Toshi::TClass ASoundManager::ms_oClass = Toshi::TClass( "ASoundManager", ASoundManager::PARENTCLASS, ASoundManager::CreateTObject, ASoundManager::CreateTObjectInPlace, ASoundManager::InitialiseClass, ASoundManager::DeinitialiseClass, 0, 1, sizeof( ASoundManager ), alignof( ASoundManager ) )
static

Definition at line 24 of file ASoundManager.h.

◆ PARENTCLASS

Toshi::TClass* ASoundManager::PARENTCLASS = & Toshi::TTask::ms_oClass
staticconstexpr

Definition at line 24 of file ASoundManager.h.

◆ SOUNDS_BASE_DIRECTORY

const TCHAR* ASoundManager::SOUNDS_BASE_DIRECTORY = "Data/Sound/"
staticconstexpr

Definition at line 245 of file ASoundManager.h.


The documentation for this class was generated from the following files: