OpenBarnyard
 
Loading...
Searching...
No Matches
AWaveBank.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "AWaveBank.h"
3#include "ASoundManager.h"
4
6
8
9//-----------------------------------------------------------------------------
10// Enables memory debugging.
11// Note: Should be the last include!
12//-----------------------------------------------------------------------------
13#include "Core/TMemoryDebugOn.h"
14
16
17AWaveBank::AWaveBank( const Toshi::TPString8& a_strBank, const Toshi::TPString8& a_strPath, TBOOL a_bSetFrequency )
18{
19 m_iNumWaves = 0;
20 m_iNumLoads = 0;
21 m_strBank = a_strBank;
22 m_strPath = a_strPath;
24
26 m_bSetFrequency = a_bSetFrequency;
27
28 ASoundManager::ms_WaveBanks.Insert( a_strBank, this );
29}
30
31AWaveSampleHandle AWaveBank::GetWaveSample( TINT a_iWaveIndex, TINT a_iUnused ) const
32{
33 TASSERT( a_iWaveIndex < m_iNumWaves );
34 return m_pWaves[ a_iWaveIndex ].pSampleHandle;
35}
36
37void AWaveBank::ResetWave( TINT a_iWaveIndex )
38{
39}
40
42{
43 ASoundManager::ms_WaveBanks.Remove( m_strBank );
44 delete[] m_pWaves;
45}
46
48{
49 TASSERT( a_iWaveIndex < m_iNumWaves );
50 return &m_pWaves[ a_iWaveIndex ];
51}
52
54{
55 TASSERT( a_iWaveIndex < m_iNumWaves );
56 return m_pWaves[ a_iWaveIndex ].iIndex;
57}
58
60{
61 TASSERT( a_iWaveIndex < m_iNumWaves );
62 return m_pWaves[ a_iWaveIndex ].iFrequency;
63}
64
65AWaveSampleHandle AWaveBank::CreateWaveSample( TINT a_iWaveIndex, TINT a_iUnused )
66{
67 TASSERT( a_iWaveIndex < m_iNumWaves );
68
69 if ( m_pWaves[ a_iWaveIndex ].pSampleHandle == TNULL )
70 {
71 m_pWaves[ a_iWaveIndex ].pSampleHandle = GetWaveSample( a_iWaveIndex, a_iUnused );
72 }
73
74 return m_pWaves[ a_iWaveIndex ].pSampleHandle;
75}
76
77void AWaveBank::SetWaveFlag1( TINT a_iWaveIndex )
78{
79 TASSERT( a_iWaveIndex < m_iNumWaves );
80 m_pWaves[ a_iWaveIndex ].iFlags &= ~2;
81 m_pWaves[ a_iWaveIndex ].iFlags |= 1;
82}
83
84void AWaveBank::SetWaveFlag2( TINT a_iWaveIndex )
85{
86 TASSERT( a_iWaveIndex < m_iNumWaves );
87 m_pWaves[ a_iWaveIndex ].iFlags &= ~1;
88 m_pWaves[ a_iWaveIndex ].iFlags |= 2;
89}
90
91void AWaveBank::ParseWavesData( const PBProperties* a_pBankProperties, TUINT a_uiForcedFlags )
92{
93 TVALIDPTR( a_pBankProperties );
94
95 m_iNumWaves = 0;
96
97 T2DynamicVector<AWave> vecWaves( GetGlobalAllocator(), 128, 128 );
98
99 for ( TUINT i = 0; i < a_pBankProperties->GetPropertyCount(); i++ )
100 {
101 const PBProperties::PBProperty* pProperty = a_pBankProperties->GetPropertyByIndex( i );
102
103 // Skip any properties other than Wave
104 if ( pProperty->GetName().GetString()[ 0 ] != 'W' ) continue;
105
106 TINT iFrequency = 22050;
107 TFLOAT fLength = 0.0f;
108 TUINT uiFlags = a_uiForcedFlags;
109
110 const PBProperties* pWaveProperties = pProperty->GetValue()->GetProperties();
111
112 // Parse flags
113 const PBPropertyValue* pFlagsProperty = pWaveProperties->GetProperty( "flags" );
114 if ( pFlagsProperty && uiFlags == 0 ) uiFlags = pFlagsProperty->GetInteger();
115
116 // Parse frequency
117 const PBPropertyValue* pFreqProperty = pWaveProperties->GetProperty( "frequency" );
118 if ( pFreqProperty )
119 {
120 if ( m_bSetFrequency )
121 iFrequency = pFreqProperty->GetInteger();
122 else
123 iFrequency = ASoundManager::GetSingleton()->m_iGlobalFrequency;
124 }
125
126 // Parse length
127 pWaveProperties->GetOptionalPropertyValue( fLength, "length" );
128
129 vecWaves.EmplaceBack( uiFlags, iFrequency, fLength, TNULL, -1 );
130 m_iNumWaves += 1;
131 }
132
133 // Allocate the actual array that will store info about samples
135
136 // Copy data from the vector
137 for ( TINT i = 0; i < m_iNumWaves; i++ )
138 m_pWaves[ i ] = vecWaves[ i ];
139}
#define TASSERT(X,...)
Definition Defines.h:138
#define TOSHI_NAMESPACE_USING
Definition Defines.h:46
#define TVALIDPTR(PTR)
Definition Defines.h:139
TFORCEINLINE T2Allocator * GetGlobalAllocator()
Definition T2Allocator.h:49
unsigned int TUINT
Definition Typedefs.h:8
float TFLOAT
Definition Typedefs.h:4
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
bool TBOOL
Definition Typedefs.h:6
Dynamic vector container for the Toshi engine.
const class PBProperties * GetProperties() const
TINT GetInteger() const
const TCHAR * GetString() const
TUINT32 GetPropertyCount() const
const PBPropertyValue * GetProperty(const TCHAR *a_szName) const
TBOOL GetOptionalPropertyValue(T &a_rOutValue, const TCHAR *a_szName) const
const PBProperty * GetPropertyByIndex(TSIZE a_iIndex) const
PBPropertyValue * GetValue()
PBPropertyName & GetName()
T * EmplaceBack(Args &&... args)
@ POOL_Sound
Definition AMemory.h:37
static Toshi::TMemory::MemBlock * GetMemBlock(POOL a_ePool)
Definition AMemory.cpp:38
Definition AWave.h:6
Toshi::TPString8 m_strBank
Definition AWaveBank.h:56
AWave * m_pWaves
Definition AWaveBank.h:60
TINT GetWaveFrequency(TINT a_iWaveIndex)
Definition AWaveBank.cpp:59
virtual void ResetWave(TINT a_iWaveIndex)
Definition AWaveBank.cpp:37
AWaveSampleHandle CreateWaveSample(TINT a_iWaveIndex, TINT a_iUnused)
Definition AWaveBank.cpp:65
virtual AWaveSampleHandle GetWaveSample(TINT a_iWaveIndex, TINT a_iUnused) const
Definition AWaveBank.cpp:31
TBOOL m_bSetFrequency
Definition AWaveBank.h:59
AWaveBankFileHandle m_FileHandle
Definition AWaveBank.h:61
virtual ~AWaveBank()
Definition AWaveBank.cpp:41
TINT m_iNumWaves
Definition AWaveBank.h:54
void SetWaveFlag1(TINT a_iWaveIndex)
Definition AWaveBank.cpp:77
Toshi::TPString8 m_strPath
Definition AWaveBank.h:57
TINT GetWaveId(TINT a_iWaveIndex)
Definition AWaveBank.cpp:53
void ParseWavesData(const PBProperties *a_pBankProperties, TUINT a_uiForcedFlags)
Definition AWaveBank.cpp:91
AWave * GetWave(TINT a_iWaveIndex)
Definition AWaveBank.cpp:47
AWaveBank(const Toshi::TPString8 &a_strBank, const Toshi::TPString8 &a_strPath, TBOOL a_bSetFrequency)
Definition AWaveBank.cpp:17
void SetWaveFlag2(TINT a_iWaveIndex)
Definition AWaveBank.cpp:84
TINT m_iNumLoads
Definition AWaveBank.h:55