Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
sound.h
Go to the documentation of this file.
1#ifndef DW3_SOUND_H
2#define DW3_SOUND_H
3
4/* Sound banks (sound/) */
5
6#include "common.h"
7#include <sys/types.h>
8#include <libgte.h>
9#include <libgpu.h>
10
11/*
12 * Sound ids pack everything needed to play them:
13 * bit 31 a key-on of one VAB tone (sound effect), else a SEP sequence
14 * bit 30 exclusive (music): stops the previous exclusive sound
15 * bits 18-24 the sound bank id (see findSoundBank)
16 * key-on: program bits 11-17, tone bits 7-10, note bits 0-6
17 * sequence: SEQ bits 8-15, track (SEP) bits 0-7
18 */
19#define SOUND_IS_KEY_ON(id) ((u32)(id) >> 31)
20#define SOUND_IS_EXCLUSIVE(id) (((id) >> 30) & 1)
21#define SOUND_BANK(id) (((id) >> 18) & 0x7F)
22#define SOUND_PROG(id) (((id) >> 11) & 0x7F)
23#define SOUND_TONE(id) (((id) >> 7) & 0xF)
24#define SOUND_NOTE(id) ((id) & 0x7F)
25#define SOUND_SEQ(id) (((id) >> 8) & 0xFF)
26#define SOUND_SEP(id) ((id) & 0xFF)
27
28/* The banks loaded at once: slot 0 keeps bank 1 (system sounds), 1 and 2 alternate */
29#define SOUND_SLOT_COUNT 3
30
31/* The tracks (SEPs) of each SEQ */
32#define SOUND_SEP_COUNT 16
33
34/* The loudest volume of a voice or track */
35#define SOUND_VOLUME_MAX 0x7F
36
37/* Sounds the overlays share, with SOUNDTST's names */
38#define SOUND_SELECT 0x8004503C /* SYSTEM00: a choice is taken */
39#define SOUND_MENU_CANCEL 0x800450BD /* SYSTEM01 */
40#define SOUND_CURSOR 0x8004513E /* SYSTEM02: a cursor moves */
41#define SOUND_MENU_OPEN 0x40019 /* SYSTEM03 */
42#define SOUND_MENU_CLOSE 0x4001A /* SYSTEM04 */
43#define SOUND_MENU_MOVE 0x4001B /* SYSTEM06 */
44#define SOUND_MENU_CONFIRM 0x4001C /* SYSTEM07 */
45#define SOUND_COUNT 0x800452C6 /* SYSTEM10: a number counts up or down */
46#define SOUND_RECOVERY 0x40014 /* RECOVERY */
47#define SOUND_TELEPORT 0x4001D /* TELEPORT */
48#define SOUND_WIN_JINGLE 0x6004001E /* W_JINGLE: a battle won */
49#define SOUND_INN_JINGLE 0x4004000D /* JINGLE04: a night at the inn */
50#define SOUND_SWITCH01 0x8004103C
51#define SOUND_SWITCH02 0x800410BD
52#define SOUND_SWITCH03 0x8004113E
53#define SOUND_COMCD103 0x800429BF
54#define SOUND_COMCD115 0xA0042FCB /* held until SOUND.keyOff */
55#define SOUND_COMEX113 0x800446C9
56#define SOUND_PLAYER11 0xA0045EC9 /* held until SOUND.keyOff */
57#define SOUND_SYSTEM05 0x80045341
58#define SOUND_GONDRA_S 0x340004
59#define SOUND_SE000002 0xA40006
60#define SOUND_ELEVATER 0x1080001
61#define SOUND_CARD_001 0x800460BD
62
63/*
64 * A field's or a battle's music (FieldState.music, Battle.music): track
65 * (SEP) n of the first sequence of a sound bank, exclusive (bit 30) and with
66 * bit 29, which playSound doesn't read but every one of SOUNDTST's tunes
67 * has, and its loops (BT_LOOP0, EX_AT_LP), not its jingles. A stage's music
68 * is of the bank it loads (FieldState.soundBank, MUSIC_BANK).
69 */
70#define MUSIC(bank, n) (0x60000000 | (bank) << 18 | (n))
71
72/* The music by where the game plays it (FieldState.music, AreaBattle.music, the
73 screens'), each with SOUNDTST's name for it */
74#define MUSIC_CONFUSION MUSIC(1, 0) /* COM_CNFS: in a battle while a partner is confused (WFIGHTMN switchConfusionMusic) */
75#define MUSIC_GAME_OVER MUSIC(1, 8) /* GAMEOVER: a battle lost (WFIGHTMN endBattleOnKnockOut) */
76#define MUSIC_BATTLE MUSIC(2, 0) /* BATL0000: the maps' random battles (AreaBattle, nearly all of them) */
77#define MUSIC_BATTLE_1 MUSIC(3, 0) /* BATL1000: the Digimon Arena's battles and some event battles (AreaBattle) */
78#define MUSIC_ASUKA_CITY MUSIC(4, 0) /* ASKA_BGM: the Central Sector's streets and bridges, the Underground Path */
79#define MUSIC_ADMIN_CENTER MUSIC(5, 0) /* KANRIBGM: the cities' Main Lobby, Admin Center, Digimon Arena, Master Room */
80#define MUSIC_SEWERS MUSIC(6, 0) /* BGM_0003: the Admin Center's basement and the cities' sewers */
81#define MUSIC_SHOP_1 MUSIC(7, 0) /* SHOP1BGM: the inns, shops and towers */
82#define MUSIC_SHOP_2 MUSIC(8, 0) /* SHOP2BGM: Lamb Chop, the Yellow Cruiser and El Dorado */
83#define MUSIC_FIELD MUSIC(9, 0) /* FIELDBGM: Central Park, the Wire Forest Entrance, Shell Beach, Plug Cape */
84#define MUSIC_DUEL_ISLAND MUSIC(0xA, 0) /* BGM_0008: Duel Island */
85#define MUSIC_PROTOCOL_RUINS MUSIC(0xB, 0) /* PYRA_BGM: the Protocol Ruins */
86#define MUSIC_SEIRYU_CITY MUSIC(0xC, 0) /* SEIR_BGM: Seiryu City */
87#define MUSIC_MAGASTA MUSIC(0xD, 0) /* BGM_0011: the Undersea Base (Magasta), and the Deeper Crevice's gondola */
88#define MUSIC_STATION MUSIC(0xE, 0) /* BGM_0012: the East and South Stations */
89#define MUSIC_SHAMAN_HOUSE MUSIC(0xF, 0) /* BGM_0013: the Shaman House */
90#define MUSIC_RELIABILITY_SPOT MUSIC(0x10, 0) /* BGM_0014: the Reliability Spot */
91#define MUSIC_JUNGLE_SHRINE MUSIC(0x11, 0) /* BGM_0015: the Jungle Grave, the Jungle Shrine and the Catacomb */
92#define MUSIC_SUZAKU_CITY MUSIC(0x12, 0) /* BGM_0016: Suzaku City and its Hall */
93#define MUSIC_BUG_MAZE MUSIC(0x13, 0) /* BGM_0017: the Bug Maze (Network Break) */
94#define MUSIC_BADLAND MUSIC(0x14, 0) /* BGM_0018: the Badlands */
95#define MUSIC_SECRET_ROOM MUSIC(0x15, 0) /* BGM_0019: the Secret Room, the rebels' hideout */
96#define MUSIC_MIRAGE_HALL MUSIC(0x16, 0) /* BGM_0020: the Mirage Hall and Mirage Room */
97#define MUSIC_BYAKKO_CITY MUSIC(0x17, 0) /* BGM_0021: Byakko City and the Bai Hu Dome */
98#define MUSIC_LEGENDARY_GYM MUSIC(0x18, 0) /* BGM_0022: the Legendary Gym */
99#define MUSIC_DUNGEON MUSIC(0x19, 0) /* BGM_0023: the Ice, Fire and Dark Dungeons */
100#define MUSIC_GENBU_CITY MUSIC(0x1A, 0) /* BGM_0024: Genbu City */
101#define MUSIC_ONLINE_CENTER MUSIC(0x1B, 0) /* ON_CNBGM: MAGAMI's Online Center */
102#define MUSIC_GUNSLINGER MUSIC(0x1C, 0) /* BGM_0026: the Gunslinger (the Spy Satellite) */
103#define MUSIC_SEABED MUSIC(0x1D, 0) /* BGM_0027: the Seabed tunnels */
104#define MUSIC_CIRCUIT_BOARD MUSIC(0x1E, 0) /* BGM_0028: the Circuit Board tunnels */
105#define MUSIC_CITY_CRISIS MUSIC(0x1F, 0) /* BGM_0029: the cities and their streets instead of their music while the story is at a crisis (Knightmon reprogrammed, the A.o.A's headquarters, the Amaterasu server's Oinkmon) */
106#define MUSIC_MEMORY_CARD MUSIC(0x20, 0) /* BGM_0030: the memory card screen and the player's name entry */
107#define MUSIC_TRAINING MUSIC(0x21, 2) /* TRAINING: the gym's training */
108#define MUSIC_BOSS MUSIC(0x22, 0) /* BOSS_000: the sectors' boss battles */
109#define MUSIC_BOSS_1 MUSIC(0x23, 0) /* BOSS_001: the Digimon Arena's, the cities', the dungeons' and the A.o.A's boss battles */
110#define MUSIC_LAST_BOSS MUSIC(0x24, 0) /* LASTBOSS: Lord Megadeath's battle (WSTAG820) */
111#define MUSIC_LAST_BOSS_1 MUSIC(0x25, 0) /* LASTB_01: the extra chapter's last battle (WSTAG927, the Digimon Arena) */
112#define MUSIC_LAST_BOSS_2 MUSIC(0x26, 0) /* LASTB_02: Lord Megadeath's second form (WSTAG820, fighter 0x1D3's entrance) */
113#define MUSIC_CARD_BATTLE MUSIC(0x27, 4) /* CBTLMAIN: the card battles */
114#define MUSIC_STREET_CORNER MUSIC(0x29, 0) /* BGM00000: the Street Corner (Kusanagi City) */
115#define MUSIC_STREET_CORNER_1 MUSIC(0x29, 1) /* BGM00001: the Street Corner at STORY_JUNGLE_SOUND */
116#define MUSIC_STREET_CORNER_2 MUSIC(0x29, 2) /* BGM00002: the Street Corner at STORY_REAL_WORLD */
117#define MUSIC_STREET_CORNER_3 MUSIC(0x29, 3) /* BGM00003: the Street Corner at STORY_ASUKA_HEADQUARTERS */
118#define MUSIC_AOA_HEADQUARTERS MUSIC(0x2A, 0) /* ENV_0002: the A.o.A Headquarters */
119#define MUSIC_CONTROL_ROOM MUSIC(0x2B, 0) /* ENV_0003: the cities' Control Room */
120#define MUSIC_WATER_TUNNEL MUSIC(0x2C, 0) /* ENV_0004: the Water Tunnel */
121#define MUSIC_WIRE_FOREST MUSIC(0x2D, 0) /* ENV05_00: the Wire Forests and the Kicking Forest */
122#define MUSIC_WIND_PRAIRIE MUSIC(0x2E, 0) /* ENV_0006: the Wind Prairie */
123#define MUSIC_TYRANNO_VALLEY MUSIC(0x2F, 0) /* ENV_0007: Tyranno Valley, Snow Mountain, Kulon Mine and the Battle Gate */
124#define MUSIC_GALE_TOWER MUSIC(0x30, 0) /* ENV_0008: the Gale Tower */
125#define MUSIC_FOREST_INN_BF MUSIC(0x31, 0) /* ENV_0009: the Forest Inn's basement */
126#define MUSIC_PROTOCOL_FOREST MUSIC(0x32, 0) /* ENV10_00: the Protocol Forest */
127#define MUSIC_DIGIMON_LAB MUSIC(0x33, 0) /* ENV_0011: Asuka's Digimon Lab and Login Room */
128#define MUSIC_SWAMP MUSIC(0x34, 0) /* ENV_0012: the South Sector's swamps and Bulk Bridge */
129#define MUSIC_ETHER_JUNGLE MUSIC(0x35, 0) /* ENV_0013: the Ether Jungle */
130#define MUSIC_COAST MUSIC(0x36, 0) /* ENV_0014: Shell Beach, Plug Cape, Phoenix Bay and South Cape */
131#define MUSIC_UG_LAKE MUSIC(0x37, 0) /* ENV_0015: the UG Lake */
132#define MUSIC_DESERT MUSIC(0x38, 0) /* ENV_0016: the West Sector's deserts and the Mirage Tower */
133#define MUSIC_DUM_DUM_FACTORY MUSIC(0x39, 0) /* ENV_0017: Bullet Valley, the Dum Dum Factory, its Duct Rooms and Operation Room */
134#define MUSIC_WEST_SEWERS MUSIC(0x3A, 0) /* ENV_0018: the West Sector's Sewers and Secret Stairs */
135#define MUSIC_STORAGE_ROOM MUSIC(0x3B, 0) /* ENV_0019: Byakko City's Storage Room */
136#define MUSIC_UNDERGROUND_CAVE MUSIC(0x3C, 0) /* ENV_0020: the Underground Cave */
137#define MUSIC_BOOT_MOUNTAIN MUSIC(0x3D, 0) /* ENV_0021: Boot Mountain, and the Byakko Dome */
138#define MUSIC_FREEZE_MOUNTAIN MUSIC(0x3E, 0) /* ENV_0022: Freeze Mountain and the Lake of Ice */
139#define MUSIC_KULON_PIT MUSIC(0x3F, 0) /* ENV_0023: the Kulon Pit */
140#define MUSIC_CHAMBER_ROOM MUSIC(0x40, 1) /* ENV_0024: the Chamber Rooms */
141#define MUSIC_PELCHE_OASIS MUSIC(0x41, 0) /* ENV_0025: the Pelche Oasis */
142#define MUSIC_EAUCTION MUSIC(0x42, 0) /* EAUCTION: the Cargo Tower at some points of the story (FIELDSTG_setupField) */
143#define MUSIC_CARGO_TOWER MUSIC(0x42, 2) /* ENV_0204: the Cargo Tower */
144#define MUSIC_MAIN_LOBBY_DEMO MUSIC(0x43, 3) /* ENV_0205: the story events' copy of Asuka's Main Lobby (WSTAG212) */
145#define MUSIC_SATELLITE_CONTROL_ROOM MUSIC(0x44, 1) /* ENV_0206: the Spy Satellite's Control Room */
146
147/* The sound bank of a music, which a stage loads for it (FieldState.soundBank) */
148#define MUSIC_BANK(music) ((music) >> 18 & 0x7F)
149
150/* One of the SOUND_SLOT_COUNT loaded sound banks: a VAB and its SEP sequences */
151typedef struct SoundBank {
152 /* 0x00 */ s32 id;
153 /* 0x04 */ s16 vabId;
154 /* 0x06 */ s16 numSeqs;
155 /* 0x08 */ s16 seqs[4];
156 /* 0x10 */ void *headBuffer; /* VAB header and SEPs are copied here */
157 /* 0x14 */ s32 spuAddr;
158} SoundBank;
159
160/* A bank's files (SOUND_BANK_FILES[id]) */
161typedef struct SoundFiles {
162 /* 0x00 */ s32 bodyFile; /* VAB body, sent to the SPU */
163 /* 0x04 */ s32 headFile; /* archive: VAB header and SEPs */
164 /* 0x08 */ s32 vhIndex; /* of the VAB header in headFile */
165 /* 0x0C */ s32 bodyEntry; /* (file << 16) | slot */
166 /* 0x10 */ s32 seps[FLEXIBLE]; /* indices in headFile, 0-terminated */
167} SoundFiles;
168
169/* SoundLoader.state: waiting for the header file, the body file, then the SPU */
171
172/* Loads a bank in the background (updateSoundLoading) */
173typedef struct SoundLoader {
174 /* 0x0 */ SoundFiles *files;
175 /* 0x4 */ s16 state; /* SOUND_LOAD_* */
176 /* 0x6 */ s16 slot;
178
179/* The sound engine (SOUND) */
180typedef struct SoundState {
181 /* 0x0000 */ u8 seqTable[0x4200]; /* SsSetTableSize(6 SEQs, 16 SEPs) */
183 /* 0x4248 */ s32 music; /* the exclusive sound playing */
184 /* 0x424C */ s32 lastSlot;
185 /* 0x4250 */ SoundLoader loader;
186 /* 0x4258 */ void (*init)(void);
187 /* 0x425C */ short (*playSound)(s32 id); /* returns the voice of a key-on */
188 /* 0x4260 */ short (*keyOn)(s32 slot, short prog, short note);
189 /* 0x4264 */ void (*keyOff)(s32 id, s16 voice);
190 /* 0x4268 */ void (*loadBank)(s32 id);
191 /* 0x426C */ void (*loadBankInto)(s32 slot, s32 id);
192 /* 0x4270 */ void (*updateLoading)(void);
193 /* 0x4274 */ s32 (*isLoading)(void);
194 /* 0x4278 */ void (*stopAll)(void);
195 /* 0x427C */ void (*stopSound)(s32 id);
196 /* 0x4280 */ void (*fadeOut)(s32 id);
197} SoundState;
198
200short playSound(s32 packed);
201void stopAllSounds(void);
202void stopSound(s32 packed);
203void fadeOutSound(s32 packed);
204s32 isSoundLoading(void);
205void loadSoundBankInto(s32 index, s32 id);
206void loadSoundBank(s32 id);
207void updateSoundLoading(void);
208short soundKeyOn(s32 slot, short prog, short note);
209void soundKeyOff(s32 packed, s16 voice);
210void initSound(void);
211
212extern SoundState SOUND;
214extern s32 SOUND_SPU_ADDRS[];
215extern void *SOUND_HEAD_BUFFERS[];
216
217#endif /* DW3_SOUND_H */
signed int s32
Definition common.h:11
#define FLEXIBLE
The length of an array that ends a struct and runs as far as each object of it needs: s32 seps[FLEXIB...
Definition common.h:29
signed short s16
Definition common.h:9
unsigned char u8
Definition common.h:8
void stopSound(s32 packed)
Stops a sequence sound (key-on sounds are left alone)
Definition sound.c:272
#define SOUND_SLOT_COUNT
The banks loaded at once: slot 0 keeps bank 1 (system sounds), 1 and 2 alternate.
Definition sound.h:29
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
SoundLoadState
SoundLoader.state: waiting for the header file, the body file, then the SPU.
Definition sound.h:170
@ 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
s32 SOUND_SPU_ADDRS[]
Definition sound.c:176
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
short playSound(s32 packed)
Plays a packed sound id (see engine/sound.h); returns the voice of a key-on.
Definition sound.c:212
void fadeOutSound(s32 packed)
Fades a sequence sound out over a second (key-on sounds are left alone)
Definition sound.c:288
s32 isSoundLoading(void)
Whether a bank is still being loaded.
Definition sound.c:309
void loadSoundBankInto(s32 index, s32 id)
Closes what slot slot holds and starts loading bank id into it.
Definition sound.c:314
void * SOUND_HEAD_BUFFERS[]
Each slot's buffer, and its SPU address.
Definition sound.c:175
void loadSoundBank(s32 id)
Loads a bank into slot 1 or 2, whichever was not used last.
Definition sound.c:338
SoundFiles * SOUND_BANK_FILES[]
The banks by id: bits 18-24 of a sound id.
Definition sound.c:153
void soundKeyOff(s32 packed, s16 voice)
Releases the voice that a key-on sound id started.
Definition sound.c:408
void stopAllSounds(void)
Stops every track of the loaded banks and every voice.
Definition sound.c:251
void updateSoundLoading(void)
Header: copied to the slot's buffer, then the body goes to the SPU.
Definition sound.c:351
s32 findSoundBank(s32 id)
The slot (0-2) that holds bank id, or -1.
Definition sound.c:200
void initSound(void)
Starts libsnd, gives each slot its buffers and loads the system sounds (bank 1) into slot 0.
Definition sound.c:421
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
short(* keyOn)(s32 slot, short prog, short note)
Definition sound.h:188
s32 music
the exclusive sound playing
Definition sound.h:183
void(* init)(void)
Definition sound.h:186
s32(* isLoading)(void)
Definition sound.h:193
u8 seqTable[0x4200]
SsSetTableSize(6 SEQs, 16 SEPs)
Definition sound.h:181
void(* loadBankInto)(s32 slot, s32 id)
Definition sound.h:191
void(* stopSound)(s32 id)
Definition sound.h:195
void(* fadeOut)(s32 id)
Definition sound.h:196
void(* loadBank)(s32 id)
Definition sound.h:190
SoundLoader loader
Definition sound.h:185
void(* updateLoading)(void)
Definition sound.h:192
SoundBank banks[3]
Definition sound.h:182
s32 lastSlot
Definition sound.h:184
void(* stopAll)(void)
Definition sound.h:194
short(* playSound)(s32 id)
returns the voice of a key-on
Definition sound.h:187
void(* keyOff)(s32 id, s16 voice)
Definition sound.h:189