fork/training-mode-ce

git clone https://git.julia.blue/fork/training-mode-ce

AitchAdd warnings and fix them (#297)4f5d26e

nix
13.7 KiB386 linesraw
1#ifndef MEX_H_AUDIO
2#define MEX_H_AUDIO
3
4#include "structs.h"
5#include "datatypes.h"
6
7typedef enum FGMGroup
8{
9    FGMGROUP_PERSIST,   // main, pokemon, nr_name, end
10    FGMGROUP_ANNOUNCER, // nr_title, nr_select, nr_1p, nr_vs
11    FGMGROUP_CHARACTER, // character ssms + null.ssm
12    FGMGROUP_STAGE,     // stage ssms + last.ssm
13    FGMGROUP_1P,        // ending, 1pend
14} FGMGroup;
15
16typedef enum FGM_Main
17{
18    FGMMAIN_KAIFUKU = 125,
19    FGMMAIN_SCORECOUNT,
20    FGMMAIN_COIN_GET = 147,
21    FGMMAIN_CS_CANCEL = 172,
22    FGMMAIN_CS_KETTEI,
23    FGMMAIN_CS_MV,
24    FGMMAIN_CS_BEEP1,
25    FGMMAIN_INFOBEEP,
26    FGMMAIN_PAUSE,
27    FGMMAIN_CS_ERASE_CAUTION1 = 188,
28    FGMMAIN_CS_ERASE_CAUTION2,
29} FGM_Main;
30
31enum FGMID
32{
33    FGM_MAIN,
34    FGM_POKEMON,
35    FGM_NR_TITLE,
36    FGM_NR_SELECT,
37    FGM_NR_1P,
38    FGM_NR_VS,
39    FGM_CAPTAIN,
40    FGM_CLINK,
41    FGM_DK,
42    FGM_DRMARIO,
43    FGM_FALCO,
44    FGM_FOX,
45    FGM_GKOOPA,
46    FGM_ICE,
47    FGM_KIRBY,
48    FGM_KOOPA,
49    FGM_LINK,
50    FGM_LUIGI,
51    FGM_MARIO,
52    FGM_MARS,
53    FGM_MEWTWO,
54    FGM_NESS,
55    FGM_PEACH,
56    FGM_PICHU,
57    FGM_PIKACHU,
58    FGM_PURIN,
59    FGM_SAMUS,
60    FGM_ZS,
61    FGM_YOSHI,
62    FGM_GW,
63    FGM_GANON,
64    FGM_EMBLEM,
65    FGM_MHANDS,
66    FGM_KIRBYTM,
67    FGM_CASTLE,
68    FGM_CORNERIA,
69    FGM_GREATBAY,
70    FGM_KONGO,
71    FGM_MUTECITY,
72    FGM_ONETT,
73    FGM_ZEBES,
74    FGM_GARDEN,
75    FGM_KLAID,
76    FGM_GREEN,
77    FGM_VENOM,
78    FGM_BIGBLUE,
79    FGM_FOURSIDE,
80    FGM_PUPUPU,
81    FGM_PSTADIUM,
82    FGM_1PADV,
83    FGM_ENDING,
84    FGM_NR_NAME,
85    FGM_1PEND,
86    FGM_LAST,
87    FGM_END,
88    FGM_NULL,
89};
90
91typedef struct _AXPBADDR
92{
93    u16 loopFlag;         // 0x0, one shot or looped sample (see above)
94    u16 format;           // 0x2, sample format used (see above)
95    u16 loopAddressHi;    // 0x4, Loop start
96    u16 loopAddressLo;    // 0x6
97    u16 endAddressHi;     // 0x8, Loop/sample end, including last sample played
98    u16 endAddressLo;     // 0xa
99    u16 currentAddressHi; // 0xc, Current playback position
100    u16 currentAddressLo; // 0xe
101} AXPBADDR;
102
103typedef struct _AXPBMIX
104{
105    u16 vL;          // volume left
106    u16 vDeltaL;     // volume ramp left
107    u16 vR;          // volume right
108    u16 vDeltaR;     // volume ramp right
109    u16 vAuxAL;      // volume AUX A left
110    u16 vDeltaAuxAL; // volume ramp AUX A left
111    u16 vAuxAR;      // volume AUX A right
112    u16 vDeltaAuxAR; // volume ramp AUX A right
113    u16 vAuxBL;      // volume AUX B left
114    u16 vDeltaAuxBL; // volume ramp AUX B left
115    u16 vAuxBR;      // volume AUX B right
116    u16 vDeltaAuxBR; // volume ramp AUX B right
117    u16 vAuxBS;      // volume AUX B surround
118    u16 vDeltaAuxBS; // volume ramp AUX B surround
119    u16 vS;          // volume surround
120    u16 vDeltaS;     // volume ramp surround
121    u16 vAuxAS;      // volume AUX A surround
122    u16 vDeltaAuxAS; // volume ramp AUX A surround
123} AXPBMIX;
124
125typedef struct _AXPBITD
126{
127    u16 flag;         // on or off for this voice
128    u16 bufferHi;     // buffer in RAM
129    u16 bufferLo;     // buffer in RAM
130    u16 shiftL;       // phase shift samples left (current)
131    u16 shiftR;       // phase shift samples right (current)
132    u16 targetShiftL; // phase shift samples left (target)
133    u16 targetShiftR; // phase shift samples right (target)
134} AXPBITD;
135
136typedef struct _AXPBUPDATE
137{
138    u16 updNum[5]; // number of updates per 1ms step
139    u16 dataHi;    // location of update data in main memory
140    u16 dataLo;
141} AXPBUPDATE;
142
143typedef struct _AXPBDPOP
144{
145    s16 aL;
146    s16 aAuxAL;
147    s16 aAuxBL;
148    s16 aR;
149    s16 aAuxAR;
150    s16 aAuxBR;
151    s16 aS;
152    s16 aAuxAS;
153    s16 aAuxBS;
154} AXPBDPOP;
155
156typedef struct _AXPBVE
157{
158    u16 currentVolume; // .15 volume at start of frame
159    s16 currentDelta;  // signed per sample delta delta
160} AXPBVE;
161
162typedef struct _AXPBADPCM
163{
164    u16 a[8][2];    // coef table a1[0],a2[0],a1[1],a2[1]....
165    u16 gain;       // gain to be applied (0 for ADPCM, 0x0800 for PCM8/16)
166    u16 pred_scale; // predictor / scale combination (nibbles, as in hardware)
167    u16 yn1;        // y[n - 1]
168    u16 yn2;        // y[n - 2]
169} AXPBADPCM;
170
171typedef struct _AXPBFIR
172{
173    u16 numCoefs; // reserved, keep zero
174    u16 coefsHi;  // reserved, keep zero
175    u16 coefsLo;  // reserved, keep zero
176} AXPBFIR;
177
178typedef struct _AXPBSRC
179{
180    // ratio = (f32)ratio * 0x10000;
181    u16 ratioHi;            // sampling ratio, integer
182    u16 ratioLo;            // sampling ratio, fraction
183    u16 currentAddressFrac; // current fractional sample position
184    u16 last_samples[4];    // last 4 input samples
185} AXPBSRC;
186
187typedef struct _AXPBADPCMLOOP
188{
189    u16 loop_pred_scale; // predictor / scale combination (nibbles, as in hardware)
190    u16 loop_yn1;        // y[n - 1]
191    u16 loop_yn2;        // y[n - 2]
192} AXPBADPCMLOOP;
193
194typedef struct _AXPB
195{
196    u16 nextHi;              // 0x0, pointer to next parameter buffer (MRAM)
197    u16 nextLo;              // 0x2,
198    u16 currHi;              // 0x4, pointer to this parameter buffer (MRAM)
199    u16 currLo;              // 0x6
200    u16 srcSelect;           // 0x8, Select type of SRC (none,4-tap,linear)
201    u16 coefSelect;          // 0xa, Coef. to be used with 4-tap SRC
202    u16 mixerCtrl;           // 0xc, Mixer control bits
203    u16 state;               // 0xe, current state
204    u16 type;                // 0x10, type of voice
205    AXPBMIX mix;             // 0x12
206    AXPBITD itd;             // 0x36
207    AXPBUPDATE update;       // 0x44
208    AXPBDPOP dpop;           // 0x52
209    AXPBVE ve;               // 0x64
210    AXPBFIR fir;             // 0x68
211    AXPBADDR addr;           // 0x6E
212    AXPBADPCM adpcm;         // 0x7E
213    AXPBSRC src;             // 0xA6
214    AXPBADPCMLOOP adpcmLoop; // 0xB4
215    u16 pad[3];              // 0xBA, 32 byte alignment
216} AXPB;
217
218typedef struct _AXVPB
219{
220    void *next;  // 0x0, used in priority stacks
221    void *prev;  // 0x4, used in priority stacks
222    void *next1; // 0x8, used in callback stack
223    // these are used in voice allocation
224    u32 priority;    // 0xc, index to stack
225    void *callback;  // 0x10, user callback for specified
226    u32 userContext; // 0x14, user assigned context for callback
227    // vars & flags for updating and sync PBs
228    u32 index;           // 0x18, index of VPB in array
229    u32 sync;            // 0x1c, bit mask for each PB item to sync
230    u32 depop;           // 0x20, should depop voice
231    u32 updateMS;        // 0x24, update current ms
232    u32 updateCounter;   // 0x28, counter for n updates
233    u32 updateTotal;     // 0x2c, bounds checking for update block
234    u16 *updateWrite;    // 0x30, write pointer for PB updates
235    u16 updateData[128]; // 0x34, data for PB updates
236    void *itdBuffer;     // 0x134, pointer to ITD buffer
237    AXPB pb;             // 0x138, write params to this PB 0x
238} AXVPB;
239
240typedef struct FGMLive // i really need to look into this more
241{
242    u8 x0[0x8];      // 0x0
243    int flags;       // 0x8
244    int index;       // 0xc, index in the FGMLive array
245    int x10 : 24;    // 0x10, if this is -1, the FGM is not playing yet, still queued
246    u16 sound_index; // 0x14 local to the bank
247    u16 x16;         // 0x16
248    u8 x18;          // 0x18
249    u8 priority;     // 0x19
250    u8 volume;       // 0x1a
251    u8 x1b;          // 0x1b
252    u8 x1c;          // 0x1c
253    u8 x1d;          // 0x1d
254    u8 x1e;          // 0x1e
255    u8 x1f;          // 0x1f
256    u8 x20[0x9];     // 0x20
257    u8 x29;          // 0x29, reverb maybe
258    u8 x2a[0xa];     // 0x2a
259
260} FGMLive;
261
262typedef struct HPSHeader
263{
264    char magic[8];               // 0x0
265    int freq;                    // 0x8
266    int channel_num;             // 0xc
267    u16 is_loop;                 // 0x10
268    u16 format;                  // 0x12
269    int sa;                      // 0x14
270    int ea;                      // 0x18
271    int ca;                      // 0x1c
272    u16 coef[16];                // 0x20
273    u16 gain;                    // 0x40
274    u16 initial_predictor_scale; // 0x42
275    u16 initial_sample_history1; // 0x44
276    u16 initial_sample_history2; // 0x46
277} HPSHeader;
278
279typedef struct HPSChunkHeader
280{
281    int length;           // 0x0
282    int length_minus_one; // 0x4
283    int next;             // 0x8
284    u16 initPS;           // 0xc
285    u16 initsh1;          // 0xe
286    u16 initsh2;          // 0x10
287    u16 gain;             // 0x12
288    int extra;            // 0x14
289    int x18;              // 0x18
290    int x1c;              // 0x1c
291} HPSChunkHeader;
292
293struct BGMData // this name sucks, dont know enough about it to rename it
294{
295    unsigned int unk : 26;
296    unsigned int vbp_index : 6;
297};
298
299struct VPB
300{
301    int voice_index;        // 0x0, internally "vID"
302    int x4;                 // 0x4
303    u8 x8;                  // 0x8
304    u8 x9_80 : 1;           // 0x9, 0x80
305    u8 x9_40 : 1;           // 0x9, 0x40
306    u8 x9_20 : 1;           // 0x9, 0x20
307    u8 x9_10 : 1;           // 0x9, 0x10
308    u8 is_initializing : 1; // 0x9, 0x08, is raised when initalizing the hps load process @ 8038b76c, is lowered when the first chunk is played @ 8038b310
309    u8 x9_04 : 1;           // 0x9, 0x04
310    u8 pause : 1;           // 0x9, 0x02, if this is not set it inits x24 when playing the hps @ 8038b180
311    u8 axvpb_num;           // 0xa, number of daisy chained axvpb's at 0xc
312    u8 xb;                  // 0xb
313    AXVPB *axvpb;           // 0xc
314    AXVPB *axvpb2;          // 0x10
315    float freq;             // 0x14, are combined together to set ratioHi of AXPBSRC @ 8038b244
316    float pitch_x18;        // 0x18, are combined together to set ratioHi of AXPBSRC @ 8038b244
317    float pitch_x1c;        // 0x1c, are combined together to set ratioHi of AXPBSRC @ 8038b244
318    VPB *prev;              // 0x20, is equal to the previous value of stc_bgm_vpb, before it was replaced with a ptr to this one
319    u16 currentVolume;      // 0x24, name derived from r4 @ 8038b200
320    u8 is_updated_prev;     // 0x26, raised when prev is set @ 8038b33c
321    u8 x27;                 // 0x27
322    float volume_x28;       // 0x28, is used to calculate x24 @ 8038b194
323    u8 x2c[0x8];            // 0x2c
324    float volume_x34;       // 0x34, is used to calculate x24 @ 8038b194
325    float volume_x38;       // 0x38 (gets ignored completely?)
326    u8 x3c[0x14];           // 0x3c
327};
328
329struct AXLive
330{
331    u8 x0[0x384];                        // 0x0
332    VPB voice_data[64];                  // 0x384
333    u8 x1784[0xc0];                      // 0x1784, some constants
334    BGMData bgm_data_lookup[263];        // 0x1844, array of BGMData corresponding to SFX that were played with an instance_slot param > 0 when calling SFX_PlayRaw. this is used to stop previous instances when playing the same sfx
335    HPSChunkHeader hps_chunk_headers[3]; // 0x1c60, circular buffer of 3 most recent hps headers
336};
337
338static FGMLive *fgm_live = (void *)0x804c45a0; // points to an array of ? FGMLive structs
339static AXLive *ax_live = (void *)0x804c28e0;
340static VPB *stc_voice_data = (void *)0x804c2c64;
341static float *stc_fgm_volume = R13_OFFSET(-0x7dbc);
342static float *stc_bgm_volume = R13_OFFSET(-0x7db8);
343static BGMData *stc_bgm_data = R13_OFFSET(-0x5668);                      // voice index of the bgm currently playing, is -1 when nothing is playing
344static VPB *stc_bgm_vpb = R13_OFFSET(-0x3f54);                           // is set when the first hps sample is played @ 8038b33c. value is copied to the prev member of the vpb struct before being updated
345static int *stc_bgm_data_seed = R13_OFFSET(-0x3f50);                     // is used to generate the next bgm's bgm_data
346static int *stc_bgm_tick = R13_OFFSET(-0x3f44);                          // how many times bgm audio has been updated (incremented @ 8038ad44)
347static BGMData *stc_bgm_data2 = R13_OFFSET(-0x3f40);                     // contains some data about the bgm, including its voice_index
348static int *stc_bgm_entrynum = R13_OFFSET(-0x3f3c);                      // entrynum of the hps file currently playing again
349static int *stc_bgm_is_playing = R13_OFFSET(-0x5668);                    // is -1 when not playing
350static int *stc_bgm_curLoadingHpsChunkHeaderIndex = R13_OFFSET(-0x3f38); // index of the cur hps chunk header loaded (0-2 circular buffer)
351static int *stc_bgm_lastLoadedHPSChunkIndex = R13_OFFSET(-0x3f34);       // index of the most recent hps chunk loaded (0-2 circular buffer), changes after hps chunk is loaded @ 8038ad6c
352static int *stc_bgm_curPlayingHpsChunkHeaderIndex = R13_OFFSET(-0x3f2c); // index of the cur hps chunk header playing (0-2 circular buffer)
353static u8 *stc_bgm_isLoadingHPSChunk = R13_OFFSET(-0x3f28);              // flag that indicates an hps chunk is being loaded
354static int *stc_bgm_aramAlloc = R13_OFFSET(-0x3f20);                     // start of the 3 hps chunk circular buffer
355static int *stc_fgm_tick = R13_OFFSET(-0x3f14);                          // how many times fgm audio has been updated (incremented @ 8038ad44)
356static FGMLive *stc_last_fgmlive = R13_OFFSET(-0x3f0c);                  // points to the most recently created FGMLive struct
357
358int SFX_Play(int sfxID);
359int SFX_PlayRaw(int sfx, int volume, int pan, int instance_slot, int fgm_kind); // any instance_slot other than 0 will remember the current instance and destroy it if another is requested to play with that slot
360int SFX_PlayCommon(int sfxID);
361int SFX_PlayCrowd(int sfxID);
362void SFX_StopCrowd();
363
364char *Nametag_GetText(int tag_index);
365void Audio_ResetCache(int group_index);
366void Audio_QueueFileLoad(int group_index, u64 ssm_index);
367void Audio_UpdateCache();
368void Audio_SyncLoadAll();
369void BGM_DecideMenuBGM();
370int BGM_GetMenuBGM();
371void BGM_PlayFile(char *filename, int volume, int unk);
372void BGM_Play(int hpsID);
373void BGM_Stop();
374void BGM_Pause();
375void BGM_Resume();
376void BGM_SetVolume(float volume); // 0 - 1
377int FGM_CheckActive(u32 fgm_id);
378void FGM_Stop(u32 fgm_id);
379int FGM_SetVolume(u32 sfxid, u8 volume);
380int FGM_SetPanning(u32 sfxid, u8 panning);
381void FGM_PauseKind(int kind); // pausing in-game pauses kinds 5,6,7,8
382void FGM_ResumeKind(int kind);
383
384AXVPB *AXAcquireVoice(u32 priority, void *callback, u32 userContext);
385
386#endif