-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspyro_sfx_streamdata.bt
More file actions
149 lines (120 loc) · 4.49 KB
/
spyro_sfx_streamdata.bt
File metadata and controls
149 lines (120 loc) · 4.49 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
//------------------------------------------------
//--- 010 Editor v11.0.1 Binary Template
//
// File: SpyroStreamSounds.bt
// Authors: jmarti856, Swyter
// Version: 1.0
// Purpose: Parse SFX Streambanks files.
// Category: Audio
// File Mask: *__streamdata.sfx
// ID Bytes: 4D 55 53 58
//------------------------------------------------
//*===============================================================================================
//* Typedefs for the sfx file
//*===============================================================================================
typedef char ID[4];
typedef char Padding[2];
//*===============================================================================================
//* DEFINE STRUCTS USED IN THE SFX FILE
//*===============================================================================================
//The first parameters of the header ara always little endian
LittleEndian(); local int sfxIsBigEndian = 0;
typedef struct
{
ID Magic;
uint Hashcode <format=hex>;
uint FileVersion;
uint FileSize <format=hex>;
ID Platform;
uint TimeStamp;
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;
typedef struct
{
uint FileStart1 <format=hex>;
uint FileStart1Length <format=hex>;
uint FileStart2 <format=hex>;
uint FileStart2Length <format=hex>;
uint FileStart3 <format=hex>;
uint FileStart3Length <format=hex>;
} StreamBanksHeader;
//*===============================================================================================
//* 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 Streambanks Header
SetBackColor(cGreen);
StreamBanksHeader SBHeader;
//Go to FileStart1 pos
if (FSeek(SBHeader.FileStart1) < 0)
{
Warning( "Error searching the SFX file start 1 position");
return -1;
}
typedef uint SBLookUpTable <format=hex>;
local uint totalSounds = SBHeader.FileStart1Length / sizeof(SBLookUpTable);
local uint index = 0;
SetBackColor(cBlue);
SBLookUpTable offsets[totalSounds];
for (index = 0; index < totalSounds; index++)
{
/* swy: use the lookup table for the current index to compute
an absolute offset to the right place */
FSeek(SBHeader.FileStart2 + offsets[index]);
typedef struct
{
uint MarkerSize <format=hex>;
uint AudioOffset <format=hex>;
uint AudioSize <format=hex>;
/* swy: the following two offsets are relative to this point; the offsets are technically
not needed, as long as we know the structure sizes and count, because they
are always continuously stored, right afterwards */
uint StartMarkerCount;
uint MarkerCount;
uint StartMarkerOffset <format=hex>;
uint MarkerOffset <format=hex>;
uint BaseVolume;
enum<uint> MTyp { Start = 10, End = 9, Goto = 7, Loop = 6, Pause = 5, Jump = 0 };
typedef struct
{
int Name;
uint Position;
MTyp MarkerType;
uint LoopStart;
uint LoopMarkerCount;
/* -- */
uint MarkerPosition;
} StartMarker;
SetBackColor(cAqua); FSeek(startof(StartMarkerCount) + StartMarkerOffset);
StartMarker StartMarkers[StartMarkerCount];
typedef struct
{
int Name;
uint Position;
MTyp MarkerType;
uint LoopStart;
uint LoopMarkerCount;
} Marker;
SetBackColor(cLtGreen); FSeek(startof(StartMarkerCount) + MarkerOffset);
Marker Markers[MarkerCount];
/* swy: the audio data is far away; get there via offset, store as part of our SFX struct and go back */
FSeek(SBHeader.FileStart2 + AudioOffset); SetBackColor(cDkRed); ubyte AudioData[AudioSize];
local uint cur_index = index; /* swy: save a local copy of the current state of the for loop for future reference and creating the printf-style string */
} StreamedSound <read=Str("[%i] startmarkers: %u, markers: %u, bufsize: %#x", cur_index*-1-1, StartMarkerCount, MarkerCount, AudioSize), optimize=false>;
SetBackColor(cLtRed);
StreamedSound stream;
}