This repository has been archived by the owner on Jan 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
CAEBankLoader.cpp
133 lines (125 loc) · 3.15 KB
/
CAEBankLoader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "StdInc.h"
CAEBankLoader::CAEBankLoader()
{
m_initialized = false;
m_streamingChannel = 4;
}
CAEBankLoader::~CAEBankLoader()
{
if (m_initialized)
{
delete m_bankSlots;
CMemoryMgr::Free(m_soundBuffers);
delete m_bankLookup;
delete m_streamHandles;
}
}
void CAEBankLoader::InitialiseRequestList()
{
for (size_t i = 0; i < ELEMS_COUNT(m_soundRequests); i++)
{
m_soundRequests[i].m_bankSlot = -1;
m_soundRequests[i].m_bank = -1;
m_soundRequests[i].m_sound = -1;
m_soundRequests[i].m_bankSlot = NULL;
m_soundRequests[i].m_loadingStatus = 0;
}
pad1 = 0;
m_requestsToLoad = 0;
m_requestListNext = 0;
}
void CAEBankLoader::CalculateBufferSize()
{
size_t sumOffset = 0;
for (size_t i = 0; i < m_numBankSlots; i++)
{
m_bankSlots[i].m_offsetOnBuffer = sumOffset;
sumOffset += m_bankSlots[i].m_slotBufferSize;
}
}
bool CAEBankLoader::LoadBankLookupFile()
{
int file = CFileMgr::OpenFile("AUDIO\\CONFIG\\BANKLKUP.DAT", "rb");
if (file <= 0)
{
return false;
}
size_t totalSize = CFileMgr::GetTotalSize(file);
if (!totalSize)
{
CFileMgr::CloseFile(file);
return false;
}
m_numBanks = totalSize / sizeof(CAEBankSlotItem);
m_bankLookup = new CAEBankLookupItem[m_numBanks];
if (CFileMgr::Read(file, (char*)m_bankLookup, totalSize) != totalSize)
{
CFileMgr::CloseFile(file);
return false;
}
CFileMgr::CloseFile(file);
return true;
}
bool CAEBankLoader::LoadBankSlotFile()
{
int file = CFileMgr::OpenFile("AUDIO\\CONFIG\\BANKSLOT.DAT", "rb");
if (file <= 0)
{
return false;
}
size_t totalSize = CFileMgr::GetTotalSize(file);
if (totalSize <= 1)
{
CFileMgr::CloseFile(file);
return false;
}
if (!CFileMgr::Read(file, (char*)&m_numBankSlots, sizeof(m_numBankSlots)))
{
CFileMgr::CloseFile(file);
return false;
}
m_bankSlots = new CAEBankSlot[m_numBankSlots];
if (!m_bankSlots)
{
CFileMgr::CloseFile(file);
return false;
}
if (CFileMgr::Read(file, (char*)m_bankSlots, totalSize - 2) != totalSize - 2)
{
CFileMgr::CloseFile(file);
delete[] m_bankSlots;
return false;
}
CFileMgr::CloseFile(file);
CalculateBufferSize();
m_soundBuffersSize = m_bankSlots[m_numBankSlots - 1].m_offsetOnBuffer + m_bankSlots[m_numBankSlots - 1].m_slotBufferSize;
m_soundBuffers = (char*)CMemoryMgr::Malloc(m_soundBuffersSize);
return true;
}
void* CAEBankLoader::GetSoundBuffer(uint16_t bankSlotId, int* slotSize)
{
if (!m_initialized )
{
return 0;
}
if (bankSlotId >= m_numBankSlots)
{
slotSize = 0;
return NULL;
}
*slotSize = m_bankSlots[bankSlotId].m_slotBufferSize;
return &m_soundBuffers[m_bankSlots[bankSlotId].m_offsetOnBuffer];
}
bool CAEBankLoader::Initialise()
{
InitialiseRequestList();
if (LoadBankSlotFile() && LoadBankLookupFile() && LoadSFXPakLookupFile())
{
m_initialized = 1;
return true;
}
else
{
return false;
}
}