Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Audio/Legacy/AudioLegacy.cpp
1168 views
1
2
3
int32 RSDK::Legacy::globalSFXCount = 0;
4
int32 RSDK::Legacy::stageSFXCount = 0;
5
6
int32 RSDK::Legacy::musicVolume = 0;
7
int32 RSDK::Legacy::sfxVolume = 0;
8
int32 RSDK::Legacy::bgmVolume = 0;
9
int32 RSDK::Legacy::musicCurrentTrack = 0;
10
int32 RSDK::Legacy::musicChannel = 0;
11
12
float RSDK::Legacy::v4::musicRatio = 0.0f;
13
14
RSDK::Legacy::TrackInfo RSDK::Legacy::musicTracks[LEGACY_TRACK_COUNT];
15
16
char RSDK::Legacy::v4::sfxNames[SFX_COUNT][0x40];
17
18
void RSDK::Legacy::SetMusicTrack(const char *filePath, uint8 trackID, bool32 loop, uint32 loopPoint)
19
{
20
TrackInfo *track = &musicTracks[trackID & 0xF];
21
22
// StrCopy(track->fileName, "Data/Music/");
23
// StrAdd(track->fileName, filePath);
24
StrCopy(track->fileName, filePath);
25
track->trackLoop = loop;
26
track->loopPoint = loopPoint;
27
}
28
29
int32 RSDK::Legacy::PlayMusic(int32 trackID)
30
{
31
TrackInfo *track = &musicTracks[trackID & 0xF];
32
33
if (!track->fileName[0]) {
34
StopChannel(musicChannel);
35
}
36
else {
37
uint32 startPos = 0;
38
if (RSDK::Legacy::v4::musicRatio) {
39
startPos = (uint32)(GetChannelPos(musicChannel) * RSDK::Legacy::v4::musicRatio);
40
RSDK::Legacy::v4::musicRatio = 0.0;
41
}
42
43
int32 loopPoint = track->loopPoint;
44
if (!loopPoint && track->trackLoop)
45
loopPoint = 1;
46
47
musicCurrentTrack = trackID;
48
musicChannel = PlayStream(track->fileName, musicChannel, startPos, loopPoint, true);
49
musicVolume = 100;
50
}
51
52
return musicChannel;
53
}
54
55
void RSDK::Legacy::SetMusicVolume(int32 volume)
56
{
57
musicVolume = CLAMP(volume, 0, 100);
58
SetChannelAttributes(musicChannel, musicVolume * 0.01f, 0.f, 1.f);
59
}
60
61
void RSDK::Legacy::v4::SwapMusicTrack(const char *filePath, uint8 trackID, uint32 loopPoint, uint32 ratio)
62
{
63
TrackInfo *track = &musicTracks[trackID & 0xF];
64
65
if (StrLength(filePath) <= 0) {
66
StopChannel(musicChannel);
67
}
68
else {
69
// StrCopy(track->fileName, "Data/Music/");
70
// StrAdd(track->fileName, filePath);
71
StrCopy(track->fileName, filePath);
72
track->trackLoop = true;
73
track->loopPoint = loopPoint;
74
musicRatio = ratio / 10000.0f;
75
76
PlayMusic(trackID);
77
}
78
}
79
80
void RSDK::Legacy::LoadSfx(char *filename, uint8 slot, uint8 scope)
81
{
82
if (sfxList[slot].scope == SCOPE_NONE)
83
LoadSfxToSlot(filename, slot, 1, scope);
84
}
85
86
void RSDK::Legacy::v3::SetSfxAttributes(int32 channelID, int32 loop, int8 pan)
87
{
88
if (channelID < 0 || channelID >= CHANNEL_COUNT)
89
return;
90
91
if (channels[channelID].state == CHANNEL_SFX) {
92
RSDK::SetChannelAttributes(channelID, 1.0, pan / 100.0f, 1.0);
93
if (loop != -1)
94
channels[channelID].loop = loop ? 0 : -1;
95
}
96
}
97
98
void RSDK::Legacy::v4::SetSfxName(const char *sfxName, int32 sfxID)
99
{
100
int32 sfxNameID = 0;
101
int32 soundNameID = 0;
102
while (sfxName[sfxNameID]) {
103
if (sfxName[sfxNameID] != ' ')
104
sfxNames[sfxID][soundNameID++] = sfxName[sfxNameID];
105
++sfxNameID;
106
}
107
sfxNames[sfxID][soundNameID] = 0;
108
109
PrintLog(PRINT_NORMAL, "Set SFX (%d) name to: %s", sfxID, sfxName);
110
}
111
112
void RSDK::Legacy::v4::SetSfxAttributes(int32 sfxID, int32 loop, int8 pan)
113
{
114
for (int32 c = 0; c < CHANNEL_COUNT; ++c) {
115
if (channels[c].soundID == sfxID && channels[c].state == CHANNEL_SFX) {
116
RSDK::SetChannelAttributes(c, 1.0, pan / 100.0f, 1.0);
117
if (loop != -1)
118
channels[c].loop = loop ? 0 : -1;
119
}
120
}
121
}
122
123
#if RETRO_USE_MOD_LOADER
124
char RSDK::Legacy::v3::globalSfxNames[SFX_COUNT][0x40];
125
char RSDK::Legacy::v3::stageSfxNames[SFX_COUNT][0x40];
126
127
void RSDK::Legacy::v3::SetSfxName(const char *sfxName, int32 sfxID, bool32 global)
128
{
129
char *sfxNamePtr = global ? globalSfxNames[sfxID] : stageSfxNames[sfxID];
130
131
int32 sfxNamePos = 0;
132
int32 sfxPtrPos = 0;
133
uint8 mode = 0;
134
while (sfxName[sfxNamePos]) {
135
if (sfxName[sfxNamePos] == '.' && mode == 1)
136
mode = 2;
137
else if ((sfxName[sfxNamePos] == '/' || sfxName[sfxNamePos] == '\\') && !mode)
138
mode = 1;
139
else if (sfxName[sfxNamePos] != ' ' && mode == 1)
140
sfxNamePtr[sfxPtrPos++] = sfxName[sfxNamePos];
141
++sfxNamePos;
142
}
143
sfxNamePtr[sfxPtrPos] = 0;
144
PrintLog(PRINT_NORMAL, "Set %s SFX (%d) name to: %s", (global ? "Global" : "Stage"), sfxID, sfxNamePtr);
145
}
146
#endif
147