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

#include <ASound.h>

Classes

struct  Sample
 

Public Member Functions

 ASound ()
 
TINT GetFirstWaveForTrack (TINT a_iTrack) const
 
TINT GetRandomSample (TINT a_iWaveIndexMin, TINT a_iWaveIndexMax)
 
TINT GetRandomSampleWeighted (TINT a_iTrackIndex, TINT a_iWaveIndexMin, TINT a_iWaveIndexMax)
 
Toshi::T2DynamicVector< Sample > & GetSamples ()
 

Friends

class ASoundManager
 

Detailed Description

Definition at line 12 of file ASound.h.

Constructor & Destructor Documentation

◆ ASound()

ASound::ASound ( )

Definition at line 12 of file ASound.cpp.

13 : m_iFlags( 0 ), m_iId( 0 ), m_uiCategoryIndex( 0 ), m_ui8Priority( 255 ), m_fMinDist( 1.0f ), m_vecSamples( AMemory::GetAllocator( AMemory::POOL_Sound ), 1, 1 ), m_vecTracks( AMemory::GetAllocator( AMemory::POOL_Sound ), 1, 1 )
14{
15}
@ POOL_Sound
Definition AMemory.h:37
static Toshi::T2Allocator * GetAllocator(POOL a_ePool)
Definition AMemory.cpp:31

Member Function Documentation

◆ GetFirstWaveForTrack()

TINT ASound::GetFirstWaveForTrack ( TINT a_iTrack) const

Definition at line 17 of file ASound.cpp.

18{
19 TINT iFirstWaveIndex = 0;
20 for ( TINT iTrack = 0; iTrack < a_iTrack; iTrack++ )
21 iFirstWaveIndex += m_vecTracks[ iTrack ];
22
23 return iFirstWaveIndex;
24}
int TINT
Definition Typedefs.h:7

◆ GetRandomSample()

TINT ASound::GetRandomSample ( TINT a_iWaveIndexMin,
TINT a_iWaveIndexMax )

Definition at line 26 of file ASound.cpp.

27{
28 return a_iWaveIndexMin + ARandom::GetSingleton()->m_oRandom.GetInt( a_iWaveIndexMax - a_iWaveIndexMin );
29}

◆ GetRandomSampleWeighted()

TINT ASound::GetRandomSampleWeighted ( TINT a_iTrackIndex,
TINT a_iWaveIndexMin,
TINT a_iWaveIndexMax )

Definition at line 31 of file ASound.cpp.

32{
33 TASSERT( a_iTrackIndex != -1 );
34 TASSERT( a_iWaveIndexMax - a_iWaveIndexMin > 0 );
35
36 TINT iNumWaves = a_iWaveIndexMax - a_iWaveIndexMin;
37 TINT iTrackNumWaves = m_vecTracks[ a_iTrackIndex ];
38 TINT* pWeights = new ( AMemory::GetMemBlock( AMemory::POOL_Sound ) ) TINT[ iTrackNumWaves ];
39
40 TINT iTotalWeight = 0;
41 for ( TINT i = 0; i < a_iWaveIndexMax - a_iWaveIndexMin; i++ )
42 {
43 pWeights[ i ] = m_vecSamples[ i + a_iWaveIndexMin ].iWeight;
44 iTotalWeight += pWeights[ i ];
45 }
46
47 TINT* pWeightedSamples = new ( AMemory::GetMemBlock( AMemory::POOL_Sound ) ) TINT[ iTotalWeight ];
48 for ( TINT i = 0, j = 0; i < a_iWaveIndexMax - a_iWaveIndexMin; i++ )
49 {
50 // Copy sample index N (weight) times to the array
51 for ( TINT k = 0; k < pWeights[ i ]; k++ )
52 {
53 TASSERT( j < iTotalWeight );
54 pWeightedSamples[ j++ ] = a_iWaveIndexMin + i;
55 }
56 }
57
58 TINT iSelectedSample = ARandom::GetSingleton()->m_oRandom.GetInt( iTotalWeight );
59
60 delete[] pWeights;
61 delete[] pWeightedSamples;
62
63 return iSelectedSample;
64}
#define TASSERT(X,...)
Definition Defines.h:138
static Toshi::TMemory::MemBlock * GetMemBlock(POOL a_ePool)
Definition AMemory.cpp:38

◆ GetSamples()

Toshi::T2DynamicVector< Sample > & ASound::GetSamples ( )
inline

Definition at line 42 of file ASound.h.

42{ return m_vecSamples; }

Friends And Related Symbol Documentation

◆ ASoundManager

friend class ASoundManager
friend

Definition at line 15 of file ASound.h.


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