diff --git a/include/jaudio_NES/audiocommon.h b/include/jaudio_NES/audiocommon.h index aad4cf4e..0f092a1f 100644 --- a/include/jaudio_NES/audiocommon.h +++ b/include/jaudio_NES/audiocommon.h @@ -13,6 +13,8 @@ extern "C" { #define AUDIO_ARAM_SIZE 0x400000 /* 4MB */ #define AUDIO_ARAM_HEAP_SIZE 0xC000 +#define AUDIO_GROUP_MAX 5 + #define NA_MAKE_COMMAND(a0, a1, a2, a3) \ (u32)((((a0) & 0xFF) << 24) | (((a1) & 0xFF) << 16) | (((a2) & 0xFF) << 8) | (((a3) & 0xFF) << 0)) diff --git a/include/jaudio_NES/audiostruct.h b/include/jaudio_NES/audiostruct.h index e3e730bb..c64ebb31 100644 --- a/include/jaudio_NES/audiostruct.h +++ b/include/jaudio_NES/audiostruct.h @@ -4,6 +4,7 @@ #include "types.h" #include "jaudio_NES/audiocommon.h" #include "PR/abi.h" +#include "libultra/libultra.h" #ifdef __cplusplus extern "C" { @@ -17,7 +18,7 @@ struct link_ { /* 0x00 */ link* next; /* 0x04 */ link* prev; union { - /* 0x08 */ int numAfter; /* when link is head */ + /* 0x08 */ s32 numAfter; /* when link is head */ /* 0x08 */ void* pData; /* when link is node */ }; /* 0x0C */ chnode* pNode; @@ -75,69 +76,229 @@ typedef struct ArcHeader_ { /* 0x10 */ ArcEntry entries[]; /* variable size */ } ArcHeader; -/* sizeof(AutoHeapstrc) == 0xC */ -typedef struct AutoHeapstrc_ { - /* 0x00 */ int seqLen; - /* 0x04 */ int bankLen; - /* 0x08 */ int waveLen; -} AutoHeapstrc; +/* sizeof(adpcmloop) == 0x10|0x30*/ +typedef struct adpcmloop_ { + /* 0x00 */ u32 loop_start; + /* 0x04 */ u32 loop_end; + /* 0x08 */ u32 count; + /* 0x0C */ u32 sample_end; + /* 0x10 */ s16 predictor_state[16]; /* exists count > 0*/ +} adpcmloop; -/* sizeof(DataHeapstrc) == 0x8 */ -typedef struct DataHeapstrc_ { - /* 0x00 */ int dataLen; - /* 0x04 */ int autoLen; -} DataHeapstrc; +/* sizeof(adpcmbook) == [0x8, 0x8+n]*/ +typedef struct adpcmbook_ { + /* 0x00 */ s32 order; + /* 0x04 */ s32 n_predictors; + /* 0x08 */ s16 codebook[0]; /* variable length */ +} adpcmbook; -/* sizeof(delay) == 0x30 */ -typedef struct delay_ { - /* 0x00 */ u8 _00[0x30 - 0x00]; /* TODO */ -} delay; +typedef struct smzwavetable_ { + /* 0x00 */ u32 bit31 : 1; + /* 0x00 */ u32 codec : 3; + /* 0x00 */ u32 medium : 2; + /* 0x00 */ u32 bit26 : 1; + /* 0x00 */ u32 is_relocated : 1; + /* 0x00 */ u32 size : 24; + /* 0x04 */ u8* sample; + /* 0x08 */ adpcmloop* loop; + /* 0x0C */ adpcmbook* book; +} smzwavetable; -/* sizeof(commonch) == 0x20 */ -typedef struct commonch_ { - /* 0x00 */ u8 _00; - /* 0x01 */ u8 _01; - /* 0x02 */ u8 _02; - /* 0x03 */ u8 _03; - /* 0x04 */ u8 _04; - /* 0x05 */ u8 _05; - /* 0x06 */ u8 _06; - /* 0x07 */ u8 _07; - /* 0x08 */ u16 _08; - /* 0x0A */ u16 _0A; - /* 0x0C */ u16 _0C; - /* 0x0E */ u16 _0E; - /* 0x10 */ void* _10; - /* 0x14 */ int _14; - /* 0x18 */ u8 _18; - /* 0x19 */ u8 _19; - /* 0x1A */ u8 _1A; - /* 0x1B */ u8 _1B[4]; -} commonch; - -/* sizeof(driverch) == 0x18 */ -typedef struct driverch_ { - /* 0x00 */ u8 _00; - /* 0x01 */ u8 _01; - /* 0x02 */ u8 _02; - /* 0x03 */ u8 _03; - /* 0x04 */ u8 _04; - /* 0x05 */ u8 _05; - /* 0x06 */ u8 _06; - /* 0x07 */ u8 _07; - /* 0x08 */ u16 _08; - /* 0x0A */ u16 _0A; - /* 0x0C */ u32 _0C; - /* 0x10 */ u8* _10; - /* 0x14 */ s16 _14; - /* 0x16 */ s16 _16; -} driverch; +/* sizeof(wtstr) == 0x08 */ +typedef struct wtstr_ { + /* 0x00 */ smzwavetable* wavetable; + /* 0x04 */ f32 tuning; +} wtstr; /* sizeof(phase) == 0x01 */ typedef struct phase_ { /* 0x00 */ u8 _00; } phase; +/* sizeof(sweep) == 0x0C */ +typedef struct sweep_ { + /* 0x00 */ u8 mode; + /* 0x02 */ u16 current; + /* 0x04 */ u16 speed; + /* 0x08 */ f32 extent; +} sweep; + +/* sizeof(vibparam) == 0x0E */ +typedef struct vibparam_ { + /* 0x00 */ u16 rate_start; + /* 0x02 */ u16 depth_start; + /* 0x04 */ u16 rate_target; + /* 0x06 */ u16 depth_target; + /* 0x08 */ u16 rate_change_delay; + /* 0x0A */ u16 depth_change_delay; + /* 0x0C */ u16 delay; +} vibparam; + +/* sizeof(tmtable) == 0x1C */ +typedef struct tmtable_ { + /* 0x00 */ vibparam* vibrato_params; + /* 0x04 */ u32 time; + /* 0x08 */ s16* curve; + /* 0x0C */ f32 depth; + /* 0x10 */ f32 rate; + /* 0x14 */ u8 active; + /* 0x16 */ u16 rate_change_timer; + /* 0x18 */ u16 depth_change_timer; + /* 0x1A */ u16 delay; +} tmtable; + +/* sizeof(envdat) == 0x04 */ +typedef struct envdat_ { + /* 0x00 */ s16 delay; + /* 0x02 */ s16 value; +} envdat; + +/* sizeof(envp) == 0x20 */ +typedef struct envp_ { + /* 0x00 */ u8 unused : 1; + /* 0x00 */ u8 hang : 1; + /* 0x00 */ u8 decay : 1; + /* 0x00 */ u8 release : 1; + /* 0x00 */ u8 status : 1; + + /* 0x01 */ u8 envelope_idx; + /* 0x02 */ s16 delay; + /* 0x04 */ f32 sustain; + /* 0x08 */ f32 velocity; + /* 0x0C */ f32 fadeout_velocity; + /* 0x10 */ f32 current; + /* 0x14 */ f32 target; + /* 0x18 */ f32 _18; + /* 0x1C */ envdat* pEnvData; +} envp; + +/* sizeof(env) == 0x08 */ +typedef struct env_ { + /* 0x00 */ u8 decay_idx; + /* 0x01 */ u8 sustain; + /* 0x04 */ envdat* envelope; +} env; + +/* sizeof(commonch) == 0x20 */ +typedef struct commonch_ { + /* 0x00 */ vu8 enabled : 1; + /* 0x00 */ u8 needs_init : 1; + /* 0x00 */ u8 finished : 1; + /* 0x00 */ u8 unused : 1; + /* 0x00 */ u8 strong_right : 1; + /* 0x00 */ u8 strong_left : 1; + /* 0x00 */ u8 strong_reverb_right : 1; + /* 0x00 */ u8 storng_reverb_left : 1; + + /* 0x01 */ u8 reverb_idx : 3; + /* 0x01 */ u8 book_ofs : 2; + /* 0x01 */ u8 is_synth_wave : 1; + /* 0x01 */ u8 has_two_parts : 1; + /* 0x01 */ u8 use_haas_effect : 1; + + /* 0x02 */ u8 gain; + /* 0x03 */ u8 haas_effect_left_delay_size; + /* 0x04 */ u8 haas_effect_right_delay_size; + /* 0x05 */ u8 target_reverb_volume; + /* 0x06 */ u8 harmonic_idx_cur_and_prev; + /* 0x07 */ u8 comb_filter_size; + /* 0x08 */ u16 target_volume_left; + /* 0x0A */ u16 target_volume_right; + /* 0x0C */ u16 frequency_fixed_point; + /* 0x0E */ u16 comb_filter_gain; + union { + /* 0x10 */ wtstr* tuned_sample; + /* 0x10 */ s16* wave_sample_addr; // for synth waves + }; + /* 0x14 */ s16* filter; + /* 0x18 */ u8 _18; + /* 0x19 */ u8 surround_effect_idx; + /* 0x1A */ u8 _1A; + /* 0x1B */ u8 _1B[4]; +} commonch; + +/* TODO: see if this has a name anywhere */ +/* sizeof(synthparams) == 0x2E0 */ +typedef struct synthparams_ { + /* 0x000 */ s16 adpcm_state[16]; + /* 0x020 */ s16 final_resample_state[16]; + /* 0x040 */ s16 filter_state[32]; + /* 0x080 */ s16 unused_state[16]; + /* 0x0A0 */ s16 haas_effect_delay_state[32]; + /* 0x0E0 */ s16 comb_filter_state[128]; + /* 0x1E0 */ s16 surround_effect_state[128]; +} synthparams; + +/* sizeof(driverch) == 0x20 */ +typedef struct driverch_ { + /* 0x00 */ u8 at_loop_point : 1; + /* 0x00 */ u8 stop_loop : 1; + /* 0x01 */ u8 sample_dma_idx; + /* 0x02 */ u8 prev_haas_effect_left_delay_size; + /* 0x03 */ u8 prev_haas_effect_right_delay_size; + /* 0x04 */ u8 cur_reverb_vol; + /* 0x05 */ u8 num_parts; + /* 0x06 */ u8 comb_filter_needs_init; + /* 0x07 */ u8 vel_conv_table_idx; + /* 0x08 */ u16 sample_pos_fractional_part; + /* 0x0A */ u16 sound_effect_gain; + /* 0x0C */ s32 sample_pos_integer_part; + /* 0x10 */ synthparams* synth_params; + /* 0x14 */ s16 current_volume_left; + /* 0x16 */ s16 current_volume_right; + /* 0x18 */ u8 _18[8]; // unused? +} driverch; + +/* TODO: madeup name, see if there's an exposde one */ +/* sizeof(playbackparams) == 0x18 */ +typedef struct playbackparams_ { + /* 0x00 */ u8 target_reverb_volume; + /* 0x01 */ u8 gain; + /* 0x02 */ u8 pan; + /* 0x03 */ u8 surround_effect_idx; + /* 0x04 */ phase stereo_phase; + /* 0x05 */ u8 comb_filter_size; + /* 0x06 */ u16 comb_filter_gain; + /* 0x08 */ f32 frequency_scale; + /* 0x0C */ f32 velocity; + /* 0x10 */ s16* filter; + /* 0x14 */ s16* filter_buf; +} playbackparams; + +/* TODO: madeup name, see if there's an exposed one */ +/* sizeof(playbackch) == 0xA0 */ +typedef struct playbackch_ { + /* 0x00 */ u8 priority; + /* 0x01 */ u8 wave_id; + /* 0x02 */ u8 harmonic_index; + /* 0x03 */ u8 bank_id; + /* 0x04 */ u8 status; + /* 0x05 */ u8 stereo_headset_effects; + /* 0x06 */ s16 adsr_volume_scale_unused; + /* 0x08 */ f32 portamento_frequency_scale; + /* 0x0C */ f32 vibrato_frequency_scale; + /* 0x10 */ note* wanted_parent_note; + /* 0x14 */ note* current_parent_note; + /* 0x18 */ note* previous_parent_note; + /* 0x1C */ playbackparams params; + /* 0x34 */ envp adsr_envp; + /* 0x54 */ sweep portamento_sweep; + /* 0x60 */ tmtable vibrato_tmtable; + /* 0x7C */ s32 _7C; + /* 0x80 */ u8 _80; + /* 0x84 */ u32 start_sample_pos; + /* 0x88 */ u8 _88[0x18]; +} playbackch; + +/* sizeof(channel) == 0x100 */ +struct channel_ { + /* 0x00 */ link link; + /* 0x10 */ driverch driver_ch; + /* 0x30 */ playbackch playback_ch; + /* 0xD0 */ commonch common_ch; + /* 0xF0 */ u8 _F0[0x10]; +}; + /* sizeof(drvparam) == 0x1C */ typedef struct drvparam_ { /* 0x00 */ u8 _00; @@ -154,48 +315,101 @@ typedef struct drvparam_ { /* 0x1A */ u16 _1A; } drvparam; -/* sizeof(envdat) == 0x04 */ -typedef struct envdat_ { - /* 0x00 */ s16 delay; - /* 0x02 */ s16 value; -} envdat; - -/* sizeof(envp) == 0x20 */ -typedef struct envp_ { - /* 0x00 */ u8 state; - /* 0x01 */ u8 envelope_table_row; - /* 0x02 */ s16 key; - /* 0x04 */ f32 min_vol; - /* 0x08 */ f32 attack; - /* 0x0C */ f32 decay_release; - /* 0x10 */ f32 volume; - /* 0x14 */ f32 target_volume; - /* 0x18 */ f32 _18; - /* 0x1C */ envdat* pEnvData; -} envp; - -/* sizeof(env) == 0x08 */ -typedef struct env_ { - /* 0x00 */ u8 decay_idx; - /* 0x01 */ u8 sustain; - /* 0x04 */ envdat* envelope; -} env; - -/* sizeof(vibparam) == 0x0E */ -typedef struct vibparam_ { - /* 0x00 */ u16 rate_start; - /* 0x02 */ u16 depth_start; - /* 0x04 */ u16 rate_target; - /* 0x06 */ u16 depth_target; - /* 0x08 */ u16 rate_change_delay; - /* 0x0A */ u16 depth_change_delay; - /* 0x0C */ u16 delay; -} vibparam; - +/* sizeof(voicetable) == 0x20 */ typedef struct voicetable_ { - + /* 0x00 */ u8 is_relocated; + /* 0x01 */ u8 normal_range_low; + /* 0x02 */ u8 normal_range_high; + /* 0x03 */ u8 adsr_decay_idx; + /* 0x04 */ envdat* envelope; + /* 0x08 */ wtstr low_pitch_tuned_sample; + /* 0x10 */ wtstr normal_pitch_tuned_sample; + /* 0x18 */ wtstr high_pitch_tuned_sample; } voicetable; +/* sizeof(percvoicetable) == 0x10 */ +typedef struct percvoicetable_ { + /* 0x00 */ u8 adsr_decay_idx; + /* 0x01 */ u8 pan; + /* 0x02 */ u8 is_relocated; + /* 0x04 */ wtstr tuned_sample; + /* 0x0C */ envdat* envelope; +} percvoicetable; + +/* sizeof(veffvoicetable) == 0x08 */ +typedef struct veffvoicetable_ { + /* 0x00 */ wtstr tuned_sample; +} veffvoicetable; + +/* sizeof(voiceinfo) == 0x14 */ +typedef struct voiceinfo_ { + /* 0x00 */ u8 num_instruments; + /* 0x01 */ u8 num_drums; + /* 0x02 */ u8 wave_bank_id0; + /* 0x03 */ u8 wave_bank_id1; + /* 0x04 */ u16 num_sfx; + /* 0x08 */ voicetable** instruments; + /* 0x0C */ percvoicetable** percussion; + /* 0x10 */ veffvoicetable* effects; +} voiceinfo; + +/* sizeof(delayparam) == 0x1C */ +typedef struct delayparam_ { + /* 0x00 */ s16 n_samples_after_downsampling; + /* 0x02 */ s16 n_samples; + /* 0x04 */ s16* to_down_sample_left; + /* 0x08 */ s16* to_down_sample_right; + /* 0x0C */ s32 start_pos; + /* 0x10 */ s16 size; + /* 0x12 */ s16 wrapped_size; + /* 0x14 */ u16 load_resample_pitch; + /* 0x16 */ u16 save_resample_pitch; + /* 0x18 */ u16 save_resample_num_samples; +} delayparam; + +/* sizeof(delay) == 0x2D0 */ +typedef struct delay_ { + /* 0x000 */ u8 resample_flags; + /* 0x001 */ u8 use_reverb; + /* 0x002 */ u8 frames_to_ignore; + /* 0x003 */ u8 cur_frame; + /* 0x004 */ u8 downsample_rate; + /* 0x005 */ s8 mix_reverb_idx; + /* 0x006 */ u16 delay_num_samples; + /* 0x008 */ s16 mix_reverb_strength; + /* 0x00A */ s16 volume; + /* 0x00C */ u16 decay_ratio; + /* 0x00E */ u16 downsample_pitch; + /* 0x010 */ s16 leak_rtl; + /* 0x012 */ s16 leak_ltl; + /* 0x014 */ u16 sub_delay; + /* 0x016 */ s16 sub_volume; + /* 0x018 */ u8 resample_effect_on; + /* 0x019 */ s8 resample_effect_extra_samples; + /* 0x01A */ u16 resample_effect_load_unk; + /* 0x01C */ u16 resample_effect_save_unk; + /* 0x01E */ u8 delay_num_samples_after_downsampling; + /* 0x020 */ s32 next_reverb_buf_pos; + /* 0x024 */ s32 delay_num_samples_unk; + /* 0x028 */ s16* left_reverb_buf; + /* 0x02C */ s16* right_reverb_buf; + /* 0x030 */ s16* left_load_resample_buf; + /* 0x034 */ s16* right_load_resample_buf; + /* 0x038 */ s16* left_save_resample_buf; + /* 0x03C */ s16* right_save_resample_buf; + /* 0x040 */ delayparam params[2][AUDIO_GROUP_MAX]; + /* 0x158 */ delayparam sub_params[2][AUDIO_GROUP_MAX]; + /* 0x270 */ s16* filter_left; + /* 0x274 */ s16* filter_right; + /* 0x278 */ s16* filter_left_init; + /* 0x27C */ s16* filter_right_init; + /* 0x280 */ s16* filter_left_state; + /* 0x284 */ s16* filter_right_state; + /* 0x288 */ wtstr tuned_sample; + /* 0x290 */ smzwavetable sample; + /* 0x2A0 */ adpcmloop adpcm_loop; +} delay; + /* sizeof(seqplayer) == 0x1C */ typedef struct seqplayer_ { /* 0x00 */ u8* pc; @@ -260,13 +474,14 @@ typedef struct sub_ { /* 0x50 */ group* group; /* 0x54 */ struct note_* note_layers[4]; /* 0x64 */ seqplayer seq_player; - /* 0x80 */ env asdr_env; + /* 0x80 */ env adsr_env; /* 0x88 */ chnode channel_node; /* 0xC8 */ s8 seq_script_io[8]; /* 0xD0 */ u8* sfx_state; /* 0xD4 */ s16* filter; /* 0xD8 */ phase stereo_phase; /* 0xDC */ s32 sample_start_pos; + /* 0xE0 */ u8 _unk[0x100 - 0x0E0]; } sub; /* sizeof(group) == 0x160 */ @@ -309,7 +524,7 @@ struct group_ { /* 0x078 */ seqplayer seq_player; /* 0x094 */ u8* short_note_velocity_tbl; /* 0x098 */ u8* short_note_gate_time_tbl; - /* 0x09C */ u8 note_pool[0x40]; /* TODO: this is a struct according to MM decomp */ + /* 0x09C */ chnode channel_node; /* 0x0DC */ s32 skip_ticks; /* 0x0E0 */ s32 script_counter; /* is u32 in MM decomp */ /* 0x0E4 */ u8 unkE4[0x158 - 0x0E4]; @@ -318,20 +533,354 @@ struct group_ { /* sizeof(note) == 0x90 */ struct note_ { - u8 _00[0x90 - 0x00]; + /* 0x00 */ u8 enabled : 1; + /* 0x00 */ u8 finished : 1; + /* 0x00 */ u8 muted : 1; + /* 0x00 */ u8 continuous : 1; + /* 0x00 */ u8 _00bit3 : 1; + /* 0x00 */ u8 ignore_drum_pan : 1; + /* 0x00 */ u8 _00bit1 : 1; + /* 0x00 */ u8 note_properties_need_init : 1; + /* 0x01 */ phase stereo_phase; + /* 0x02 */ u8 inst_or_wave; + /* 0x03 */ u8 gate_time; + /* 0x04 */ u8 semitone; + /* 0x05 */ u8 portamento_target_note; + /* 0x06 */ u8 pan; + /* 0x07 */ u8 note_pan; + /* 0x08 */ u8 surround_effect_idx; + /* 0x09 */ u8 target_reverb_volume; + + struct { + /* 0x0A */ u16 bit0 : 1; + /* 0x0A */ u16 bit1 : 1; + /* 0x0A */ u16 bit2 : 1; + /* 0x0A */ u16 use_vibrato : 1; + /* 0x0A */ u16 bit4 : 1; + /* 0x0A */ u16 bit5 : 1; + /* 0x0A */ u16 bit6 : 1; + /* 0x0A */ u16 bit7 : 1; + /* 0x0B */ u16 bit8 : 1; + /* 0x0B */ u16 bit9 : 1; + /* 0x0B */ u16 bitA : 1; + /* 0x0B */ u16 bitB : 1; + /* 0x0B */ u16 bitC : 1; + /* 0x0B */ u16 bitD : 1; + /* 0x0B */ u16 bitE : 1; + /* 0x0B */ u16 bitF : 1; + }; + + /* 0x0C */ vibparam vibrato_params; + /* 0x1A */ s16 delay; + /* 0x1C */ s16 gate_delay; + /* 0x1E */ s16 delay2; + /* 0x20 */ u16 portamento_time; + /* 0x22 */ s16 transposition; + /* 0x24 */ s16 short_note_default_delay; + /* 0x26 */ s16 last_delay; + /* 0x28 */ env adsr_env; + /* 0x30 */ sweep portamento_sweep; + /* 0x3C */ channel* channel; + /* 0x40 */ f32 frequency_scale; + /* 0x44 */ f32 bend; + /* 0x48 */ f32 velocity_square2; + /* 0x4C */ f32 velocity_square; + /* 0x50 */ f32 note_velocity; + /* 0x54 */ f32 note_frequency_scale; + /* 0x58 */ voicetable* instrument; + /* 0x5C */ wtstr* tuned_sample; + /* 0x60 */ sub* sub_track; + /* 0x64 */ seqplayer seq_player; + /* 0x80 */ link link; }; +/* sizeof(Bgloadreq) == 0x14 */ +typedef struct Bgloadreq_ { + /* 0x00 */ u32 end_and_medium_key; + /* 0x04 */ smzwavetable* sample; + /* 0x08 */ u8* ram_addr; + /* 0x0C */ u32 encoded_info; + /* 0x10 */ s32 is_free; +} Bgloadreq; + +/* sizeof(Bgload) == 0x58 */ +typedef struct Bgload_ { + /* 0x00 */ s8 status; + /* 0x01 */ s8 delay; + /* 0x02 */ s8 medium; + /* 0x04 */ u8* ram_addr; + /* 0x08 */ u32 current_device_addr; + /* 0x0C */ u8* current_ram_addr; + /* 0x10 */ size_t bytes_remaining; + /* 0x14 */ size_t chunk_size; + /* 0x18 */ s32 unk_medium_param; + /* 0x1C */ u32 ret_msg; + /* 0x20 */ OSMesgQueue* ret_mq; + /* 0x24 */ OSMesgQueue mq; + /* 0x3C */ OSMesg msg[1]; + /* 0x40 */ OSIoMesg io_mesg; +} Bgload; + +/* sizeof(lpscache) == 0x64 */ +typedef struct lpscache_ { + /* 0x00 */ u8 medium; + /* 0x01 */ u8 seq_or_bank_id; + /* 0x02 */ u16 inst_id; + /* 0x04 */ s32 unk_medium_param; + /* 0x08 */ u32 current_device_addr; + /* 0x0C */ u8* current_ram_addr; + /* 0x10 */ u8* ram_addr; + /* 0x14 */ s32 status; + /* 0x18 */ size_t bytes_remaining; + /* 0x1C */ s8* is_done; + /* 0x20 */ smzwavetable sample; + /* 0x30 */ OSMesgQueue mq; + /* 0x48 */ OSMesg msg[1]; + /* 0x4C */ OSIoMesg io_mesg; +} lpscache; + +/* sizeof(WaveLoad) == 0x10 */ +typedef struct WaveLoad_ { + /* 0x00 */ u8* ram_addr; + /* 0x04 */ u32 device_addr; + /* 0x08 */ u16 size_unused; + /* 0x0A */ u16 size; + /* 0x0C */ u8 unused; + /* 0x0D */ u8 reuse_idx; + /* 0x0E */ u8 time_to_live; +} WaveLoad; + +/* sizeof(audioparams) == 0x28 */ +typedef struct audioparams_ { + /* 0x00 */ s16 spec; + /* 0x02 */ u16 sampling_frequency; + /* 0x04 */ u16 ai_sampling_frequency; + /* 0x06 */ s16 num_samples_per_frame_target; + /* 0x08 */ s16 num_samples_per_frame_max; + /* 0x0A */ s16 num_samples_per_frame_min; + /* 0x0C */ s16 updates_per_frame; + /* 0x0E */ s16 num_samples_per_update; + /* 0x10 */ s16 num_samples_per_update_max; + /* 0x12 */ s16 num_samples_per_update_min; + /* 0x14 */ s16 num_playing_sequences; + /* 0x18 */ f32 resample_rate; + /* 0x1C */ f32 updates_per_frame_inverse; + /* 0x20 */ f32 updates_per_frame_inverse_scaled; + /* 0x24 */ f32 updates_per_frame_scaled; +} audioparams; + +/* sizeof(StayHeapstrc) == 0x0C */ +typedef struct StayHeapstrc_ { + /* 0x00 */ size_t seq_heap_size; + /* 0x04 */ size_t bank_heap_size; + /* 0x08 */ size_t wave_heap_size; +} StayHeapstrc; + +/* sizeof(DataHeapstrc) == 0x08 */ +typedef struct DataHeapstrc_ { + /* 0x00 */ size_t data_size; + /* 0x04 */ size_t auto_size; +} DataHeapstrc; + +/* sizeof(AutoHeapstrc) == 0xC */ +typedef struct AutoHeapstrc_ { + /* 0x00 */ size_t seqLen; + /* 0x04 */ size_t bankLen; + /* 0x08 */ size_t waveLen; +} AutoHeapstrc; + +/* sizeof(AudioHeapstrc) == 0x10 */ +typedef struct AudioHeapstrc_ { + /* 0x00 */ size_t misc_heap_size; + /* 0x04 */ size_t unused0; + /* 0x08 */ size_t unused1; + /* 0x0C */ size_t cache_heap_size; +} AudioHeapstrc; + +/* sizeof(SwMember) == 0x14 */ +typedef struct SwMember_ { + /* 0x00 */ u8 in_use; + /* 0x01 */ s8 original_medium; + /* 0x02 */ u8 sample_bank_id; + /* 0x03 */ u8 _pad[5]; + /* 0x08 */ u8* allocated_addr; + /* 0x0C */ void* sample_addr; + /* 0x10 */ size_t size; +} SwMember; + +/* sizeof(SwHeap) == 0x298 */ +typedef struct SwHeap_ { + /* 0x000 */ ALHeap heap; + /* 0x004 */ SwMember entries[32]; + /* 0x294 */ s32 num_entries; +} SwHeap; + +/* TODO: this needs a better name, I don't see any functions which reference it */ +/* sizeof(ALHeapEntry) == 0xC */ +typedef struct ALHeapEntry_ { + /* 0x00 */ u8* addr; + /* 0x04 */ size_t size; + /* 0x08 */ s16 table_type; + /* 0x0A */ s16 id; +} ALHeapEntry; + +/* sizeof(SZStay) == 0xD8 */ +typedef struct SZStay_ { + /* 0x00 */ u32 num_entries; + /* 0x04 */ ALHeap heap; + /* 0x18 */ ALHeapEntry entries[16]; +} SZStay; + +/* sizeof(SZAuto) == 0x30 */ +typedef struct SZAuto_ { + /* 0x00 */ u32 use_entry_idx; + /* 0x04 */ ALHeap heap; + /* 0x18 */ ALHeapEntry entries[2]; +} SZAuto; + +/* sizeof(SZHeap) == 0x11C */ +typedef struct SZHeap_ { + /* 0x000 */ SZStay stay_heap; + /* 0x0D8 */ SZAuto auto_heap; + /* 0x108 */ ALHeap unused_heap; /* Might be another struct with a heap, its size matches ALHeap in MM and AC */ +} SZHeap; + +typedef u32 (*SequenceCallback)(s8, sub*); + /* sizeof(AudioGlobals) == 0x92b0 */ typedef struct AudioGlobals { - /* 0x0000 */ u8 unk0[0x2850 - 0x0000]; + /* 0x0000 */ u8 _0000; + /* 0x0001 */ s8 num_synth_reverbs; + /* 0x0002 */ u16 _0002; + /* 0x0004 */ u16 _0004; + /* 0x0006 */ u8 _0006[10]; + /* 0x0010 */ s16* adpcm_code_book; + /* 0x0014 */ commonch* common_channel; + /* 0x0018 */ delay synth_delay[4]; + /* 0x0B58 */ u8 _0B58[0x30]; + /* 0x0B88 */ smzwavetable* used_samples[128]; + /* 0x0D88 */ Bgloadreq requested_samples[128]; + /* 0x1788 */ s32 num_used_samples; + /* 0x178C */ s32 num_requested_samples; + /* 0x1790 */ Bgload bgloads[16]; + /* 0x1D10 */ OSMesgQueue bgload_mq; + /* 0x1D28 */ u8 _1D28[0x40]; + /* 0x1D68 */ Bgload* current_bgload; + /* 0x1D6C */ u32 slow_load_pos; + /* 0x1D70 */ lpscache lps_cache[2]; + /* 0x1E38 */ OSPiHandle* cart_handle; + /* 0x1E3C */ OSPiHandle* drive_handle; + /* 0x1E40 */ OSMesgQueue external_load_queue; + /* 0x1E58 */ OSMesg external_load_mesg_buf[16]; + /* 0x1E98 */ OSMesgQueue preload_sample_queue; + /* 0x1EB0 */ OSMesg preload_sample_mesg_buf[16]; + /* 0x1EF0 */ OSMesgQueue cur_audio_frame_dma_queue; + /* 0x1F08 */ OSMesg cur_audio_frame_dma_mesg_buf[64]; + /* 0x2008 */ OSIoMesg cur_adio_frame_dma_io_mesg_buf[64]; + /* 0x2608 */ OSMesgQueue sync_dma_queue; + /* 0x2620 */ OSMesg sync_dma_queue_msg[1]; + /* 0x2624 */ OSIoMesg sync_dma_io_mesg; + /* 0x263C */ WaveLoad* waveload_list; + /* 0x2640 */ u32 num_waveloads; + /* 0x2644 */ u32 waveload_count; + /* 0x2648 */ s32 _2648; + /* 0x264C */ u8 waveload_dma_queue0[256]; + /* 0x274C */ u8 waveload_dma_queue1[256]; + /* 0x284C */ u8 waveload_dma_queue0_rpos; /* read pos */ + /* 0x284D */ u8 waveload_dma_queue1_rpos; /* read pos */ + /* 0x284E */ u8 waveload_dma_queue0_wpos; /* write pos */ + /* 0x284F */ u8 waveload_dma_queue1_wpos; /* write pos */ /* 0x2850 */ ArcHeader* seq_header; /* 0x2854 */ ArcHeader* bank_header; /* 0x2858 */ ArcHeader* wave_header; /* 0x285C */ ArcHeader* data_header; /* 0x2860 */ u16* map_header; - /* 0x2864 */ u8 unk2864[0x3788 - 0x2864]; - /* 0x3788 */ group groups[5]; - /* 0x3E68 */ u8 unk3E68[0x5448]; + /* 0x2864 */ u16 num_sequences; + /* 0x2868 */ voiceinfo* voice_info; + /* 0x286C */ audioparams audio_params; + /* 0x2894 */ f32 _2894; /* tempo scale? */ + /* 0x2898 */ s32 waveload_dma_buf0_size; + /* 0x289C */ s32 waveload_dma_buf1_size; + /* 0x28A0 */ u8 _28A0[16]; + /* 0x28B0 */ s32 waveload_dma_cur_buf_size; + /* 0x28B4 */ s32 max_audio_cmds; + /* 0x28B8 */ s32 num_channels; + /* 0x28BC */ s16 max_tempo; + /* 0x28BE */ s8 sound_mode; + /* 0x28C0 */ s32 frame_audio_task_count; + /* 0x28C4 */ s32 current_frame_dma_count; + /* 0x28C8 */ s32 rsp_task_idx; + /* 0x28CC */ s32 current_ai_buffer_idx; + /* 0x28D0 */ Acmd* abi_cmd_bufs[3]; + /* 0x28DC */ Acmd* unused_current_abi_cmd_buf; + /* 0x28E0 */ void* unused_current_audio_task; + /* 0x28E4 */ u8 unused_rsp_tasks[2][0x50]; // Actually a struct but we don't need it + /* 0x2984 */ u8 _2984[0x54]; // unsure what this is, new to DnM+/AC? + /* 0x29D8 */ f32 _29D8; + /* 0x29DC */ s32 refresh_rate; + /* 0x29E0 */ s16* ai_buffers[4]; + /* 0x29F0 */ s16 num_samples_per_frame[4]; + /* 0x29F8 */ u32 audio_random_seed; + /* 0x29FC */ s32 audio_error_flags; // unsure about the name, from MM + /* 0x2A00 */ vu32 reset_timer; + /* 0x2A04 */ SequenceCallback seq_callbacks[4]; + /* 0x2A14 */ s8 _2A14; + /* 0x2A18 */ s32 num_abi_cmds_max; + /* 0x2A1C */ s32 _2A1C; + /* 0x2A20 */ ALHeap session_heap; + /* 0x2A34 */ ALHeap external_heap; + /* 0x2A48 */ ALHeap init_heap; + /* 0x2A5C */ ALHeap misc_heap; + /* 0x2A70 */ ALHeap unused_heap0; + /* 0x2A84 */ ALHeap unused_heap1; + /* 0x2A98 */ ALHeap sz_data_heap; + /* 0x2AAC */ ALHeap data_heap; + /* 0x2AC0 */ ALHeap sz_auto_heap; + /* 0x2AD4 */ SZHeap seq_heap; + /* 0x2BF0 */ SZHeap bank_heap; + /* 0x2D0C */ SZHeap wave_heap; + /* 0x2E28 */ ALHeap emem_heap; + /* 0x2E3C */ ALHeapEntry emem_entries[32]; + /* 0x2FBC */ SwHeap emem_persistent_wave_heap; + /* 0x3254 */ SwHeap emem_temporary_wave_heap; + /* 0x34EC */ AudioHeapstrc audio_heap_info; + /* 0x34FC */ DataHeapstrc cache_heap; + /* 0x3504 */ StayHeapstrc persistent_common_heap_info; + /* 0x3510 */ StayHeapstrc temporary_common_heap_info; + /* 0x351C */ u8 wave_load_status[172]; + /* 0x35C8 */ u8 bank_load_status[172]; + /* 0x3674 */ u8 sequence_load_status[252]; + /* 0x3770 */ u8 reset_status; + /* 0x3771 */ u8 spec_id; + /* 0x3774 */ s32 audio_reset_fadeout_frames_left; + /* 0x3778 */ f32* adsr_decay_table; + /* 0x377C */ u8* audio_heap_p; + /* 0x3780 */ size_t audio_heap_size; + /* 0x3784 */ channel* channels; + /* 0x3788 */ group groups[AUDIO_GROUP_MAX]; + /* 0x3E68 */ note notes[128]; + /* 0x8668 */ sub null_sub_track; /* used for 'null' sub tracks */ + /* 0x8748 */ group* groups_p[AUDIO_GROUP_MAX]; + /* 0x877C */ s32 _877C; + /* 0x8780 */ link note_link; + /* 0x8790 */ chnode channel_node; /* main chnode */ + /* 0x87D0 */ group main_group; + /* 0x8930 */ sub main_sub; + /* 0x8A30 */ u8 thread_cmd_write_pos; + /* 0x8A31 */ u8 thread_cmd_read_pos; + /* 0x8A32 */ u8 thread_cmd_queue_finished; + /* 0x8A34 */ u16 thread_cmd_group_mask[AUDIO_GROUP_MAX]; + /* 0x8A40 */ OSMesgQueue* audio_reset_mq_p; + /* 0x8A44 */ OSMesgQueue* task_start_mq_p; + /* 0x8A48 */ OSMesgQueue* thread_cmd_proc_mq_p; + /* 0x8A4C */ OSMesgQueue task_start_mq; + /* 0x8A64 */ OSMesgQueue thread_cmd_proc_mq; + /* 0x8A7C */ OSMesgQueue audio_reset_mq; + /* 0x8A94 */ OSMesg task_start_msg_buf[1]; + /* 0x8A98 */ OSMesg audio_reset_msg_buf[1]; + /* 0x8A9C */ OSMesg thread_cmd_proc_msg_buf[4]; + /* 0x8AAC */ AudioPort audio_port_cmds[256]; + /* 0x92AC */ s32 _92AC; } AudioGlobals; typedef union SOUNDID_ { diff --git a/include/libultra/libultra.h b/include/libultra/libultra.h index 5e5c8cc4..c5e4bc40 100644 --- a/include/libultra/libultra.h +++ b/include/libultra/libultra.h @@ -9,32 +9,31 @@ #include "libultra/shutdown.h" #include "libultra/os_timer.h" #include "libultra/os_thread.h" +#include "libultra/os_pi.h" #include "libultra/initialize.h" #include "libc/math.h" /* TODO: sins and coss belong in libultra */ #define N64_SCREEN_HEIGHT 240 #define N64_SCREEN_WIDTH 320 - #ifdef __cplusplus extern "C" { #endif typedef u64 Z_OSTime; -int bcmp (void *v1, void *v2, u32 size); -void bcopy(void *src, void *dst, size_t n); -void bzero(void *ptr, size_t size); +int bcmp(void* v1, void* v2, u32 size); +void bcopy(void* src, void* dst, size_t n); +void bzero(void* ptr, size_t size); void osSyncPrintf(const char* fmt, ...); void osWritebackDCache(void* vaddr, u32 nbytes); u32 osGetCount(void); OSTime osGetTime(void); -extern s32 osAppNMIBuffer[]; +extern s32 osAppNMIBuffer[]; extern int osShutdown; extern u8 __osResetSwitchPressed; - #ifdef __cplusplus } #endif diff --git a/include/libultra/os_pi.h b/include/libultra/os_pi.h new file mode 100644 index 00000000..dca566e9 --- /dev/null +++ b/include/libultra/os_pi.h @@ -0,0 +1,68 @@ +#ifndef OS_PI_H +#define OS_PI_H + +#include "types.h" +#include "libultra/osMesg.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + /* 0x00 */ u32 errStatus; + /* 0x04 */ void* dramAddr; + /* 0x08 */ void* C2Addr; + /* 0x0C */ u32 sectorSize; + /* 0x10 */ u32 C1ErrNum; + /* 0x14 */ u32 C1ErrSector[4]; +} __OSBlockInfo; // size = 0x24 + +typedef struct { + /* 0x00 */ u32 cmdType; + /* 0x04 */ u16 transferMode; + /* 0x06 */ u16 blockNum; + /* 0x08 */ s32 sectorNum; + /* 0x0C */ uintptr_t devAddr; + /* 0x10 */ u32 bmCtlShadow; + /* 0x14 */ u32 seqCtlShadow; + /* 0x18 */ __OSBlockInfo block[2]; +} __OSTranxInfo; // size = 0x60 + +typedef struct OSPiHandle { + /* 0x00 */ struct OSPiHandle* next; + /* 0x04 */ u8 type; + /* 0x05 */ u8 latency; + /* 0x06 */ u8 pageSize; + /* 0x07 */ u8 relDuration; + /* 0x08 */ u8 pulse; + /* 0x09 */ u8 domain; + /* 0x0C */ uintptr_t baseAddress; + /* 0x10 */ u32 speed; + /* 0x14 */ __OSTranxInfo transferInfo; +} OSPiHandle; // size = 0x74 + +typedef struct { + /* 0x0 */ u8 type; + /* 0x4 */ uintptr_t address; +} OSPiInfo; // size = 0x8 + +typedef struct { + /* 0x0 */ u16 type; + /* 0x2 */ u8 pri; + /* 0x3 */ u8 status; + /* 0x4 */ OSMesgQueue* retQueue; +} OSIoMesgHdr; // size = 0x8 + +typedef struct { + /* 0x00 */ OSIoMesgHdr hdr; + /* 0x08 */ void* dramAddr; + /* 0x0C */ uintptr_t devAddr; + /* 0x10 */ size_t size; + /* 0x14 */ OSPiHandle* piHandle; +} OSIoMesg; // size = 0x88 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/static/jaudio_NES/rhythm.c b/src/static/jaudio_NES/rhythm.c index 53055192..b566f2c5 100644 --- a/src/static/jaudio_NES/rhythm.c +++ b/src/static/jaudio_NES/rhythm.c @@ -367,15 +367,11 @@ static s8 Na_RhythmGrpProcess(s8 arg0, group* group) { int r27; int r30; int r31; - (void)arg0; int ret = 1; r29 = 24; static int pre_beat_type = -1; - static u8 init; static int pre_frame_per_step = -1; - { static u8 init; } - tempo_adjust(group); if (Na_GetRhythmBeatType() == 0) { if (Nap_ReadGrpPort(2, 2) % 2 != 0) { @@ -387,6 +383,9 @@ static s8 Na_RhythmGrpProcess(s8 arg0, group* group) { r29 = 24; } + /* random call to arg0 so it is stored on the stack, can also do (void)arg0 */ + if (arg0) {} + r31 = Nap_ReadGrpPort(2, 3); if (Nap_ReadGrpPort(2, 2) % 2 != 0) { r27 = r31;