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