-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobots_sfx_soundbanks.bt
222 lines (185 loc) · 5.47 KB
/
robots_sfx_soundbanks.bt
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
//------------------------------------------------
//--- 010 Editor v11.0.1 Binary Template
//
// File: RobotsSoundBanks.bt
// Authors: jmarti856, Swyter
// Version: 1.0
// Purpose: Parse SFX soundbanks files.
// Category: Audio
// File Mask: *_sb_*.sfx
// ID Bytes: 4D 55 53 58
//------------------------------------------------
//*===============================================================================================
//* DEFINE STRUCTS USED IN THE SFX FILE
//*===============================================================================================
//The first parameters of the header are always little endian
LittleEndian(); local int sfxIsBigEndian = 0;
typedef struct
{
char Magic[4];
uint Hashcode<format=hex>;
uint ConstantOffset<format=hex>;
uint FileSize <format=hex>;
char Platform[4];
uint TimeSpan;
uint unk;
uint structPadding;
if (ReadUInt() != 0x0800) /* For GC */
{
Printf("[i] This is a GameCube SFX. Changing endianness to big-endian.");
BigEndian(); sfxIsBigEndian = 1;
}
} CommonHeader <read=Str("soundbank hc: %#010x, magic: %s, platform: %s", Hashcode, Magic, Platform)>;
//*===============================================================================================
//* READ FILE
//*===============================================================================================
// Define the headers
SetBackColor(cLtPurple);
CommonHeader header;
// Check for valid header
if(header.Magic != "MUSX")
{
Warning( "File is not a valid SFX file. Template stopped." );
return -1;
}
// Read Soundbanks Header
SetBackColor(cGreen);
struct SoundBanksHeader
{
uint SFXStart <format=hex>;
uint SFXLength;
uint SampleInfoStart <format=hex>;
uint SampleInfoLength;
uint SpecialSampleInfoStart <format=hex>;
uint SpecialSampleInfoLength;
uint SampleDataStart <format=hex>;
uint SampleDataLength;
} SBHeader;
//Go to SFXStart pos
if (FSeek( SBHeader.SFXStart ) < 0)
{
Warning( "Error searching the SFX start position");
return -1;
}
//Get the number of stored sounds in this section
uint totalSounds;
SetBackColor(cBlue);
struct SoundsArray
{
uint HashCode <format=hex>;
uint Location <format=hex>;
} StoredSound[totalSounds] <read=Str("hc: %#010x | loc: %#010x", HashCode, Location)>;
//Read SFX Array & SFX Params
local int index = 0;
local long currentPos = 0;
typedef struct
{
SetBackColor(cDkRed);
short DuckerLength; SetBackColor(cRed);
short MinDelay;
short MaxDelay;
ubyte ReverbSend;
enum<ubyte> TTyp {TT_2D, TT_Amb, TT_3D, TT_3D_Rnd_Pos, TT_2D_PL2};
TTyp TrackingType;
ubyte MaxVoices;
ubyte Priority;
ubyte Ducker;
ubyte MasterVolume;
union
{
short Data <format=hex>;
struct
{
short GroupHashCode : 8 <format=hex>;
short GroupMaxChannels : 8 <format=hex>;
} Split;
} Group;
short Flags;
short UserFlags;
ubyte DopplerValue;
ubyte UserValue;
short SamplesCount;
typedef struct
{
SetBackColor(cLtBlue);
short FileRef; SetBackColor(cAqua);
ubyte PitchOffset;
ubyte RandomPitchOffset;
ubyte BaseVolume;
ubyte RandomVolumeOffset;
ubyte Pan;
ubyte RandomPan;
} Samples <read=Str(" [-] fileref: %i, pitch: %u/%u, bvol: %u/%u, pan: %u/%u", FileRef, PitchOffset, RandomPitchOffset, BaseVolume, RandomVolumeOffset, Pan, RandomPan), optimize=false>;
local int j = 0;
for (j=0; j<SamplesCount; j++) /* swy: avoid optimizations, so that each sample gets its own line */
Samples smpParam;
local uint idx = index;
} Sounds <read=Str("hc: %#010x | sampl: %u, group: %x; %x %x (%s)", StoredSound[idx].HashCode, SamplesCount, Group.Data, Group.Split.GroupHashCode, Group.Split.GroupMaxChannels, EnumToString(TrackingType)), optimize=false>;
for (index = 0; index < totalSounds; index++)
{
FSeek(StoredSound[index].Location + SBHeader.SFXStart);
Sounds sfxParams;
}
//Read Sample Info Section
if (FSeek( SBHeader.SampleInfoStart ) < 0)
{
Warning( "Error searching the sample info start position");
return -1;
}
//Get the number of stored samples in this section
uint totalSamples;
typedef struct
{
SetBackColor(cLtGreen);
uint Flags;
uint Address <format=hex>;
uint AudioDataSize <format=hex>;
uint Frequency;
uint RealSize <format=hex>;
uint PSI;
uint LoopOffset;
uint Duration;
/* -- */
currentPos = FTell(); FSeek(SBHeader.SampleDataStart + Address);
SetBackColor(cDkRed);
ubyte audioData[RealSize];
FSeek(currentPos);
} SampleInfo <optimize=false, read=Str("[/] freq: %u | durat: %u, offset: %x", Frequency, Duration, Address)>;
//Read samples params
for (index = 0; index < totalSamples; index++)
SampleInfo sampleInfoParams;
//Read Special Sample Info Section
typedef struct
{
SetBackColor(cLtGreen);
/* swy: this stored the GameCube-specific playback metadata; not needed for other platforms */
uint NumSamples;
uint NibblesADPCM;
uint SampleRate;
ushort LoopFlag;
ushort Format;
uint StartOffset;
uint EndOffset;
uint unk;
ushort DecodeCoefficients[16]<format=hex>;
ushort Gain;
ushort Predictor;
ushort SampleHistory;
ushort SampleHistory2;
ushort PredictorLoop;
ushort SampleHistoryLoop;
ushort SampleHistoryLoop2;
ushort PaddingSamples[10];
ushort padding;
} SpecialSample;
if (SBHeader.SampleInfoStart != SBHeader.SpecialSampleInfoStart)
{
if (FSeek(SBHeader.SpecialSampleInfoStart ) < 0)
{
Warning( "Error searching the special sample info start position");
return -1;
}
local int totalSpecialSamples = SBHeader.SpecialSampleInfoLength / sizeof(SpecialSample);
for (index = 0; index < totalSpecialSamples; index++)
SpecialSample specialInfo;
}