Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
sound.c
Go to the documentation of this file.
1#include "engine/game.h"
2#include "libsnd.h"
3
4/* Each bank's files (SOUND_BANK_FILES[id]), numbered in the Japanese disc as
5 in the USA one */
6#if VERSION_US || VERSION_JP
7SoundFiles SOUND_FILES_01 = {370, 357, 0x1650000, 0x1720000, {0x1650001, 0x1650002, 0}};
8SoundFiles SOUND_FILES_02 = {361, 348, 0x15C0000, 0x1690000, {0x15C0001, 0}};
9SoundFiles SOUND_FILES_03 = {1122, 1120, 0x4600000, 0x4620000, {0x4600001, 0}};
10SoundFiles SOUND_FILES_04 = {362, 349, 0x15D0000, 0x16A0000, {0x15D0001, 0}};
11SoundFiles SOUND_FILES_05 = {363, 350, 0x15E0000, 0x16B0000, {0x15E0001, 0}};
12SoundFiles SOUND_FILES_06 = {514, 512, 0x2000000, 0x2020000, {0x2000001, 0}};
13SoundFiles SOUND_FILES_07 = {364, 351, 0x15F0000, 0x16C0000, {0x15F0001, 0}};
14SoundFiles SOUND_FILES_08 = {365, 352, 0x1600000, 0x16D0000, {0x1600001, 0}};
15SoundFiles SOUND_FILES_09 = {366, 353, 0x1610000, 0x16E0000, {0x1610001, 0}};
16SoundFiles SOUND_FILES_0A = {522, 519, 0x2070000, 0x20A0000, {0x2070001, 0}};
17SoundFiles SOUND_FILES_0B = {367, 354, 0x1620000, 0x16F0000, {0x1620001, 0}};
18SoundFiles SOUND_FILES_0C = {368, 355, 0x1630000, 0x1700000, {0x1630001, 0}};
19SoundFiles SOUND_FILES_0D = {540, 534, 0x2160000, 0x21C0000, {0x2160001, 0}};
20SoundFiles SOUND_FILES_0E = {553, 552, 0x2280000, 0x2290000, {0x2280001, 0}};
21SoundFiles SOUND_FILES_0F = {563, 562, 0x2320000, 0x2330000, {0x2320001, 0}};
22SoundFiles SOUND_FILES_10 = {568, 567, 0x2370000, 0x2380000, {0x2370001, 0}};
23SoundFiles SOUND_FILES_11 = {588, 587, 0x24B0000, 0x24C0000, {0x24B0001, 0}};
24SoundFiles SOUND_FILES_12 = {594, 593, 0x2510000, 0x2520000, {0x2510001, 0}};
25SoundFiles SOUND_FILES_13 = {650, 649, 0x2890000, 0x28A0000, {0x2890001, 0}};
26SoundFiles SOUND_FILES_14 = {613, 612, 0x2640000, 0x2650000, {0x2640001, 0}};
27SoundFiles SOUND_FILES_15 = {701, 697, 0x2B90000, 0x2BD0000, {0x2B90001, 0}};
28SoundFiles SOUND_FILES_16 = {517, 516, 0x2040000, 0x2050000, {0x2040001, 0}};
29SoundFiles SOUND_FILES_17 = {805, 804, 0x3240000, 0x3250000, {0x3240001, 0}};
30SoundFiles SOUND_FILES_18 = {541, 536, 0x2180000, 0x21D0000, {0x2180001, 0}};
31SoundFiles SOUND_FILES_19 = {702, 698, 0x2BA0000, 0x2BE0000, {0x2BA0001, 0}};
32SoundFiles SOUND_FILES_1A = {703, 699, 0x2BB0000, 0x2BF0000, {0x2BB0001, 0}};
33SoundFiles SOUND_FILES_1B = {369, 356, 0x1640000, 0x1710000, {0x1640001, 0}};
34SoundFiles SOUND_FILES_1C = {1064, 1062, 0x4260000, 0x4280000, {0x4260001, 0}};
35SoundFiles SOUND_FILES_1D = {621, 620, 0x26C0000, 0x26D0000, {0x26C0001, 0}};
36SoundFiles SOUND_FILES_1E = {704, 700, 0x2BC0000, 0x2C00000, {0x2BC0001, 0}};
37SoundFiles SOUND_FILES_1F = {515, 513, 0x2010000, 0x2030000, {0x2010001, 0}};
38SoundFiles SOUND_FILES_20 = {500, 498, 0x1F20000, 0x1F40000, {0x1F20001, 0}};
39SoundFiles SOUND_FILES_21 = {720, 719, 0x2CF0000, 0x2D00000, {0x2CF0001, 0}};
40SoundFiles SOUND_FILES_22 = {542, 537, 0x2190000, 0x21E0000, {0x2190001, 0}};
41SoundFiles SOUND_FILES_23 = {1123, 1121, 0x4610000, 0x4630000, {0x4610001, 0}};
42SoundFiles SOUND_FILES_24 = {1360, 1359, 0x54F0000, 0x5500000, {0x54F0001, 0}};
43SoundFiles SOUND_FILES_25 = {1979, 1949, 0x79D0000, 0x7BB0000, {0x79D0001, 0}};
44SoundFiles SOUND_FILES_26 = {1980, 1976, 0x7B80000, 0x7BC0000, {0x7B80001, 0}};
45SoundFiles SOUND_FILES_27 = {1100, 1099, 0x44B0000, 0x44C0000, {0x44B0001, 0}};
46SoundFiles SOUND_FILES_28 = {1211, 1210, 0x4BA0000, 0x4BB0000, {0x4BA0001, 0}};
47SoundFiles SOUND_FILES_29 = {371, 358, 0x1660000, 0x1730000, {0x1660001, 0}};
48SoundFiles SOUND_FILES_2A = {849, 847, 0x34F0000, 0x3510000, {0x34F0001, 0}};
49SoundFiles SOUND_FILES_2B = {850, 848, 0x3500000, 0x3520000, {0x3500001, 0}};
50SoundFiles SOUND_FILES_2C = {543, 538, 0x21A0000, 0x21F0000, {0x21A0001, 0}};
51SoundFiles SOUND_FILES_2D = {372, 359, 0x1670000, 0x1740000, {0x1670001, 0}};
52SoundFiles SOUND_FILES_2E = {881, 879, 0x36F0000, 0x3710000, {0x36F0001, 0}};
53SoundFiles SOUND_FILES_2F = {882, 880, 0x3700000, 0x3720000, {0x3700001, 0}};
54SoundFiles SOUND_FILES_30 = {927, 922, 0x39A0000, 0x39F0000, {0x39A0001, 0}};
55SoundFiles SOUND_FILES_31 = {928, 923, 0x39B0000, 0x3A00000, {0x39B0001, 0}};
56SoundFiles SOUND_FILES_32 = {373, 360, 0x1680000, 0x1750000, {0x1680001, 0}};
57SoundFiles SOUND_FILES_33 = {501, 499, 0x1F30000, 0x1F50000, {0x1F30001, 0}};
58SoundFiles SOUND_FILES_34 = {929, 924, 0x39C0000, 0x3A10000, {0x39C0001, 0}};
59SoundFiles SOUND_FILES_35 = {930, 925, 0x39D0000, 0x3A20000, {0x39D0001, 0}};
60SoundFiles SOUND_FILES_36 = {931, 926, 0x39E0000, 0x3A30000, {0x39E0001, 0}};
61SoundFiles SOUND_FILES_37 = {942, 939, 0x3AB0000, 0x3AE0000, {0x3AB0001, 0}};
62SoundFiles SOUND_FILES_38 = {943, 940, 0x3AC0000, 0x3AF0000, {0x3AC0001, 0}};
63SoundFiles SOUND_FILES_39 = {944, 941, 0x3AD0000, 0x3B00000, {0x3AD0001, 0}};
64SoundFiles SOUND_FILES_3A = {998, 992, 0x3E00000, 0x3E60000, {0x3E00001, 0}};
65SoundFiles SOUND_FILES_3B = {999, 993, 0x3E10000, 0x3E70000, {0x3E10001, 0}};
66SoundFiles SOUND_FILES_3C = {1000, 994, 0x3E20000, 0x3E80000, {0x3E20001, 0}};
67SoundFiles SOUND_FILES_3D = {1001, 995, 0x3E30000, 0x3E90000, {0x3E30001, 0}};
68SoundFiles SOUND_FILES_3E = {1002, 996, 0x3E40000, 0x3EA0000, {0x3E40001, 0}};
69SoundFiles SOUND_FILES_3F = {1003, 997, 0x3E50000, 0x3EB0000, {0x3E50001, 0}};
70SoundFiles SOUND_FILES_40 = {1065, 1063, 0x4270000, 0x4290000, {0x4270001, 0}};
71SoundFiles SOUND_FILES_41 = {1578, 1577, 0x6290000, 0x62A0000, {0x6290001, 0}};
72SoundFiles SOUND_FILES_42 = {544, 539, 0x21B0000, 0x2200000, {0x21B0001, 0}};
73SoundFiles SOUND_FILES_43 = {1939, 1938, 0x7920000, 0x7930000, {0x7920001, 0}};
74SoundFiles SOUND_FILES_44 = {2087, 2086, 0x8260000, 0x8270000, {0x8260001, 0}};
75SoundFiles SOUND_FILES_45 = {1826, 1824, 0x7200000, 0x7220000, {0x7200001, 0}};
76SoundFiles SOUND_FILES_46 = {1827, 1825, 0x7210000, 0x7230000, {0x7210001, 0}};
77SoundFiles SOUND_FILES_47 = {2186, 2185, 0x8890001, 0x88A0000, {0x8890000, 0}};
78#elif VERSION_EU
79SoundFiles SOUND_FILES_01 = {384, 371, 0x1730000, 0x1800000, {0x1730001, 0x1730002, 0}};
80SoundFiles SOUND_FILES_02 = {375, 362, 0x16A0000, 0x1770000, {0x16A0001, 0}};
81SoundFiles SOUND_FILES_03 = {1138, 1136, 0x4700000, 0x4720000, {0x4700001, 0}};
82SoundFiles SOUND_FILES_04 = {376, 363, 0x16B0000, 0x1780000, {0x16B0001, 0}};
83SoundFiles SOUND_FILES_05 = {377, 364, 0x16C0000, 0x1790000, {0x16C0001, 0}};
84SoundFiles SOUND_FILES_06 = {529, 527, 0x20F0000, 0x2110000, {0x20F0001, 0}};
85SoundFiles SOUND_FILES_07 = {378, 365, 0x16D0000, 0x17A0000, {0x16D0001, 0}};
86SoundFiles SOUND_FILES_08 = {379, 366, 0x16E0000, 0x17B0000, {0x16E0001, 0}};
87SoundFiles SOUND_FILES_09 = {380, 367, 0x16F0000, 0x17C0000, {0x16F0001, 0}};
88SoundFiles SOUND_FILES_0A = {537, 534, 0x2160000, 0x2190000, {0x2160001, 0}};
89SoundFiles SOUND_FILES_0B = {381, 368, 0x1700000, 0x17D0000, {0x1700001, 0}};
90SoundFiles SOUND_FILES_0C = {382, 369, 0x1710000, 0x17E0000, {0x1710001, 0}};
91SoundFiles SOUND_FILES_0D = {555, 549, 0x2250000, 0x22B0000, {0x2250001, 0}};
92SoundFiles SOUND_FILES_0E = {568, 567, 0x2370000, 0x2380000, {0x2370001, 0}};
93SoundFiles SOUND_FILES_0F = {578, 577, 0x2410000, 0x2420000, {0x2410001, 0}};
94SoundFiles SOUND_FILES_10 = {583, 582, 0x2460000, 0x2470000, {0x2460001, 0}};
95SoundFiles SOUND_FILES_11 = {603, 602, 0x25A0000, 0x25B0000, {0x25A0001, 0}};
96SoundFiles SOUND_FILES_12 = {609, 608, 0x2600000, 0x2610000, {0x2600001, 0}};
97SoundFiles SOUND_FILES_13 = {665, 664, 0x2980000, 0x2990000, {0x2980001, 0}};
98SoundFiles SOUND_FILES_14 = {628, 627, 0x2730000, 0x2740000, {0x2730001, 0}};
99SoundFiles SOUND_FILES_15 = {716, 712, 0x2C80000, 0x2CC0000, {0x2C80001, 0}};
100SoundFiles SOUND_FILES_16 = {532, 531, 0x2130000, 0x2140000, {0x2130001, 0}};
101SoundFiles SOUND_FILES_17 = {820, 819, 0x3330000, 0x3340000, {0x3330001, 0}};
102SoundFiles SOUND_FILES_18 = {556, 551, 0x2270000, 0x22C0000, {0x2270001, 0}};
103SoundFiles SOUND_FILES_19 = {717, 713, 0x2C90000, 0x2CD0000, {0x2C90001, 0}};
104SoundFiles SOUND_FILES_1A = {718, 714, 0x2CA0000, 0x2CE0000, {0x2CA0001, 0}};
105SoundFiles SOUND_FILES_1B = {383, 370, 0x1720000, 0x17F0000, {0x1720001, 0}};
106SoundFiles SOUND_FILES_1C = {1080, 1078, 0x4360000, 0x4380000, {0x4360001, 0}};
107SoundFiles SOUND_FILES_1D = {636, 635, 0x27B0000, 0x27C0000, {0x27B0001, 0}};
108SoundFiles SOUND_FILES_1E = {719, 715, 0x2CB0000, 0x2CF0000, {0x2CB0001, 0}};
109SoundFiles SOUND_FILES_1F = {530, 528, 0x2100000, 0x2120000, {0x2100001, 0}};
110SoundFiles SOUND_FILES_20 = {515, 513, 0x2010000, 0x2030000, {0x2010001, 0}};
111SoundFiles SOUND_FILES_21 = {735, 734, 0x2DE0000, 0x2DF0000, {0x2DE0001, 0}};
112SoundFiles SOUND_FILES_22 = {557, 552, 0x2280000, 0x22D0000, {0x2280001, 0}};
113SoundFiles SOUND_FILES_23 = {1139, 1137, 0x4710000, 0x4730000, {0x4710001, 0}};
114SoundFiles SOUND_FILES_24 = {1376, 1375, 0x55F0000, 0x5600000, {0x55F0001, 0}};
115SoundFiles SOUND_FILES_25 = {1994, 1964, 0x7AC0000, 0x7CA0000, {0x7AC0001, 0}};
116SoundFiles SOUND_FILES_26 = {1995, 1991, 0x7C70000, 0x7CB0000, {0x7C70001, 0}};
117SoundFiles SOUND_FILES_27 = {1116, 1115, 0x45B0000, 0x45C0000, {0x45B0001, 0}};
118SoundFiles SOUND_FILES_28 = {1227, 1226, 0x4CA0000, 0x4CB0000, {0x4CA0001, 0}};
119SoundFiles SOUND_FILES_29 = {385, 372, 0x1740000, 0x1810000, {0x1740001, 0}};
120SoundFiles SOUND_FILES_2A = {864, 862, 0x35E0000, 0x3600000, {0x35E0001, 0}};
121SoundFiles SOUND_FILES_2B = {865, 863, 0x35F0000, 0x3610000, {0x35F0001, 0}};
122SoundFiles SOUND_FILES_2C = {558, 553, 0x2290000, 0x22E0000, {0x2290001, 0}};
123SoundFiles SOUND_FILES_2D = {386, 373, 0x1750000, 0x1820000, {0x1750001, 0}};
124SoundFiles SOUND_FILES_2E = {897, 895, 0x37F0000, 0x3810000, {0x37F0001, 0}};
125SoundFiles SOUND_FILES_2F = {898, 896, 0x3800000, 0x3820000, {0x3800001, 0}};
126SoundFiles SOUND_FILES_30 = {943, 938, 0x3AA0000, 0x3AF0000, {0x3AA0001, 0}};
127SoundFiles SOUND_FILES_31 = {944, 939, 0x3AB0000, 0x3B00000, {0x3AB0001, 0}};
128SoundFiles SOUND_FILES_32 = {387, 374, 0x1760000, 0x1830000, {0x1760001, 0}};
129SoundFiles SOUND_FILES_33 = {516, 514, 0x2020000, 0x2040000, {0x2020001, 0}};
130SoundFiles SOUND_FILES_34 = {945, 940, 0x3AC0000, 0x3B10000, {0x3AC0001, 0}};
131SoundFiles SOUND_FILES_35 = {946, 941, 0x3AD0000, 0x3B20000, {0x3AD0001, 0}};
132SoundFiles SOUND_FILES_36 = {947, 942, 0x3AE0000, 0x3B30000, {0x3AE0001, 0}};
133SoundFiles SOUND_FILES_37 = {958, 955, 0x3BB0000, 0x3BE0000, {0x3BB0001, 0}};
134SoundFiles SOUND_FILES_38 = {959, 956, 0x3BC0000, 0x3BF0000, {0x3BC0001, 0}};
135SoundFiles SOUND_FILES_39 = {960, 957, 0x3BD0000, 0x3C00000, {0x3BD0001, 0}};
136SoundFiles SOUND_FILES_3A = {1014, 1008, 0x3F00000, 0x3F60000, {0x3F00001, 0}};
137SoundFiles SOUND_FILES_3B = {1015, 1009, 0x3F10000, 0x3F70000, {0x3F10001, 0}};
138SoundFiles SOUND_FILES_3C = {1016, 1010, 0x3F20000, 0x3F80000, {0x3F20001, 0}};
139SoundFiles SOUND_FILES_3D = {1017, 1011, 0x3F30000, 0x3F90000, {0x3F30001, 0}};
140SoundFiles SOUND_FILES_3E = {1018, 1012, 0x3F40000, 0x3FA0000, {0x3F40001, 0}};
141SoundFiles SOUND_FILES_3F = {1019, 1013, 0x3F50000, 0x3FB0000, {0x3F50001, 0}};
142SoundFiles SOUND_FILES_40 = {1081, 1079, 0x4370000, 0x4390000, {0x4370001, 0}};
143SoundFiles SOUND_FILES_41 = {1594, 1593, 0x6390000, 0x63A0000, {0x6390001, 0}};
144SoundFiles SOUND_FILES_42 = {559, 554, 0x22A0000, 0x22F0000, {0x22A0001, 0}};
145SoundFiles SOUND_FILES_43 = {1954, 1953, 0x7A10000, 0x7A20000, {0x7A10001, 0}};
146SoundFiles SOUND_FILES_44 = {2104, 2103, 0x8370000, 0x8380000, {0x8370001, 0}};
147SoundFiles SOUND_FILES_45 = {1842, 1840, 0x7300000, 0x7320000, {0x7300001, 0}};
148SoundFiles SOUND_FILES_46 = {1843, 1841, 0x7310000, 0x7330000, {0x7310001, 0}};
149SoundFiles SOUND_FILES_47 = {2203, 2202, 0x89A0001, 0x89B0000, {0x89A0000, 0}};
150#endif
151
152/* The banks by id: bits 18-24 of a sound id */
168
169/* Each slot's buffer for the VAB header and the SEPs, in this unit's .bss (see the Makefile) */
173
174/* Each slot's buffer, and its SPU address */
176s32 SOUND_SPU_ADDRS[SOUND_SLOT_COUNT] = {0x1010, 0x49C10, 0x62410};
177
178/* rsin and rcos (libgte) read rsin_tbl[a - 0x800] and the like: their
179 addresses before the table fall in seqTable */
181 {0},
182 {{0}},
183 0,
184 0,
185 {NULL},
186 initSound,
187 playSound,
195 stopSound,
197};
198
199/* The slot (0-2) that holds bank `id`, or -1 */
201 s32 i;
202
203 for (i = 0; i < SOUND_SLOT_COUNT; i++) {
204 if (SOUND.banks[i].id == id) {
205 return i;
206 }
207 }
208 return -1;
209}
210
211/* Plays a packed sound id (see engine/sound.h); returns the voice of a key-on */
212short playSound(s32 packed) {
213 s32 id = SOUND_BANK(packed);
214 u32 keyOn = SOUND_IS_KEY_ON(packed);
215 s32 exclusive = SOUND_IS_EXCLUSIVE(packed);
216 s32 prog = SOUND_PROG(packed);
217 s32 tone = SOUND_TONE(packed);
218 s32 note = SOUND_NOTE(packed);
219 s32 seq = SOUND_SEQ(packed);
220 s32 sep = SOUND_SEP(packed);
221 s32 slot = findSoundBank(id);
222 s32 voice = -1;
223
224 if (slot != -1) {
225 if (slot != 0) {
226 SOUND.lastSlot = slot;
227 }
228 if (exclusive) {
229 if (SOUND.music == packed) {
230 return 0;
231 }
232 if (SOUND.music != 0) {
234 }
235 SOUND.music = packed;
236 }
237 if (keyOn) {
238 voice = SsUtKeyOn(SOUND.banks[slot].vabId, prog, tone, note, 0, SOUND_VOLUME_MAX, SOUND_VOLUME_MAX);
239 } else {
240 id = sep;
241 SsSepStop(SOUND.banks[slot].seqs[seq], id);
242 SsSepSetVol(SOUND.banks[slot].seqs[seq], id, SOUND_VOLUME_MAX, SOUND_VOLUME_MAX);
243 SsSepPlay(SOUND.banks[slot].seqs[seq], id, 1, 1);
244 }
245 return voice;
246 }
247 return 0;
248}
249
250/* Stops every track of the loaded banks and every voice */
251void stopAllSounds(void) {
252 s32 i;
253 s32 j;
254 s32 k;
255 SoundBank *bank;
256
257 for (i = 0; i < SOUND_SLOT_COUNT; i++) {
258 bank = &SOUND.banks[i];
259 if (bank->vabId != -1) {
260 for (j = 0; j < bank->numSeqs; j++) {
261 for (k = 0; k < SOUND_SEP_COUNT; k++) {
262 SsSepStop(bank->seqs[j], k);
263 }
264 }
265 }
266 }
267 SsUtAllKeyOff(0);
268 SOUND.music = 0;
269}
270
271/* Stops a sequence sound (key-on sounds are left alone) */
272void stopSound(s32 packed) {
273 s32 id = SOUND_BANK(packed);
274 u32 keyOn = SOUND_IS_KEY_ON(packed);
275 s32 seq = SOUND_SEQ(packed);
276 s32 sep = SOUND_SEP(packed);
277 s32 slot = findSoundBank(id);
278
279 if (slot != -1 && !keyOn) {
280 SsSepStop(SOUND.banks[slot].seqs[seq], sep);
281 if (SOUND.music == packed) {
282 SOUND.music = 0;
283 }
284 }
285}
286
287/* Fades a sequence sound out over a second (key-on sounds are left alone) */
288void fadeOutSound(s32 packed) {
289 s32 id = SOUND_BANK(packed);
290 u32 keyOn = SOUND_IS_KEY_ON(packed);
291 s32 seq = SOUND_SEQ(packed);
292 s32 sep = SOUND_SEP(packed);
293 s32 slot = findSoundBank(id);
294
295 if (slot != -1 && !keyOn) {
296#if PAL_VIDEO
297 /* one second, in frames */
298 SsSepSetDecrescendo(SOUND.banks[slot].seqs[seq], sep, 0x80, NTSC_MODE ? 0x3C : 0x32);
299#else
300 SsSepSetDecrescendo(SOUND.banks[slot].seqs[seq], sep, 0x80, 0x3C);
301#endif
302 if (SOUND.music == packed) {
303 SOUND.music = 0;
304 }
305 }
306}
307
308/* Whether a bank is still being loaded */
312
313/* Closes what slot `slot` holds and starts loading bank `id` into it */
314void loadSoundBankInto(s32 slot, s32 id) {
315 SoundBank *bank = &SOUND.banks[slot];
316 SoundLoader *loader = &SOUND.loader;
317 s32 i;
318 s32 j;
319
320 bank->id = id;
321 if (bank->vabId != -1) {
322 for (i = 0; i < bank->numSeqs; i++) {
323 for (j = 0; j < SOUND_SEP_COUNT; j++) {
324 SsSepStop(bank->seqs[i], j);
325 }
326 SsSepClose(bank->seqs[i]);
327 }
328 SsVabClose(bank->vabId);
329 bank->vabId = -1;
330 }
331 loader->state = SOUND_LOAD_HEAD;
332 loader->files = SOUND_BANK_FILES[id];
333 loader->slot = slot;
335}
336
337/* Loads a bank into slot 1 or 2, whichever was not used last */
339 if (SOUND.banks[1].id != id && SOUND.banks[2].id != id) {
340 if (SOUND.lastSlot == 1) {
341 loadSoundBankInto(2, id);
342 SOUND.lastSlot = 2;
343 } else {
344 loadSoundBankInto(1, id);
345 SOUND.lastSlot = 1;
346 }
347 }
348}
349
350/* Header: copied to the slot's buffer, then the body goes to the SPU */
352 SoundLoader *loader = &SOUND.loader;
353 s32 slot = loader->slot;
354 SoundBank *bank = &SOUND.banks[slot];
355 s32 *src;
356 s32 *dst;
357 s32 n;
358 s32 i;
359 s32 j;
360
361 switch (loader->state) {
362 case SOUND_LOAD_IDLE:
363 break;
364 case SOUND_LOAD_HEAD:
365 if (FILE_CACHE.isLoading(loader->files->headFile) != 0) {
366 return;
367 }
368 src = FILE_CACHE.load(loader->files->headFile);
369 dst = bank->headBuffer;
370 n = FILE_TABLE.getSectorCount(loader->files->headFile) * (CD_SECTOR_SIZE / sizeof(s32));
371 for (j = 0; j < n; j++) {
372 *dst++ = *src++;
373 }
374 FILE_CACHE.free(loader->files->headFile);
375 bank->vabId = SsVabOpenHeadSticky(FILE_CACHE.getArchiveEntry(loader->files->vhIndex, bank->headBuffer), slot, bank->spuAddr);
377 loader->state++;
378 /* fallthrough */
379 case SOUND_LOAD_BODY:
380 if (FILE_CACHE.isLoading(loader->files->bodyFile) != 0) {
381 return;
382 }
383 HEAP.lock(FILE_CACHE.load(loader->files->bodyFile), 1);
384 bank->vabId = SsVabTransBody(FILE_CACHE.getEntry(loader->files->bodyEntry), bank->vabId);
385 loader->state++;
386 /* fallthrough */
388 if (SsVabTransCompleted(0) == 0) {
389 return;
390 }
391 i = 0;
392 HEAP.lock(FILE_CACHE.load(loader->files->bodyFile), 0);
393 FILE_CACHE.free(loader->files->bodyFile);
394 for (; loader->files->seps[i] != 0; i++) {
395 bank->seqs[i] = SsSepOpen(FILE_CACHE.getArchiveEntry(loader->files->seps[i], bank->headBuffer), bank->vabId, SOUND_SEP_COUNT);
396 }
397 bank->numSeqs = i;
398 loader->state = SOUND_LOAD_IDLE;
399 }
400}
401
402/* Plays one note of a program from the bank in slot `slot`; returns the voice */
403short soundKeyOn(s32 slot, short prog, short note) {
404 return SsUtKeyOn(SOUND.banks[slot].vabId, prog, 0, note, 0, SOUND_VOLUME_MAX, SOUND_VOLUME_MAX);
405}
406
407/* Releases the voice that a key-on sound id started */
408void soundKeyOff(s32 packed, s16 voice) {
409 s32 id = SOUND_BANK(packed);
410 s32 prog = SOUND_PROG(packed);
411 s32 tone = SOUND_TONE(packed);
412 s32 note = SOUND_NOTE(packed);
413 s32 slot = findSoundBank(id);
414
415 if (voice != -1 && slot != -1) {
416 SsUtKeyOff(voice, SOUND.banks[slot].vabId, prog, tone, note);
417 }
418}
419
420/* Starts libsnd, gives each slot its buffers and loads the system sounds (bank 1) into slot 0 */
421void initSound(void) {
422 s32 i;
423
424 SsSetTableSize(SOUND.seqTable, 6, 16);
425#if PAL_VIDEO
426 if (NTSC_MODE) {
427 SsSetTickMode(SS_NOTICK);
428 } else {
429 SsSetTickMode(SS_NOTICK | 50); /* 50 ticks a second */
430 }
431#else
432 SsSetTickMode(SS_NOTICK);
433#endif
434 SsStart2();
436 SsSetSerialAttr(0, 0, 1);
437 SsSetSerialVol(0, SOUND_VOLUME_MAX, SOUND_VOLUME_MAX);
438 SsUtSetReverbType(SS_REV_TYPE_STUDIO_B);
439 SsUtSetReverbDepth(0, 0);
440 SsUtReverbOn();
441 for (i = 0; i < SOUND_SLOT_COUNT; i++) {
442 SOUND.banks[i].vabId = -1;
443 SOUND.banks[i].numSeqs = 0;
446 }
447 SOUND.loader.slot = 0;
450 loadSoundBankInto(0, 1);
451 while (isSoundLoading() != 0) {
454 }
455}
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
unsigned int u32
Definition common.h:12
signed short s16
Definition common.h:9
s32 NTSC_MODE
The European version runs at 50 Hz (PAL) unless NTSC_MODE is set; its clocks then advance 0x133,...
Definition eu_settings.c:14
#define CD_SECTOR_SIZE
The bytes of data in a sector (Mode 2 Form 1), as the reader reads them.
Definition file.h:48
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
FileTableFuncs FILE_TABLE
The disc's file table.
Heap HEAP
The functions that return what a call left in v0 (allocMemHigh, findTask) and the ones that take othe...
Definition heap.c:184
void stopSound(s32 packed)
Stops a sequence sound (key-on sounds are left alone)
Definition sound.c:272
SoundFiles SOUND_FILES_3D
Definition sound.c:139
SoundFiles SOUND_FILES_24
Definition sound.c:114
SoundFiles SOUND_FILES_41
Definition sound.c:143
SoundFiles SOUND_FILES_0D
Definition sound.c:91
SoundFiles SOUND_FILES_14
Definition sound.c:98
SoundFiles SOUND_FILES_39
Definition sound.c:135
SoundFiles SOUND_FILES_47
Definition sound.c:149
SoundFiles SOUND_FILES_38
Definition sound.c:134
SoundFiles SOUND_FILES_2F
Definition sound.c:125
SoundFiles SOUND_FILES_3B
Definition sound.c:137
SoundFiles SOUND_FILES_1D
Definition sound.c:107
SoundFiles SOUND_FILES_42
Definition sound.c:144
SoundFiles SOUND_FILES_0B
Definition sound.c:89
SoundFiles SOUND_FILES_2C
Definition sound.c:122
SoundFiles SOUND_FILES_0A
Definition sound.c:88
SoundFiles SOUND_FILES_2A
Definition sound.c:120
SoundState SOUND
rsin and rcos (libgte) read rsin_tbl[a - 0x800] and the like: their addresses before the table fall i...
Definition sound.c:180
s32 SOUND_HEAD_BUFFER_2[10240]
Definition sound.c:172
SoundFiles SOUND_FILES_04
Definition sound.c:82
SoundFiles SOUND_FILES_13
Definition sound.c:97
SoundFiles SOUND_FILES_3F
Definition sound.c:141
SoundFiles * SOUND_BANK_FILES[72]
The banks by id: bits 18-24 of a sound id.
Definition sound.c:153
SoundFiles SOUND_FILES_23
Definition sound.c:113
void loadSoundBankInto(s32 slot, s32 id)
Closes what slot slot holds and starts loading bank id into it.
Definition sound.c:314
SoundFiles SOUND_FILES_21
Definition sound.c:111
SoundFiles SOUND_FILES_46
Definition sound.c:148
short soundKeyOn(s32 slot, short prog, short note)
Plays one note of a program from the bank in slot slot; returns the voice.
Definition sound.c:403
SoundFiles SOUND_FILES_22
Definition sound.c:112
SoundFiles SOUND_FILES_2D
Definition sound.c:123
SoundFiles SOUND_FILES_12
Definition sound.c:96
short playSound(s32 packed)
Plays a packed sound id (see engine/sound.h); returns the voice of a key-on.
Definition sound.c:212
SoundFiles SOUND_FILES_35
Definition sound.c:131
SoundFiles SOUND_FILES_1C
Definition sound.c:106
void fadeOutSound(s32 packed)
Fades a sequence sound out over a second (key-on sounds are left alone)
Definition sound.c:288
SoundFiles SOUND_FILES_0E
Definition sound.c:92
SoundFiles SOUND_FILES_3C
Definition sound.c:138
SoundFiles SOUND_FILES_28
Definition sound.c:118
SoundFiles SOUND_FILES_06
Definition sound.c:84
SoundFiles SOUND_FILES_40
Definition sound.c:142
SoundFiles SOUND_FILES_10
Definition sound.c:94
SoundFiles SOUND_FILES_3E
Definition sound.c:140
SoundFiles SOUND_FILES_3A
Definition sound.c:136
SoundFiles SOUND_FILES_05
Definition sound.c:83
s32 SOUND_SPU_ADDRS[3]
Definition sound.c:176
SoundFiles SOUND_FILES_17
Definition sound.c:101
SoundFiles SOUND_FILES_19
Definition sound.c:103
s32 isSoundLoading(void)
Whether a bank is still being loaded.
Definition sound.c:309
SoundFiles SOUND_FILES_29
Definition sound.c:119
SoundFiles SOUND_FILES_33
Definition sound.c:129
SoundFiles SOUND_FILES_1E
Definition sound.c:108
SoundFiles SOUND_FILES_16
Definition sound.c:100
SoundFiles SOUND_FILES_0F
Definition sound.c:93
void loadSoundBank(s32 id)
Loads a bank into slot 1 or 2, whichever was not used last.
Definition sound.c:338
SoundFiles SOUND_FILES_36
Definition sound.c:132
SoundFiles SOUND_FILES_2B
Definition sound.c:121
SoundFiles SOUND_FILES_0C
Definition sound.c:90
SoundFiles SOUND_FILES_25
Definition sound.c:115
SoundFiles SOUND_FILES_44
Definition sound.c:146
SoundFiles SOUND_FILES_26
Definition sound.c:116
void soundKeyOff(s32 packed, s16 voice)
Releases the voice that a key-on sound id started.
Definition sound.c:408
SoundFiles SOUND_FILES_02
Definition sound.c:80
void stopAllSounds(void)
Stops every track of the loaded banks and every voice.
Definition sound.c:251
SoundFiles SOUND_FILES_15
Definition sound.c:99
SoundFiles SOUND_FILES_09
Definition sound.c:87
s32 SOUND_HEAD_BUFFER_1[10240]
Definition sound.c:171
SoundFiles SOUND_FILES_1F
Definition sound.c:109
SoundFiles SOUND_FILES_07
Definition sound.c:85
SoundFiles SOUND_FILES_18
Definition sound.c:102
void * SOUND_HEAD_BUFFERS[3]
Each slot's buffer, and its SPU address.
Definition sound.c:175
void updateSoundLoading(void)
Header: copied to the slot's buffer, then the body goes to the SPU.
Definition sound.c:351
SoundFiles SOUND_FILES_1A
Definition sound.c:104
s32 findSoundBank(s32 id)
The slot (0-2) that holds bank id, or -1.
Definition sound.c:200
SoundFiles SOUND_FILES_32
Definition sound.c:128
SoundFiles SOUND_FILES_45
Definition sound.c:147
SoundFiles SOUND_FILES_37
Definition sound.c:133
s32 SOUND_HEAD_BUFFER_0[14336]
Each slot's buffer for the VAB header and the SEPs, in this unit's .bss (see the Makefile)
Definition sound.c:170
SoundFiles SOUND_FILES_20
Definition sound.c:110
SoundFiles SOUND_FILES_03
Definition sound.c:81
void initSound(void)
Starts libsnd, gives each slot its buffers and loads the system sounds (bank 1) into slot 0.
Definition sound.c:421
SoundFiles SOUND_FILES_2E
Definition sound.c:124
SoundFiles SOUND_FILES_27
Definition sound.c:117
SoundFiles SOUND_FILES_43
Definition sound.c:145
SoundFiles SOUND_FILES_30
Definition sound.c:126
SoundFiles SOUND_FILES_1B
Definition sound.c:105
SoundFiles SOUND_FILES_34
Definition sound.c:130
SoundFiles SOUND_FILES_31
Definition sound.c:127
SoundFiles SOUND_FILES_11
Definition sound.c:95
SoundFiles SOUND_FILES_08
Definition sound.c:86
SoundFiles SOUND_FILES_01
Each bank's files (SOUND_BANK_FILES[id]), numbered in the Japanese disc as in the USA one.
Definition sound.c:79
#define SOUND_BANK(id)
Definition sound.h:21
#define SOUND_SLOT_COUNT
The banks loaded at once: slot 0 keeps bank 1 (system sounds), 1 and 2 alternate.
Definition sound.h:29
#define SOUND_VOLUME_MAX
The loudest volume of a voice or track.
Definition sound.h:35
@ SOUND_LOAD_HEAD
Definition sound.h:170
@ SOUND_LOAD_TRANSFER
Definition sound.h:170
@ SOUND_LOAD_BODY
Definition sound.h:170
@ SOUND_LOAD_IDLE
Definition sound.h:170
#define SOUND_IS_EXCLUSIVE(id)
Definition sound.h:20
#define SOUND_PROG(id)
Definition sound.h:22
#define SOUND_IS_KEY_ON(id)
Sound ids pack everything needed to play them: bit 31 a key-on of one VAB tone (sound effect),...
Definition sound.h:19
#define SOUND_SEP(id)
Definition sound.h:26
#define SOUND_SEQ(id)
Definition sound.h:25
#define SOUND_SEP_COUNT
The tracks (SEPs) of each SEQ.
Definition sound.h:32
#define SOUND_NOTE(id)
Definition sound.h:24
#define SOUND_TONE(id)
Definition sound.h:23
void *(* getArchiveEntry)(s32 index, void *archive)
Definition file.h:97
void(* free)(s32 file)
Definition file.h:93
void *(* load)(u32 file)
Definition file.h:92
s32(* isLoading)(s32 file)
Definition file.h:88
void(* request)(s32 file)
Definition file.h:90
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
void(* update)(void)
Definition file.h:91
s32(* getSectorCount)(s32 file)
Definition file.h:17
void(* lock)()
Definition heap.h:34
One of the SOUND_SLOT_COUNT loaded sound banks: a VAB and its SEP sequences.
Definition sound.h:151
s16 numSeqs
Definition sound.h:154
s32 id
Definition sound.h:152
s32 spuAddr
Definition sound.h:157
s16 vabId
Definition sound.h:153
void * headBuffer
VAB header and SEPs are copied here.
Definition sound.h:156
s16 seqs[4]
Definition sound.h:155
A bank's files (SOUND_BANK_FILES[id])
Definition sound.h:161
s32 headFile
archive: VAB header and SEPs
Definition sound.h:163
s32 vhIndex
of the VAB header in headFile
Definition sound.h:164
s32 seps[0]
indices in headFile, 0-terminated
Definition sound.h:166
s32 bodyFile
VAB body, sent to the SPU.
Definition sound.h:162
s32 bodyEntry
(file << 16) | slot
Definition sound.h:165
Loads a bank in the background (updateSoundLoading)
Definition sound.h:173
SoundFiles * files
Definition sound.h:174
s16 state
SOUND_LOAD_*.
Definition sound.h:175
s16 slot
Definition sound.h:176
The sound engine (SOUND)
Definition sound.h:180
s32 music
the exclusive sound playing
Definition sound.h:183
u8 seqTable[0x4200]
SsSetTableSize(6 SEQs, 16 SEPs)
Definition sound.h:181
void(* stopSound)(s32 id)
Definition sound.h:195
SoundLoader loader
Definition sound.h:185
SoundBank banks[3]
Definition sound.h:182
s32 lastSlot
Definition sound.h:184