-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobots_sfx_soundbanks.bt
More file actions
301 lines (271 loc) · 9.28 KB
/
Copy pathrobots_sfx_soundbanks.bt
File metadata and controls
301 lines (271 loc) · 9.28 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
//------------------------------------------------
//--- 010 Editor Binary Template
//
// File: spyro_sfx_soundbanks.bt
// Purpose: Parse EuroSound soundbank MUSX files generated by EuroSoundRedux.
// File Mask: *_*.sfx
// ID Bytes: 4D 55 53 58
//------------------------------------------------
LittleEndian();
string GetSfxFlagName(int bit)
{
if (bit == 0) return "MaxReject";
if (bit == 1) return "UnPausable";
if (bit == 2) return "IgnoreMasterVolume";
if (bit == 3) return "MultiSample";
if (bit == 4) return "RandomPick";
if (bit == 5) return "Shuffled";
if (bit == 6) return "Looped";
if (bit == 7) return "PolyPhonic";
if (bit == 8) return "UnderWater";
if (bit == 9) return "PauseInstant";
if (bit == 10) return "HasSubSfx";
if (bit == 11) return "StealOnLouder";
if (bit == 12) return "TreatLikeMusic";
if (bit == 13) return "KillMeOwnGroup";
if (bit == 14) return "GroupStealReject";
if (bit == 15) return "OneInstancePerFrame";
return "Unknown";
}
string GetFlagsText(ushort flags)
{
local string text = "";
local int bit;
for (bit = 0; bit < 16; bit++)
{
if ((flags & (1 << bit)) != 0)
{
if (Strlen(text) > 0)
text += "|";
text += GetSfxFlagName(bit);
}
}
if (Strlen(text) == 0)
return "none";
return text;
}
typedef struct
{
char Magic[4];
uint Hashcode <format=hex>;
uint FileVersion;
uint FileSize <format=hex>;
char Platform[4];
uint TimeStamp;
uint CodecFlag;
uint Padding;
} MusxHeader <read=Str("MUSX hc=%#010x platform=%c%c%c%c size=%u", Hashcode, Platform[0], Platform[1], Platform[2], Platform[3], FileSize)>;
typedef struct
{
uint Offset <format=hex>;
uint Size <format=hex>;
} MusxEntry <read=Str("offset=%#x size=%#x", Offset, Size)>;
typedef struct
{
uint Hashcode <format=hex>;
uint Offset <format=hex>;
} SfxLookup <read=Str("hc=%#010x offset=%#x", Hashcode, Offset)>;
typedef struct
{
short FileRef;
byte PitchOffset;
ubyte RandomPitchOffset;
byte BaseVolume;
byte RandomVolumeOffset;
byte Pan;
byte RandomPan;
} SfxSample <read=Str("ref=%d pitch=%d rndPitch=%u vol=%d rndVol=%d pan=%d rndPan=%d", FileRef, PitchOffset, RandomPitchOffset, BaseVolume, RandomVolumeOffset, Pan, RandomPan)>;
typedef struct
{
ushort GroupHashCode <format=hex>;
ubyte GroupMaxChannels;
ubyte Padding <format=hex>;
} ExpandedGroupData <read=Str("groupHash=%#06x maxChannels=%u pad=%#02x", GroupHashCode, GroupMaxChannels, Padding)>;
typedef struct
{
ushort Packed <format=hex>;
local uint GroupMaxChannels = Packed & 0x000f;
local uint GroupHashCode = (Packed >> 4) & 0x0fff;
} CompactGroupData <read=Str("groupHash=%#05x maxChannels=%u packed=%#06x", GroupHashCode, GroupMaxChannels, Packed)>;
typedef struct
{
ubyte MaxReject;
ubyte UnPausable;
ubyte IgnoreMasterVolume;
ubyte MultiSample;
ubyte RandomPick;
ubyte Shuffled;
ubyte Looped;
ubyte PolyPhonic;
ubyte UnderWater;
ubyte PauseInstant;
ubyte HasSubSfx;
ubyte StealOnLouder;
ubyte TreatLikeMusic;
ubyte KillMeOwnGroup;
ubyte GroupStealReject;
ubyte OneInstancePerFrame;
} PcSfxFlagBytes <read=Str("%s", GetFlagsText((MaxReject != 0 ? 1 : 0) | (UnPausable != 0 ? 2 : 0) | (IgnoreMasterVolume != 0 ? 4 : 0) | (MultiSample != 0 ? 8 : 0) | (RandomPick != 0 ? 16 : 0) | (Shuffled != 0 ? 32 : 0) | (Looped != 0 ? 64 : 0) | (PolyPhonic != 0 ? 128 : 0) | (UnderWater != 0 ? 256 : 0) | (PauseInstant != 0 ? 512 : 0) | (HasSubSfx != 0 ? 1024 : 0) | (StealOnLouder != 0 ? 2048 : 0) | (TreatLikeMusic != 0 ? 4096 : 0) | (KillMeOwnGroup != 0 ? 8192 : 0) | (GroupStealReject != 0 ? 16384 : 0) | (OneInstancePerFrame != 0 ? 32768 : 0)))>;
typedef struct
{
ubyte UserFlag00;
ubyte UserFlag01;
ubyte UserFlag02;
ubyte UserFlag03;
ubyte UserFlag04;
ubyte UserFlag05;
ubyte UserFlag06;
ubyte UserFlag07;
ubyte UserFlag08;
ubyte UserFlag09;
ubyte UserFlag10;
ubyte UserFlag11;
ubyte UserFlag12;
ubyte UserFlag13;
ubyte UserFlag14;
ubyte UserFlag15;
} PcUserFlagBytes;
typedef struct
{
short DuckerLength;
short MinDelay;
short MaxDelay;
ubyte ReverbSend;
enum <ubyte> TrackingType
{
TT_2D = 0,
TT_Amb = 1,
TT_3D = 2,
TT_3D_Rnd_Pos = 3,
TT_2D_PL2 = 4
} Tracking;
ubyte MaxVoices;
ubyte Priority;
ubyte Ducker;
ubyte MasterVolume;
local ushort FlagsMask = 0;
local uint DisplayGroupHashCode = 0;
local uint DisplayGroupMaxChannels = 0;
if (!isPs2)
{
ExpandedGroupData GroupData <comment="Non-PS2 platforms store a 16-bit group hash code, one-byte group maximum channels value, then one padding/unused byte.">;
PcSfxFlagBytes Flags <comment="Non-PS2 platforms store one byte per SFX flag: 0 = off, 1 = on. Order matches SfxFlags enum.">;
PcUserFlagBytes UserFlags <comment="Non-PS2 platforms store one byte per user flag: 0 = off, 1 = on.">;
DisplayGroupHashCode = GroupData.GroupHashCode;
DisplayGroupMaxChannels = GroupData.GroupMaxChannels;
FlagsMask = (Flags.MaxReject != 0 ? 1 : 0) |
(Flags.UnPausable != 0 ? 2 : 0) |
(Flags.IgnoreMasterVolume != 0 ? 4 : 0) |
(Flags.MultiSample != 0 ? 8 : 0) |
(Flags.RandomPick != 0 ? 16 : 0) |
(Flags.Shuffled != 0 ? 32 : 0) |
(Flags.Looped != 0 ? 64 : 0) |
(Flags.PolyPhonic != 0 ? 128 : 0) |
(Flags.UnderWater != 0 ? 256 : 0) |
(Flags.PauseInstant != 0 ? 512 : 0) |
(Flags.HasSubSfx != 0 ? 1024 : 0) |
(Flags.StealOnLouder != 0 ? 2048 : 0) |
(Flags.TreatLikeMusic != 0 ? 4096 : 0) |
(Flags.KillMeOwnGroup != 0 ? 8192 : 0) |
(Flags.GroupStealReject != 0 ? 16384 : 0) |
(Flags.OneInstancePerFrame != 0 ? 32768 : 0);
}
else
{
CompactGroupData GroupData <comment="PS2 stores the 12-bit group hash code in bits 15-4 and group maximum channels in bits 3-0.">;
ushort Flags <format=hex>;
ushort UserFlags <format=hex>;
DisplayGroupHashCode = (GroupData.Packed >> 4) & 0x0fff;
DisplayGroupMaxChannels = GroupData.GroupMaxChannels;
FlagsMask = Flags;
}
ubyte DopplerValue;
ubyte UserValue;
local string ActiveFlags = GetFlagsText(FlagsMask);
short SampleCount;
SfxSample Samples[SampleCount] <optimize=false>;
} SfxEntry <read=Str("samples=%d tracking=%s group=%#x maxChannels=%u flags=%s doppler=%u userValue=%u", SampleCount, EnumToString(Tracking), DisplayGroupHashCode, DisplayGroupMaxChannels, ActiveFlags, DopplerValue, UserValue), optimize=false>;
typedef struct
{
uint Flags <format=hex>;
uint Address <format=hex>;
uint AlignedDataSize <format=hex>;
uint Frequency;
uint RealDataSize <format=hex>;
uint PsiOffset <format=hex>;
uint LoopOffset <format=hex>;
if (isGc) LittleEndian();
uint DurationMs;
if (isGc) BigEndian();
} SampleInfo <read=Str("freq=%u real=%#x data=%#x duration=%u", Frequency, RealDataSize, Address, DurationMs)>;
typedef struct
{
uint NumSamples;
uint NibblesAdpcm;
uint SampleRate;
ushort LoopFlag;
ushort Format;
uint StartOffset;
uint EndOffset;
uint Unknown;
ushort DecodeCoefficients[16] <format=hex>;
ushort Gain;
ushort Predictor;
ushort SampleHistory1;
ushort SampleHistory2;
ushort PredictorLoop;
ushort SampleHistoryLoop1;
ushort SampleHistoryLoop2;
ushort PaddingSamples[10];
ushort Padding;
} GameCubeSampleHeader <read=Str("rate=%u nibbles=%u loop=%u", SampleRate, NibblesAdpcm, LoopFlag)>;
SetBackColor(cLtPurple);
MusxHeader header;
if (header.Magic != "MUSX")
{
Warning("File is not a valid MUSX file. Template stopped.");
return -1;
}
local int isGc = (header.Platform[0] == 'G' && header.Platform[1] == 'C');
local int isPc = (header.Platform[0] == 'P' && header.Platform[1] == 'C');
local int isPs2 = (header.Platform[0] == 'P' && header.Platform[1] == 'S' && header.Platform[2] == '2' && header.Platform[3] == '_');
if (isGc) BigEndian();
SetBackColor(cGreen);
MusxEntry SfxData;
MusxEntry SampleInfoData;
MusxEntry GameCubeSpecialSampleInfoData;
MusxEntry SampleData;
if (SfxData.Size > 0)
{
FSeek(SfxData.Offset);
SetBackColor(cBlue);
uint SfxCount;
SfxLookup SfxTable[SfxCount] <optimize=false>;
local int i;
for (i = 0; i < SfxCount; i++)
{
FSeek(SfxData.Offset + SfxTable[i].Offset);
SetBackColor(cLtBlue);
SfxEntry Sfx;
}
}
if (SampleInfoData.Size > 0)
{
FSeek(SampleInfoData.Offset);
SetBackColor(cLtGreen);
uint SampleCount;
SampleInfo Samples[SampleCount] <optimize=false>;
}
if (GameCubeSpecialSampleInfoData.Size > 0)
{
FSeek(GameCubeSpecialSampleInfoData.Offset);
SetBackColor(cAqua);
local uint SpecialCount = GameCubeSpecialSampleInfoData.Size / sizeof(GameCubeSampleHeader);
GameCubeSampleHeader GameCubeHeaders[SpecialCount] <optimize=false>;
}
if (SampleData.Size > 0)
{
FSeek(SampleData.Offset);
SetBackColor(cDkRed);
ubyte EncodedSampleData[SampleData.Size];
}