Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
private.h File Reference

Go to the source code of this file.

Functions

void au_amb_manager_init (AmbienceManager *arg0, s8 arg1, s8 reverbType, AuGlobals *arg3)
 
AuResult au_amb_check_player_index (u32 arg0)
 
void au_amb_load_tracks_fade (s32 arg0, s32 arg1)
 
void au_amb_set_disabled (s32 arg0, s32 arg1)
 
AuResult au_amb_start (s32 arg0, s32 arg1)
 
void au_amb_fade_setup (AmbiencePlayer *arg0)
 
void au_amb_pause (s32 arg0, s32 arg1)
 
void au_amb_resume (s32 arg0, s32 arg1)
 
void au_amb_stop_quick (s32 arg0)
 
void au_amb_stop_slow (s32 arg0, s32 arg1)
 
void au_amb_set_volume (s32 arg0, s32 arg1, s32 arg2)
 
AuResult au_amb_is_stopped (s32 arg0)
 
void au_amb_play_sequence (AmbienceManager *arg0, MSEQHeader *mseq, s32 index)
 
void au_amb_manager_update (AmbienceManager *arg0)
 
void au_amb_load_track_fade_info (AmbienceManager *manager, AmbiencePlayer *lambda)
 
void au_amb_player_update (AmbienceManager *manager, AmbiencePlayer *lambda)
 
u8 au_amb_read_next (AmbiencePlayer *arg0)
 
void au_amb_player_stop (AmbienceManager *arg0, AmbiencePlayer *arg1)
 
void au_amb_save_voices (AmbienceManager *arg0, AmbiencePlayer *lambda)
 
void au_amb_restore_voices (AmbienceManager *manager, AmbiencePlayer *lambda)
 
void au_update_stopped_voices (AuGlobals *globals)
 
void au_init_voices (AuGlobals *globals)
 
void au_update_voices (AuGlobals *globals)
 
void au_voice_after_volume_change (AuVoice *arg0)
 
s32 au_voice_get_delta (s32 arg0)
 
void au_voice_start (AuVoice *voice, EnvelopeData *arg1)
 
u8 au_voice_step (AuVoice *voice)
 
void au_voice_set_vol_changed (AuVoice *arg0)
 
void func_80052E30 (u8 index)
 
void au_engine_init (s32 outputRate)
 
void au_update_clients_2 (void)
 
void au_update_players_main (void)
 
void au_syn_update (AuGlobals *globals)
 
void au_reset_nonfree_voice (AuVoice *arg0, u8 arg1)
 
void au_reset_voice (AuVoice *arg0, u8 arg1)
 
f32 au_compute_pitch_ratio (s32 arg0)
 
void au_fade_init (Fade *fade, s32 time, s32 startValue, s32 endValue)
 
void au_fade_clear (Fade *fade)
 
void au_fade_update (Fade *fade)
 
void au_fade_set_volume (u8 arg0, u16 arg1, s32 arg2)
 
void func_80053AC8 (Fade *fade)
 
void au_fade_set_vol_scale (Fade *fade, s16 value)
 
void func_80053B04 (Fade *fade, u32 arg1, s32 target)
 
void func_80053BA8 (Fade *fade)
 
Instrumentau_get_instrument (AuGlobals *globals, u32 bank, u32 patch, EnvelopeData *arg3)
 
void au_get_bgm_player_and_file (u32 playerIndex, BGMHeader **outCurrentTrackData, BGMPlayer **outPlayer)
 
void au_get_bgm_player (u32 playerIndex, BGMPlayer **outPlayer)
 
AuResult au_load_song_files (u32 arg0, BGMHeader *arg1, BGMPlayer *arg2)
 
AuResult func_80053E58 (s32 songID, BGMHeader *arg1)
 
BGMPlayerfunc_80053F64 (s32 arg0)
 
AuResult au_ambient_load (u32 arg0)
 
BGMPlayerfunc_80054248 (u8 arg0)
 
void au_load_INIT (AuGlobals *arg0, s32 romAddr, ALHeap *heap)
 
AuResult au_fetch_SBN_file (u32 fileIdx, AuFileFormat format, SBNFileEntry *arg2)
 
void au_load_PER (AuGlobals *globals, s32 romAddr)
 
void au_load_PRG (AuGlobals *arg0, s32 romAddr)
 
InstrumentGroupau_get_BK_instruments (s32 bankGroup, u32 bankIndex)
 
SoundBankau_load_BK_to_bank (s32 bkFileOffset, SoundBank *bank, s32 bankIndex, s32 bankGroup)
 
void au_swizzle_BK_instruments (s32 bkFileOffset, SoundBank *bank, InstrumentGroup instruments, u32 instrumentCount, u8 arg4)
 
s32 * func_80054AA0 (s32 *bkFileOffset, void *vaddr, s32 bankIndex, s32 bankGroup)
 
s32 snd_load_BK (s32 bkFileOffset, s32 bankIndex)
 
void func_80054C84 (s32 bankIndex, s32 bankGroup)
 
void func_80054CE0 (s32 arg0, u32 idx)
 
s32 func_80054D74 (s32 arg0, s32 arg1)
 
void func_80054DA8 (u32 arg0)
 
void au_read_rom (s32 romAddr, void *buffer, u32 size)
 
void au_memset (void *dst, s32 size, u8 value)
 
void au_copy_bytes (s8 *src, s8 *dest, s32 size)
 
void au_copy_words (void *src, void *dst, s32 size)
 
void create_audio_system (void)
 
void nuAuMgr (void *arg)
 
s32 nuAuDmaCallBack (s32 addr, s32 len, void *state, u8 arg3)
 
void au_load_BK_headers (AuGlobals *arg0, ALHeap *)
 
void au_sfx_init (SoundManager *manager, u8 arg1, u8 arg2, AuGlobals *arg3, u8 arg4)
 
void au_sfx_load_groups_from_SEF (SoundManager *sndMgr)
 
void au_sfx_clear_queue (SoundManager *manager)
 
void au_sfx_enqueue_event (SoundManager *manager, u32 soundID, s16 volume, s16 pitchShift, u8 pan)
 
void au_sfx_update_main (SoundManager *manager)
 
s32 au_sfx_set_reverb_type (SoundManager *manager, s32 arg1)
 
void au_sfx_set_state (SoundManager *manager, s32 arg1)
 
void au_sfx_load_sound (SoundManager *manager, SoundSFXEntry *entry, SoundManagerCustomCmdList *)
 
s16 au_sfx_manager_update (SoundManager *manager)
 
void au_bgm_update_main (BGMPlayer *player)
 
BGMPlayerau_bgm_get_player_with_song_name (s32 songString)
 
AuResult au_bgm_dispatch_player_event (SongUpdateEvent *event)
 
AuResult au_bgm_stop_song (s32 songName)
 
void au_bgm_stop_all (void)
 
AuResult au_bgm_is_song_playing (s32 songName)
 
s32 func_8004DB28 (BGMPlayer *player)
 
AuResult func_8004DB4C (SongUpdateEvent *s)
 
AuResult func_8004DC80 (s32 songName)
 
AuResult func_8004DCB8 (SongUpdateEvent *update, s32 clearChanged)
 
AuResult func_8004DE2C (SongUpdateEvent *update)
 
void func_8004DFD4 (AuGlobals *globals)
 
AuResult func_8004E0F4 (SongUpdateEvent *update)
 
void au_bgm_player_init (BGMPlayer *player, s32 arg1, s32 arg2, AuGlobals *arg3)
 
void au_bgm_set_effect_indices (BGMPlayer *player, u8 *list)
 
void au_bgm_update_fade (BGMPlayer *player)
 
void func_8004E444 (BGMPlayer *arg0)
 
s32 au_bgm_player_update_main (BGMPlayer *player)
 
void au_bgm_player_initialize (BGMPlayer *player)
 
void func_8004E844 (BGMPlayer *player, s32 arg1)
 
void func_8004E880 (BGMPlayer *player, s32 sampleRate, s32 divisor)
 
void au_bgm_player_read_segment (BGMPlayer *player)
 
void au_bgm_end_segment_loop (BGMPlayer *player, u32 cmd)
 
void au_bgm_load_subsegment (BGMPlayer *player, u32 cmd)
 
void au_bgm_player_update_stop (BGMPlayer *player)
 
void au_bgm_player_update_playing (BGMPlayer *player)
 
void au_BGMCmd_E0_MasterTempo (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_E1_MasterVolume (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_E2_MasterPitchShift (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_E3 (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_E6_MasterEffect (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_E4_MasterTempoFade (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_E5_MasterVolumeFade (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_E8_TrackOverridePatch (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_E9_SubTrackVolume (BGMPlayer *arg0, BGMPlayerTrack *track)
 
void au_BGMCmd_F6_TrackVolumeFade (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_EA_SubTrackPan (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_EB_SubTrackReverb (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_EC_SegTrackVolume (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_ED_SubTrackCoarseTune (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_EE_SubTrackFineTune (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_EF_SegTrackTune (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_F0_TrackTremolo (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_F1_TrackTremoloSpeed (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_F2_TrackTremoloTime (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_F3_TrackTremoloStop (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_F4 (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_F5_TrackVoice (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_F7_SubTrackReverbType (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_FD_EventTrigger (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_FE_Detour (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_FC_Jump (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_FF (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_BGMCmd_NOP (BGMPlayer *player, BGMPlayerTrack *track)
 
void au_bgm_set_proximity_mix (s32 songName, u32 mix)
 
void au_bgm_set_playback_rate (BGMPlayer *player, f32 arg1)
 
void au_bgm_player_set_detune (BGMPlayer *player, s32 arg1)
 
void au_bgm_change_track_volume (BGMPlayer *player, s32 trackIdx, s16 arg2, u8 arg3)
 
void au_bgm_set_track_volumes (BGMPlayer *player, u8 *arg1, s32 arg2)
 
void func_80050888 (BGMPlayer *player, BGMPlayerTrack *track, s32 target, s32 duration)
 
void func_80050900 (BGMPlayer *player)
 
AuResult func_80050970 (SongUpdateEvent *arg0)
 
void func_80055110 (BGMPlayer *player)
 
AuResult snd_song_get_playing_info (s32 songName, BGMHeader **outTrackData, BGMPlayer **outPlayer)
 
void au_register_callback (AuCallback arg0, s32 arg1)
 
void au_driver_init (AuSynDriver *driver, ALConfig *config)
 
void au_driver_release (void)
 
void au_use_global_volume (void)
 
void au_set_global_volume (s16 arg0)
 
s16 au_get_global_volume (void)
 
void func_80056D5C (u8 arg0)
 
void au_bus_set_volume (u8 arg0, u16 arg1)
 
u16 au_bus_get_volume (u8 arg0, u16 arg1)
 
void au_bus_set_effect (u8 arg0, u8 effectID)
 
void au_bus_set_fx_params (u8 arg0, s16 arg1, s16 arg2, s32 arg3)
 
void au_pvoice_set_bus (u8 arg0, s8 arg1)
 
void au_syn_stop_voice (u8 voiceIdx)
 
void au_syn_start_voice (u8 index)
 
void au_syn_start_voice_params (u8 index, u8 reverbType, Instrument *table, f32 pitch, s16 vol, u8 pan, u8 fxMix, s32 delta)
 
void au_syn_set_wavetable (u8 voiceIdx, Instrument *table)
 
void au_syn_set_pitch (u8 voiceIdx, f32 pitchRatio)
 
void au_syn_set_mixer_params (u8 voiceIdx, s16 volume, s32 arg2, u8 arg3, u8 arg4)
 
void au_syn_set_pan_fxmix (u8 voiceIdx, u8 arg1, u8 arg2)
 
void au_syn_set_volume_delta (u8 voiceIdx, s16 arg1, s32 arg2)
 
void au_syn_set_pan (u8 voiceIdx, u8 pan)
 
void au_syn_set_fxmix (u8 voiceIdx, u8 dryAmt)
 
s32 au_syn_get_playing (u8 voiceIdx)
 
s32 au_syn_get_bus (u8 voiceIdx)
 
f32 au_syn_get_pitch (u8 voiceIdx)
 
u8 au_syn_get_pan (u8 voiceIdx)
 
s16 au_syn_get_dryamt (u8 voiceIdx)
 
s16 au_syn_get_wetamt (u8 voiceIdx)
 
s32 au_syn_get_volume_left (u8 voiceIdx)
 
s32 au_syn_get_volume_right (u8 voiceIdx)
 
void au_set_delay_time (s32 arg0)
 
void au_delay_left_channel (u8 arg0)
 
void au_delay_right_channel (u8 arg0)
 
void au_disable_channel_delay (void)
 
void au_delay_channel (s16 arg0)
 
void * alHeapAlloc (ALHeap *heap, s32 arg1, s32 size)
 
Acmd * au_pull_voice (AuPVoice *pvoice, Acmd *cmdBufPos)
 
void func_80058E84 (AuFX *fx, u8 mode, ALHeap *heap)
 
void func_80058F88 (AlUnkKappa *kappa, ALHeap *heap)
 
void func_80059008 (AlUnkKappa *kappa, s16 arg1, s16 arg2, s16 fc)
 
void func_8005904C (AuFX *fx, u8 effectType)
 
Acmd * au_pull_fx (AuFX *fx, Acmd *cmdBusPos, s16, s16)
 
s32 au_fx_param_hdl (AuFX *fx, s16 index, s16 paramID, s32 value)
 
SoundInstancesfx_get_env_sound_instance (s32 soundID)
 

Function Documentation

◆ au_amb_manager_init()

void au_amb_manager_init ( AmbienceManager * arg0,
s8 arg1,
s8 reverbType,
AuGlobals * arg3 )

Definition at line 39 of file 2BF90.c.

39 {
40 AmbiencePlayer* player;
41 s32 i;
42
43 au_memset(manager, sizeof(*manager), 0);
44
45 for (i = 0; i < ARRAY_COUNT(manager->players); i++) {
46 player = &manager->players[i];
47 player->id.playerIndex = i;
48 player->delay = 1;
49 player->fadeVolume = 0x7F000000;
50 }
51
52 manager->globals = globals;
53 manager->nextUpdateStep = 1;
54 manager->nextUpdateCounter = 2;
55 manager->nextUpdateInterval = 2;
56 manager->priority = priority;
57 manager->busId = busId;
58}
void au_memset(void *dst, s32 size, u8 value)
AmbVoiceStateInfo id
Definition audio.h:1133
#define ARRAY_COUNT(arr)
Definition macros.h:40

Referenced by au_engine_init().

◆ au_amb_check_player_index()

AuResult au_amb_check_player_index ( u32 arg0)

◆ au_amb_load_tracks_fade()

void au_amb_load_tracks_fade ( s32 arg0,
s32 arg1 )

Definition at line 68 of file 2BF90.c.

68 {
70}
u8 loadTracksFadeInfo
Definition audio.h:1166

Referenced by snd_ambient_mute().

◆ au_amb_set_disabled()

void au_amb_set_disabled ( s32 arg0,
s32 arg1 )

Definition at line 72 of file 2BF90.c.

72 {
74 AmbiencePlayer* ambPlayer = &manager->players[index];
75
76 if (!disable) {
77 ambPlayer->playState = AMB_PLAYER_PLAYING;
78 } else {
79 ambPlayer->playState = AMB_PLAYER_STOPPING;
80 }
81}
@ AMB_PLAYER_PLAYING
Definition 2BF90.c:21
@ AMB_PLAYER_STOPPING
Definition 2BF90.c:23
AmbiencePlayer players[4]
Definition audio.h:1169

Referenced by snd_ambient_disable(), and snd_ambient_enable().

◆ au_amb_start()

AuResult au_amb_start ( s32 arg0,
s32 arg1 )

Definition at line 83 of file 2BF90.c.

83 {
84 AmbiencePlayer* player = &gAuAmbienceManager->players[index];
86 AuResult status = AU_RESULT_OK;
87
88 if (mseq != NULL) {
89 if (player->mseqName == 0) {
91 if (time != 0) {
92 player->fadeSettingsTime = time;
93 player->fadeSettingsInitial = 0;
94 player->fadeSettingsGoal = 127;
96 au_amb_fade_setup(player);
97 }
98 } else {
99 status = AU_AMBIENCE_ERROR_1;
100 }
101 } else {
102 status = AU_AMBIENCE_ERROR_2;
103 }
104 return status;
105}
@ AMB_FADE_IN
Definition 2BF90.c:15
void au_amb_fade_setup(AmbiencePlayer *player)
Definition 2BF90.c:107
void au_amb_play_sequence(AmbienceManager *manager, MSEQHeader *mseqFile, s32 index)
Definition 2BF90.c:219
MSEQHeader * mseqFiles[4]
Definition audio.h:1164
u8 fadeSettingsType
Definition audio.h:1139
u8 fadeSettingsGoal
Definition audio.h:1143
u16 fadeSettingsTime
Definition audio.h:1141
u8 fadeSettingsInitial
Definition audio.h:1142
AuResult
Definition enums.h:1755
@ AU_AMBIENCE_ERROR_2
Definition enums.h:1760
@ AU_AMBIENCE_ERROR_1
Definition enums.h:1758

Referenced by snd_ambient_play().

◆ au_amb_fade_setup()

void au_amb_fade_setup ( AmbiencePlayer * arg0)

Definition at line 107 of file 2BF90.c.

107 {
108 u16 time = player->fadeSettingsTime;
109
110 if (player->fadeSettingsInitial == 255) {
111 player->fadeSettingsInitial = player->fadeVolume >> 0x18;
112 }
113
114 if (time >= SND_MIN_DURATION && time <= SND_MAX_DURATION) {
115 player->fadeVolume = player->fadeSettingsInitial << 0x18;
116 player->fadeGoal = player->fadeSettingsGoal;
117 player->fadeTime = (u32)(time * 10) / 115; // TODO figure out why is the ratio like this
118 player->fadeStep = ((player->fadeSettingsGoal - player->fadeSettingsInitial) << 0x18) / ((s16)player->fadeTime & 0xFFFF);
119 }
120
121 player->fadeSettingsTime = 0;
122 player->fadeSettingsInitial = 0;
123 player->fadeSettingsGoal = 0;
124}
#define SND_MIN_DURATION
Definition audio.h:55
#define SND_MAX_DURATION
Definition audio.h:56

Referenced by au_amb_manager_update(), and au_amb_start().

◆ au_amb_pause()

void au_amb_pause ( s32 arg0,
s32 arg1 )

Definition at line 126 of file 2BF90.c.

126 {
127 AmbiencePlayer* player = &gAuAmbienceManager->players[index];
128
129 if (player->mseqReadStart != NULL && player->mseqReadPos != NULL) {
130 if (time != 0) {
131 player->fadeSettingsInitial = 255;
132 player->fadeSettingsTime = time;
133 player->fadeSettingsGoal = 0;
135 return;
136 }
137 player->mode = AMB_MODE_PAUSING;
138 }
139}
@ AMB_FADE_OUT_PAUSING
Definition 2BF90.c:17
@ AMB_MODE_PAUSING
Definition 2BF90.c:11
AuFilePos mseqReadPos
Definition audio.h:1131
AuFilePos mseqReadStart
Definition audio.h:1130

Referenced by snd_ambient_pause().

◆ au_amb_resume()

void au_amb_resume ( s32 arg0,
s32 arg1 )

Definition at line 141 of file 2BF90.c.

141 {
142 AmbiencePlayer* player = &gAuAmbienceManager->players[index];
143
144 if (player->mseqReadStart != NULL && player->mseqReadPos != NULL) {
145 player->mode = AMB_MODE_RESUMING;
146 if (time != 0) {
147 player->fadeSettingsTime = time;
148 } else {
150 }
151 player->fadeSettingsInitial = 0;
154 }
155}
@ AMB_MODE_RESUMING
Definition 2BF90.c:9
#define SND_MAX_VOLUME_8
Definition audio.h:49

Referenced by snd_ambient_resume().

◆ au_amb_stop_quick()

void au_amb_stop_quick ( s32 arg0)

Definition at line 157 of file 2BF90.c.

157 {
158 AmbiencePlayer* player = &gAuAmbienceManager->players[index];
159
160 if (player->mseqReadStart != NULL && player->mseqReadPos != NULL) {
161 if (player->mode != AMB_MODE_NORMAL) {
162 player->mseqReadPos = NULL;
163 player->mseqName = 0;
164 player->mode = AMB_MODE_NORMAL;
165 return;
166 }
167 player->mseqReadPos = BlankMseqData;
168 player->delay = 1;
169 }
170}
@ AMB_MODE_NORMAL
Definition 2BF90.c:8
u8 BlankMseqData[]
Definition sfx_player.c:279

Referenced by snd_ambient_stop_quick().

◆ au_amb_stop_slow()

void au_amb_stop_slow ( s32 arg0,
s32 arg1 )

Definition at line 172 of file 2BF90.c.

172 {
173 AmbiencePlayer* player = &gAuAmbienceManager->players[index];
174
175 if (player->mseqReadStart != NULL && player->mseqReadPos != NULL) {
176 if (time != 0) {
177 player->fadeSettingsTime = time;
178 } else {
180 }
181 player->fadeSettingsInitial = 255;
182 player->fadeSettingsGoal = 0;
184 }
185}
@ AMB_FADE_OUT
Definition 2BF90.c:16

Referenced by snd_ambient_stop_slow().

◆ au_amb_set_volume()

void au_amb_set_volume ( s32 arg0,
s32 arg1,
s32 arg2 )

Definition at line 187 of file 2BF90.c.

187 {
188 AmbiencePlayer* player = &gAuAmbienceManager->players[index];
189 if ((player->mseqReadStart != 0) && (player->mseqReadPos != 0)) {
190 if (volume <= 0) {
191 volume = 1;
192 } else if (volume > SND_MAX_VOLUME_8) {
193 volume = SND_MAX_VOLUME_8;
194 }
195 if (time != 0) {
196 player->fadeSettingsTime = time;
197 } else {
199 }
200 player->fadeSettingsInitial = 255;
201 player->fadeSettingsGoal = volume;
203 }
204}

Referenced by snd_ambient_set_volume().

◆ au_amb_is_stopped()

AuResult au_amb_is_stopped ( s32 arg0)

Definition at line 206 of file 2BF90.c.

206 {
207 AmbiencePlayer* player = &gAuAmbienceManager->players[index];
208 AuResult status = AU_RESULT_OK;
209
210 if (player->mseqReadStart != NULL && player->mseqReadPos != NULL) {
211 status = AU_AMBIENCE_ERROR_1;
212 if (player->mode != AMB_MODE_NORMAL) {
213 status = AU_AMBIENCE_ERROR_2;
214 }
215 }
216 return status;
217}

Referenced by snd_ambient_is_stopped().

◆ au_amb_play_sequence()

void au_amb_play_sequence ( AmbienceManager * arg0,
MSEQHeader * mseq,
s32 index )

Definition at line 219 of file 2BF90.c.

219 {
220 AmbiencePlayer* player;
221 AmbienceTrack* track;
222 AuFilePos readPos;
223 s32 i;
224
225 player = &manager->players[index];
226 au_memset(player, sizeof(*player), 0);
227
228 player->mseqFile = mseqFile;
229 readPos = AU_FILE_RELATIVE(mseqFile->dataStart, mseqFile);
230 player->id.playerIndex = index;
231 player->mseqReadPos = readPos;
232 player->loopStartPos[1] = readPos;
233 player->loopStartPos[0] = readPos;
234 player->mseqReadStart = readPos;
235
236 player->delay = 1;
237 player->fadeVolume = 0x7F000000;
238 player->fadeGoal = 0x7F;
239
240 player->mseqName = player->mseqFile->name;
241 player->firstVoiceIdx = player->mseqFile->firstVoiceIdx;
242 player->lastVoiceIdx = player->firstVoiceIdx + 16;
243 if (player->lastVoiceIdx > 24) {
244 player->lastVoiceIdx = 24;
245 }
246 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
247 track = &player->tracks[i];
248 track->instrument = manager->globals->defaultInstrument;
249 track->volumeLerp.current = 0x7FFFFFFF;
250 track->pan = 64;
251 }
252 player->resetRequired = TRUE;
253}
u32 firstVoiceIdx
Definition audio.h:1146
MSEQHeader * mseqFile
Definition audio.h:1129
Instrument * instrument
Definition audio.h:1104
AmbienceTrack tracks[10]
Definition audio.h:1153
s32 current
Definition audio.h:577
#define AU_FILE_RELATIVE(base, offset)
Definition audio.h:40
SoundLerp volumeLerp
Definition audio.h:1107
s32 name
Definition audio.h:1096
AuFilePos loopStartPos[2]
Definition audio.h:1132
u8 firstVoiceIdx
Definition audio.h:1097
u32 lastVoiceIdx
Definition audio.h:1147
u8 * AuFilePos
Definition audio.h:14

Referenced by au_amb_start().

◆ au_amb_manager_update()

void au_amb_manager_update ( AmbienceManager * arg0)

Definition at line 255 of file 2BF90.c.

255 {
256 u32 i;
257 s32 j;
258
259 for (i = 0; i < ARRAY_COUNT(manager->voiceStates); i++) {
260 AmbienceVoiceState* voiceState = &manager->voiceStates[i];
261
262 if (voiceState->info.released == TRUE && manager->globals->voices[i].priority != manager->priority) {
263 voiceState->info.all = 0;
264 }
265 }
266
267 for (j = 0; j < ARRAY_COUNT(manager->players); j++) {
268 AmbiencePlayer* player = &manager->players[j];
269 s32 mode;
270
271 if (player->mseqReadPos != NULL) {
272 if (manager->loadTracksFadeInfo) {
273 au_amb_load_track_fade_info(manager, player);
274 }
275
276 mode = player->mode;
277 if (mode != AMB_MODE_NORMAL) {
278 if (mode == AMB_MODE_PAUSING) {
279 player->mode = AMB_MODE_STOPPED;
280 au_amb_save_voices(manager, player);
281 au_amb_player_stop(manager, player);
282 } else if (player->mode == AMB_MODE_RESUMING) {
283 player->mode = AMB_MODE_NORMAL;
284 if (player->fadeSettingsTime != 0) {
285 au_amb_fade_setup(player);
286 }
287 au_amb_restore_voices(manager, player);
288 }
289 } else {
290 // case AMB_MODE_NORMAL
291 if (player->fadeSettingsTime != 0) {
292 au_amb_fade_setup(player);
293 }
294 if (player->playState == AMB_PLAYER_STOPPING) {
295 au_amb_player_stop(manager, player);
297 }
298 au_amb_player_update(manager, player);
299 }
300 }
301 }
302
303 manager->loadTracksFadeInfo = FALSE;
304}
void au_amb_player_stop(AmbienceManager *manager, AmbiencePlayer *player)
Definition 2BF90.c:688
void au_amb_player_update(AmbienceManager *manager, AmbiencePlayer *player)
Definition 2BF90.c:333
void au_amb_restore_voices(AmbienceManager *manager, AmbiencePlayer *player)
Definition 2BF90.c:729
void au_amb_load_track_fade_info(AmbienceManager *manager, AmbiencePlayer *player)
Definition 2BF90.c:306
void au_amb_save_voices(AmbienceManager *arg0, AmbiencePlayer *player)
Definition 2BF90.c:705
@ AMB_MODE_STOPPED
Definition 2BF90.c:10
@ AMB_PLAYER_STOPPED
Definition 2BF90.c:22
AmbVoiceStateInfo info
Definition audio.h:1122

Referenced by au_update_clients_2().

◆ au_amb_load_track_fade_info()

void au_amb_load_track_fade_info ( AmbienceManager * manager,
AmbiencePlayer * lambda )

Definition at line 306 of file 2BF90.c.

306 {
307 MSEQHeader* mseqFile;
308 MSEQTrackData* trackData;
309 AmbienceTrack* track;
310 s32 offset;
311 s32 count;
312
313 mseqFile = player->mseqFile;
314 count = mseqFile->trackSettingsCount;
315 if (count != 0 && mseqFile->trackSettingsOffset != 0) {
316 trackData = AU_FILE_RELATIVE(mseqFile->trackSettingsOffset, mseqFile);
317 while (count--) {
318 track = &player->tracks[trackData->trackIndex];
319 if (trackData->type == 0) {
320 track->tuneLerp.time = trackData->time;
321 track->tuneLerp.step = (trackData->delta << 0x10) / trackData->time;
322 track->tuneLerp.goal = trackData->goal;
323 } else if (trackData->type == 1) {
324 track->volumeLerp.time = trackData->time;
325 track->volumeLerp.step = (trackData->delta << 0x10) / trackData->time;
326 track->volumeLerp.goal = trackData->goal;
327 }
328 trackData++;
329 }
330 }
331}
u8 trackSettingsCount
Definition audio.h:1098
s32 step
Definition audio.h:578
SoundLerp tuneLerp
Definition audio.h:1106
s16 time
Definition audio.h:579
u16 trackSettingsOffset
Definition audio.h:1099
s16 goal
Definition audio.h:580

Referenced by au_amb_manager_update().

◆ au_amb_player_update()

void au_amb_player_update ( AmbienceManager * manager,
AmbiencePlayer * lambda )

Definition at line 333 of file 2BF90.c.

333 {
334 u8 isVolumeChanged[16];
335 u8 isPitchChanged[16];
336 AuGlobals* globals;
337 u8 fadeVolChanged;
338 AmbienceVoiceState* voiceState;
339 AuVoice* voice;
340 BGMDrumInfo* drum;
341 u32 trackIdx;
342 s32 temp;
343 s32 i;
344 u16 bankPatch;
345 u32 count;
346 s32 loopId;
347 u8 op, arg1, arg2;
348 AmbienceTrack* track;
349
350 globals = manager->globals;
351 fadeVolChanged = FALSE;
352 for (i = 0; i < 16U; i++) { // required to use unsigned literal
353 isVolumeChanged[i] = FALSE;
354 isPitchChanged[i] = FALSE;
355 }
356
357 if (player->resetRequired == TRUE) {
358 au_amb_player_stop(manager, player);
359 player->resetRequired = FALSE;
360 }
361
362 if (player->fadeTime != 0) {
363 player->fadeVolume += player->fadeStep;
364 player->fadeTime--;
365 if (player->fadeTime == 0) {
366 player->fadeVolume = player->fadeGoal << 0x18;
367 if (player->fadeSettingsType == AMB_FADE_IN) {
368 // do nothing
369 } else if (player->fadeSettingsType == AMB_FADE_OUT) {
370 player->mseqReadPos = BlankMseqData;
371 player->delay = 1;
372 } else if (player->fadeSettingsType == AMB_FADE_OUT_PAUSING) {
373 player->mode = AMB_MODE_PAUSING;
374 }
375 }
376 fadeVolChanged = TRUE;
377 }
378
379 // update pitch
380 for (trackIdx = 0; trackIdx < ARRAY_COUNT(player->tracks); trackIdx++) {
381 track = &player->tracks[trackIdx];
382 if (track->tuneLerp.time != 0) {
383 track->tuneLerp.time--;
384 if (track->tuneLerp.time != 0) {
385 track->tuneLerp.current += track->tuneLerp.step;
386 } else {
387 track->tuneLerp.current = track->tuneLerp.goal << 0x10;
388 }
389
390 temp = player->id.all + (trackIdx << 0x10);
391 for (i = player->firstVoiceIdx; i < player->lastVoiceIdx; i++) {
392 voiceState = &manager->voiceStates[i - player->firstVoiceIdx];
393 // update all voices belonging to current track
394 if ((voiceState->info.all & 0xFFFF0000) == temp) {
395 voice = &globals->voices[i];
396 if (voice->priority == manager->priority && trackIdx != TRACK_ID_DRUM) {
397 voice->pitchRatio = au_compute_pitch_ratio(voiceState->pitch + (track->tuneLerp.current >> 0x10)) * track->instrument->pitchRatio;
399 isPitchChanged[i - player->firstVoiceIdx] = TRUE;
400 }
401 }
402 }
403 }
404 }
405
406 // update volume
407 for (trackIdx = 0; trackIdx < ARRAY_COUNT(player->tracks); trackIdx++) {
408 track = &player->tracks[trackIdx];
409 if (track->volumeLerp.time != 0) {
410 track->volumeLerp.time--;
411 if (track->volumeLerp.time != 0) {
412 track->volumeLerp.current += track->volumeLerp.step;
413 } else {
414 track->volumeLerp.current = track->volumeLerp.goal << 0x10;
415 }
416
417 temp = player->id.all + (trackIdx << 0x10);
418 for (i = player->firstVoiceIdx; i < player->lastVoiceIdx; i++) {
419 voiceState = &manager->voiceStates[i - player->firstVoiceIdx];
420 // update all voices belonging to current track
421 if ((voiceState->info.all & 0xFFFF0000) == temp) {
422 voice = &globals->voices[i];
423 if (voice->priority == manager->priority) {
424 track = &player->tracks[voiceState->info.trackIndex];
425 voice->clientVolume = ((player->fadeVolume >> 0x18) * (track->volumeLerp.current >> 0x10) * voiceState->volume) >> 0xE;
427 }
428 }
429 }
430 }
431 }
432
433 player->delay--;
434 if (player->delay <= 0) {
435 while (player->delay == 0) {
436 op = au_amb_read_next(player);
437 if ((s8)op >= 0) {
438 if (op == 0) {
439 // stop
440 player->mseqReadPos = NULL;
441 player->mseqName = 0;
442 au_amb_player_stop(manager, player);
443 break;
444 }
445 if (op >= 0x78) {
446 // long delay
447 player->delay = ((op & 7) << 8) + au_amb_read_next(player) + 0x78;
448 } else {
449 //short delay
450 player->delay = op;
451 }
452 continue;
453 }
454
455 // op >= 0x80
456 // op & 0xF0 : command
457 // op & 0xF : track index
458
459 arg1 = au_amb_read_next(player);
460 trackIdx = op & 0xF;
461 track = &player->tracks[trackIdx];
462
463 switch (op & 0xF0) {
465 // arg1: sound index
466 if (player->playState == AMB_PLAYER_PLAYING) {
467 temp = player->id.all + (trackIdx << 0x10) + (arg1 << 8);
468 for (i = player->firstVoiceIdx; i < player->lastVoiceIdx; i++) {
469 if (manager->voiceStates[i - player->firstVoiceIdx].info.all == temp) {
470 manager->voiceStates[i - player->firstVoiceIdx].info.released = 1;
471 voice = &globals->voices[i];
472 if (voice->priority == manager->priority) {
474 }
475 }
476 }
477 }
478 break;
480 // arg1: pitch or drum sound id
481 // arg2: volume
482 arg2 = au_amb_read_next(player);
483 if (player->playState == AMB_PLAYER_PLAYING) {
484 // find free voice
485 for (i = player->firstVoiceIdx; i < player->lastVoiceIdx; i++) {
486 voice = &globals->voices[i];
487 if (voice->priority == AU_PRIORITY_FREE) {
488 break;
489 }
490 }
491 if (i >= player->lastVoiceIdx) {
492 // use another ambience voice
493 for (i = player->firstVoiceIdx; i < player->lastVoiceIdx; i++) {
494 voice = &globals->voices[i];
495 if (voice->priority == manager->priority) {
496 au_reset_voice(voice, i);
497 break;
498 }
499 }
500 }
501 if (i >= player->lastVoiceIdx) {
502 // try stealing voice with lower priority
503 for (i = player->firstVoiceIdx; i < player->lastVoiceIdx; i++) {
504 voice = &globals->voices[i];
505 if (voice->priority < manager->priority) {
506 au_reset_voice(voice, i);
507 break;
508 }
509 }
510 }
511 if (i < player->lastVoiceIdx) {
512 isVolumeChanged[i - player->firstVoiceIdx] = TRUE;
513 isPitchChanged[i - player->firstVoiceIdx] = TRUE;
514 voiceState = &manager->voiceStates[i - player->firstVoiceIdx];
515 // set playerIndex, trackIndex and tune
516 voiceState->info.all = player->id.all + (trackIdx << 0x10) + (arg1 << 8);
517 if (track->flags & 1) {
518 voiceState->isResumable = TRUE;
519 } else {
520 voiceState->isResumable = FALSE;
521 }
522 if (trackIdx != TRACK_ID_DRUM) {
523 if (track->flags & 1) {
524 voiceState->isResumable = TRUE;
525 } else {
526 voiceState->isResumable = FALSE;
527 }
528
529 voiceState->pitch = (arg1 & 0x7F) * 100 - track->instrument->keyBase;
530 voiceState->volume = arg2 & 0x7F;
531 voice->clientVolume = ((player->fadeVolume >> 0x18) * (track->volumeLerp.current >> 0x10) * voiceState->volume) >> 0xE;
532 voice->pitchRatio = au_compute_pitch_ratio(voiceState->pitch + (track->tuneLerp.current >> 0x10)) * track->instrument->pitchRatio;
533 voice->pan = track->pan;
534 voice->reverb = track->reverb;
535 voice->instrument = track->instrument;
536 voice->busId = manager->busId;
539 } else {
540 voiceState->isResumable = FALSE;
541 drum = &manager->globals->dataPER->drums[arg1 & 0x7F];
542 bankPatch = drum->bankPatch;
543 voice->instrument = au_get_instrument(manager->globals, bankPatch >> 8, bankPatch & 0xFF, &voice->envelope);
544 voiceState->pitch = drum->keyBase - voice->instrument->keyBase;
545 voiceState->volume = ((arg2 & 0x7F) * drum->volume) >> 7;
546 voice->clientVolume = ((player->fadeVolume >> 0x18) * (track->volumeLerp.current >> 0x10) * voiceState->volume) >> 0xE;
547 voice->pitchRatio = au_compute_pitch_ratio(voiceState->pitch) * voice->instrument->pitchRatio;
548 voice->pan = drum->pan;
549 voice->reverb = drum->reverb;
550 voice->busId = manager->busId;
551 }
553 voice->priority = manager->priority;
554 voice->clientPriority = voice->priority;
555 }
556 }
557 break;
559 // higher bit: set pan (1) or volume (0)
560 // lower 7 bits: value
561 if (arg1 & 0x80) {
562 track->pan = arg1 & 0x7F;
563 temp = player->id.all + (trackIdx << 0x10);
564 for (i = player->firstVoiceIdx; i < player->lastVoiceIdx; i++) {
565 voiceState = &manager->voiceStates[i - player->firstVoiceIdx];
566 if ((voiceState->info.all & 0xFFFF0000) == temp) {
567 voice = &globals->voices[i];
568 if (voice->priority == manager->priority && trackIdx != TRACK_ID_DRUM) {
569 voice->pan = track->pan;
571 }
572 }
573 }
574 } else {
575 track->volumeLerp.current = arg1 << 0x18;
576 if (track->volumeLerp.current != 0) {
577 track->volumeLerp.current |= 0xFFFFFF;
578 }
579 temp = player->id.all + (trackIdx << 0x10);
580 for (i = player->firstVoiceIdx; i < player->lastVoiceIdx; i++) {
581 voiceState = &manager->voiceStates[i - player->firstVoiceIdx];
582 if ((voiceState->info.all & 0xFFFF0000) == temp) {
583 voice = &globals->voices[i];
584 if (voice->priority == manager->priority) {
585 voice->clientVolume = ((player->fadeVolume >> 0x18) * (track->volumeLerp.current >> 0x10) * voiceState->volume) >> 0xE;
586 if (!isVolumeChanged[i - player->firstVoiceIdx]) {
588 isVolumeChanged[i - player->firstVoiceIdx] = TRUE;
589 }
590 }
591 }
592 }
593 }
594 break;
596 // arg1: sub command
597 // arg2: depends on sub command
598 arg2 = au_amb_read_next(player);
599 switch (arg1) {
601 // arg2: loop id
602 player->loopStartPos[arg2 & 1] = player->mseqReadPos;
603 break;
605 // arg2 lower bit: loop id
606 // (arg2 & 0x7C) >> 2: loop count
607 loopId = arg2 & 1;
608 count = (arg2 & 0x7C) >> 2;
609 if (count != 0) {
610 if (player->loopCount[loopId] != 0) {
611 player->loopCount[loopId]--;
612 // if it's the last iteration then don't jump to the loop start
613 if (player->loopCount[loopId] != 0) {
614 player->mseqReadPos = player->loopStartPos[loopId];
615 }
616 } else {
617 // first iteration, set loop counter
618 player->mseqReadPos = player->loopStartPos[loopId];
619 player->loopCount[loopId] = count;
620 }
621 } else {
622 // infinite loop
623 player->mseqReadPos = player->loopStartPos[loopId];
624 player->loopCount[loopId] = 0;
625 }
626 break;
628 track->reverb = arg2;
629 break;
631 if (arg2 == 1) {
632 track->flags |= 1;
633 }
634 break;
635 }
636 break;
638 // arg1: bank
639 // arg2: patch
640 arg2 = au_amb_read_next(player);
641 if (trackIdx != TRACK_ID_DRUM) {
642 track->instrument = au_get_instrument(manager->globals, arg1, arg2, &track->envelope);
643 }
644 break;
646 // arg1: coarse tune
647 // arg2: fine tune
648 track->tuneLerp.current = (arg1 << 0x18) + (au_amb_read_next(player) << 0x10);
649 temp = player->id.all + (trackIdx << 0x10);
650 for (i = player->firstVoiceIdx; i < player->lastVoiceIdx; i++) {
651 voiceState = &manager->voiceStates[i - player->firstVoiceIdx];
652 if ((voiceState->info.all & 0xFFFF0000) == temp) {
653 voice = &globals->voices[i];
654 if (voice->priority == manager->priority && trackIdx != TRACK_ID_DRUM) {
655 voice->pitchRatio = au_compute_pitch_ratio(voiceState->pitch + (track->tuneLerp.current >> 0x10)) * track->instrument->pitchRatio;
657 isPitchChanged[i - player->firstVoiceIdx] = 1;
658 }
659 }
660 }
661 break;
662 case 0xF0: // required to match
663 break;
664 }
665 }
666 }
667 if (fadeVolChanged) {
668 for (i = player->firstVoiceIdx; i < player->lastVoiceIdx; i++) {
669 voiceState = &manager->voiceStates[i - player->firstVoiceIdx];
670 // update all voices belonging to this player
671 if ((voiceState->info.all & 0xFF000000) == player->id.all) {
672 voice = &globals->voices[i];
673 if (voice->priority == manager->priority && !isVolumeChanged[i - player->firstVoiceIdx]) {
674 track = &player->tracks[voiceState->info.trackIndex];
675 voice->clientVolume = ((player->fadeVolume >> 0x18) * (track->volumeLerp.current >> 0x10) * voiceState->volume) >> 0xE;
677 }
678 }
679 }
680 }
681}
u8 au_amb_read_next(AmbiencePlayer *state)
Definition 2BF90.c:683
#define TRACK_ID_DRUM
Definition 2BF90.c:5
@ MSEQ_CMD_C0_SET_INSTRUMENT
Definition 2BF90.c:31
@ MSEQ_CMD_SUB_68_SET_REVERB
Definition 2BF90.c:35
@ MSEQ_CMD_SUB_67_END_LOOP
Definition 2BF90.c:34
@ MSEQ_CMD_SUB_69_SET_RESUMABLE
Definition 2BF90.c:36
@ MSEQ_CMD_90_PLAY_SOUND
Definition 2BF90.c:28
@ MSEQ_CMD_B0_MULTI
Definition 2BF90.c:30
@ MSEQ_CMD_SUB_66_START_LOOP
Definition 2BF90.c:33
@ MSEQ_CMD_A0_SET_VOLUME_PAN
Definition 2BF90.c:29
@ MSEQ_CMD_80_STOP_SOUND
Definition 2BF90.c:27
@ MSEQ_CMD_E0_TUNING
Definition 2BF90.c:32
void au_reset_voice(AuVoice *voice, u8 voiceIdx)
Instrument * au_get_instrument(AuGlobals *globals, u32 bank, u32 patch, EnvelopeData *envData)
f32 au_compute_pitch_ratio(s32 pitch)
u8 * cmdListPress
Definition audio.h:533
AuVoice voices[24]
Definition audio.h:938
u8 * cmdListRelease
Definition audio.h:534
EnvelopeData envelope
Definition audio.h:721
s16 keyBase
Definition audio.h:765
BGMDrumInfo drums[12]
Definition audio.h:831
f32 pitchRatio
Definition audio.h:714
@ AU_VOICE_SYNC_FLAG_PAN_FXMIX
Definition audio.h:83
@ AU_VOICE_SYNC_FLAG_PITCH
Definition audio.h:82
@ AU_VOICE_SYNC_FLAG_ALL
Definition audio.h:80
s16 bankPatch
Definition audio.h:764
s8 clientPriority
Definition audio.h:740
s16 clientVolume
Definition audio.h:737
AmbienceVoiceState voiceStates[16]
Definition audio.h:1170
u8 pan
Definition audio.h:717
u8 volume
Definition audio.h:766
u8 syncFlags
Definition audio.h:739
Instrument * instrument
Definition audio.h:713
PEREntry * dataPER
Definition audio.h:908
u8 envelopeFlags
Definition audio.h:734
s8 reverb
Definition audio.h:768
u8 reverb
Definition audio.h:718
u16 keyBase
Definition audio.h:558
@ AU_PRIORITY_FREE
Definition audio.h:65
EnvelopeData envelope
Definition audio.h:1105
AuGlobals * globals
Definition audio.h:1160
u8 busId
Definition audio.h:719
@ AU_VOICE_ENV_FLAG_KEY_RELEASED
Definition audio.h:75
@ AU_VOICE_ENV_FLAG_VOL_CHANGED
Definition audio.h:76
u8 priority
Definition audio.h:741

Referenced by au_amb_manager_update().

◆ au_amb_read_next()

u8 au_amb_read_next ( AmbiencePlayer * arg0)

Definition at line 683 of file 2BF90.c.

683 {
684 u8 value = *state->mseqReadPos++;
685 return value;
686}

Referenced by au_amb_player_update().

◆ au_amb_player_stop()

void au_amb_player_stop ( AmbienceManager * arg0,
AmbiencePlayer * arg1 )

Definition at line 688 of file 2BF90.c.

688 {
689 AuVoice* voice;
690 AmbienceVoiceState* voiceState;
691 s32 i;
692
693 for (i = player->firstVoiceIdx; i < player->lastVoiceIdx; i++) {
694 voiceState = &manager->voiceStates[i - player->firstVoiceIdx];
695 if (voiceState->info.playerIndex == player->id.playerIndex) {
696 voice = &manager->globals->voices[i];
697 if (voice->priority == manager->priority) {
698 au_reset_voice(voice, i);
699 }
700 voiceState->info.all = 0;
701 }
702 }
703}

Referenced by au_amb_manager_update(), and au_amb_player_update().

◆ au_amb_save_voices()

void au_amb_save_voices ( AmbienceManager * arg0,
AmbiencePlayer * lambda )

Definition at line 705 of file 2BF90.c.

705 {
706 AmbienceSavedVoice* savedVoice = player->savedVoices;
707 u32 numSaved = 0;
708 s32 i;
709
710 for (i = player->firstVoiceIdx; i < player->lastVoiceIdx; i++) {
711 AmbienceVoiceState* voiceState = &arg0->voiceStates[i - player->firstVoiceIdx];
712
713 if (!voiceState->isResumable) {
714 continue;
715 }
716
717 savedVoice->trackIndex = voiceState->info.trackIndex;
718 savedVoice->tune = voiceState->info.tune;
719 savedVoice->volume = voiceState->volume;
720
721 savedVoice++;
722 numSaved++;
723 if (numSaved >= ARRAY_COUNT(player->savedVoices)) {
724 break;
725 }
726 }
727}

Referenced by au_amb_manager_update().

◆ au_amb_restore_voices()

void au_amb_restore_voices ( AmbienceManager * manager,
AmbiencePlayer * lambda )

Definition at line 729 of file 2BF90.c.

729 {
730 AuGlobals* globals;
731 AuVoice* voice;
732 AmbienceSavedVoice* savedVoice;
733 AmbienceVoiceState* voiceState;
734 AmbienceTrack* track;
735 u32 i, j;
736
737 globals = manager->globals;
738 if (player->playState == AMB_PLAYER_PLAYING) {
739 for (i = 0; i < ARRAY_COUNT(player->savedVoices); i++) {
740 savedVoice = &player->savedVoices[i];
741 if (savedVoice->tune != 0) {
742 track = &player->tracks[savedVoice->trackIndex];
743
744 // find first free voice
745 for (j = player->firstVoiceIdx; j < player->lastVoiceIdx; j++) {
746 voice = &globals->voices[j];
747 if (voice->priority == AU_PRIORITY_FREE) {
748 break;
749 }
750 }
751
752 // try stealing a voice with lower priority
753 if (j >= player->lastVoiceIdx) {
754 for (j = player->firstVoiceIdx; j < player->lastVoiceIdx; j++) {
755 voice = &globals->voices[j];
756 if (voice->priority < manager->priority) {
757 au_reset_voice(voice, j);
758 break;
759 }
760 }
761 }
762
763 if (j < player->lastVoiceIdx) {
764 voiceState = &manager->voiceStates[j - player->firstVoiceIdx];
765 voiceState->info.all = player->id.all + (savedVoice->trackIndex << 0x10) + (savedVoice->tune << 8);
766 voiceState->pitch = (savedVoice->tune & 0x7F) * 100 - track->instrument->keyBase;
767 voiceState->volume = savedVoice->volume & 0x7F;
768 voice->clientVolume = ((player->fadeVolume >> 0x18) * (track->volumeLerp.current >> 0x10) * voiceState->volume) >> 0xE;
769 voice->pitchRatio = au_compute_pitch_ratio(voiceState->pitch + (track->tuneLerp.current >> 0x10)) * track->instrument->pitchRatio;
770 voice->pan = track->pan;
771 voice->reverb = track->reverb;
772 voice->instrument = track->instrument;
773 voice->busId = manager->busId;
777 voice->priority = manager->priority;
778 voice->clientPriority = voice->priority;
779 }
780 }
781 savedVoice->trackIndex = 0;
782 savedVoice->tune = 0;
783 savedVoice->volume = 0;
784 }
785 }
786}

Referenced by au_amb_manager_update().

◆ au_update_stopped_voices()

void au_update_stopped_voices ( AuGlobals * globals)

Definition at line 4 of file 2d9a0_len_890.c.

4 {
5 s32 i;
6
7 for (i = 0; i < ARRAY_COUNT(globals->voices); i++) {
8 AuVoice* voice = &globals->voices[i];
9
10 if (voice->stopPending) {
12 voice->stopPending = FALSE;
13 voice->cmdPtr = NULL;
15 }
16 }
17}
void au_syn_stop_voice(u8 voiceIdx)
Definition 31650.c:301
u8 stopPending
Definition audio.h:738
u8 * cmdPtr
Definition audio.h:722

◆ au_init_voices()

void au_init_voices ( AuGlobals * globals)

Definition at line 19 of file 2d9a0_len_890.c.

19 {
20 s32 i;
21
22 for (i = 0; i < ARRAY_COUNT(globals->voices); i++) {
23 AuVoice* voice = &globals->voices[i];
24
25 voice->cmdPtr = NULL;
26 voice->unk_20 = 0;
27 voice->volChangeTime = 0;
28 voice->timeLeft = 0;
29 voice->timeIntervalIndex = 0;
30 voice->unk_3C = 0;
31 voice->envelopeFlags = 0;
32 voice->relativeReleaseVolumes = FALSE;
33 voice->releaseVolumeMult = 0x80;
34 }
35}
u8 relativeReleaseVolumes
Definition audio.h:735
u8 timeIntervalIndex
Definition audio.h:732
s32 volChangeTime
Definition audio.h:724
u8 unk_3C
Definition audio.h:733
u8 releaseVolumeMult
Definition audio.h:736
s32 unk_20
Definition audio.h:723
s32 timeLeft
Definition audio.h:725

Referenced by au_engine_init().

◆ au_update_voices()

void au_update_voices ( AuGlobals * globals)

Definition at line 37 of file 2d9a0_len_890.c.

37 {
38 AuVoice* voice;
39 s8 var_a0;
40 s16 currentAmp;
41 s32 i;
42
43 for (i = 0; i < ARRAY_COUNT(globals->voices); i++) {
44 voice = &globals->voices[i];
45 if (voice->cmdPtr == NULL) {
46 continue;
47 }
49 // client volume changed on previous frame
51 continue;
52 }
54 // client released the key
55 voice->envelopeFlags &= ~AU_VOICE_ENV_FLAG_KEY_RELEASED;
57 voice->cmdPtr = (u8*)voice->envelope.cmdListRelease;
58
59 // the key can be released before press cmdlist processed completely, we must handle this case properly
60 if (voice->timeLeft > AU_5750) {
61 voice->initialAmp = voice->initialAmp + (s32) (voice->rate * (f32) (voice->volChangeTime - voice->timeLeft));
62 } else {
63 voice->initialAmp = voice->targetAmp;
64 }
65
66 voice->timeIntervalIndex = *voice->cmdPtr++;
67 var_a0 = *voice->cmdPtr;
68 if (*(s8*)voice->cmdPtr++ < 0) {
69 // in this case release volumes are relative to last press volume
70 var_a0 &= 0x7F;
71 voice->relativeReleaseVolumes = TRUE;
72 voice->releaseVolumeMult = voice->initialAmp;
73 }
74 voice->targetAmp = var_a0;
75
77 voice->volChangeTime = voice->timeLeft;
79 voice->envelopeFlags &= ~AU_VOICE_ENV_FLAG_VOL_CHANGED;
80 if (voice->timeLeft > AU_5750) {
81 voice->timeLeft -= AU_5750;
83 currentAmp = voice->initialAmp + (s32) (voice->rate * (voice->volChangeTime - voice->timeLeft));
84 } else {
85 currentAmp = voice->targetAmp;
86 }
87 voice->delta = AUDIO_SAMPLES;
88 } else {
89 voice->delta = au_voice_get_delta(voice->volChangeTime);
90 currentAmp = voice->targetAmp;
91 }
92 voice->p_volume = (((currentAmp * voice->clientVolume * voice->releaseVolumeMult) >> 0xE) * voice->volMult) >> 7;
94 } else {
95 if (voice->timeLeft == -1) {
96 // keep current volume, this is 'sustain' phase
98 voice->envelopeFlags &= ~AU_VOICE_ENV_FLAG_VOL_CHANGED;
99 voice->p_volume = (((voice->initialAmp * voice->clientVolume * voice->releaseVolumeMult) >> 0xE) * voice->volMult) >> 7;
101 }
102 } else {
103 voice->timeLeft -= AU_5750;
104 if (voice->timeLeft <= 0) {
105 if (*voice->cmdPtr == ENV_CMD_END) {
107 // if we reached the end after key release, stop the voice completely
108 voice->envelopeFlags = 0;
109 voice->cmdPtr = NULL;
110 voice->stopPending = TRUE;
111 } else {
112 // we reached the end of press cmdlist, keep the last volume until the key is released
113 voice->timeLeft = -1;
114 voice->volChangeTime = -1;
115 voice->timeIntervalIndex = ENV_TIME_300MS; // doesn't seem to affect anything
116 voice->delta = AUDIO_SAMPLES;
117 voice->rate = 0.0f;
118 voice->initialAmp = voice->targetAmp;
119 }
120 } else {
121 // get next envelope point
122 voice->timeIntervalIndex = au_voice_step(voice);
123 voice->initialAmp = voice->targetAmp;
124 voice->targetAmp = (*voice->cmdPtr++) & 0x7F;
126 voice->volChangeTime = voice->timeLeft;
127 if (voice->volChangeTime != 0) {
128 voice->rate = ((f32) voice->targetAmp - (f32) voice->initialAmp) / (f32) voice->volChangeTime;
129 } else {
130 voice->rate = 0.0f;
131 }
133 voice->envelopeFlags &= ~AU_VOICE_ENV_FLAG_VOL_CHANGED;
134 if (voice->timeLeft > AU_5750) {
135 voice->timeLeft -= AU_5750;
137 currentAmp = voice->initialAmp + (s32) (voice->rate * (voice->volChangeTime - voice->timeLeft));
138 } else {
139 currentAmp = voice->targetAmp;
140 }
141 voice->delta = AUDIO_SAMPLES;
142 } else {
143 voice->delta = au_voice_get_delta(voice->volChangeTime);
144 currentAmp = voice->targetAmp;
145 }
146 voice->p_volume = (((currentAmp * voice->clientVolume * voice->releaseVolumeMult) >> 0xE) * voice->volMult) >> 7;
148 }
149 } else {
150 // we are between two envelope points, do nothing, just handle client volume change
152 voice->envelopeFlags &= ~AU_VOICE_ENV_FLAG_VOL_CHANGED;
153 if (voice->timeLeft > AU_5750) {
154 voice->timeLeft -= AU_5750;
156 currentAmp = voice->initialAmp + (s32) (voice->rate * (voice->volChangeTime - voice->timeLeft));
157 } else {
158 currentAmp = voice->targetAmp;
159 }
160 voice->delta = AUDIO_SAMPLES;
161 voice->p_volume = (((currentAmp * voice->clientVolume * voice->releaseVolumeMult) >> 0xE) * voice->volMult) >> 7;
163 }
164 }
165 }
166 }
167 }
168}
void au_voice_after_volume_change(AuVoice *voice)
s32 au_voice_get_delta(s32 msecs)
u8 au_voice_step(AuVoice *voice)
@ ENV_CMD_END
Definition audio.h:130
s32 AuEnvelopeIntervals[]
Definition sfx_player.c:341
#define AUDIO_SAMPLES
Definition audio.h:44
s32 volMult
Definition audio.h:727
@ AU_VOICE_SYNC_FLAG_PARAMS
Definition audio.h:81
f32 rate
Definition audio.h:726
u8 initialAmp
Definition audio.h:730
#define AU_5750
Definition audio.h:22
s16 p_volume
Definition audio.h:716
s32 delta
Definition audio.h:715
@ AU_VOICE_ENV_FLAG_STOP
Definition audio.h:73
@ AU_VOICE_ENV_FLAG_HANDLED_VOL_CHANGE
Definition audio.h:74
@ ENV_TIME_300MS
Definition audio.h:193
u8 targetAmp
Definition audio.h:731

Referenced by au_update_clients_2().

◆ au_voice_after_volume_change()

void au_voice_after_volume_change ( AuVoice * arg0)

Definition at line 170 of file 2d9a0_len_890.c.

170 {
171 voice->p_volume = (((voice->targetAmp * voice->clientVolume * voice->releaseVolumeMult) >> 14) * voice->volMult) >> 7;
172 voice->delta = au_voice_get_delta(voice->timeLeft);
173 voice->envelopeFlags &= ~AU_VOICE_ENV_FLAG_HANDLED_VOL_CHANGE;
174 voice->syncFlags |= AU_VOICE_SYNC_FLAG_PARAMS;
175}

Referenced by au_update_voices().

◆ au_voice_get_delta()

s32 au_voice_get_delta ( s32 arg0)

Definition at line 177 of file 2d9a0_len_890.c.

177 {
178 return (msecs / AU_5750) * AUDIO_SAMPLES;
179}

Referenced by au_update_voices(), au_voice_after_volume_change(), and au_voice_start().

◆ au_voice_start()

void au_voice_start ( AuVoice * voice,
EnvelopeData * arg1 )

Definition at line 181 of file 2d9a0_len_890.c.

181 {
182 s32 intervalIndex;
183
184 voice->envelope.cmdListPress = envData->cmdListPress;
185 voice->cmdPtr = voice->envelope.cmdListPress;
186 voice->envelope.cmdListRelease = envData->cmdListRelease;
187 voice->volMult = 0x80;
188 voice->loopStart = NULL;
189
190 intervalIndex = au_voice_step(voice);
191 voice->envelopeFlags = 0;
192 voice->initialAmp = 0;
193 voice->targetAmp = *voice->cmdPtr++;
194 voice->timeIntervalIndex = intervalIndex;
195 voice->volChangeTime = AuEnvelopeIntervals[intervalIndex];
196 voice->timeLeft = voice->volChangeTime;
197
198 voice->p_volume = (voice->targetAmp * voice->clientVolume * voice->volMult) >> 14;
199 voice->delta = au_voice_get_delta(voice->volChangeTime);
200 if (voice->volChangeTime != 0) {
201 voice->rate = ((f32) voice->targetAmp - (f32) voice->initialAmp) / voice->volChangeTime;
202 } else {
203 voice->rate = 0.0f;
204 }
205 voice->relativeReleaseVolumes = FALSE;
206 voice->releaseVolumeMult = 0x80;
207}
u8 * loopStart
Definition audio.h:728

Referenced by au_syn_update().

◆ au_voice_step()

u8 au_voice_step ( AuVoice * voice)

Definition at line 210 of file 2d9a0_len_890.c.

210 {
211 u32 op;
212 u8 arg;
213
214 while (TRUE) {
215 if (((s8)(op = *voice->cmdPtr++)) >= 0) {
216 break;
217 }
218 switch ((u8)op) {
220 arg = *voice->cmdPtr++;
221 if (arg > 0x80) {
222 arg = 0x80;
223 }
224 voice->volMult = arg;
225 break;
227 voice->volMult += (s8) *voice->cmdPtr++;
228 if (voice->volMult > 0x80) {
229 voice->volMult = 0x80;
230 } else if (voice->volMult < 0) {
231 voice->volMult = 0;
232 }
233 break;
235 voice->loopCounter = *voice->cmdPtr++; // 0 means infinite loop
236 voice->loopStart = voice->cmdPtr;
237 break;
238 case ENV_CMD_END_LOOP:
239 voice->cmdPtr++;
240 if (voice->loopCounter == 0 || --voice->loopCounter != 0) {
241 voice->cmdPtr = voice->loopStart;
242 }
243 break;
244 default:
245 voice->cmdPtr++;
246 break;
247 }
248 }
249 return op;
250}
@ ENV_CMD_SET_MULTIPLIER
Definition audio.h:129
@ ENV_CMD_ADD_MULTIPLIER
Definition audio.h:128
@ ENV_CMD_START_LOOP
Definition audio.h:127
@ ENV_CMD_END_LOOP
Definition audio.h:126
u8 loopCounter
Definition audio.h:729

Referenced by au_update_voices(), and au_voice_start().

◆ au_voice_set_vol_changed()

void au_voice_set_vol_changed ( AuVoice * arg0)

Definition at line 253 of file 2d9a0_len_890.c.

253 {
254 voice->envelopeFlags |= AU_VOICE_ENV_FLAG_VOL_CHANGED;
255}

◆ func_80052E30()

void func_80052E30 ( u8 index)

Definition at line 18 of file 2e230_len_2190.c.

18 {
19 AuVoice* voice = &gSoundGlobals->voices[index];
20
21 voice->cmdPtr = NULL;
23}
AuGlobals * gSoundGlobals

Referenced by au_pull_voice().

◆ au_engine_init()

void au_engine_init ( s32 outputRate)

Definition at line 25 of file 2e230_len_2190.c.

25 {
26 AuGlobals* globals;
27 ALHeap* alHeap;
28 SBNFileEntry fileEntry;
29 s32* dummyTrackData;
30 u8 effects[4];
31 u32 i;
32
33 alHeap = gSynDriverPtr->heap;
34 gSoundGlobals = alHeapAlloc(alHeap, 1, sizeof(*gSoundGlobals));
35
36 gBGMPlayerA = alHeapAlloc(alHeap, 1, sizeof(*gBGMPlayerA));
37 gBGMPlayerB = alHeapAlloc(alHeap, 1, sizeof(*gBGMPlayerB));
38 gBGMPlayerC = alHeapAlloc(alHeap, 1, sizeof(*gBGMPlayerC));
39 gSoundManager = alHeapAlloc(alHeap, 1, sizeof(*gSoundManager));
43
44 globals = gSoundGlobals;
45 dummyTrackData = alHeapAlloc(alHeap, 1, 0x8000);
46 globals->dataBGM[0] = (BGMHeader*) &dummyTrackData[0];
47 globals->dataBGM[1] = (BGMHeader*) &dummyTrackData[0x1400];
48 globals->dataMSEQ[0] = (MSEQHeader*) &dummyTrackData[0x1C00];
49 globals->dataMSEQ[1] = (MSEQHeader*) &dummyTrackData[0x1400];
50
51 for (i = 0; i < ARRAY_COUNT(globals->unk_globals_6C); i++) {
52 globals->unk_globals_6C[i].bgmPlayer = alHeapAlloc(alHeap, 1, sizeof(BGMPlayer));
53 }
54
55 globals->dataSEF = alHeapAlloc(alHeap, 1, 0x5200);
56 globals->defaultInstrument = alHeapAlloc(alHeap, 1, sizeof(Instrument));
57 globals->dataPER = alHeapAlloc(alHeap, 1, 6 * sizeof(PEREntry));
58 globals->dataPRG = alHeapAlloc(alHeap, 1, 64 * sizeof(BGMInstrumentInfo));
59 globals->musicEventQueue = alHeapAlloc(alHeap, 1, 16 * sizeof(MusicEventTrigger));
60 globals->outputRate = outputRate;
61 au_reset_instrument(globals->defaultInstrument);
62 au_reset_drum_entry(&globals->defaultDrumEntry);
63 au_reset_instrument_entry(&globals->defaultPRGEntry);
65
66 globals->audioThreadCallbacks[0] = NULL;
67 globals->audioThreadCallbacks[1] = NULL;
68
69 for (i = 0; i < ARRAY_COUNT(globals->unk_globals_6C); i++) {
70 globals->unk_globals_6C[i].unk_4 = 0;
71 globals->unk_globals_6C[i].unk_5 = 0;
72 }
73
74 for (i = 0; i < ARRAY_COUNT(globals->effectChanges); i++) {
75 globals->effectChanges[i].type = AU_FX_NONE;
76 globals->effectChanges[i].changed = FALSE;
77 }
78
79 for (i = 0; i < ARRAY_COUNT(globals->voices); i++) {
80 AuVoice* voice;
83 voice = &globals->voices[i];
84 voice->instrument = NULL;
85 voice->pitchRatio = 0;
86 voice->p_volume = -1;
87 voice->pan = 0xFF;
88 voice->reverb = 0xFF;
89 voice->busId = 0;
90 voice->stopPending = FALSE;
91 voice->syncFlags = 0;
94 }
95
96 au_load_INIT(globals, audio_ROM_START, alHeap);
97
98 for (i = 0; i < ARRAY_COUNT(globals->banks); i++) {
99 globals->banks[i] = alHeapAlloc(alHeap, 1, 0x840);
100 }
101
103 effects[0] = FX_BUS_BGMA_MAIN;
104 effects[1] = FX_BUS_BGMA_AUX;
105 effects[2] = -1;
106 effects[3] = -1;
108
110 effects[0] = FX_BUS_BGMB;
111 effects[1] = -1;
112 effects[2] = -1;
113 effects[3] = -1;
115
118 au_init_voices(globals);
119 au_load_BK_headers(globals, alHeap);
120 if (au_fetch_SBN_file(globals->mseqFileList[0], AU_FMT_SEF, &fileEntry) == AU_RESULT_OK) {
121 au_read_rom(fileEntry.offset, globals->dataSEF, fileEntry.data & 0xFFFFFF);
122 }
124 if (au_fetch_SBN_file(globals->mseqFileList[1], AU_FMT_PER, &fileEntry) == AU_RESULT_OK) {
125 au_load_PER(globals, fileEntry.offset);
126 }
127 if (au_fetch_SBN_file(globals->mseqFileList[2], AU_FMT_PRG, &fileEntry) == AU_RESULT_OK) {
128 au_load_PRG(globals, fileEntry.offset);
129 }
130
131 globals->instrumentGroups[0] = globals->instrumentGroup1;
132 globals->instrumentGroups[1] = globals->instrumentGroup2;
133 globals->instrumentGroups[2] = globals->instrumentGroupX;
134 globals->instrumentGroups[3] = globals->instrumentGroup3;
135 globals->instrumentGroups[4] = globals->instrumentGroup4;
136 globals->instrumentGroups[5] = globals->instrumentGroup5;
137 globals->instrumentGroups[6] = globals->instrumentGroup6;
138 globals->instrumentGroups[7] = globals->instrumentGroup1;
139 globals->channelDelaySide = 0;
140 globals->channelDelayTime = 0;
141 globals->channelDelayBusId = 0;
142 globals->channelDelayPending = 0;
143
145 func_80055050(alHeap);
146}
void au_bgm_set_effect_indices(BGMPlayer *player, u8 *list)
void au_bgm_player_init(BGMPlayer *player, s32 priority, s32 busId, AuGlobals *globals)
void au_amb_manager_init(AmbienceManager *manager, s8 priority, s8 busId, AuGlobals *globals)
Definition 2BF90.c:39
void au_init_voices(AuGlobals *globals)
BGMPlayer * gBGMPlayerB
SoundManager * gSoundManager
void au_read_rom(s32 romAddr, void *buffer, u32 size)
void au_load_PRG(AuGlobals *arg0, s32 romAddr)
AuResult au_fetch_SBN_file(u32 fileIdx, AuFileFormat format, SBNFileEntry *outEntry)
BGMPlayer * gBGMPlayerA
BGMPlayer * gBGMPlayerC
void au_load_INIT(AuGlobals *arg0, s32 romAddr, ALHeap *heap)
void au_load_PER(AuGlobals *globals, s32 romAddr)
AmbienceManager * gAuAmbienceManager
void au_load_BK_headers(AuGlobals *globals, ALHeap *heap)
void func_80055050(ALHeap *heap)
Definition 30450.c:103
void bgm_clear_music_events(void)
Definition 30450.c:821
void au_pvoice_set_bus(u8 index, s8 busId)
Definition 31650.c:294
void * alHeapAlloc(ALHeap *heap, s32 count, s32 size)
Definition 31650.c:743
void au_delay_channel(s16 arg0)
Definition 31650.c:710
void au_syn_set_wavetable(u8 voiceIdx, Instrument *instrument)
Definition 31650.c:398
f32 outputRate
Definition audio.h:890
u8 channelDelayPending
Definition audio.h:904
SoundManager * soundManager
Definition audio.h:1004
@ AU_FX_NONE
Definition audio.h:87
Instrument * defaultInstrument
Definition audio.h:891
InstrumentGroup instrumentGroup6[4]
Definition audio.h:932
MusicEventTrigger * musicEventQueue
Definition audio.h:921
struct MSEQHeader * dataMSEQ[2]
Definition audio.h:911
InstrumentGroup instrumentGroup3[16]
Definition audio.h:927
AuCallback audioThreadCallbacks[2]
Definition audio.h:925
InstrumentGroup instrumentGroup1[4]
Definition audio.h:928
BGMInstrumentInfo * dataPRG
Definition audio.h:909
ALHeap * heap
Definition audio.h:516
@ FX_BUS_BGMA_MAIN
Definition audio.h:119
@ FX_BUS_BGMA_AUX
Definition audio.h:122
@ FX_BUS_SOUND
Definition audio.h:120
@ FX_BUS_BGMB
Definition audio.h:121
InstrumentGroup instrumentGroup2[16]
Definition audio.h:929
AuSynDriver * gSynDriverPtr
Definition 31650.c:15
u8 channelDelayBusId
Definition audio.h:905
u8 channelDelaySide
Definition audio.h:907
SoundBank * banks[3]
Definition audio.h:936
struct BGMHeader * dataBGM[2]
Definition audio.h:910
BGMInstrumentInfo defaultPRGEntry
Definition audio.h:893
struct BGMPlayer * bgmPlayer
Definition audio.h:883
s32 offset
Definition audio.h:835
InstrumentGroup instrumentGroupX[1]
Definition audio.h:926
@ AU_PRIORITY_BGM_PLAYER_MAIN
Definition audio.h:66
@ AU_PRIORITY_MSEQ_MANAGER
Definition audio.h:69
@ AU_PRIORITY_SFX_MANAGER
Definition audio.h:68
@ AU_PRIORITY_BGM_PLAYER_AUX
Definition audio.h:67
SndGlobalsSub6C unk_globals_6C[1]
Definition audio.h:912
InstrumentGroup * instrumentGroups[8]
Definition audio.h:933
AuEffectChange effectChanges[4]
Definition audio.h:903
InstrumentGroup instrumentGroup4[16]
Definition audio.h:930
u16 * mseqFileList
Definition audio.h:902
SEFHeader * dataSEF
Definition audio.h:924
InstrumentGroup instrumentGroup5[16]
Definition audio.h:931
u8 channelDelayTime
Definition audio.h:906
BGMDrumInfo defaultDrumEntry
Definition audio.h:892
u32 MusicEventTrigger
@ AU_FMT_PRG
Definition enums.h:1778
@ AU_FMT_PER
Definition enums.h:1777
@ AU_FMT_SEF
Definition enums.h:1775
void au_sfx_load_groups_from_SEF(SoundManager *sndMgr)
Definition sfx_player.c:506
void au_sfx_init(SoundManager *manager, u8 arg1, u8 arg2, AuGlobals *arg3, u8 arg4)
Definition sfx_player.c:423

Referenced by create_audio_system().

◆ au_update_clients_2()

void au_update_clients_2 ( void )

Definition at line 191 of file 2e230_len_2190.c.

191 {
192 AuGlobals* globals = gSoundGlobals;
193 SoundManager* sfxManager = gSoundManager;
195 BGMPlayer* bgmPlayer;
196
197 au_syn_update(globals);
198
199 ambManager->nextUpdateCounter -= ambManager->nextUpdateStep;
200 if (ambManager->nextUpdateCounter <= 0) {
201 ambManager->nextUpdateCounter += ambManager->nextUpdateInterval;
202 au_amb_manager_update(ambManager);
203 }
204
205 if (sfxManager->fadeInfo.fadeTime != 0) {
206 au_fade_update(&sfxManager->fadeInfo);
207 au_fade_set_volume(sfxManager->busId, sfxManager->fadeInfo.curVolume.u16, sfxManager->busVolume);
208 }
209
210 sfxManager->nextUpdateCounter -= sfxManager->nextUpdateStep;
211 if (sfxManager->nextUpdateCounter <= 0) {
212 sfxManager->nextUpdateCounter += sfxManager->nextUpdateInterval;
213 sfxManager->unk_BA = au_sfx_manager_update(sfxManager);
214 }
215
216 // update gBGMPlayerB
218 bgmPlayer = gBGMPlayerB;
219 if (bgmPlayer->fadeInfo.fadeTime != 0) {
220 au_bgm_update_fade(bgmPlayer);
221 }
222 if (bgmPlayer->songName != 0) {
223 bgmPlayer->songPlayingCounter++;
224 }
225
226 bgmPlayer->nextUpdateCounter -= bgmPlayer->nextUpdateStep;
227 if (bgmPlayer->nextUpdateCounter <= 0) {
228 bgmPlayer->nextUpdateCounter += bgmPlayer->nextUpdateInterval;
229 bgmPlayer->unk_5C = au_bgm_player_update_main(bgmPlayer);
230 }
231 }
232
234 if (globals->unk_80 != 0) {
235 func_8004DFD4(globals);
236 }
237 bgmPlayer = gBGMPlayerA;
238 if (bgmPlayer->fadeInfo.volScaleTime != 0) {
239 func_80053BA8(&bgmPlayer->fadeInfo);
240 if (bgmPlayer->fadeInfo.fadeTime == 0) {
241 func_8004E444(bgmPlayer);
242 } else {
243 au_bgm_update_fade(bgmPlayer);
244 }
245 } else if (bgmPlayer->fadeInfo.fadeTime != 0) {
246 au_bgm_update_fade(bgmPlayer);
247 }
248 if (bgmPlayer->songName != 0) {
249 bgmPlayer->songPlayingCounter++;
250 }
251
252 bgmPlayer->nextUpdateCounter -= bgmPlayer->nextUpdateStep;
253 if (bgmPlayer->nextUpdateCounter <= 0) {
254 bgmPlayer->nextUpdateCounter += bgmPlayer->nextUpdateInterval;
255 bgmPlayer->unk_5C = au_bgm_player_update_main(bgmPlayer);
256 }
257 }
258 au_update_voices(globals);
259}
void func_8004DFD4(AuGlobals *globals)
void func_8004E444(BGMPlayer *arg0)
void au_bgm_update_fade(BGMPlayer *player)
s32 au_bgm_player_update_main(BGMPlayer *player)
void au_amb_manager_update(AmbienceManager *manager)
Definition 2BF90.c:255
void au_update_voices(AuGlobals *globals)
void au_fade_update(Fade *fade)
void au_syn_update(AuGlobals *globals)
void au_fade_set_volume(u8 busId, u16 volume, s32 busVolume)
void func_80053BA8(Fade *fade)
VolumeField curVolume
Definition audio.h:366
s32 songPlayingCounter
Definition audio.h:1009
s32 nextUpdateInterval
Definition audio.h:1162
s32 songName
Definition audio.h:1010
s32 nextUpdateInterval
Definition audio.h:666
struct Fade fadeInfo
Definition audio.h:668
s32 nextUpdateInterval
Definition audio.h:1006
s32 nextUpdateStep
Definition audio.h:1161
s32 nextUpdateCounter
Definition audio.h:1007
s16 volScaleTime
Definition audio.h:378
s32 busVolume
Definition audio.h:669
s32 nextUpdateStep
Definition audio.h:665
s32 nextUpdateStep
Definition audio.h:1005
s32 unk_80
Definition audio.h:916
s16 fadeTime
Definition audio.h:369
s16 unk_5C
Definition audio.h:1021
s32 PreventBGMPlayerUpdate
Definition 30450.c:6
u16 u16
Definition audio.h:360
s32 nextUpdateCounter
Definition audio.h:1163
Fade fadeInfo
Definition audio.h:1014
s16 unk_BA
Definition audio.h:679
s32 nextUpdateCounter
Definition audio.h:667
s16 au_sfx_manager_update(SoundManager *manager)

Referenced by alAudioFrame().

◆ au_update_players_main()

void au_update_players_main ( void )

Definition at line 261 of file 2e230_len_2190.c.

261 {
262 AuGlobals* globals = gSoundGlobals;
263 BGMPlayer* player = gBGMPlayerA;
264 SoundManager* manager = gSoundManager;
265
266 if (globals->flushMusicEventQueue) {
268 }
269
271 if (BeginSoundUpdateCallback != NULL) {
273 }
274
275 au_bgm_update_main(player);
276
277 player = gBGMPlayerB;
278 au_bgm_update_main(player);
279
280 au_sfx_update_main(manager);
281}
void au_bgm_update_main(BGMPlayer *player)
AuCallback BeginSoundUpdateCallback
s32 flushMusicEventQueue
Definition audio.h:923
void au_sfx_update_main(SoundManager *manager)
Definition sfx_player.c:569

Referenced by alAudioFrame().

◆ au_syn_update()

void au_syn_update ( AuGlobals * globals)

Definition at line 283 of file 2e230_len_2190.c.

283 {
284 u32 i;
285
286 if (globals->unk_130C == 2) {
287 globals->unk_130C = 1;
289 }
290
291 if (globals->channelDelayPending && (globals->unk_130C == 0)) {
292 switch (globals->channelDelaySide) {
293 case 1:
296 globals->channelDelayPending = FALSE;
297 break;
298 case 2:
301 globals->channelDelayPending = FALSE;
302 break;
303 default:
305 globals->channelDelayPending = FALSE;
306 break;
307 }
308 }
309
310 if (globals->effectChanges[FX_BUS_BGMA_MAIN].changed) {
312 globals->effectChanges[FX_BUS_BGMA_MAIN].changed = FALSE;
313 }
314 if (globals->effectChanges[FX_BUS_SOUND].changed) {
316 globals->effectChanges[FX_BUS_SOUND].changed = FALSE;
317
318 } if (globals->effectChanges[FX_BUS_BGMB].changed) {
320 globals->effectChanges[FX_BUS_BGMB].changed = FALSE;
321 }
322 if (globals->effectChanges[FX_BUS_BGMA_AUX].changed) {
324 globals->effectChanges[FX_BUS_BGMA_AUX].changed = FALSE;
325 }
326
327 for (i = 0; i < ARRAY_COUNT(globals->voices); i++) {
328 AuVoice* voice = &globals->voices[i];
329 u8 voiceUpdateFlags = voice->syncFlags;
330
331 if (voice->stopPending) {
333 voice->stopPending = FALSE;
334 voice->cmdPtr = NULL;
335 voice->priority = AU_PRIORITY_FREE;
336 }
337
338 if (voiceUpdateFlags & AU_VOICE_SYNC_FLAG_ALL) {
339 au_voice_start(voice, &voice->envelope);
340 au_syn_start_voice_params(i, voice->busId, voice->instrument, voice->pitchRatio, voice->p_volume, voice->pan, voice->reverb, voice->delta);
341 // priority may be AU_PRIORITY_FREE if this voice was stolen and reset
342 voice->priority = voice->clientPriority;
343 } else {
344 if (voiceUpdateFlags & AU_VOICE_SYNC_FLAG_PITCH) {
345 au_syn_set_pitch(i, voice->pitchRatio);
346 }
347
348 if (voiceUpdateFlags & AU_VOICE_SYNC_FLAG_PARAMS) {
349 au_syn_set_mixer_params(i, voice->p_volume, voice->delta, voice->pan, voice->reverb);
350 } else if (voiceUpdateFlags & AU_VOICE_SYNC_FLAG_PAN_FXMIX) {
351 au_syn_set_pan_fxmix(i, voice->pan, voice->reverb);
352 }
353 }
354 voice->syncFlags = 0;
355 }
356}
void au_voice_start(AuVoice *voice, EnvelopeData *envData)
void au_disable_channel_delay(void)
Definition 31650.c:704
void au_delay_right_channel(u8 groupIdx)
Definition 31650.c:689
void au_syn_set_pitch(u8 voiceIdx, f32 pitch)
Definition 31650.c:436
void au_set_delay_time(s32 arg0)
Definition 31650.c:662
void au_bus_set_effect(u8 index, u8 effectType)
Definition 31650.c:279
void au_syn_set_pan_fxmix(u8 voiceIdx, u8 pan, u8 fxMix)
Definition 31650.c:475
void au_syn_start_voice_params(u8 voiceIdx, u8 busId, Instrument *instrument, f32 pitch, s16 vol, u8 pan, u8 fxMix, s32 delta)
Definition 31650.c:335
void au_delay_left_channel(u8 groupIdx)
Definition 31650.c:674
void au_syn_set_mixer_params(u8 voiceIdx, s16 volume, s32 delta, u8 pan, u8 fxMix)
Definition 31650.c:442
u8 unk_130C
Definition audio.h:934

Referenced by au_update_clients_2().

◆ au_reset_nonfree_voice()

void au_reset_nonfree_voice ( AuVoice * arg0,
u8 arg1 )

Definition at line 358 of file 2e230_len_2190.c.

358 {
359 if (voice->priority != AU_PRIORITY_FREE) {
360 voice->cmdPtr = NULL;
361 voice->stopPending = TRUE;
362 voice->syncFlags = 0;
364 }
365}
void au_syn_set_volume_delta(u8 voiceIdx, s16 vol, s32 delta)
Definition 31650.c:505

◆ au_reset_voice()

void au_reset_voice ( AuVoice * arg0,
u8 arg1 )

Definition at line 368 of file 2e230_len_2190.c.

368 {
369 voice->cmdPtr = NULL;
370 voice->stopPending = TRUE;
371 voice->syncFlags = 0;
373}

Referenced by au_amb_player_stop(), au_amb_player_update(), au_amb_restore_voices(), au_bgm_player_update_playing(), au_BGMCmd_FC_Jump(), and func_80050900().

◆ au_compute_pitch_ratio()

f32 au_compute_pitch_ratio ( s32 arg0)

Definition at line 381 of file 2e230_len_2190.c.

381 {
382 if (pitch >= 0) {
383 return AlTuneScaling[(pitch & 0x7F) + TUNE_SCALING_ARR_AMPLIFY_FINE]
384 * AlTuneScaling[((pitch & 0xF80) >> 7) + TUNE_SCALING_ARR_AMPLIFY_COARSE];
385 } else {
386 pitch = -pitch;
387 return AlTuneScaling[(pitch & 0x7F) + TUNE_SCALING_ARR_ATTENUATE_FINE]
388 * AlTuneScaling[((pitch & 0x3F80) >> 7) + TUNE_SCALING_ARR_ATTENUATE_COARSE];
389 }
390}
#define TUNE_SCALING_ARR_AMPLIFY_COARSE
#define TUNE_SCALING_ARR_ATTENUATE_COARSE
#define TUNE_SCALING_ARR_ATTENUATE_FINE
f32 AlTuneScaling[]
Definition sfx_player.c:360
#define TUNE_SCALING_ARR_AMPLIFY_FINE

Referenced by au_amb_player_update(), au_amb_restore_voices(), and au_bgm_player_update_playing().

◆ au_fade_init()

void au_fade_init ( Fade * fade,
s32 time,
s32 startValue,
s32 endValue )

Definition at line 392 of file 2e230_len_2190.c.

392 {
393 fade->curVolume.s32 = startValue * 0x10000;
394 fade->targetVolume = endValue;
395
396 if (time != 0) {
397 fade->fadeTime = (time * 1000) / AU_5750;
398 fade->fadeStep = (endValue * 0x10000 - fade->curVolume.s32) / fade->fadeTime;
399 } else {
400 fade->fadeTime = 1;
401 fade->fadeStep = 0;
402 }
403
404 fade->onCompleteCallback = NULL;
405}
s32 fadeStep
Definition audio.h:367
s32 s32
Definition audio.h:361
s16 targetVolume
Definition audio.h:368

Referenced by au_bgm_dispatch_player_event(), au_sfx_init(), and func_8004DFD4().

◆ au_fade_clear()

void au_fade_clear ( Fade * fade)

Definition at line 407 of file 2e230_len_2190.c.

407 {
408 fade->fadeTime = 0;
409 fade->fadeStep = 0;
410 fade->onCompleteCallback = NULL;
411}

◆ au_fade_update()

void au_fade_update ( Fade * fade)

Definition at line 413 of file 2e230_len_2190.c.

413 {
414 fade->fadeTime--;
415
416 if ((fade->fadeTime << 0x10) != 0) {
417 fade->curVolume.s32 += fade->fadeStep;
418 } else {
419 fade->curVolume.s32 = fade->targetVolume << 0x10;
420 if (fade->onCompleteCallback != NULL) {
421 fade->onCompleteCallback();
422 fade->fadeStep = 0;
423 fade->onCompleteCallback = NULL;
424 }
425 }
426}

Referenced by au_update_clients_2().

◆ au_fade_set_volume()

void au_fade_set_volume ( u8 arg0,
u16 arg1,
s32 arg2 )

Definition at line 428 of file 2e230_len_2190.c.

428 {
429 au_bus_set_volume(busId, (u32)(volume * busVolume) >> 15);
430}
void au_bus_set_volume(u8 index, u16 arg1)
Definition 31650.c:267

Referenced by au_sfx_init(), au_update_clients_2(), and func_8004E444().

◆ func_80053AC8()

void func_80053AC8 ( Fade * fade)

Definition at line 432 of file 2e230_len_2190.c.

432 {
433 if (fade->fadeTime == 0) {
434 fade->fadeTime = 1;
435 fade->fadeStep = 0;
436 fade->targetVolume = fade->curVolume.u16;
437 }
438}

Referenced by func_80054CE0().

◆ au_fade_set_vol_scale()

void au_fade_set_vol_scale ( Fade * fade,
s16 value )

Definition at line 440 of file 2e230_len_2190.c.

440 {
441 fade->volScale.s32 = value << 16;
442 fade->targetVolScale = value;
443 fade->volScaleTime = 0;
444 fade->volScaleStep = 0;
445}
s32 volScaleStep
Definition audio.h:376
VolumeField volScale
Definition audio.h:375
s16 targetVolScale
Definition audio.h:377

Referenced by au_bgm_player_init().

◆ func_80053B04()

void func_80053B04 ( Fade * fade,
u32 arg1,
s32 target )

Definition at line 447 of file 2e230_len_2190.c.

447 {
448 s16 time;
449 s32 delta;
450
451 if (arg1 >= 250 && arg1 <= 100000) {
452 time = (s32)(arg1 * 1000) / AU_5750;
453 delta = (target << 16) - fade->volScale.s32;
454
455 fade->targetVolScale = target;
456 fade->volScaleTime = time;
457 fade->volScaleStep = delta / time;
458 } else {
459 fade->volScaleTime = 0;
460 fade->volScaleStep = 0;
461 }
462}

Referenced by func_8004E0F4().

◆ func_80053BA8()

void func_80053BA8 ( Fade * fade)

Definition at line 464 of file 2e230_len_2190.c.

464 {
465 fade->volScaleTime--;
466
467 if (fade->volScaleTime != 0) {
468 fade->volScale.s32 += fade->volScaleStep;
469 } else {
470 fade->volScaleStep = 0;
471 fade->volScale.s32 = fade->targetVolScale << 16;
472 }
473}

Referenced by au_update_clients_2().

◆ au_get_instrument()

Instrument * au_get_instrument ( AuGlobals * globals,
u32 bank,
u32 patch,
EnvelopeData * arg3 )

Definition at line 476 of file 2e230_len_2190.c.

476 {
477 Instrument* instrument = (*globals->instrumentGroups[(bank & 0x70) >> 4])[patch];
478 EnvelopePreset* preset = instrument->envelopes;
479 u32 envelopeIdx = bank & 3;
480
481 if (envelopeIdx < preset->count) {
482 envData->cmdListPress = AU_FILE_RELATIVE(preset, preset->offsets[envelopeIdx].offsetPress);
483 envData->cmdListRelease = AU_FILE_RELATIVE(preset, preset->offsets[envelopeIdx].offsetRelease);
484 } else {
485 envData->cmdListPress = EnvelopePressDefault;
486 envData->cmdListRelease = &EnvelopePressDefault[4]; //EnvelopeReleaseDefault;
487 }
488 return instrument;
489}
u8 EnvelopePressDefault[]
Definition sfx_player.c:299
EnvelopeOffset offsets[1]
Definition audio.h:545
u16 offsetPress
Definition audio.h:538
EnvelopePreset * envelopes
Definition audio.h:571
u16 offsetRelease
Definition audio.h:539

Referenced by au_amb_player_update(), au_bgm_player_update_playing(), au_BGMCmd_E8_TrackOverridePatch(), and au_BGMCmd_F5_TrackVoice().

◆ au_get_bgm_player_and_file()

void au_get_bgm_player_and_file ( u32 playerIndex,
BGMHeader ** outCurrentTrackData,
BGMPlayer ** outPlayer )

Definition at line 491 of file 2e230_len_2190.c.

491 {
492 AuGlobals* globals = gSoundGlobals;
493
494 switch (playerIndex) {
495 case 0:
496 *outFile = globals->dataBGM[0];
497 *outPlayer = gBGMPlayerA;
498 break;
499 case 1:
500 *outFile = globals->dataBGM[1];
501 *outPlayer = gBGMPlayerB;
502 break;
503 case 2:
504 *outFile = globals->dataBGM[0];
505 *outPlayer = gBGMPlayerA;
506 break;
507 default:
508 *outFile = NULL;
509 *outPlayer = NULL;
510 break;
511 }
512}

Referenced by au_song_load().

◆ au_get_bgm_player()

void au_get_bgm_player ( u32 playerIndex,
BGMPlayer ** outPlayer )

Definition at line 514 of file 2e230_len_2190.c.

514 {
515 switch (playerIndex) {
516 case 0:
517 *outPlayer = gBGMPlayerA;
518 break;
519 case 1:
520 *outPlayer = gBGMPlayerB;
521 break;
522 case 2:
523 *outPlayer = gBGMPlayerA;
524 break;
525 default:
526 *outPlayer = NULL;
527 break;
528 }
529}

◆ au_load_song_files()

AuResult au_load_song_files ( u32 arg0,
BGMHeader * arg1,
BGMPlayer * arg2 )

Definition at line 531 of file 2e230_len_2190.c.

531 {
532 AuResult status;
533 SBNFileEntry fileEntry;
534 SBNFileEntry fileEntry2;
535 SBNFileEntry* bkFileEntry;
536 AuGlobals* soundData;
537 InitSongEntry* songInfo;
538 s32 i;
539 u16 bkFileIndex;
540 s32 bgmFileIndex;
541 u32 data;
542 u32 offset;
543 BGMPlayer* arg2_copy ;
544 BGMHeader* arg1_copy;
545 s32 cond;
546
547 soundData = gSoundGlobals;
548
549 // needed to match
550 cond = songID < soundData->songListLength;
551 arg2_copy = player;
552 arg1_copy = bgmFile;
553
554 if (cond) {
555 songInfo = &soundData->songList[songID];
556 status = au_fetch_SBN_file(songInfo->bgmFileIndex, AU_FMT_BGM, &fileEntry);
557 if (status != AU_RESULT_OK) {
558 return status;
559 }
560
561 if (func_8004DB28(arg2_copy)) {
562 return AU_ERROR_201;
563 }
564
565 au_read_rom(fileEntry.offset, arg1_copy, fileEntry.data & 0xFFFFFF);
566
567 for (i = 0; i < ARRAY_COUNT(songInfo->bkFileIndex); i++) {
568 bkFileIndex = songInfo->bkFileIndex[i];
569 if (bkFileIndex != 0) {
570 bkFileEntry = &soundData->sbnFileList[bkFileIndex];
571
572 offset = (bkFileEntry->offset & 0xFFFFFF) + soundData->baseRomOffset;
573 fileEntry2.offset = offset;
574
575 data = bkFileEntry->data;
576 fileEntry2.data = data;
577
578 if ((data >> 0x18) == AU_FMT_BK) {
579 snd_load_BK(offset, i);
580 }
581 }
582 }
583 bgmFileIndex = songInfo->bgmFileIndex;
584 arg2_copy->songID = songID;
585 arg2_copy->bgmFile = bgmFile;
586 arg2_copy->bgmFileIndex = bgmFileIndex;
587 return arg1_copy->name;
588 } else {
589 return AU_ERROR_151;
590 }
591}
s32 func_8004DB28(BGMPlayer *player)
s32 snd_load_BK(s32 bkFileOffset, s32 bankIndex)
struct BGMHeader * bgmFile
Definition audio.h:1024
u16 bkFileIndex[3]
Definition audio.h:867
s32 baseRomOffset
Definition audio.h:894
InitSongEntry * songList
Definition audio.h:898
s32 songID
Definition audio.h:1013
SBNFileEntry * sbnFileList
Definition audio.h:895
s32 name
Definition audio.h:758
u16 bgmFileIndex
Definition audio.h:866
s32 songListLength
Definition audio.h:899
s32 bgmFileIndex
Definition audio.h:1012
@ AU_FMT_BGM
Definition enums.h:1774
@ AU_FMT_BK
Definition enums.h:1776
@ AU_ERROR_151
Definition enums.h:1769
@ AU_ERROR_201
Definition enums.h:1770

Referenced by au_song_load().

◆ func_80053E58()

AuResult func_80053E58 ( s32 songID,
BGMHeader * arg1 )

Definition at line 593 of file 2e230_len_2190.c.

593 {
594 AuResult status;
595 SBNFileEntry fileEntry;
596 SBNFileEntry sbnEntry;
597 SBNFileEntry* bkFileEntry;
598 AuGlobals* soundData;
599 InitSongEntry* songInfo;
600 s32 i;
601 u16 bkFileIndex;
602
603 soundData = gSoundGlobals;
604 songInfo = &soundData->songList[songID];
605 status = au_fetch_SBN_file(songInfo[0].bgmFileIndex, AU_FMT_BGM, &sbnEntry);
606 if (status == AU_RESULT_OK) {
607 au_read_rom(sbnEntry.offset, bgmFile, sbnEntry.data & 0xFFFFFF);
608
609 for (i = 0; i < ARRAY_COUNT(songInfo->bkFileIndex); i++) {
610 bkFileIndex = songInfo->bkFileIndex[i];
611 if (bkFileIndex != 0) {
612 bkFileEntry = &soundData->sbnFileList[bkFileIndex];
613
614 fileEntry.offset = (bkFileEntry->offset & 0xFFFFFF) + soundData->baseRomOffset;
615 fileEntry.data = bkFileEntry->data;
616
617 if ((fileEntry.data >> 0x18) == AU_FMT_BK) {
618 snd_load_BK(fileEntry.offset, i);
619 } else {
621 }
622 }
623 }
624 }
625
626 return status;
627}
@ AU_ERROR_SBN_FORMAT_MISMATCH
Definition enums.h:1768

Referenced by func_8004DE2C().

◆ func_80053F64()

BGMPlayer * func_80053F64 ( s32 arg0)

Definition at line 629 of file 2e230_len_2190.c.

629 {
630 if (arg0 == 0) {
632 }
633 return NULL;
634}

Referenced by func_8004DCB8(), and func_8004DE2C().

◆ au_ambient_load()

AuResult au_ambient_load ( u32 arg0)

Definition at line 638 of file 2e230_len_2190.c.

638 {
639 AmbienceManager* manager;
640 SBNFileEntry fileEntry;
641 AuGlobals* globals;
642 MSEQHeader* mseqFile;
643 u32 i;
644
645 globals = gSoundGlobals;
646 manager = gAuAmbienceManager;
647 if (ambSoundID < AMBIENT_RADIO) {
648 if (manager->players[0].mseqName == 0 && SBN_LOOKUP(ambSoundID, AU_FMT_MSEQ, fileEntry) == AU_RESULT_OK) {
649 au_read_rom(fileEntry.offset, globals->dataMSEQ[0], fileEntry.data & 0xFFFFFF);
650 manager->mseqFiles[0] = globals->dataMSEQ[0];
651 for (i = 1; i < ARRAY_COUNT(manager->mseqFiles); i++) {
652 manager->mseqFiles[i] = NULL;
653 }
654 manager->numActivePlayers = 1;
655 }
656 } else if (ambSoundID == AMBIENT_RADIO
657 && manager->players[0].mseqName == 0
658 && manager->players[1].mseqName == 0
659 && manager->players[2].mseqName == 0) {
660 manager->numActivePlayers = 0;
661 for (i = 0; i < ARRAY_COUNT(manager->mseqFiles); i++) {
662 manager->mseqFiles[i] = NULL;
663 }
664
665 mseqFile = globals->dataMSEQ[1];
666 if (SBN_LOOKUP(ambSoundID, AU_FMT_MSEQ, fileEntry) == AU_RESULT_OK) {
667 au_read_rom(fileEntry.offset, mseqFile, fileEntry.data & 0xFFFFFF);
668 manager->mseqFiles[0] = mseqFile;
669
670 mseqFile = AU_FILE_RELATIVE(mseqFile, (fileEntry.data + 0x40) & 0xFFFFFF);
671 if (SBN_LOOKUP(ambSoundID + 1, AU_FMT_MSEQ, fileEntry) == AU_RESULT_OK) {
672 au_read_rom(fileEntry.offset, mseqFile, fileEntry.data & 0xFFFFFF);
673 manager->mseqFiles[1] = mseqFile;
674
675 mseqFile = AU_FILE_RELATIVE(mseqFile, (fileEntry.data + 0x40) & 0xFFFFFF);
676 if (SBN_LOOKUP(ambSoundID + 2, AU_FMT_MSEQ, fileEntry) == AU_RESULT_OK) {
677 au_read_rom(fileEntry.offset, mseqFile, fileEntry.data & 0xFFFFFF);
678 manager->mseqFiles[2] = mseqFile;
679
680 mseqFile = AU_FILE_RELATIVE(mseqFile, (fileEntry.data + 0x40) & 0xFFFFFF);
681 if (SBN_LOOKUP(ambSoundID + 3, AU_FMT_MSEQ, fileEntry) == AU_RESULT_OK) {
682 au_read_rom(fileEntry.offset, mseqFile, fileEntry.data & 0xFFFFFF);
683 manager->mseqFiles[3] = mseqFile;
684
685 manager->numActivePlayers = 4;
686 if (SBN_LOOKUP(ambSoundID + 4, AU_FMT_BK, fileEntry) == AU_RESULT_OK) {
687 snd_load_BK(fileEntry.offset, 2);
688 }
689 }
690 }
691 }
692 }
693 }
694
695 return AU_RESULT_OK;
696}
#define SBN_LOOKUP(i, fmt, e)
@ AMBIENT_RADIO
Definition enums.h:1895
@ AU_FMT_MSEQ
Definition enums.h:1779

Referenced by snd_load_ambient().

◆ func_80054248()

BGMPlayer * func_80054248 ( u8 arg0)

Definition at line 698 of file 2e230_len_2190.c.

698 {
699 switch (arg0) {
700 case 1:
701 return gBGMPlayerA;
702 case 2:
703 return gBGMPlayerB;
704 case 4:
705 return (BGMPlayer*)gSoundManager; // TODO: why return pointer to SoundManager?
706 default:
707 return NULL;
708 }
709}

Referenced by func_8004DE2C().

◆ au_load_INIT()

void au_load_INIT ( AuGlobals * arg0,
s32 romAddr,
ALHeap * heap )

Definition at line 711 of file 2e230_len_2190.c.

711 {
712 SBNHeader sbnHeader;
713 INITHeader initHeader;
714 SBNFileEntry* entry;
715 s32 tableSize, initBase, size;
716 s32 tblAddr, shortsAddr;
717 s32* data;
718 s32 numEntries;
719 s32 tblOffset, shortsOffset;
720 s32* romPtr = &arg0->baseRomOffset;
721
722 au_read_rom(romAddr, &sbnHeader, sizeof(sbnHeader));
723 numEntries = sbnHeader.numEntries;
724 arg0->baseRomOffset = romAddr;
725 tableSize = numEntries * sizeof(SBNFileEntry);
726 arg0->fileListLength = sbnHeader.numEntries;
727 arg0->sbnFileList = alHeapAlloc(heap, 1, tableSize);
728 au_read_rom(arg0->baseRomOffset + sbnHeader.tableOffset, arg0->sbnFileList, tableSize);
729
730 entry = arg0->sbnFileList;
731 while (sbnHeader.numEntries--) {
732 if ((entry->offset & 0xFFFFFF) == 0) {
733 break;
734 }
735
736 size = entry->data;
737 entry->data = (size + 0xF) & ~0xF;
738 entry++;
739 }
740
741 if (sbnHeader.INIToffset != 0) {
742 initBase = *romPtr + sbnHeader.INIToffset;
743 au_read_rom(initBase, &initHeader, sizeof(initHeader));
744
745 tblOffset = initHeader.tblOffset;
746 size = (initHeader.tblSize + 0xF) & 0xFFF0;
747 tblAddr = initBase + tblOffset;
748 arg0->songList = alHeapAlloc(heap, 1, size);
749 au_read_rom(tblAddr, arg0->songList, size);
750
751 shortsOffset = initHeader.shortsOffset;
752 size = (initHeader.shortsSize + 0xF) & 0xFFF0;
753 shortsAddr = initBase + shortsOffset;
754 arg0->mseqFileList = alHeapAlloc(heap, 1, size);
755 au_read_rom(shortsAddr, arg0->mseqFileList, size);
756
757 arg0->bkFileListOffset = initBase + initHeader.entriesOffset;
758 arg0->bkListLength = (initHeader.entriesSize + 0xF) & 0xFFF0;
759 arg0->songListLength = initHeader.tblSize / sizeof(InitSongEntry) - 1;
760 }
761}
u16 shortsSize
Definition audio.h:821
s32 numEntries
Definition audio.h:795
u16 shortsOffset
Definition audio.h:820
s32 bkFileListOffset
Definition audio.h:900
s32 bkListLength
Definition audio.h:901
u16 tblSize
Definition audio.h:819
s32 fileListLength
Definition audio.h:896
s32 INIToffset
Definition audio.h:799
s32 tableOffset
Definition audio.h:794
u16 entriesSize
Definition audio.h:817
u16 entriesOffset
Definition audio.h:816
u16 tblOffset
Definition audio.h:818

Referenced by au_engine_init().

◆ au_fetch_SBN_file()

AuResult au_fetch_SBN_file ( u32 fileIdx,
AuFileFormat format,
SBNFileEntry * arg2 )

Definition at line 763 of file 2e230_len_2190.c.

763 {
764 SBNFileEntry fileEntry;
765 s32 status = AU_RESULT_OK;
766
767 if (fileIdx < gSoundGlobals->fileListLength) {
768 SBNFileEntry* entry = &gSoundGlobals->sbnFileList[fileIdx];
769 s32 offset = (entry->offset & 0xFFFFFF) + gSoundGlobals->baseRomOffset;
770
771 fileEntry.offset = offset;
772 fileEntry.data = entry->data;
773 if ((fileEntry.data >> 0x18) == format) {
774 outEntry->offset = offset;
775 outEntry->data = fileEntry.data;
776 } else {
778 }
779 } else {
781 }
782 return status;
783}
@ AU_ERROR_SBN_INDEX_OUT_OF_RANGE
Definition enums.h:1767

Referenced by au_engine_init(), au_load_BK_headers(), au_load_song_files(), and func_80053E58().

◆ au_load_PER()

void au_load_PER ( AuGlobals * globals,
s32 romAddr )

Definition at line 785 of file 2e230_len_2190.c.

785 {
786 PERHeader header;
787 u32 size;
788 s32 numItemsLeft;
789 s32 numItems;
790 void* end;
791
792 au_read_rom(romAddr, &header, sizeof(header));
793 size = header.mdata.size - sizeof(header);
794 au_read_rom(romAddr + sizeof(header), globals->dataPER, size);
795 numItems = size / sizeof(PEREntry);
796 numItemsLeft = 6 - numItems;
797 if (numItemsLeft > 0) {
798 end = &globals->dataPER[numItems];
799 au_copy_words(&globals->defaultDrumEntry, end, sizeof(BGMDrumInfo));
800 au_copy_words(end, end + sizeof(BGMDrumInfo), numItemsLeft * sizeof(PEREntry) - sizeof(BGMDrumInfo));
801 }
802}
void au_copy_words(void *src, void *dst, s32 size)
AUFileMetadata mdata
Definition audio.h:826

Referenced by au_engine_init().

◆ au_load_PRG()

void au_load_PRG ( AuGlobals * arg0,
s32 romAddr )

Definition at line 804 of file 2e230_len_2190.c.

804 {
805 PERHeader header;
806 u32 size;
807 s32 numItemsLeft;
808 s32 numItems;
809 s32 dataRomAddr;
810 void* end;
811
812 au_read_rom(romAddr, &header, sizeof(header));
813 dataRomAddr = romAddr + sizeof(header);
814 size = header.mdata.size - sizeof(header);
815 if (size > 0x200) {
816 size = 0x200;
817 }
818 au_read_rom(dataRomAddr, arg0->dataPRG, size);
819 numItems = size / sizeof(BGMInstrumentInfo);
820 numItemsLeft = 0x40 - numItems;
821 if (numItemsLeft > 0) {
822 end = &arg0->dataPRG[numItems];
823 au_copy_words(&arg0->defaultPRGEntry, end, sizeof(BGMInstrumentInfo));
824 au_copy_words(end, end + sizeof(BGMInstrumentInfo), numItemsLeft * sizeof(BGMInstrumentInfo) - sizeof(BGMInstrumentInfo));
825 }
826}

Referenced by au_engine_init().

◆ au_get_BK_instruments()

InstrumentGroup * au_get_BK_instruments ( s32 bankGroup,
u32 bankIndex )

Definition at line 862 of file 2e230_len_2190.c.

862 {
863 InstrumentGroup* ret = NULL;
864 AuGlobals* temp = gSoundGlobals;
865
866 // TODO fake match - this multiplying the bankIndex by 16 and then dividing it right after is dumb
867 bankIndex *= 16;
868
869 switch (bankGroup) {
870 case 1:
871 ret = &temp->instrumentGroup1[bankIndex / 16];
872 break;
873 case 2:
874 ret = &temp->instrumentGroup2[bankIndex / 16];
875 break;
876 case 4:
877 ret = &temp->instrumentGroup4[bankIndex / 16];
878 break;
879 case 5:
880 ret = &temp->instrumentGroup5[bankIndex / 16];
881 break;
882 case 6:
883 ret = &temp->instrumentGroup6[bankIndex / 16];
884 break;
885 case 3:
886 ret = &temp->instrumentGroup3[bankIndex / 16];
887 break;
888 }
889
890 return ret;
891}
Instrument * InstrumentGroup[16]
Definition audio.h:574

Referenced by au_load_BK_to_bank(), func_80054AA0(), and func_80054C84().

◆ au_load_BK_to_bank()

SoundBank * au_load_BK_to_bank ( s32 bkFileOffset,
SoundBank * bank,
s32 bankIndex,
s32 bankGroup )

Definition at line 911 of file 2e230_len_2190.c.

911 {
912 ALHeap* heap = gSynDriverPtr->heap;
913 BKHeader bkHeader;
914 BKHeader* header = &bkHeader;
915 u16 keepReading;
916 u16 readState;
917 InstrumentGroup* group;
918 Instrument** inst;
919 s32 instrumentCount;
920 s32 size;
921 u32 i;
922
923 au_read_rom(bkFileOffset, header, sizeof(*header));
924 readState = BK_READ_FETCH_HEADER;
925 keepReading = TRUE;
926
927 while (keepReading) {
928 switch (readState) {
929 case BK_READ_DONE:
930 keepReading = FALSE;
931 break;
933 if (header->signature != AL_HEADER_SIG_BK) {
934 keepReading = FALSE;
935 } else if (header->size == 0) {
936 keepReading = FALSE;
937 } else {
938 readState = BK_READ_FETCH_DATA;
939 }
940 break;
942 if (header->format == AL_HEADER_SIG_CR) {
943 readState = BK_READ_PROCESS_CR;
944 } else if (header->format == AL_HEADER_SIG_DR) {
945 readState = BK_READ_PROCESS_DR;
946 } else if (header->format == AL_HEADER_SIG_SR) {
947 readState = BK_READ_PROCESS_SR;
948 } else {
949 keepReading = FALSE;
950 }
951 break;
952
954 size = ALIGN16_(header->instrumetsSize)
955 + ALIGN16_(header->unkSizeA)
956 + ALIGN16_(header->predictorsSize)
957 + ALIGN16_(header->unkSizeB)
958 + sizeof(*header);
959 if (bank == NULL) {
960 bank = alHeapAlloc(heap, 1, size);
961 }
962 au_read_rom(bkFileOffset, bank, size);
963
964 group = au_get_BK_instruments(bankGroup, bankIndex);
965 inst = (*group);
966 instrumentCount = 0;
967
968 for (i = 0; i < ARRAY_COUNT(header->instruments); inst++, i++) {
969 u16 instOffset = header->instruments[i];
970 if (instOffset != 0) {
971 instrumentCount++;
972 *inst = AU_FILE_RELATIVE(bank, instOffset);
973 } else {
974 *inst = NULL;
975 }
976 }
977
978 if (instrumentCount != 0) {
979 readState = BK_READ_SWIZZLE_CR;
980 } else {
981 keepReading = FALSE;
982 }
983 break;
985 au_swizzle_BK_instruments(bkFileOffset, bank, *group, 16, 1);
986 readState = BK_READ_DONE;
987 break;
988
989 // inferred states
991 case BK_READ_UNK_DR:
993 case BK_READ_UNK_SR:
994 default:
995 keepReading = FALSE;
996 break;
997 }
998 }
999
1000 return bank;
1001}
#define AL_HEADER_SIG_BK
#define AL_HEADER_SIG_DR
#define AL_HEADER_SIG_CR
@ BK_READ_SWIZZLE_CR
@ BK_READ_PROCESS_DR
@ BK_READ_FETCH_HEADER
@ BK_READ_UNK_DR
@ BK_READ_PROCESS_SR
@ BK_READ_FETCH_DATA
@ BK_READ_PROCESS_CR
@ BK_READ_DONE
@ BK_READ_UNK_SR
#define AL_HEADER_SIG_SR
InstrumentGroup * au_get_BK_instruments(s32 bankGroup, u32 bankIndex)
void au_swizzle_BK_instruments(s32 bkFileOffset, SoundBank *bank, InstrumentGroup instruments, u32 instrumentCount, u8 arg4)
u16 format
Definition audio.h:852
u16 predictorsSize
Definition audio.h:860
u16 signature
Definition audio.h:848
#define ALIGN16_(val)
Definition audio.h:39
u16 unkSizeA
Definition audio.h:858
u16 instrumetsSize
Definition audio.h:856
u16 unkSizeB
Definition audio.h:862
s32 size
Definition audio.h:850
u16 instruments[16]
Definition audio.h:855

Referenced by au_load_BK_headers(), and snd_load_BK().

◆ au_swizzle_BK_instruments()

void au_swizzle_BK_instruments ( s32 bkFileOffset,
SoundBank * bank,
InstrumentGroup instruments,
u32 instrumentCount,
u8 arg4 )

Definition at line 1003 of file 2e230_len_2190.c.

1003 {
1004 Instrument* defaultInstrument = gSoundGlobals->defaultInstrument;
1005 SoundBank* sb = bank;
1006 f32 outputRate = gSoundGlobals->outputRate;
1007 s32 i;
1008
1009 if (sb->swizzled == 0) {
1010 for (i = 0; i < instrumentCount; i++) {
1011 Instrument* instrument = instruments[i];
1012
1013 if (instrument != NULL) {
1014 if (instrument->base != 0) {
1015 instrument->base += bkFileOffset;
1016 }
1017 if (instrument->loopPredictor != NULL) {
1018 instrument->loopPredictor = AU_FILE_RELATIVE(bank, instrument->loopPredictor);
1019 }
1020 if (instrument->predictor != NULL) {
1021 instrument->predictor = AU_FILE_RELATIVE(bank, instrument->predictor);
1022 }
1023 if (instrument->envelopes != NULL) {
1024 instrument->envelopes = AU_FILE_RELATIVE(bank, instrument->envelopes);
1025 }
1026 instrument->unk_25 = arg4;
1027 instrument->pitchRatio = instrument->outputRate / outputRate;
1028 } else {
1029 instruments[i] = defaultInstrument;
1030 }
1031 }
1032 sb->swizzled = 1;
1033 }
1034}
u16 * predictor
Definition audio.h:556
u8 * base
Definition audio.h:550
UNK_PTR loopPredictor
Definition audio.h:552
u8 unk_25
Definition audio.h:564
u8 swizzled
Definition audio.h:872

Referenced by au_load_BK_to_bank(), and func_80054AA0().

◆ func_80054AA0()

s32 * func_80054AA0 ( s32 * bkFileOffset,
void * vaddr,
s32 bankIndex,
s32 bankGroup )

Definition at line 1036 of file 2e230_len_2190.c.

1036 {
1037 ALHeap* heap = gSynDriverPtr->heap;
1038 BKHeader localHeader;
1039 void* fileData = vaddr;
1040 BKHeader* header = &localHeader;
1041 InstrumentGroup* group;
1042 Instrument* instruments;
1043 Instrument** inst;
1044 u32 instrCount;
1045 u32 readState;
1046 s32 keepReading;
1047
1048 u32 i;
1049 s32 swizzleArg;
1050 swizzleArg = 0;
1051 readState = BK_READ_FETCH_HEADER;
1052 keepReading = TRUE;
1053
1054
1055 while (keepReading) {
1056 switch (readState) {
1057 case BK_READ_DONE:
1058 keepReading = FALSE;
1059 break;
1061 au_read_rom(*bkFileOffset, &localHeader, sizeof(localHeader));
1062 if (header->signature != AL_HEADER_SIG_BK) {
1063 keepReading = FALSE;
1064 } else if (header->size == 0) {
1065 keepReading = FALSE;
1066 } else if (header->format != AL_HEADER_SIG_CR) {
1067 keepReading = FALSE;
1068 } else {
1069 readState = BK_READ_FETCH_DATA;
1070 }
1071 break;
1072 case BK_READ_FETCH_DATA:
1073 if (fileData == NULL) {
1074 fileData = alHeapAlloc(heap, 1, header->size);
1075 }
1076 au_read_rom(*bkFileOffset, fileData, header->size);
1077
1078 instrCount = 0;
1079 group = au_get_BK_instruments(bankGroup, bankIndex);
1080 inst = (*group);
1081 for(i = 0; i < ARRAY_COUNT(header->instruments); inst++, i++) {
1082 u16 instOffset = header->instruments[i];
1083 if(instOffset != 0) {
1084 instrCount++;
1085 *inst = AU_FILE_RELATIVE(fileData, instOffset);
1086 } else {
1087 *inst = NULL;
1088 }
1089 }
1090
1091 if (instrCount != 0) {
1092 readState = BK_READ_SWIZZLE;
1093 } else {
1094 keepReading = FALSE;
1095 }
1096 break;
1097 case BK_READ_SWIZZLE:
1098 au_swizzle_BK_instruments((s32)fileData, fileData, *group, 0x10U, swizzleArg);
1099 readState = BK_READ_DONE;
1100 break;
1101 default:
1102 keepReading = FALSE;
1103 break;
1104 }
1105 }
1106 return fileData;
1107}
@ BK_READ_SWIZZLE

◆ snd_load_BK()

s32 snd_load_BK ( s32 bkFileOffset,
s32 bankIndex )

Definition at line 1109 of file 2e230_len_2190.c.

1109 {
1110 au_load_BK_to_bank(bkFileOffset, gSoundGlobals->banks[bankIndex], bankIndex, 1);
1111 return 0;
1112}
SoundBank * au_load_BK_to_bank(s32 bkFileOffset, SoundBank *bank, s32 bankIndex, s32 bankGroup)

Referenced by au_ambient_load(), au_load_song_files(), func_80053E58(), and snd_load_BGM().

◆ func_80054C84()

void func_80054C84 ( s32 bankIndex,
s32 bankGroup )

Definition at line 1114 of file 2e230_len_2190.c.

1114 {
1115 u32 i;
1117 InstrumentGroup* group = au_get_BK_instruments(bankGroup, bankIndex);
1118 Instrument** ptr = *group;
1119 if (group != NULL) {
1120 for (i = 0; i < ARRAY_COUNT(*group); i++) {
1121 *ptr++ = instrument;
1122 }
1123 }
1124}

◆ func_80054CE0()

void func_80054CE0 ( s32 arg0,
u32 idx )

Definition at line 1126 of file 2e230_len_2190.c.

1126 {
1127 if (idx < ARRAY_COUNT(D_80078530)) {
1128 s32 temp_s0 = D_80078530[idx];
1129 if (arg0 & 1) {
1130 gBGMPlayerA->busVolume = temp_s0;
1132 gBGMPlayerB->busVolume = temp_s0;
1134 }
1135 if (arg0 & 0x10) {
1136 gSoundManager->busVolume = temp_s0;
1138 }
1139 }
1140}
u16 D_80078530[9]
Definition sfx_player.c:289
void func_80053AC8(Fade *fade)
s32 busVolume
Definition audio.h:1015

Referenced by func_800561A4(), and func_800561C4().

◆ func_80054D74()

s32 func_80054D74 ( s32 arg0,
s32 arg1 )

Definition at line 1142 of file 2e230_len_2190.c.

1142 {
1143 if (arg0 & 0x10) {
1145 }
1146 return 0;
1147}
s32 au_sfx_set_reverb_type(SoundManager *manager, s32 arg1)
Definition sfx_player.c:664

Referenced by func_800561E4().

◆ func_80054DA8()

void func_80054DA8 ( u32 arg0)

Definition at line 1149 of file 2e230_len_2190.c.

1149 {
1150 if (bMonoSound % 2 == 1) {
1151 // mono sound
1152 if (gSoundGlobals->unk_130C == 0) {
1154 }
1155 } else {
1156 // stereo sound
1157 if (gSoundGlobals->unk_130C != 0) {
1160 }
1161 }
1162}

Referenced by audio_set_mono(), and audio_set_stereo().

◆ au_read_rom()

void au_read_rom ( s32 romAddr,
void * buffer,
u32 size )

Definition at line 1166 of file 2e230_len_2190.c.

1166 {
1167 s32 nchunks = size / 0x2000;
1168 s32 offset = 0;
1169
1170 if (nchunks != 0) {
1171 while (nchunks--) {
1172 nuPiReadRom(romAddr + offset, buffer + offset, 0x2000);
1173 offset += 0x2000;
1174 }
1175 }
1176
1177 size %= 0x2000;
1178 if (size != 0) {
1179 nuPiReadRom(romAddr + offset, buffer + offset, size);
1180 }
1181}

Referenced by au_ambient_load(), au_engine_init(), au_load_BK_headers(), au_load_BK_to_bank(), au_load_INIT(), au_load_PER(), au_load_PRG(), au_load_song_files(), func_80053E58(), and func_80054AA0().

◆ au_memset()

void au_memset ( void * dst,
s32 size,
u8 value )

Definition at line 1183 of file 2e230_len_2190.c.

1183 {
1184 s32 count;
1185 s32 intValue;
1186
1187 if (size == 0) {
1188 return;
1189 }
1190
1191 if (size < 1024) {
1192 while (size--) {
1193 *(u8*)dst++ = value;
1194 }
1195 } else {
1196 count = (u32)dst & 0x3;
1197 if (count != 0) {
1198 count = 4 - count;
1199 size -= count;
1200 while (count--) {
1201 *(u8*)dst++ = value;
1202 }
1203 }
1204
1205 count = size >> 2;
1206 intValue = (value << 8) + value;
1207 intValue = (intValue << 16) + intValue;
1208 while (count--) {
1209 *(u32*)dst = intValue;
1210 dst += 4;
1211 }
1212
1213 count = size & 3;
1214 if (count != 0) {
1215 while (count--) {
1216 *(u8*)dst++ = value;
1217 }
1218 }
1219 }
1220}

Referenced by au_amb_manager_init(), and au_amb_play_sequence().

◆ au_copy_bytes()

void au_copy_bytes ( s8 * src,
s8 * dest,
s32 size )

Definition at line 1222 of file 2e230_len_2190.c.

1222 {
1223 if (size > 0) {
1224 while (size-- != 0) {
1225 *dest++ = *src++;
1226 }
1227 }
1228}

◆ au_copy_words()

void au_copy_words ( void * src,
void * dst,
s32 size )

Definition at line 1230 of file 2e230_len_2190.c.

1230 {
1231 size /= 4;
1232
1233 if (size > 0) {
1234 if (!(((s32) src | (s32) dst) & 3)) {
1235 s32* srcIt = src;
1236 s32* dstIt = dst;
1237
1238 size--;
1239 do {
1240 *dstIt++ = *srcIt++;
1241 } while (size-- != 0);
1242 }
1243 }
1244}

Referenced by au_load_PER(), au_load_PRG(), func_8004DCB8(), and func_8004DFD4().

◆ create_audio_system()

void create_audio_system ( void )

Definition at line 39 of file 25f00_len_940.c.

39 {
40 u32 i;
41 u32 outputRate, frameSize;
42 ALConfig config;
43
44 nuAuTaskStop = NU_AU_TASK_RUN;
45 nuAuPreNMI = 0;
47 config.num_pvoice = 24;
48 config.num_bus = 4;
49 outputRate = osAiSetFrequency(32000);
50 frameSize = (nusched.retraceCount * outputRate + 59) / 60;
51 config.outputRate = outputRate;
52 config.unk_0C = 0;
53 config.heap = &nuAuHeap;
54 config.dmaNew = nuAuDmaNew;
55 AlFrameSize = ((frameSize / AUDIO_SAMPLES) + 1) * AUDIO_SAMPLES;
57
58 for (i = 0; i < ARRAY_COUNT(AlCmdListBuffers); i++) {
60 }
61
62 for (i = 0; i < ARRAY_COUNT(nuAuTasks); i++) {
63 nuAuTasks[i].next = NULL;
64 nuAuTasks[i].msg = 0;
65 nuAuTasks[i].list.t.type = M_AUDTASK;
66#if VERSION_IQUE
67 nuAuTasks[i].list.t.ucode_boot = (u64*) rspbootTextStart;
68 nuAuTasks[i].list.t.ucode_boot_size = (u32) rspbootTextEnd - (u32) rspbootTextStart;
69#else
70 nuAuTasks[i].list.t.ucode_boot = (u64*) rspbootUcodeBuffer;
71 nuAuTasks[i].list.t.ucode_boot_size = 0x100;
72#endif
73 nuAuTasks[i].list.t.ucode = n_aspMain_text_bin;
74 nuAuTasks[i].list.t.ucode_data = n_aspMain_data_bin;
75 nuAuTasks[i].list.t.ucode_data_size = SP_UCODE_DATA_SIZE;
76 nuAuTasks[i].list.t.dram_stack = NULL;
77 nuAuTasks[i].list.t.dram_stack_size = 0;
78 nuAuTasks[i].list.t.output_buff = NULL;
79 nuAuTasks[i].list.t.output_buff_size = 0;
80 nuAuTasks[i].list.t.yield_data_ptr = NULL;
81 nuAuTasks[i].list.t.yield_data_size = 0;
82 }
83
84 for (i = 0; i < ARRAY_COUNT(D_800A3628); i++) {
85 D_800A3628[i] = alHeapAlloc(config.heap, 1, AlFrameSize * 4);
86 }
87
88 nuAuDmaBufList[0].node.next = nuAuDmaBufList[0].node.prev = NULL;
89 for (i = 0; i < ARRAY_COUNT(nuAuDmaBufList) - 1; i++) {
90 alLink(&nuAuDmaBufList[i+1].node, &nuAuDmaBufList[i].node);
91 nuAuDmaBufList[i].ptr = alHeapAlloc(config.heap, 1, 0x500);
92 }
93 nuAuDmaBufList[i].ptr = alHeapAlloc(config.heap, 1, 0x500);
94
95 osCreateMesgQueue(&nuAuDmaMesgQ, nuAuDmaMesgBuf, 50);
97 au_driver_init(&auSynDriver, &config);
99 osCreateThread(&nuAuMgrThread, NU_MAIN_THREAD_ID, nuAuMgr, NULL, &AuStack[NU_AU_STACK_SIZE / sizeof(u64)], NU_AU_MGR_THREAD_PRI); //why main thread?
100 osStartThread(&nuAuMgrThread);
101}
BSS OSThread nuAuMgrThread
u8 AuHeapBase[AUDIO_HEAP_SIZE]
u8 nuAuPreNMI
u64 n_aspMain_data_bin[]
AuSynDriver auSynDriver
BSS NUDMABuffer nuAuDmaBufList[50]
ALHeap nuAuHeap
void alLink(ALLink *element, ALLink *after)
BSS NUScTask nuAuTasks[3]
BSS s32 AlFrameSize
void nuAuPreNMIProc(NUScMsg mesg_type, u32 frameCounter)
BSS OSMesg nuAuDmaMesgBuf[50]
BSS u8 * D_800A3628[3]
void nuAuMgr(void *arg)
BSS u64 AuStack[NU_AU_STACK_SIZE/sizeof(u64)]
u64 n_aspMain_text_bin[]
BSS s32 AlMinFrameSize
u8 nuAuTaskStop
ALDMAproc nuAuDmaNew(NUDMAState **state)
NUAuPreNMIFunc nuAuPreNMIFunc
BSS Acmd * AlCmdListBuffers[3]
BSS OSMesgQueue nuAuDmaMesgQ
void au_engine_init(s32 outputRate)
void au_driver_init(AuSynDriver *driver, ALConfig *config)
Definition 31650.c:25
void alHeapInit(ALHeap *hp, u8 *base, s32 len)
Definition 31650.c:725
ALHeap * heap
Definition audio.h:1186
s32 num_pvoice
Definition audio.h:1180
#define AUDIO_HEAP_SIZE
Definition audio.h:42
void * dmaNew
Definition audio.h:1185
u8 unk_0C
Definition audio.h:1183
s32 outputRate
Definition audio.h:1182
#define AUDIO_COMMAND_LIST_BUFFER_SIZE
Definition audio.h:45
s32 num_bus
Definition audio.h:1181

◆ nuAuMgr()

void nuAuMgr ( void * arg)

Definition at line 110 of file 25f00_len_940.c.

110 {
111 NUScClient auClient;
112 OSMesgQueue auMesgQ;
113 OSMesg auMsgBuf[NU_AU_MESG_MAX];
114 OSMesgQueue auRtnMesgQ;
115 OSMesg auRtnMesgBuf;
116 NUScMsg* mesg_type;
117 s32 cmdList_len;
118 Acmd* cmdListAfter_ptr;
119 s32 cmdListIndex;
120 s32 bufferIndex;
121 s32 sampleSize;
122 Acmd* cmdListBuf;
123 u8* bufferPtr;
124 s32 samples;
125 s32 cond;
126
127 osCreateMesgQueue(&auMesgQ, auMsgBuf, NU_AU_MESG_MAX);
128 osCreateMesgQueue(&auRtnMesgQ, &auRtnMesgBuf, 1);
129 nuScAddClient(&auClient, &auMesgQ, NU_SC_RETRACE_MSG | NU_SC_PRENMI_MSG);
130
131 cmdList_len = 0;
132 cmdListIndex = 0;
133 bufferIndex = 0;
134 samples = 0;
135 cmdListBuf = AlCmdListBuffers[0];
136 bufferPtr = D_800A3628[0];
137 while (TRUE) {
138 osRecvMesg(&auMesgQ, (OSMesg*)&mesg_type, OS_MESG_BLOCK);
139 switch (*mesg_type) {
140 case NU_SC_RETRACE_MSG:
141 if (cmdList_len != 0 && nuAuTaskStop == NU_AU_TASK_RUN) {
142 nuAuTasks[cmdListIndex].msgQ = &auRtnMesgQ;
143 nuAuTasks[cmdListIndex].list.t.data_ptr = (u64*)cmdListBuf;
144 nuAuTasks[cmdListIndex].list.t.data_size = (cmdListAfter_ptr - cmdListBuf) * sizeof(Acmd);
146 osSendMesg(&nusched.audioRequestMQ, &nuAuTasks[cmdListIndex], OS_MESG_BLOCK);
149 osRecvMesg(&auRtnMesgQ, NULL, 1);
150 if (++bufferIndex == 3) {
151 bufferIndex = 0;
152 }
153 if (++cmdListIndex == 3) {
154 cmdListIndex = 0;
155 }
156 }
157 profiler_audio_started(); // XXX: is this the right place?
158 if (osAiGetStatus() & AI_STATUS_FIFO_FULL) {
159 cond = FALSE;
161 continue;
162 }
163 sampleSize = osAiGetLength() >> 2;
164 if (cmdList_len != 0 && nuAuTaskStop == NU_AU_TASK_RUN) {
165 osAiSetNextBuffer(bufferPtr, samples * 4);
166 cmdListBuf = AlCmdListBuffers[cmdListIndex];
167 bufferPtr = D_800A3628[bufferIndex];
168 }
169 if (sampleSize < AUDIO_SAMPLES || cond) {
170 samples = AlFrameSize;
171 cond = FALSE;
172 } else {
173 samples = AlMinFrameSize;
174 cond = TRUE;
175 }
176 cmdListAfter_ptr = alAudioFrame(cmdListBuf, &cmdList_len, (s16*)osVirtualToPhysical(bufferPtr), samples);
177 if (nuAuPreNMIFunc != 0 && nuAuPreNMI != 0) {
178 nuAuPreNMIFunc(NU_SC_RETRACE_MSG, nuAuPreNMI);
179 nuAuPreNMI++;
180 }
181
182 break;
183 case NU_SC_PRENMI_MSG:
184 if (nuAuPreNMIFunc) {
185 nuAuPreNMIFunc(NU_SC_PRENMI_MSG, nuAuPreNMI);
186 }
187 nuAuPreNMI++;
188 break;
189 }
191 }
192}
void nuAuCleanDMABuffers(void)
Acmd * alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen)
Definition 31650.c:119
@ PROFILER_RSP_AUDIO
Definition profiling.h:99
#define profiler_rsp_started(which)
Definition profiling.h:160
#define profiler_rsp_completed(which)
Definition profiling.h:161
#define profiler_audio_completed()
Definition profiling.h:164
#define profiler_audio_started()
Definition profiling.h:163

Referenced by create_audio_system().

◆ nuAuDmaCallBack()

s32 nuAuDmaCallBack ( s32 addr,
s32 len,
void * state,
u8 arg3 )

Definition at line 194 of file 25f00_len_940.c.

194 {
195 NUDMABuffer* dmaPtr;
196 NUDMABuffer* freeBuffer;
197 OSIoMesg* mesg;
198 s32 delta;
199 u32 startAddr;
200 s32 addrEnd, buffEnd;
201 NUDMABuffer* lastDmaPtr;
202
203 if (arg3 == 0) {
204 return osVirtualToPhysical((void*)addr);
205 }
206
207 lastDmaPtr = NULL;
208 dmaPtr = nuAuDmaState.firstUsed;
209 addrEnd = addr + len;
210
211 while (dmaPtr != NULL) {
212 startAddr = dmaPtr->startAddr;
213 buffEnd = dmaPtr->startAddr + 0x500;
214 if (addr >= startAddr && buffEnd >= addrEnd) {
215 dmaPtr->frameCnt = nuAuFrameCounter;
216 freeBuffer = (NUDMABuffer*)(dmaPtr->ptr + addr - dmaPtr->startAddr);
217 return osVirtualToPhysical(freeBuffer);
218 } else if (addr < startAddr) {
219 break;
220 }
221 lastDmaPtr = dmaPtr;
222 dmaPtr = (NUDMABuffer*)dmaPtr->node.next;
223 }
224
225 dmaPtr = nuAuDmaState.firstFree;
226 if (dmaPtr == NULL) {
227 return osVirtualToPhysical(nuAuDmaState.firstUsed);
228 }
229
230 nuAuDmaState.firstFree = (NUDMABuffer*)dmaPtr->node.next;
231 alUnlink(&dmaPtr->node);
232
233 if (lastDmaPtr != NULL) {
234 alLink(&dmaPtr->node, &lastDmaPtr->node);
235 } else if (nuAuDmaState.firstUsed != NULL){
236 lastDmaPtr = nuAuDmaState.firstUsed;
237 nuAuDmaState.firstUsed = dmaPtr;
238 dmaPtr->node.next = &lastDmaPtr->node;
239 dmaPtr->node.prev = NULL;
240 lastDmaPtr->node.prev = &dmaPtr->node;
241 } else {
242 nuAuDmaState.firstUsed = dmaPtr;
243 dmaPtr->node.next = NULL;
244 dmaPtr->node.prev = NULL;
245 }
246
247 freeBuffer = (NUDMABuffer*)dmaPtr->ptr;
248 delta = addr & 1;
249 addr -= delta;
250 dmaPtr->startAddr = addr;
251 dmaPtr->frameCnt = nuAuFrameCounter;
252
253 mesg = &nuAuDmaIOMesgBuf[nuAuDmaNext++];
254 mesg->hdr.pri = OS_MESG_PRI_NORMAL;
255 mesg->hdr.retQueue = &nuAuDmaMesgQ;
256 mesg->dramAddr = freeBuffer;
257 mesg->devAddr = addr;
258 mesg->size = 0x500;
259 osEPiStartDma(nuPiCartHandle, mesg, 0);
260 return osVirtualToPhysical(freeBuffer) + delta;
261}
u32 nuAuFrameCounter
BSS NUDMAState nuAuDmaState
void alUnlink(ALLink *element)
s32 nuAuDmaNext
BSS OSIoMesg nuAuDmaIOMesgBuf[50]

Referenced by nuAuDmaNew().

◆ au_load_BK_headers()

void au_load_BK_headers ( AuGlobals * arg0,
ALHeap * heap )

Definition at line 10 of file 303c0_len_3e10.c.

10 {
11 SBNFileEntry fileEntry;
12 BufferEntry buffer[80];
13 s32 i;
14
15 au_read_rom(globals->bkFileListOffset, &buffer, globals->bkListLength);
16
17 for (i = 0; i < ARRAY_COUNT(buffer); i++) {
18 if (buffer[i].fileIndex == 0xFFFF) {
19 break;
20 }
21
22 au_fetch_SBN_file(buffer[i].fileIndex, AU_FMT_BK, &fileEntry);
23 au_load_BK_to_bank(fileEntry.offset, NULL, buffer[i].bankIndex, buffer[i].bankGroup);
24 }
25}

Referenced by au_engine_init().

◆ au_sfx_init()

void au_sfx_init ( SoundManager * manager,
u8 arg1,
u8 arg2,
AuGlobals * arg3,
u8 arg4 )

Definition at line 423 of file sfx_player.c.

423 {
424 u32 i;
425 s32 c = 434782;
426
427 manager->globals = globals;
428 manager->nextUpdateStep = 312500;
429 manager->nextUpdateCounter = c;
430 manager->nextUpdateInterval = c;
431 manager->priority = priority;
432 manager->busId = busId;
433
434 if (minVoiceIdx > 16) {
435 manager->sfxPlayerSelector = 16;
436 } else {
437 manager->sfxPlayerSelector = minVoiceIdx;
438 }
439
440 manager->busVolume = 0x8000;
441 manager->baseVolume = 0x8000;
442 manager->playCounter = 0;
443 manager->randomValue = 0;
444
445 for (i = 0; i < ARRAY_COUNT(manager->players); i++) {
446 SoundPlayer* player = &manager->players[i];
447
448 player->sefDataReadPos = NULL;
449 player->sfxVolume = 0;
450 player->delay = 0;
451 player->playLength = 0;
452 player->coarseTune = 0;
453 player->fineTune = 0;
454 player->sfxPan = 0;
455 player->reverb = 0;
456 player->instrumentIndex = 0;
457 player->envelopePreset = 0;
458 player->playVelocity = 0;
459 player->exclusiveID = 0;
460 player->cmdList_mode2[0] = 0;
461 player->cmdList_mode2[1] = 0;
462 player->cmdList_mode2[2] = 0;
463 player->cmdList_mode2[3] = 64; // default pan
464 player->cmdList_mode2[4] = 0;
465 player->cmdList_mode2[5] = 0x80 + 48; // default tune, higher bit is meaningless
466 player->cmdList_mode2[6] = 0;
467 player->cmdList_mode2[7] = 0;
468 }
469
470 for (i = 0; i < ARRAY_COUNT(manager->bgmSounds); i++) {
471 manager->bgmSounds[i].s32 = 0;
472 }
473
474 for (i = 0; i < ARRAY_COUNT(manager->customCmdList); i++) {
475 manager->customCmdList[i].data[0] = 0;
476 }
477
478 manager->resetPending = FALSE;
480 au_sfx_clear_queue(manager);
481 au_fade_init(&manager->fadeInfo, 0, 0x7FFF, 0x7FFF);
482 au_fade_set_volume(manager->busId, manager->fadeInfo.curVolume.u16, manager->busVolume);
483 manager->lastCustomEffectIdx = 0xFF;
484
493
494 manager->customReverbAmounts[0] = 0x10;
495 manager->customReverbAmounts[1] = 0x20;
496 manager->customReverbAmounts[2] = 0x20;
497 manager->customReverbAmounts[3] = 0x20;
498 manager->customReverbAmounts[4] = 0x20;
499 manager->customReverbAmounts[5] = 0x30;
500 manager->customReverbAmounts[6] = 0x40;
501 manager->customReverbAmounts[7] = 0x50;
502
503 au_sfx_set_reverb_type(manager, 0);
504}
void au_fade_init(Fade *fade, s32 time, s32 startValue, s32 endValue)
@ SND_MANAGER_STATE_ENABLED
Definition audio.h:237
u8 instrumentIndex
Definition audio.h:628
s32 * customReverbParams[8]
Definition audio.h:671
u8 lastCustomEffectIdx
Definition audio.h:673
u16 playLength
Definition audio.h:618
AuFilePos sefDataReadPos
Definition audio.h:596
struct AuGlobals * globals
Definition audio.h:659
s16 coarseTune
Definition audio.h:619
SoundManager90 bgmSounds[4]
Definition audio.h:676
u16 baseVolume
Definition audio.h:678
u8 reverb
Definition audio.h:627
u8 envelopePreset
Definition audio.h:629
SoundPlayer players[8]
Definition audio.h:693
s32 playCounter
Definition audio.h:664
s32 randomValue
Definition audio.h:670
u8 cmdList_mode2[8]
Definition audio.h:609
SoundManagerCustomCmdList customCmdList[4]
Definition audio.h:677
u8 sfxPlayerSelector
Definition audio.h:681
u8 exclusiveID
Definition audio.h:624
s16 sfxVolume
Definition audio.h:605
s8 fineTune
Definition audio.h:620
u16 delay
Definition audio.h:617
s8 customReverbAmounts[8]
Definition audio.h:672
u8 priority
Definition audio.h:680
s32 resetPending
Definition audio.h:692
u8 playVelocity
Definition audio.h:630
u8 sfxPan
Definition audio.h:626
s32 CUSTOM_ECHO_PARAMS_1[]
Definition sfx_player.c:95
s32 CUSTOM_SMALL_ROOM_PARAMS[]
Definition sfx_player.c:84
void au_sfx_set_state(SoundManager *manager, s32 state)
Definition sfx_player.c:684
s32 CUSTOM_ECHO_PARAMS_3[]
Definition sfx_player.c:113
s32 CUSTOM_ECHO_PARAMS_2[]
Definition sfx_player.c:104
void au_sfx_clear_queue(SoundManager *manager)
Definition sfx_player.c:526
s32 au_sfx_set_reverb_type(SoundManager *manager, s32 arg1)
Definition sfx_player.c:664

Referenced by au_engine_init().

◆ au_sfx_load_groups_from_SEF()

void au_sfx_load_groups_from_SEF ( SoundManager * sndMgr)

Definition at line 506 of file sfx_player.c.

506 {
507 SEFHeader* sefData = manager->globals->dataSEF;
508 s32 sections = ARRAY_COUNT(sefData->sections);
509 u32 i;
510
511 manager->sefData = (u8*)sefData;
512
513 for (i = 0; i < sections; i++) {
514 if (sefData->sections[i] != 0) {
515 manager->normalSounds[i] = AU_FILE_RELATIVE(sefData, sefData->sections[i]);
516 }
517 }
518
519 if (sefData->hasExtraSection == 1) {
520 if (sefData->section2000 != 0) {
521 manager->extraSounds = AU_FILE_RELATIVE(sefData, sefData->section2000);
522 }
523 }
524}
u16 sections[8]
Definition audio.h:810
u16 section2000
Definition audio.h:811
u8 hasExtraSection
Definition audio.h:808

Referenced by au_engine_init().

◆ au_sfx_clear_queue()

void au_sfx_clear_queue ( SoundManager * manager)

Definition at line 526 of file sfx_player.c.

526 {
527 s32 i;
528
529 for (i = 0; i < ARRAY_COUNT(manager->soundQueue); i++) {
530 manager->soundQueue[i].soundID = 0;
531 manager->soundQueue[i].upperSoundID = 0;
532 manager->soundQueue[i].volume = 0;
533 manager->soundQueue[i].pitchShift = 0;
534 manager->soundQueue[i].pan = 0;
535 }
536
537 manager->unk_165 = 0;
538 manager->sfxQueueNextPos = 0;
539 manager->sfxQueuePosOffset = 0;
540 manager->unk_162 = 0;
541}
u16 soundID
Definition audio.h:524
s16 pitchShift
Definition audio.h:527
u8 sfxQueueNextPos
Definition audio.h:689
u8 sfxQueuePosOffset
Definition audio.h:688
SoundSFXEntry soundQueue[16]
Definition audio.h:686
u16 upperSoundID
Definition audio.h:525

Referenced by au_sfx_init().

◆ au_sfx_enqueue_event()

void au_sfx_enqueue_event ( SoundManager * manager,
u32 soundID,
s16 volume,
s16 pitchShift,
u8 pan )

Definition at line 543 of file sfx_player.c.

543 {
544 u32 queuePos = manager->sfxQueueNextPos;
545 s32 queueAmt = manager->sfxQueueNextPos - manager->sfxQueuePosOffset;
546
547 if (queueAmt < 0) {
548 queueAmt += 16;
549 }
550
551 if (queueAmt < 16) {
552 u32 queueNextPos = queuePos;
553
554 manager->soundQueue[queueNextPos].soundID = soundID & (SOUND_ID_LOWER | SOUND_ID_STOP | SOUND_ID_ADJUST | SOUND_ID_TRIGGER_MASK);
555 manager->soundQueue[queueNextPos].upperSoundID = ((soundID >> 0x10) & 0x3FF);
556 manager->soundQueue[queueNextPos].volume = volume;
557 manager->soundQueue[queueNextPos].pitchShift = pitchShift;
558 manager->soundQueue[queueNextPos].pan = pan;
559
560 queueNextPos++;
561 if (queueNextPos >= 16) {
562 queueNextPos = 0;
563 }
564
565 manager->sfxQueueNextPos = queueNextPos;
566 }
567}
@ SOUND_ID_ADJUST
Definition enums.h:529
@ SOUND_ID_TRIGGER_MASK
Definition enums.h:530
@ SOUND_ID_STOP
Definition enums.h:526
@ SOUND_ID_LOWER
Definition enums.h:527

Referenced by snd_adjust_sound(), snd_adjust_sound_with_shift(), snd_start_sound(), snd_start_sound_raw(), snd_start_sound_with_shift(), and snd_stop_sound().

◆ au_sfx_update_main()

void au_sfx_update_main ( SoundManager * manager)

Definition at line 569 of file sfx_player.c.

569 {
570 SoundSFXEntry newEntry;
571 SoundSFXEntry* sfxEntry;
572 u32 i, j, k;
573 s32 count;
574
575 manager->playCounter++;
576 if (manager->resetPending) {
577 au_sfx_reset_players(manager);
578 manager->resetPending = FALSE;
579 }
580
581 // sounds started by special seq command FF-05
582 for (i = 0; i < ARRAY_COUNT(manager->bgmSounds); i++) {
583 k = manager->bgmSounds[i].unk_0;
584 if (k == 0) {
585 // do nothing
586 } else if (k < 2) {
587 AlUnkGemini* unkData = &D_80078370[k-1];
588 u16 sound2 = unkData->sound2;
589 if (sound2 != 0) {
590 for (j = 0; j < ARRAY_COUNT(manager->players); j++) {
591 if (manager->players[j].curSoundID == sound2) {
592 newEntry.soundID = unkData->sound1;
593 newEntry.upperSoundID = 0;
594 newEntry.pitchShift = 0;
595 if ((unkData->flags & 1) && (manager->bgmSounds[i].volume != 0)) {
596 newEntry.volume = (manager->bgmSounds[i].volume << 8) + 0xFF;
597 } else {
598 newEntry.volume = 0;
599 }
600 newEntry.pan = 0;
601 au_sfx_load_sound(manager, &newEntry, NULL);
602 break;
603 }
604 }
605 } else {
606 newEntry.soundID = unkData->sound1;
607 newEntry.upperSoundID = 0;
608 newEntry.volume = 0;
609 newEntry.pitchShift = 0;
610 newEntry.pan = 0;
611 au_sfx_load_sound(manager, &newEntry, NULL);
612 }
613 }
614 manager->bgmSounds[i].s32 = 0;
615 }
616
617 // sounds started from sef command 17
618 for (i = 0; i < ARRAY_COUNT(manager->customCmdList); i++) {
619 if (manager->customCmdList[i].data[0] != 0) {
620 newEntry.soundID = 1;
621 newEntry.upperSoundID = 0;
622 newEntry.volume = 0;
623 newEntry.pitchShift = 0;
624 newEntry.pan = 0;
625 au_sfx_load_sound(manager, &newEntry, &manager->customCmdList[i]);
626 }
627 manager->customCmdList[i].data[0] = 0;
628 }
629
630 count = manager->sfxQueueNextPos - manager->sfxQueuePosOffset;
631 if (count < 0) {
632 count += ARRAY_COUNT(manager->soundQueue);
633 }
634 j = manager->sfxQueuePosOffset;
635 if (count > 0 && count < ARRAY_COUNT(manager->soundQueue)) {
636 for (i = 0; i < count; i++) {
637 sfxEntry = &manager->soundQueue[j];
638 if (sfxEntry->soundID & SOUND_ID_LOWER) {
639 if (sfxEntry->soundID & SOUND_ID_STOP) {
640 au_sfx_stop_by_id(manager, sfxEntry->soundID);
641 } else if (!(sfxEntry->soundID & (SOUND_ID_ADJUST | SOUND_ID_TRIGGER_MASK))) {
642 au_sfx_load_sound(manager, sfxEntry, NULL);
643 } else {
644 if (sfxEntry->soundID & SOUND_ID_TRIGGER_MASK) {
645 au_sfx_set_triggers(manager, sfxEntry->soundID);
646 }
647 if (sfxEntry->soundID & SOUND_ID_ADJUST) {
648 au_sfx_set_modifiers(manager, sfxEntry);
649 }
650 }
651 }
652 sfxEntry->soundID = SOUND_NONE;
653
654 j++;
655 if (j >= ARRAY_COUNT(manager->soundQueue)) {
656 j = 0;
657 }
658 }
659 manager->sfxQueuePosOffset = manager->sfxQueueNextPos;
660 }
661}
u16 sound1
Definition audio.h:1174
u16 curSoundID
Definition audio.h:622
u16 sound2
Definition audio.h:1175
@ SOUND_NONE
Definition enums.h:547
void au_sfx_load_sound(SoundManager *manager, SoundSFXEntry *entry, SoundManagerCustomCmdList *customSEF)
Definition sfx_player.c:692
AlUnkGemini D_80078370[]
Definition sfx_player.c:121

Referenced by au_update_players_main().

◆ au_sfx_set_reverb_type()

s32 au_sfx_set_reverb_type ( SoundManager * manager,
s32 arg1 )

Definition at line 664 of file sfx_player.c.

664 {
665 s32 customIdx = (u8) arg1;
666
667 if (customIdx != 0xF0) {
668 if (customIdx < ARRAY_COUNT(manager->customReverbParams)) {
669 if (manager->lastCustomEffectIdx != customIdx) {
670 manager->lastCustomEffectIdx = customIdx;
672 manager->globals->effectChanges[FX_BUS_SOUND].changed = TRUE;
673 AU_FX_CUSTOM_PARAMS[0] = manager->customReverbParams[customIdx];
674 }
675 manager->defaultReverbAmt = manager->customReverbAmounts[customIdx];
676 } else {
677 manager->lastCustomEffectIdx = 0xFF;
678 manager->defaultReverbAmt = 0;
679 }
680 }
681 return manager->lastCustomEffectIdx;
682}
@ AU_FX_CUSTOM_0
Definition audio.h:93
s8 defaultReverbAmt
Definition audio.h:674
s32 * AU_FX_CUSTOM_PARAMS[0]
Definition reverb.c:103

Referenced by au_sfx_init(), and func_80054D74().

◆ au_sfx_set_state()

void au_sfx_set_state ( SoundManager * manager,
s32 arg1 )

Definition at line 684 of file sfx_player.c.

684 {
685 if (state == SND_MANAGER_STATE_ENABLED) {
687 } else if (state == SND_MANAGER_STATE_DISABLED) {
689 }
690}
@ SND_MANAGER_STATE_DISABLED
Definition audio.h:238

Referenced by au_sfx_init(), disable_sounds(), and enable_sounds().

◆ au_sfx_load_sound()

void au_sfx_load_sound ( SoundManager * manager,
SoundSFXEntry * entry,
SoundManagerCustomCmdList * customSEF )

Definition at line 692 of file sfx_player.c.

692 {
693 SoundPlayer* player;
694 s32 playerIndex;
695 u16* cmdList;
696 s32 trackCount;
697 s32 foundPlayer = FALSE;
698 u32 exclusiveID;
699 s32 sectionIndex;
700 u16 soundInfo;
701 u32 priority, polyphonyMode, useSpecificPlayerMode;
702 s32 v1;
703 s32* normalSounds;
704
705 #define NEXT_CMD trackCount--; if (trackCount <= 0 ) { break; } cmdList += 2;
706
707 u32 soundIndex = (entry->soundID - 1) & 0xFF;
708 u16 soundIDLower = entry->soundID & SOUND_ID_LOWER;
709 u16 soundID = entry->soundID;
710
711 if (soundID & SOUND_ID_UNK) {
712 // sound from extra section
713 soundIndex = (entry->soundID - 1) & SOUND_ID_UNK_INDEX_MASK;
714 if (soundIndex < 0x140) {
715 cmdList = (u16*)&manager->extraSounds[soundIndex];
716 if (*cmdList != 0) {
717 // check if any player is playing this sound
718 for (playerIndex = 7; playerIndex >= 0; playerIndex--) {
719 player = &manager->players[playerIndex];
720 if (player->curSoundID == soundIDLower) {
721 foundPlayer = TRUE;
722 break;
723 }
724 }
725
726 if (!foundPlayer) {
727 //find free player
728 for (playerIndex = 7; playerIndex >= 0; playerIndex--) {
729 player = &manager->players[playerIndex];
730 if (player->sefDataReadPos == NULL) {
731 foundPlayer = TRUE;
732 break;
733 }
734 }
735 }
736
737 if (foundPlayer) {
738 au_sfx_play_sound(manager, player, (s8*)cmdList, entry, 0, 0);
739 }
740 }
741 }
742 } else {
743 if (soundIndex >= 0xC0) {
744 if (customSEF != NULL) {
745 cmdList = (u16*)customSEF;
746 } else {
747 sectionIndex = ((soundIDLower - 1) >> 8) + 4;
748 normalSounds = manager->normalSounds[sectionIndex];
749 v1 = soundIndex - 0xC0;
750 cmdList = (u16*)&manager->normalSounds[sectionIndex][v1];
751 }
752
753 if (*cmdList != 0) {
754 // check if any player is playing this sound
755 for (playerIndex = 7; playerIndex >= 0; playerIndex--) {
756 player = &manager->players[playerIndex];
757 if (player->curSoundID == soundIDLower) {
758 foundPlayer = TRUE;
759 break;
760 }
761 }
762
763 if (!foundPlayer) {
764 //find free player
765 for (playerIndex = 7; playerIndex >= 0; playerIndex--) {
766 player = &manager->players[playerIndex];
767 if (player->sefDataReadPos == NULL) {
768 foundPlayer = TRUE;
769 break;
770 }
771 }
772 }
773
774 if (foundPlayer) {
775 au_sfx_play_sound(manager, player, (u8*)cmdList, entry, 0, 0);
776 }
777 }
778 } else {
779 if (customSEF != NULL) {
780 cmdList = (u16*)customSEF;
781 } else {
782 sectionIndex = ((soundID) >> 8) & 3;
783 cmdList = (u16*)&manager->normalSounds[sectionIndex][soundIndex];
784 }
785
786 if (*cmdList != 0) {
787 // read sound info chunk
788 soundInfo = cmdList[1];
789
790 priority = (soundInfo & 0x300) >> 8; // bits 8, 9
791 polyphonyMode = (soundInfo & 0x60) >> 5; // bits 5, 6,
792 useSpecificPlayerMode = soundInfo;
793 useSpecificPlayerMode = (useSpecificPlayerMode & 0x80) >> 7; // bit 7
794
795 if (polyphonyMode == 0) {
796 if (entry->upperSoundID != 0) {
797 for (playerIndex = 0; playerIndex < 8; playerIndex++) {
798 player = &manager->players[playerIndex];
799 if (player->curSoundID == entry->upperSoundID) {
800 foundPlayer = TRUE;
801 break;
802 }
803 }
804 }
805
806 if (useSpecificPlayerMode == 0) {
807 if (!foundPlayer) {
808 playerIndex = soundInfo & 0x7;
809 player = &manager->players[playerIndex];
810 if (player->sefDataReadPos == NULL || priority >= player->priority) {
811 au_sfx_play_sound(manager, player, AU_FILE_RELATIVE(manager->sefData, *cmdList), entry, priority, 0);
812 }
813 return;
814 }
815 }
816
817 if (!foundPlayer) {
818 // lower 4 bits of soundInfo: max playerIndex
819 // check if any player is playing this sound
820 for (playerIndex = soundInfo & 0x7; playerIndex >= 0; playerIndex--) {
821 player = &manager->players[playerIndex];
822 if (player->curSoundID == soundIDLower) {
823 foundPlayer = TRUE;
824 break;
825 }
826 }
827 }
828
829 if (!foundPlayer) {
830 // find free player
831 for (playerIndex = soundInfo & 0x7; playerIndex >= 0; playerIndex--) {
832 player = &manager->players[playerIndex];
833 if (player->sefDataReadPos == NULL) {
834 foundPlayer = TRUE;
835 break;
836 }
837 }
838 }
839
840 if (!foundPlayer) {
841 // if there is no free player try stealing one with lower priority
842 for (playerIndex = soundInfo & 0x7; playerIndex >= 0; playerIndex--) {
843 player = &manager->players[playerIndex];
844 if (player->priority < priority) {
845 foundPlayer = TRUE;
846 break;
847 }
848 }
849 }
850
851 if (!foundPlayer) {
852 playerIndex = soundInfo & 0x7;
853 player = &manager->players[playerIndex];
854 if (player->priority <= priority) {
855 foundPlayer = TRUE;
856 }
857 }
858
859 if (foundPlayer) {
860 au_sfx_play_sound(manager, player, AU_FILE_RELATIVE(manager->sefData, *cmdList), entry, priority, 0);
861 }
862 } else {
863 cmdList = AU_FILE_RELATIVE(manager->sefData, *cmdList);
864 exclusiveID = (soundInfo & 0x1800) >> 11; // bits 11, 12
865 if (exclusiveID != 0) {
866 au_sfx_stop_by_exlusive_id(manager, exclusiveID);
867 } else {
868 au_sfx_stop_by_id(manager, entry->soundID);
869 }
870
871 trackCount = 2 << (polyphonyMode - 1); // 2 or 4 or 8
872
873 if (useSpecificPlayerMode != 0) {
874 for (playerIndex = 7; playerIndex >= 0; playerIndex--) {
875 if (*cmdList != 0) {
876 // first check the players that were stopped just now
877 player = &manager->players[playerIndex];
878 if (player->sefDataReadPos == BlankSEFData) {
879 au_sfx_play_sound(manager, player, AU_FILE_RELATIVE(manager->sefData, *cmdList), entry, priority, exclusiveID);
880 NEXT_CMD;
881 }
882 } else {
883 NEXT_CMD;
884 }
885
886 }
887
888 if (trackCount != 0) {
889 for (playerIndex = 7; playerIndex >= 0;){
890 if (*cmdList != 0) {
891 // then check any free players
892 player = &manager->players[playerIndex];
893 if (player->sefDataReadPos == NULL) {
894 au_sfx_play_sound(manager, player, AU_FILE_RELATIVE(manager->sefData, *cmdList), entry, priority, exclusiveID);
895 NEXT_CMD;
896 }
897 playerIndex--;
898 } else {
899 NEXT_CMD;
900 }
901 }
902 }
903
904 if (trackCount != 0) {
905 for (playerIndex = 7; playerIndex >= 0; playerIndex--) {
906 if (*cmdList != 0) {
907 // then try to steal
908 player = &manager->players[playerIndex];
909 if (exclusiveID > player->exclusiveID && priority >= player->priority) {
910 au_sfx_play_sound(manager, player, AU_FILE_RELATIVE(manager->sefData, *cmdList), entry, priority, exclusiveID);
911 NEXT_CMD;
912 }
913 } else {
914 NEXT_CMD;
915 }
916 }
917 }
918 } else {
919 s32 i;
920 for (i = 0; i < trackCount; i++) {
921 if (*cmdList != 0) {
922 soundInfo = cmdList[1];
923 playerIndex = soundInfo & 7;
924 player = &manager->players[playerIndex];
925 priority = (soundInfo & 0x300) >> 8; // bits 8, 9
926 if (player->sefDataReadPos == NULL || priority >= player->priority) {
927 au_sfx_play_sound(manager, player, AU_FILE_RELATIVE(manager->sefData, *cmdList), entry, priority, exclusiveID);
928 }
929 cmdList += 2;
930 }
931 }
932 }
933 }
934 }
935 }
936 }
937 #undef NEXT_CMD
938}
s32 * extraSounds
Definition audio.h:663
u8 * sefData
Definition audio.h:661
s32 * normalSounds[8]
Definition audio.h:662
u8 priority
Definition audio.h:623
@ SOUND_ID_UNK_INDEX_MASK
Definition enums.h:535
@ SOUND_ID_UNK
Definition enums.h:528
#define NEXT_CMD
u8 BlankSEFData[]
Definition sfx_player.c:220

Referenced by au_sfx_update_main().

◆ au_sfx_manager_update()

s16 au_sfx_manager_update ( SoundManager * manager)

Definition at line 1080 of file sfx_player.c.

1080 {
1081 SoundPlayer* player;
1082 AuVoice* voice;
1083 u32 start;
1084 u8 end;
1085 u8 i;
1086
1087 // update pseudorandom number with fast 'good enough' method
1088 manager->randomValue = (u16)manager->randomValue + (u16)manager->playCounter;
1089
1090 start = manager->sfxPlayerSelector;
1091 for (i = start, end = start + 8; i < end; i++) {
1092 player = &manager->players[i - manager->sfxPlayerSelector];
1093 if (player->sefDataReadPos != NULL) {
1094 voice = &manager->globals->voices[i];
1095 manager->curVoice = voice;
1096 if (voice->priority <= manager->priority) {
1097 manager->curVoiceIndex = i;
1098 switch (player->sfxParamsFlags & SFX_PARAM_FLAG_MODE) {
1100 au_sfx_update_basic(manager, player, voice, i);
1101 break;
1103 au_sfx_update_sequence(manager, player, voice, i);
1104 break;
1106 break;
1107 }
1108 } else {
1109 player->sefDataReadPos = NULL;
1110 player->curSoundID = 0;
1111 player->priority = 0;
1112 }
1113 }
1114 }
1115 return 0;
1116}
u8 curVoiceIndex
Definition audio.h:683
u8 sfxParamsFlags
Definition audio.h:625
struct AuVoice * curVoice
Definition audio.h:660
@ SFX_PARAM_MODE_SEQUENCE
Definition sfx_player.c:49
@ SFX_PARAM_FLAG_MODE
Definition sfx_player.c:52
@ SFX_PARAM_MODE_ADVANCED
Definition sfx_player.c:47
@ SFX_PARAM_MODE_BASIC
Definition sfx_player.c:51

Referenced by au_update_clients_2().

◆ au_bgm_update_main()

void au_bgm_update_main ( BGMPlayer * player)

Definition at line 22 of file 28910_len_5090.c.

22 {
23 BGMHeader* bgmFile;
24 BGMFileInfo* bgmData;
25 s32 unkType;
26 u32 segmentID;
27 s32 segmentOffset;
28 u32 value;
29 s32 delta;
30 u8 var_a1;
31 u8 pos;
32 u32 i;
33
34 segmentID = 0;
35 unkType = -1;
36 player->updateCounter++;
37
38 if (player->unk_258 != 0) {
39 if (player->unk_258 < ARRAY_COUNT(player->unk_238)) {
40 pos = player->unk_259;
41 for (var_a1 = 0; var_a1 < player->unk_258; var_a1++) {
42 value = player->unk_238[pos];
43 if (value != 0) {
44 if (value < 16) {
45 unkType = value & 3;
46 segmentID = value >> 2;
47 }
48 pos++;
49 if (pos >= ARRAY_COUNT(player->unk_238)) {
50 pos = 0;
51 }
52 }
53 }
54 delta = player->unk_25A - player->unk_259;
55 if (delta < 0) {
56 delta += ARRAY_COUNT(player->unk_238);
57 }
58 player->unk_258 -= delta;
59 player->unk_259 = player->unk_25A;
60 } else {
61 player->unk_258 = 0;
62 }
63 if (unkType != -1) {
64 if (unkType != 0) {
65 if (unkType != player->unk_58) {
66 player->unk_58 = unkType & 0xFF;
67 player->unk_5A = unkType & 0xFF;
70 if (unkType == 2) {
71 bgmFile = player->globals->dataBGM[1];
72 } else {
73 bgmFile = player->globals->dataBGM[0];
74 }
75 player->bgmFile = bgmFile;
76 bgmData = &bgmFile->info;
77 func_8004E880(player, BGM_SAMPLE_RATE, BgmDivisors[((u8*)player->unk_74)[0] & 7]); //TODO revise unk_74 typing
78
79 segmentOffset = bgmData->segments[segmentID];
80 if (segmentOffset == 0) {
81 segmentOffset = bgmData->segments[0];
82 }
83 player->segmentStartPos = AU_FILE_RELATIVE(bgmFile, segmentOffset << 2);
84 player->segmentReadPos = AU_FILE_RELATIVE(bgmFile, segmentOffset << 2);
85
86 if (bgmData->drums != 0) {
87 player->drumsInfo = AU_FILE_RELATIVE(player->bgmFile, bgmData->drums << 2);
88 player->bgmDrumCount = bgmData->drumCount;
89 for (i = 0; i < player->bgmDrumCount; i++) {
90 BGMDrumInfo* drum = &player->drumsInfo[i];
91 player->drums[i] = drum;
92 }
93 for (; i < ARRAY_COUNT(player->drums); i++) {
94 player->drums[i] = player->drums[0];
95 }
96 } else {
97 player->drumsInfo = NULL;
98 player->bgmDrumCount = 0;
99 }
100
101 if (bgmData->instruments != 0) {
102 player->instrumentsInfo = AU_FILE_RELATIVE(player->bgmFile, bgmData->instruments << 2);
103 player->bgmInstrumentCount = bgmData->instrumentCount;
104 return;
105 }
106 player->instrumentsInfo = NULL;
107 player->bgmInstrumentCount = 0;
108 }
109 } else {
110 if (player->unk_58 != 0) {
112 player->nextUpdateCounter = 1;
113 player->nextUpdateStep = 1;
114 } else {
115 au_bgm_stop_player(player);
116 }
117 }
118 }
119 }
120}
void func_8004E880(BGMPlayer *player, s32 sampleRate, s32 divisor)
u8 BgmDivisors[8]
Definition sfx_player.c:271
u16 drumCount
Definition audio.h:750
BGMInstrumentInfo * instrumentsInfo
Definition audio.h:1030
#define BGM_SAMPLE_RATE
Definition audio.h:52
u16 unk_58
Definition audio.h:1019
u16 instrumentCount
Definition audio.h:752
u8 unk_25A
Definition audio.h:1079
u8 unk_258
Definition audio.h:1077
BGMDrumInfo * drumsInfo
Definition audio.h:1029
AuGlobals * globals
Definition audio.h:1003
s32 unk_74
Definition audio.h:1028
u8 bgmDrumCount
Definition audio.h:1060
s16 unk_5A
Definition audio.h:1020
u8 unk_259
Definition audio.h:1078
BGMFileInfo info
Definition audio.h:760
u16 drums
Definition audio.h:749
u16 segments[4]
Definition audio.h:748
BGMDrumInfo * drums[12]
Definition audio.h:1031
@ BGM_PLAY_STATE_STOP
Definition audio.h:105
@ BGM_PLAY_STATE_INIT
Definition audio.h:104
u8 bgmInstrumentCount
Definition audio.h:1061
SegData * segmentReadPos
Definition audio.h:1025
u16 instruments
Definition audio.h:751
s32 updateCounter
Definition audio.h:1008
s32 unk_238[8]
Definition audio.h:1076
SegData * segmentStartPos
Definition audio.h:1026
u8 masterState
Definition audio.h:1065
Vec3s pos
Definition demo_api.c:17

Referenced by au_update_players_main().

◆ au_bgm_get_player_with_song_name()

BGMPlayer * au_bgm_get_player_with_song_name ( s32 songString)

Definition at line 122 of file 28910_len_5090.c.

122 {
123 if (songString != gBGMPlayerA->globals->dataBGM[0]->name) {
124 if (songString == gBGMPlayerA->globals->dataBGM[1]->name) {
125 return gBGMPlayerB;
126 }
127 } else {
128 return gBGMPlayerA;
129 }
130 return NULL;
131}
BGMPlayer * gBGMPlayerB
BGMPlayer * gBGMPlayerA

Referenced by au_bgm_dispatch_player_event(), au_bgm_is_song_playing(), au_bgm_set_proximity_mix(), au_bgm_stop_song(), func_8004DB4C(), func_8004DCB8(), func_8004DE2C(), func_8004E0F4(), and func_80050970().

◆ au_bgm_dispatch_player_event()

AuResult au_bgm_dispatch_player_event ( SongUpdateEvent * event)

Definition at line 133 of file 28910_len_5090.c.

133 {
134 BGMPlayer* player;
135 BGMFileInfo* fileInfo;
136 s32 songName;
137 s32 variation;
138 s32 duration;
139 s32 volume0;
140 s32 volume1;
141 AuResult status;
142 u32 i;
143
144 status = AU_RESULT_OK;
145 songName = event->songName;
146 variation = event->variation;
147 if (songName != 0) {
148 player = au_bgm_get_player_with_song_name(songName);
149 if (player != NULL) {
150 fileInfo = &player->bgmFile->info;
151 duration = event->duration;
152 if (duration != 0) {
153 if (duration > SND_MAX_DURATION) {
154 duration = SND_MAX_DURATION;
155 } else if (duration < SND_MIN_DURATION) {
156 duration = SND_MIN_DURATION;
157 }
158 }
159 volume0 = event->startVolume;
160 if (volume0 > 0x7F) {
161 volume0 = 0x7F;
162 }
163 if (volume0 != 0) {
164 volume0 = (volume0 << 8) | 0xFF;
165 }
166 volume1 = event->finalVolume;
167 if (volume1 > 0x7F) {
168 volume1 = 0x7F;
169 }
170 if (volume1 != 0) {
171 volume1 = (volume1 << 8) | 0xFF;
172 } else {
173 volume1 = 0x7FFF;
174 }
175
176 au_fade_init(&player->fadeInfo, duration, volume0, volume1);
177 player->fadeInfo.targetVolScale = 0x7FFF;
178 player->fadeInfo.volScaleTime = 1;
179 func_8004E880(player, BGM_SAMPLE_RATE, BgmDivisors[fileInfo->numSegments & 7]);
180
181 if (variation < 0 || variation >= 4 || fileInfo->segments[variation] == 0) {
182 variation = 0;
183 }
184 player->curSegmentID = variation;
185
186 player->segmentStartPos = AU_FILE_RELATIVE(player->bgmFile, fileInfo->segments[variation] << 2);
187 player->segmentReadPos = player->segmentStartPos;
188
189 if (fileInfo->drums != 0) {
190 player->drumsInfo = AU_FILE_RELATIVE(player->bgmFile, fileInfo->drums << 2);
191 player->bgmDrumCount = fileInfo->drumCount;
192
193 for (i = 0; i < player->bgmDrumCount; i++) {
194 BGMDrumInfo* drum = &player->drumsInfo[i];
195 player->drums[i] = drum;
196 }
197 for (; i < ARRAY_COUNT(player->drums); i++) {
198 player->drums[i] = player->drums[0];
199 }
200 } else {
201 player->drumsInfo = NULL;
202 player->bgmDrumCount = 0;
203 }
204 if (fileInfo->instruments != 0) {
205 player->instrumentsInfo = AU_FILE_RELATIVE(player->bgmFile, fileInfo->instruments << 2);
206 player->bgmInstrumentCount = fileInfo->instrumentCount;
207 } else {
208 player->instrumentsInfo = NULL;
209 player->bgmInstrumentCount = 0;
210 }
211 player->songName = songName;
213 } else {
215 }
216 } else {
218 }
219 return status;
220}
BGMPlayer * au_bgm_get_player_with_song_name(s32 songString)
void au_bgm_player_initialize(BGMPlayer *player)
u8 numSegments
Definition audio.h:746
u32 curSegmentID
Definition audio.h:1023
@ AU_ERROR_NULL_SONG_NAME
Definition enums.h:1761
@ AU_ERROR_SONG_NOT_PLAYING
Definition enums.h:1759

Referenced by au_song_start(), au_song_start_variation(), snd_set_song_fade(), and snd_set_song_variation_fade().

◆ au_bgm_stop_song()

AuResult au_bgm_stop_song ( s32 songName)

Definition at line 222 of file 28910_len_5090.c.

222 {
223 BGMPlayer* player;
224 AuResult status = AU_RESULT_OK;
225
226 if (songName != 0) {
227 player = au_bgm_get_player_with_song_name(songName);
228 if (player != NULL) {
229 if (songName == player->songName) {
230 au_bgm_stop_player(player);
231 }
232 } else {
234 }
235 } else {
237 }
238
239 return status;
240}

Referenced by au_song_stop().

◆ au_bgm_stop_all()

void au_bgm_stop_all ( void )

Definition at line 242 of file 28910_len_5090.c.

242 {
243 au_bgm_stop_player(gBGMPlayerA);
244 au_bgm_stop_player(gBGMPlayerB);
245}

Referenced by au_stop_songs().

◆ au_bgm_is_song_playing()

AuResult au_bgm_is_song_playing ( s32 songName)

Definition at line 256 of file 28910_len_5090.c.

256 {
257 BGMPlayer* player;
258 AuResult result = AU_RESULT_OK;
259
260 if (songName != 0) {
261 player = au_bgm_get_player_with_song_name(songName);
262 if (player != NULL) {
263 result = (songName == player->songName);
264 } else {
266 }
267 } else {
269 }
270
271 return result;
272}

Referenced by au_song_is_playing().

◆ func_8004DB28()

s32 func_8004DB28 ( BGMPlayer * player)

Definition at line 274 of file 28910_len_5090.c.

274 {
275 if (player->songName != NULL && player->masterState != 0) {
276 return 1;
277 } else {
278 return 0;
279 }
280}

Referenced by au_load_song_files(), and func_8004DE2C().

◆ func_8004DB4C()

AuResult func_8004DB4C ( SongUpdateEvent * s)

Definition at line 282 of file 28910_len_5090.c.

282 {
283 AuResult status;
284 BGMPlayer* player;
285 u32 songName = s->songName;
286 u32 duration = s->duration;
287 s16 volume = s->finalVolume;
288
289 status = AU_RESULT_OK;
290 if (songName != 0) {
291 if (duration >= SND_MIN_DURATION && duration <= SND_MAX_DURATION) {
292 player = au_bgm_get_player_with_song_name(songName);
293 if (player != NULL) {
294 if (player->songName == songName) {
295 if (player->masterState != BGM_PLAY_STATE_IDLE) {
296 if (player->unk_220 == 0) {
297 player->fadeInfo.targetVolume = volume;
298 player->fadeInfo.fadeTime = (duration * 1000) / AU_5750;
299 player->fadeInfo.fadeStep = ((volume << 0x10) - player->fadeInfo.curVolume.s32) / player->fadeInfo.fadeTime;
300 player->fadeInfo.variation = s->variation;
301 if (s->unk14 == 1) {
302 player->fadeSongName = songName;
303 }
304 }
305 }
306 }
307 } else {
309 }
310 } else {
312 }
313 } else {
315 }
316 return status;
317}
@ BGM_PLAY_STATE_IDLE
Definition audio.h:101
s32 fadeSongName
Definition audio.h:1011
u8 unk_220
Definition audio.h:1064
@ AU_ERROR_INVALID_SONG_DURATION
Definition enums.h:1763

Referenced by func_80055BB8(), and snd_set_song_variation_fade_time().

◆ func_8004DC80()

AuResult func_8004DC80 ( s32 songName)

Definition at line 319 of file 28910_len_5090.c.

319 {
321
322 s.songName = songName;
323 s.duration = 0;
324 s.startVolume = 0;
325 s.finalVolume = 0;
326 s.variation = 0;
327 s.unk14 = 0;
328 return func_8004DCB8(&s, 0);
329}
AuResult func_8004DCB8(SongUpdateEvent *update, s32 clearChanged)

Referenced by au_bgm_update_fade().

◆ func_8004DCB8()

AuResult func_8004DCB8 ( SongUpdateEvent * update,
s32 clearChanged )

Definition at line 331 of file 28910_len_5090.c.

331 {
332 AuResult status;
333 BGMPlayer* playerA;
334 BGMPlayer* playerB;
335 s32 songName;
336 s32 variation;
337 u32 i;
338 u32 j;
339
340 songName = update->songName;
341 variation = update->variation;
342 status = AU_RESULT_OK;
343
344 if (songName != 0) {
345 playerA = au_bgm_get_player_with_song_name(songName);
346 if (playerA != NULL) {
347 if (update->unk14 == 0) {
348 playerB = func_80053F64(variation);
349 if (playerB != NULL) {
350 if (songName == playerA->songName) {
351 if (!clearChanged) {
352 for (i = 0; i < ARRAY_COUNT(playerA->tracks); i++) {
353 BGMPlayerTrack* track = &playerA->tracks[i];
354 if (track->bgmReadPos != 0) {
355 for (j = track->unk_52; j < track->unk_53; j++) {
356 track->changed.all = 0;
357 }
358 }
359 }
360 }
361 playerA->globals->unk_globals_6C[variation].unk_5 = playerA->priority;
362 playerA->globals->unk_globals_6C[variation].unk_4 = 1;
363 playerA->fadeSongName = 0;
364 au_copy_words(playerA, playerB, sizeof(*playerA));
365 if (clearChanged == 0) {
366 au_bgm_stop_player(playerA);
367 }
368 }
369 } else {
371 }
372 } else {
373 if (songName == playerA->songName) {
374 if (playerA->masterState != BGM_PLAY_STATE_IDLE) {
375 playerA->unk_220 = 1;
376 func_80050900(playerA);
377 }
378 }
379 }
380 } else {
382 }
383 } else {
385 }
386 return status;
387}
void func_80050900(BGMPlayer *player)
BGMPlayer * func_80053F64(s32 arg0)
SoundPlayChange changed
Definition audio.h:961
u8 priority
Definition audio.h:1073
BGMPlayerTrack tracks[16]
Definition audio.h:1081
AuFilePos bgmReadPos
Definition audio.h:942
void N update(void)
Definition 07.c:80

Referenced by func_8004DC80(), func_80055AF0(), func_80055B80(), and func_80055BF0().

◆ func_8004DE2C()

AuResult func_8004DE2C ( SongUpdateEvent * update)

Definition at line 389 of file 28910_len_5090.c.

389 {
390 AuResult status;
391 BGMPlayer* playerA;
392 BGMPlayer* playerB;
393 s32 variation;
394 s32 songName;
395 s32 volume0;
396 s32 volume1;
397 s32 duration;
398
399 songName = update->songName;
400 variation = update->variation;
401 status = AU_RESULT_OK;
402
403 if (songName != 0) {
404 if (update->unk14 == 0) {
405 playerA = func_80053F64(variation);
406 if (playerA != NULL && playerA->globals->unk_globals_6C[variation].unk_4 == 1) {
407 playerB = func_80054248(playerA->globals->unk_globals_6C[variation].unk_5);
408 if (playerB != NULL) {
409 if (func_8004DB28(playerB) == 0) {
410 status = func_80053E58(playerA->songID, playerA->bgmFile);
411 duration = update->duration;
412 if (duration != 0) {
413 if (duration > SND_MAX_DURATION) {
414 duration = SND_MAX_DURATION;
415 } else if (duration < SND_MIN_DURATION) {
416 duration = SND_MIN_DURATION;
417 }
418 }
419 volume0 = update->startVolume;
420 if (volume0 > BGM_MAX_VOLUME) {
421 volume0 = BGM_MAX_VOLUME;
422 }
423 if (volume0 != 0) {
424 volume0 = (volume0 << 8) | 0xFF;
425 }
426 volume1 = update->finalVolume;
427 if (volume1 > BGM_MAX_VOLUME) {
428 volume1 = BGM_MAX_VOLUME;
429 }
430 if (volume1 != 0) {
431 volume1 = (volume1 << 8) | 0xFF;
432 } else {
433 volume1 = 0x7FFF;
434 }
435 playerB->globals->unk_74 = playerB;
436 playerB->globals->unk_78 = playerA;
437 playerB->globals->unkSongName = songName;
438 playerB->globals->unkFadeTime = duration;
439 playerB->globals->unkFadeStart = volume0;
440 playerB->globals->unkFadeEnd = volume1;
441 playerB->globals->unk_80 = 1;
442 } else {
443 status = AU_ERROR_7;
444 }
445 } else {
446 status = AU_ERROR_6;
447 }
448 } else {
450 }
451 } else {
452 playerB = au_bgm_get_player_with_song_name(songName);
453 if (playerB != NULL) {
454 if (songName == playerB->songName) {
455 if (playerB->unk_220 != 0) {
456 playerB->unk_220 = 0;
457 }
458 }
459 }
460 }
461 } else {
463 }
464 return status;
465}
AuResult func_80053E58(s32 songID, BGMHeader *bgmFile)
BGMPlayer * func_80054248(u8 arg0)
s32 unkFadeTime
Definition audio.h:917
s32 unkSongName
Definition audio.h:915
struct BGMPlayer * unk_74
Definition audio.h:913
s32 unkFadeEnd
Definition audio.h:919
#define BGM_MAX_VOLUME
Definition audio.h:58
s32 unkFadeStart
Definition audio.h:918
struct BGMPlayer * unk_78
Definition audio.h:914
@ AU_ERROR_7
Definition enums.h:1765
@ AU_ERROR_6
Definition enums.h:1764

Referenced by func_80055B28(), and func_80055C2C().

◆ func_8004DFD4()

void func_8004DFD4 ( AuGlobals * globals)

Definition at line 467 of file 28910_len_5090.c.

467 {
468 BGMPlayer* player;
469 BGMPlayerTrack* track;
470 SeqNote* note;
471 u32 i;
472 u32 j;
473 s32 k;
474
475 player = globals->unk_74;
476 au_copy_words(globals->unk_78, globals->unk_74, sizeof(*player));
477 if (globals->unkSongName == player->songName) {
478 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
479 track = &player->tracks[i];
480 if (track->bgmReadPos != NULL) {
481 for (j = track->unk_52; j < track->unk_53; j++) {
482 note = &player->notes[j];
483 note->noteLength = 0;
484 }
485 }
486 }
487 for (k = 0; k < ARRAY_COUNT(player->effectIndices); k++) {
488 if (player->effectIndices[k] != 0xFF) {
489 player->seqCmdArgs.MasterEffect.index = player->effectIndices[k];
490 player->seqCmdArgs.MasterEffect.value = player->effectValues[k];
491 au_BGMCmd_E6_MasterEffect(player, track);
492 }
493 }
494 au_fade_init(&player->fadeInfo, globals->unkFadeTime, globals->unkFadeStart, globals->unkFadeEnd);
495 }
496 globals->unk_80 = 0;
497}
void au_BGMCmd_E6_MasterEffect(BGMPlayer *player, BGMPlayerTrack *track)
SeqNote notes[24]
Definition audio.h:1082
u8 effectIndices[4]
Definition audio.h:1016
SeqArgs seqCmdArgs
Definition audio.h:1041
u8 effectValues[4]
Definition audio.h:1068
struct SeqArgs::@65 MasterEffect
s32 noteLength
Definition audio.h:993

Referenced by au_update_clients_2().

◆ func_8004E0F4()

AuResult func_8004E0F4 ( SongUpdateEvent * update)

Definition at line 499 of file 28910_len_5090.c.

499 {
500 BGMPlayer* player;
501 AuResult status = AU_RESULT_OK;
502
503 if (update->songName != 0) {
504 player = au_bgm_get_player_with_song_name(update->songName);
505 if (player != NULL) {
506 func_80053B04(&player->fadeInfo, update->duration, update->finalVolume);
507 }
508 else {
510 }
511 } else {
513 }
514 return status;
515}
void func_80053B04(Fade *fade, u32 arg1, s32 target)

Referenced by func_80055C64(), and func_80055C94().

◆ au_bgm_player_init()

void au_bgm_player_init ( BGMPlayer * player,
s32 arg1,
s32 arg2,
AuGlobals * arg3 )

Definition at line 517 of file 28910_len_5090.c.

517 {
518 s16 i;
519
520 player->globals = globals;
521 func_8004E880(player, BGM_SAMPLE_RATE, 48);
522 player->busVolume = 0x8000;
524 player->masterVolume = 0x7F000000;
525 player->updateCounter = 0;
526 player->songPlayingCounter = 0;
527 player->songName = 0;
528 player->fadeSongName = 0;
529 player->unk_58 = 0;
530 player->unk_5A = 0;
531 player->segmentReadPos = NULL;
532 player->segmentStartPos = NULL;
533 player->subSegmentStartPos = 0;
534 player->masterTempoTime = 0;
535 player->masterTempoTarget = 0;
536 player->masterTempoStep = 0;
537 player->masterVolumeTime = 0;
538 player->masterVolumeTarget = 0;
539 player->masterVolumeStep = 0;
540 player->masterPitchShift = 0;
541 player->detune = 0;
542 player->unk_220 = 0;
543 player->trackVolsConfig = NULL;
544 player->bFadeConfigSetsVolume = FALSE;
546 player->priority = priority;
547 player->busId = busId;
548 *(s32*)player->segLoopCounters = 0;
549 player->unk_222 = 0;
550 player->unk_223 = 0;
551 player->playbackRate = 1.0f;
552 player->unk_22A[0] = 0;
553 player->unk_22A[1] = 1;
554 player->unk_22A[2] = 0;
555 player->unk_22A[3] = 0;
556 player->unk_22A[4] = 0;
557 player->unk_22A[5] = 2;
558 player->unk_22A[6] = 3;
559 player->unk_22A[7] = 4;
560
561 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
562 BGMPlayerTrack* temp = &player->tracks[i];
563
564 temp->subTrackVolume = 0;
565 temp->delayTime = 0;
566 temp->subTrackCoarseTune = 0;
567 temp->subTrackFineTune = 0;
568 temp->subTrackPan = 0;
569 temp->subTrackReverb = 0;
570 temp->patch = 0;
571 temp->isDrumTrack = FALSE;
572 temp->segTrackVolume = 0x7F;
573 temp->unk_4C = 0;
574
575 if (i < ARRAY_COUNT(player->unk_238)) {
576 player->unk_238[i] = 0;
577 }
578 }
579
580 for (i = 0; i < ARRAY_COUNT(player->notes); i++) {
581 SeqNote* note = &player->notes[i];
582
583 note->volume = 0;
584 note->adjustedPitch = 0;
585 note->noteLength = 0;
586 note->unk_14 = 0;
587 note->noteVelocity = 0;
588 note->unk_note_17 = 0;
589 }
590
591 au_fade_set_vol_scale(&player->fadeInfo, 0x7FFF);
592 func_80055110(player);
593}
void au_fade_set_vol_scale(Fade *fade, s16 value)
void func_80055110(BGMPlayer *player)
Definition 30450.c:133
u8 busId
Definition audio.h:1074
s8 segTrackVolume
Definition audio.h:965
#define BGM_DEFAULT_TEMPO
Definition audio.h:53
s32 masterVolumeTarget
Definition audio.h:1038
s32 masterTempo
Definition audio.h:1032
SegData * subSegmentStartPos
Definition audio.h:1027
s32 masterTempoStep
Definition audio.h:1033
s32 masterTempoTarget
Definition audio.h:1034
u8 unk_222
Definition audio.h:1066
s32 subTrackVolume
Definition audio.h:947
u8 * trackVolsConfig
Definition audio.h:1050
u16 subTrackCoarseTune
Definition audio.h:963
s32 masterTempoTime
Definition audio.h:1035
u8 unk_223
Definition audio.h:1067
u8 unk_note_17
Definition audio.h:999
u8 noteVelocity
Definition audio.h:998
s32 delayTime
Definition audio.h:951
s16 volume
Definition audio.h:991
u16 masterPitchShift
Definition audio.h:1053
s32 masterVolume
Definition audio.h:1036
s16 adjustedPitch
Definition audio.h:992
s32 masterVolumeTime
Definition audio.h:1039
u8 bFadeConfigSetsVolume
Definition audio.h:1071
u8 unk_22A[8]
Definition audio.h:1070
s32 masterVolumeStep
Definition audio.h:1037
u8 segLoopCounters[4]
Definition audio.h:1044
s8 subTrackFineTune
Definition audio.h:964
f32 playbackRate
Definition audio.h:1040
s16 unk_14
Definition audio.h:997
s16 detune
Definition audio.h:1054
u8 subTrackReverb
Definition audio.h:967

Referenced by au_engine_init().

◆ au_bgm_set_effect_indices()

void au_bgm_set_effect_indices ( BGMPlayer * player,
u8 * list )

Definition at line 595 of file 28910_len_5090.c.

595 {
596 s32 i;
597 s32 remaining;
598
599 for (i = 0; i < ARRAY_COUNT(player->effectIndices); i++) {
600 s8 idx = *list++;
601
602 if (idx < 0) {
603 break;
604 }
605 player->effectIndices[i] = idx;
606 }
607
608 remaining = ARRAY_COUNT(player->effectIndices) - i;
609 if (remaining > 0) {
610 while (remaining-- != 0) {
611 player->effectIndices[i++] = -1;
612 }
613 }
614}

Referenced by au_engine_init().

◆ au_bgm_update_fade()

void au_bgm_update_fade ( BGMPlayer * player)

Definition at line 616 of file 28910_len_5090.c.

616 {
617 player->fadeInfo.fadeTime--;
618
619 if (player->fadeInfo.fadeTime != 0) {
620 player->fadeInfo.curVolume.s32 += player->fadeInfo.fadeStep;
621 } else {
622 player->fadeInfo.curVolume.s32 = player->fadeInfo.targetVolume << 16;
623
624 if (player->fadeInfo.onCompleteCallback != NULL) {
625 player->fadeInfo.onCompleteCallback();
626 }
627
628 if (player->fadeSongName != 0) {
630 } else if (player->fadeInfo.curVolume.s32 == 0) {
631 au_bgm_stop_player(player);
632 }
633 }
634 func_8004E444(player);
635}
AuResult func_8004DC80(s32 songName)

Referenced by au_update_clients_2().

◆ func_8004E444()

void func_8004E444 ( BGMPlayer * arg0)

Definition at line 637 of file 28910_len_5090.c.

637 {
638 u16 mult = (arg0->fadeInfo.curVolume.u16 * arg0->fadeInfo.volScale.u16) >> 15;
639 s32 i;
640
641 for (i = 0; i < ARRAY_COUNT(arg0->effectIndices); i++) {
642 s8 busId = arg0->effectIndices[i];
643
644 if (busId < 0) {
645 return;
646 }
647 au_fade_set_volume(busId, mult, arg0->busVolume);
648 }
649}

Referenced by au_bgm_update_fade(), and au_update_clients_2().

◆ au_bgm_player_update_main()

s32 au_bgm_player_update_main ( BGMPlayer * player)

Definition at line 651 of file 28910_len_5090.c.

651 {
652 u16 hasMore = TRUE;
653 s32 retVal = FALSE;
654
655 // update pseudorandom numbers with fast 'good enough' method
656 player->randomValue1 = (u16)player->randomValue1 + (u16)player->songPlayingCounter + (u16)player->updateCounter;
657 player->randomValue2 = (u16)player->randomValue2 + ((player->songPlayingCounter << 4) & 0xFFFF) + ((player->updateCounter >> 4) & 0xFFFF);
658 do {
659 switch (player->masterState) {
661 hasMore = FALSE;
662 break;
664 if (player->unk_220 == 0) {
666 if (player->masterState == BGM_STATE_PLAY_SUBSEG) {
667 hasMore = FALSE;
668 }
669 } else {
670 hasMore = FALSE;
671 }
672 break;
675 break;
678 hasMore = FALSE;
679 break;
682 break;
683 default:
684 retVal = TRUE;
685 hasMore = FALSE;
686 break;
687 }
688 } while (hasMore);
689 return retVal;
690}
void au_bgm_player_update_stop(BGMPlayer *player)
void au_bgm_player_read_segment(BGMPlayer *player)
void au_bgm_player_update_playing(BGMPlayer *player)
s32 randomValue2
Definition audio.h:1018
s32 randomValue1
Definition audio.h:1017
@ BGM_PLAY_STATE_NEXT_SUBSEG
Definition audio.h:103
@ BGM_STATE_PLAY_SUBSEG
Definition audio.h:102

Referenced by au_update_clients_2().

◆ au_bgm_player_initialize()

void au_bgm_player_initialize ( BGMPlayer * player)

Definition at line 692 of file 28910_len_5090.c.

692 {
693 s32* buf;
694 s32 cmd;
695 s32 keepReading;
696 s32 i;
697
698 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
699 BGMPlayerTrack* track = &player->tracks[i];
700 track->instrument = NO_INSTRUMENT;
701 track->subTrackVolume = 0x7FFF0000;
702 track->subTrackPan = 0x40;
703 track->subTrackReverb = 0;
704 track->patch = 0;
705 track->subTrackCoarseTune = 0;
706 track->subTrackFineTune = 0;
707 track->segTrackVolume = 0x7F;
708 track->unk_4C = 0;
709 track->unkVolume = 0x7FFF0000;
710 track->savedPos = NULL;
711 track->prevReadPos = NULL;
712 track->detourLength = 0;
713 track->segTrackTune = 0;
714 track->trackTremoloTime = 0;
715 track->trackTremoloAmount = 0;
716 track->trackTremoloSpeed = 0;
717 track->subTrackVolumeStep = 0;
718 track->subTrackVolumeTarget = 0;
719 track->subTrackVolumeTime = 0;
720 track->unkVolumeStep = 0;
721 track->unkVolumeTarget = 0;
722 track->unkVolumeTime = 0;
723 track->unk_4D = 0;
724 track->unk_4E = 0;
725 track->unk_4F = 0;
726 track->unk_50 = 0;
727 track->unk_51 = 0;
728 track->polyphonicIdx = 0;
729 track->unk_57 = 0;
730 track->isDrumTrack = FALSE;
731 track->parentTrackIdx = 0;
732 track->unk_5A = 0;
733 track->subtrackBusId = player->busId;
734 track->index = i;
735 }
736
737 for (i = 0; i < ARRAY_COUNT(player->notes); i++) {
738 SeqNote* note = &player->notes[i];
739 note->ins = NO_INSTRUMENT;
740 note->pitchRatio = 2.0f;
741 note->unk_14 = 0;
742 note->noteVelocity = 0;
743 note->noteLength = 0;
744 note->tremoloTime = 0;
745 }
746
747 func_80050900(player);
748 player->playbackRate = 128.0f; // set to 1.0 later om...
750 player->masterTempoBPM = BGM_DEFAULT_TEMPO / 100;
751 player->unk_21E = 0x80;
752 player->masterVolume = 0x7F000000;
753 player->fadeSongName = 0;
754 player->unk_74 = 0;
755 player->masterTempoTarget = 0;
756 player->masterPitchShift = 0;
757 player->detune = 0;
758 player->masterVolumeTime = 0;
759 player->masterVolumeTarget = 0;
760 player->masterVolumeStep = 0;
761 player->proxMixValue = 0;
762 player->proxMixID = 0;
763 player->proxMixVolume = 0;
764 player->segActiveLoopEndPos[3] = NULL;
765 player->segActiveLoopEndPos[2] = NULL;
766 player->segActiveLoopEndPos[1] = NULL;
767 player->segActiveLoopEndPos[0] = NULL;
768 *(s32*)player->segLoopCounters = 0;
769 player->segLoopDepth = 0;
770 player->unk_222 = 0;
771 player->unk_223 = 0;
772 player->trackVolsConfig = NULL;
773 player->bFadeConfigSetsVolume = FALSE;
774 player->unk_233 = 1;
775 player->unk_211 = 0;
776 player->playbackRate = 1.0f;
777
778 for (i = 0; i < ARRAY_COUNT(player->unk_212); i++) {
779 func_8004E844(player, i);
780 }
781
782 for (i = 0; i < ARRAY_COUNT(player->effectValues); i++) {
783 player->effectValues[i] = 0;
784 }
785
786 player->unk_220 = 0;
787 player->songPlayingCounter = 0;
788 for (i = 0; i < ARRAY_COUNT(player->segLoopStartLabels); i++) {
789 player->segLoopStartLabels[i] = player->segmentReadPos;
790 }
791
792 // find labels
793 buf = player->segmentReadPos;
794 keepReading = TRUE;
795 while (keepReading) {
796 cmd = *buf++;
797 if (cmd == 0) {
798 keepReading = FALSE;
799 } else if ((cmd & 0xF0000000) == BGM_SEGMENT_LABEL << 28) {
800 player->segLoopStartLabels[cmd & 0x1F] = buf;
801 }
802 }
803
805}
void func_8004E844(BGMPlayer *player, s32 arg1)
s8 subtrackBusId
Definition audio.h:983
u8 unk_212[8]
Definition audio.h:1057
u8 segLoopDepth
Definition audio.h:1055
u8 unk_211
Definition audio.h:1056
u8 tremoloTime
Definition audio.h:995
#define NO_INSTRUMENT
Definition audio.h:17
s32 unkVolumeStep
Definition audio.h:954
u8 proxMixID
Definition audio.h:1046
u8 unk_21E
Definition audio.h:1062
u8 trackTremoloTime
Definition audio.h:978
u16 masterTempoBPM
Definition audio.h:1051
u8 polyphonicIdx
Definition audio.h:976
s32 subTrackVolumeStep
Definition audio.h:948
u8 trackTremoloSpeed
Definition audio.h:977
s16 trackTremoloAmount
Definition audio.h:958
s16 unkVolumeTime
Definition audio.h:956
s16 detourLength
Definition audio.h:960
s32 subTrackVolumeTime
Definition audio.h:950
#define BGM_SEGMENT_LABEL
Definition audio.h:60
s16 unkVolumeTarget
Definition audio.h:955
AuFilePos savedPos
Definition audio.h:943
u8 parentTrackIdx
Definition audio.h:981
u8 unk_233
Definition audio.h:1072
s32 unkVolume
Definition audio.h:953
s32 subTrackVolumeTarget
Definition audio.h:949
SegData * segActiveLoopEndPos[4]
Definition audio.h:1043
s16 segTrackTune
Definition audio.h:957
f32 pitchRatio
Definition audio.h:990
AuFilePos prevReadPos
Definition audio.h:944
Instrument * ins
Definition audio.h:989
SegData * segLoopStartLabels[32]
Definition audio.h:1042
Instrument * instrument
Definition audio.h:945
s32 proxMixValue
Definition audio.h:1045
u8 proxMixVolume
Definition audio.h:1047

Referenced by au_bgm_dispatch_player_event(), and au_bgm_player_update_main().

◆ func_8004E844()

void func_8004E844 ( BGMPlayer * player,
s32 arg1 )

Definition at line 807 of file 28910_len_5090.c.

807 {
808 s32 i;
809 u16* temp = player->unk_174[arg1];
810 player->unk_212[arg1] = 0;
811
812 for (i = 0; i < 9; i++) {
813 *temp++ = 0xFF00;
814 }
815}
s16 unk_174[8][9]
Definition audio.h:1049

Referenced by au_bgm_player_initialize(), and au_BGMCmd_FF().

◆ func_8004E880()

void func_8004E880 ( BGMPlayer * player,
s32 sampleRate,
s32 divisor )

Definition at line 818 of file 28910_len_5090.c.

818 {
819 u32 A;
820
821 A = 10434782 / (u32)divisor;
822
823 if (A > 500000) {
824 A = 500000;
825 } else if (A < 80000) {
826 A = 80000;
827 }
828 if (A < sampleRate) {
829 sampleRate = A;
830 }
831 player->nextUpdateStep = sampleRate;
832 player->nextUpdateInterval = A;
833 player->nextUpdateCounter = A;
834 player->maxTempo = A / 1000;
835}
u16 maxTempo
Definition audio.h:1052
#define A(sym)
Definition macros.h:36

Referenced by au_bgm_dispatch_player_event(), au_bgm_player_init(), and au_bgm_update_main().

◆ au_bgm_player_read_segment()

void au_bgm_player_read_segment ( BGMPlayer * player)

Definition at line 838 of file 28910_len_5090.c.

838 {
839 u16 continueReading = TRUE;
840 u32 cmd;
841
842 player->masterTempoStep = 0;
843 player->masterTempoTime = 0;
844 while (continueReading) {
845 cmd = *player->segmentReadPos++;
846 if (cmd == BGM_SEGMENT_END) {
848 continueReading = FALSE;
849 } else {
850 switch (cmd >> 12) {
851 case BGM_SEGMENT_SUBSEG << 16:
852 au_bgm_load_subsegment(player, cmd);
854 continueReading = FALSE;
855 break;
856 case BGM_SEGMENT_START_LOOP << 16:
857 break;
858 case BGM_SEGMENT_WAIT << 16:
859 continueReading = FALSE;
860 break;
861 case BGM_SEGMENT_END_LOOP << 16:
862 au_bgm_end_segment_loop(player, cmd);
863 break;
864 case BGM_SEGMENT_6 << 16:
865 if (!(player->unk_223 & 1)) {
866 au_bgm_end_segment_loop(player, cmd);
867 }
868 break;
869 case BGM_SEGMENT_7 << 16:
870 if (player->unk_223 & 1) {
871 au_bgm_end_segment_loop(player, cmd);
872 }
873 break;
874 default:
875 continueReading = FALSE;
876 break;
877 }
878 }
879 }
880}
void au_bgm_load_subsegment(BGMPlayer *player, u32 cmd)
void au_bgm_end_segment_loop(BGMPlayer *player, u32 cmd)
@ BGM_SEGMENT_START_LOOP
Definition audio.h:111
@ BGM_SEGMENT_6
Definition audio.h:114
@ BGM_SEGMENT_END_LOOP
Definition audio.h:113
@ BGM_SEGMENT_SUBSEG
Definition audio.h:110
@ BGM_SEGMENT_END
Definition audio.h:109
@ BGM_SEGMENT_7
Definition audio.h:115
@ BGM_SEGMENT_WAIT
Definition audio.h:112

Referenced by au_bgm_player_update_main().

◆ au_bgm_end_segment_loop()

void au_bgm_end_segment_loop ( BGMPlayer * player,
u32 cmd )

Definition at line 882 of file 28910_len_5090.c.

882 {
883 s32 labelIndex = cmd & 0x1F; // 01F (bits 0-4)
884 s32 iterCount = (cmd >> 5) & 0x7F; // FE0 (bits 5-11)
885 u32 depth;
886
887 depth = player->segLoopDepth;
888 if (player->segActiveLoopEndPos[depth] != NULL) {
889 if (player->segActiveLoopEndPos[depth] == player->segmentReadPos) {
890 if (player->segLoopCounters[depth] != 0) {
891 player->segLoopCounters[depth]--;
892 if ((player->segLoopCounters[depth]) == 0) {
893 player->segActiveLoopEndPos[depth] = NULL;
894 if (depth > 0) {
895 depth--;
896 }
897 } else {
898 player->segmentReadPos = player->segLoopStartLabels[labelIndex];
899 }
900 } else {
901 player->segmentReadPos = player->segLoopStartLabels[labelIndex];
902 }
903 } else if (depth < 4) {
904 depth++;
905 player->segActiveLoopEndPos[depth] = player->segmentReadPos;
906 player->segLoopCounters[depth] = iterCount;
907 player->segmentReadPos = player->segLoopStartLabels[labelIndex];
908 }
909 } else {
910 player->segActiveLoopEndPos[depth] = player->segmentReadPos;
911 player->segLoopCounters[depth] = iterCount;
912 player->segmentReadPos = player->segLoopStartLabels[labelIndex];
913 }
914 player->segLoopDepth = depth;
915}

Referenced by au_bgm_player_read_segment().

◆ au_bgm_load_subsegment()

void au_bgm_load_subsegment ( BGMPlayer * player,
u32 cmd )

Definition at line 917 of file 28910_len_5090.c.

917 {
918 BGMPlayerTrack* track;
919 u32 trackInfo;
920 s32* trackList;
921 u32 parentIdx;
922 s32 count;
923 s32 nextRelativePos;
924 s32 bUsesPolyphony;
925 s32 i;
926
927 nextRelativePos = 0;
928 bUsesPolyphony = FALSE;
929 player->subSegmentStartPos = AU_FILE_RELATIVE(player->segmentStartPos, (cmd & 0xFFFF) << 2);
930 trackList = player->subSegmentStartPos;
931 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
932 track = &player->tracks[i];
933 trackInfo = *trackList++;
934 track->bgmReadPos = (AuFilePos) (trackInfo >> 0x10);
935 if (track->bgmReadPos != NULL) {
936 if ((trackInfo & 0x100) == 0) {
937 track->polyphonicIdx = (trackInfo & (0x7 << 0xD)) >> 0xD;
938 track->isDrumTrack = (trackInfo >> 7) & 1;
939 parentIdx = (trackInfo & (0xF << 9)) >> 9;
940 track->parentTrackIdx = 0;
941 if (parentIdx != 0) {
942 BGMPlayerTrack* parentTrack = &player->tracks[parentIdx - 1];
943 if ((parentIdx - 1) < i) {
944 track->unk_51 = parentTrack->unk_51;
945 track->unk_52 = parentTrack->unk_52;
946 track->unk_53 = parentTrack->unk_53;
947
948 track->bgmReadPos = (track->bgmReadPos + (s32)player->subSegmentStartPos);
949 track->delayTime = 1;
950
951 track->parentTrackIdx = parentIdx;
952 if (player->unk_233 != 0) {
953 track->unk_5A = 1;
954 }
955 bUsesPolyphony = TRUE;
956 } else {
957 track->bgmReadPos = NULL;
958 }
959 } else {
960 count = player->unk_22A[track->polyphonicIdx];
961 track->unk_51 = count;
962 track->unk_52 = nextRelativePos;
963 nextRelativePos += count;
964 track->unk_53 = nextRelativePos;
965
966 track->bgmReadPos = (track->bgmReadPos + (s32)player->subSegmentStartPos);
967 track->delayTime = 1;
968 }
969 } else {
970 track->bgmReadPos = NULL;
971 }
972 }
973 }
974 player->unk_21B = nextRelativePos; // last Voice?
975 if (bUsesPolyphony) {
976 player->unk_233 = 0;
977 }
978}
u8 unk_21B
Definition audio.h:1059

Referenced by au_bgm_player_read_segment().

◆ au_bgm_player_update_stop()

void au_bgm_player_update_stop ( BGMPlayer * player)

Definition at line 980 of file 28910_len_5090.c.

980 {
981 s32 i;
982
983 player->unk_220 = 0;
984 player->songName = 0;
985 player->fadeSongName = 0;
986 player->unk_58 = 0;
987 player->unk_5A = 0;
988 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
989 player->tracks[i].bgmReadPos = NULL;
990 }
991 func_80050900(player);
994}

Referenced by au_bgm_player_update_main().

◆ au_bgm_player_update_playing()

void au_bgm_player_update_playing ( BGMPlayer * player)

Definition at line 1004 of file 28910_len_5090.c.

1004 {
1005 s32 bVolumeFading;
1006 u8 sp1F;
1007 s16 notePitch;
1008 u8 bFinished;
1009
1010 AuVoice* voice;
1011 BGMDrumInfo* drumInfo;
1012 BGMPlayerTrack* track;
1013 SeqNote* note;
1014 s32 var_a0;
1015 s32 temp;
1016 s32 var_a1_5;
1017 s32 bAcquiredVoiceIdx;
1018 u8 opcode;
1019 u8 noteVelocity;
1020 s32 noteLength;
1021 u32 i;
1022 u8 voiceIdx;
1023 s32 temp2;
1024 bVolumeFading = FALSE;
1025 bFinished = FALSE;
1026
1027 if (player->masterTempoTime != 0) {
1028 player->masterTempoTime--;
1029 if (player->masterTempoTime == 0) {
1030 player->masterTempo = player->masterTempoTarget;
1031 player->masterTempoTarget = 0;
1032 player->masterTempoStep = 0;
1033 } else {
1034 player->masterTempo += player->masterTempoStep;
1035 }
1036 player->nextUpdateStep = player->masterTempo * 10;
1037 }
1038 if (player->masterVolumeTime != 0) {
1039 player->masterVolumeTime--;
1040 if (player->masterVolumeTime == 0) {
1041 player->masterVolume = player->masterVolumeTarget;
1042 player->masterVolumeTarget = 0;
1043 player->masterVolumeStep = 0;
1044 } else {
1045 player->masterVolume += player->masterVolumeStep;
1046 }
1047 bVolumeFading = TRUE;
1048 }
1049 player->volumeChanged = FALSE;
1050 if (player->trackVolsConfig != NULL) {
1051 if (player->bFadeConfigSetsVolume) {
1052 // setting track volumes
1053 s32 lenLimit = 16;
1054 while (lenLimit-- != 0) {
1055 i = *player->trackVolsConfig++;
1056 if (i == 0) {
1057 break;
1058 }
1059 track = &player->tracks[i - 1];
1060 player->seqCmdArgs.TrackVolumeFade.time = 48;
1061 player->seqCmdArgs.TrackVolumeFade.value = *(player->trackVolsConfig++);
1062 if (track->bgmReadPos != 0) {
1063 au_BGMCmd_F6_TrackVolumeFade(player, track);
1064 }
1065 }
1066 }
1067 else {
1068 // clearing track volumes
1069 s32 lenLimit = 16;
1070 while (lenLimit-- != 0) {
1071 i = *player->trackVolsConfig++;
1072 if (i == 0) {
1073 break;
1074 }
1075 track = &player->tracks[i - 1];
1076 player->seqCmdArgs.TrackVolumeFade.time = 48;
1077 player->trackVolsConfig++; // ignore arg
1078 player->seqCmdArgs.TrackVolumeFade.value = 0;
1079 if (track->bgmReadPos != 0) {
1080 au_BGMCmd_F6_TrackVolumeFade(player, track);
1081 }
1082 }
1083 }
1084 player->trackVolsConfig = NULL;
1085 player->bFadeConfigSetsVolume = FALSE;
1086 }
1087 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
1088 track = &player->tracks[i];
1089 if (track->bgmReadPos != NULL) {
1090 track->changed.all = 0;
1091 if (bVolumeFading || player->volumeChanged) {
1092 track->changed.volume = 1;
1093 } else {
1094 track->changed.volume = 0;
1095 }
1096 if (track->subTrackVolumeTime != 0) {
1097 track->subTrackVolumeTime--;
1098 if (track->subTrackVolumeTime == 0) {
1099 track->subTrackVolume = track->subTrackVolumeTarget;
1100 } else {
1101 track->subTrackVolume += track->subTrackVolumeStep;
1102 }
1103 track->changed.volume = 1;
1104 }
1105 if (track->unkVolumeTime != 0) {
1106 track->unkVolumeTime--;
1107 if (track->unkVolumeTime == 0) {
1108 track->unkVolume = track->unkVolumeTarget << 0x10;
1109 } else {
1110 track->unkVolume += track->unkVolumeStep;
1111 }
1112 track->changed.volume = 1;
1113 }
1114 track->delayTime--;
1115 if (track->delayTime <= 0) {
1116 sp1F = track->unk_52;
1117 while (track->delayTime == 0) {
1118 opcode = *(track->bgmReadPos++);
1119 POST_BGM_READ();
1120
1121 if (opcode < 0x80) {
1122 if (opcode == 0) {
1123 if (track->prevReadPos != 0) {
1124 track->bgmReadPos = track->prevReadPos;
1125 track->prevReadPos = 0;
1126 } else {
1127 bFinished = TRUE;
1128 break;
1129 }
1130 } else {
1131 if (opcode >= 0x78) {
1132 // long delay
1133 track->delayTime = (((opcode & 7) << 8) + *(track->bgmReadPos++)) + 0x78;
1134 POST_BGM_READ();
1135
1136 } else {
1137 // delay
1138 track->delayTime = opcode;
1139 }
1140 }
1141 } else {
1142 // note
1143 if (opcode < 0xD4) {
1144 notePitch = (opcode & 0x7F);
1145 noteVelocity = *(track->bgmReadPos++);
1146 POST_BGM_READ();
1147 noteLength = *(track->bgmReadPos++);
1148 POST_BGM_READ();
1149 if (!(noteLength < 0xC0)) {
1150 noteLength = (((u8)noteLength & ~0xC0) << 8) + *(track->bgmReadPos++) + 0xC0;
1151 POST_BGM_READ();
1152 }
1153 bAcquiredVoiceIdx = FALSE;
1154 if (track->unk_5A == 0) {
1155 // find first free voice
1156 for (voiceIdx = sp1F; voiceIdx < track->unk_53; voiceIdx++) {
1157 voice = &player->globals->voices[voiceIdx];
1158 sp1F++;
1159 if (voice->priority == AU_PRIORITY_FREE) {
1160 bAcquiredVoiceIdx = TRUE;
1161 break;
1162 }
1163 }
1164
1165 if (!bAcquiredVoiceIdx) {
1166 if (track->polyphonicIdx >= 5) { // 5 = AL_DEFAULT_PRIORITY?
1167 // try stealing a voice with lower priority
1168 for (voiceIdx = track->unk_52; voiceIdx < track->unk_53; voiceIdx++) {
1169 voice = &player->globals->voices[voiceIdx];
1170 if (voice->priority < player->priority) {
1171 au_reset_voice(voice, voiceIdx);
1172 bAcquiredVoiceIdx = TRUE;
1173 break;
1174 }
1175 }
1176 // try stealing a voice with equal priority and zero note length
1177 if (!bAcquiredVoiceIdx) {
1178 for (voiceIdx = track->unk_52; voiceIdx < track->unk_53; voiceIdx++) {
1179 voice = &player->globals->voices[voiceIdx];
1180 if (voice->priority == player->priority) {
1181 note = &player->notes[voiceIdx];
1182 if (note->noteLength == 0) {
1183 au_reset_voice(voice, voiceIdx);
1184 bAcquiredVoiceIdx = TRUE;
1185 break;
1186 }
1187 }
1188 }
1189 }
1190 // try stealing a voice with equal priority and lowest note length
1191 if (!bAcquiredVoiceIdx) {
1192 s32 shortestLength = 0xFFFF;
1193 u8 voice_it;
1194 AuVoice* curVoice;
1195 SeqNote* curNote;
1196 for (voice_it = track->unk_52; voice_it < track->unk_53; voice_it++) {
1197 curVoice = &player->globals->voices[voice_it];
1198 if (curVoice->priority == player->priority) {
1199 curNote = &player->notes[voice_it];
1200 if (curNote->unk_note_17 == 0 && curNote->noteLength < shortestLength) {
1201 shortestLength = curNote->noteLength;
1202 voice = curVoice;
1203 note = curNote;
1204 voiceIdx = voice_it;
1205 bAcquiredVoiceIdx = TRUE;
1206 }
1207 }
1208 }
1209 if (bAcquiredVoiceIdx) {
1210 note->noteLength = 0;
1211 au_reset_voice(voice, voiceIdx);
1212 }
1213 }
1214
1215 } else {
1216 voiceIdx = track->unk_52;
1217 voice = &player->globals->voices[voiceIdx];
1218 note = &player->notes[voiceIdx];
1219 note->noteLength = 0;
1220 if (voice->priority <= player->priority) {
1221 au_reset_voice(voice, voiceIdx);
1222 bAcquiredVoiceIdx = TRUE;
1223 }
1224 }
1225 }
1226 }
1227 if (bAcquiredVoiceIdx) {
1228 note = &player->notes[voiceIdx];
1229 note->tremoloTime = 0;
1230 if (noteVelocity > 0) {
1231 note->noteVelocity = noteVelocity + 1;
1232 } else {
1233 note->noteVelocity = 0;
1234 }
1235 note->noteLength = noteLength;
1236 if (track->isDrumTrack) {
1237 if (notePitch < 72) { // = 6 * 12
1238 drumInfo = &player->globals->dataPER->drums[notePitch];
1239 } else {
1240 drumInfo = player->drums[notePitch - 72]; // = 6 * 12
1241 }
1242 note->ins = au_get_instrument(player->globals, (u16)drumInfo->bankPatch >> 8, (u16)drumInfo->bankPatch & 0xFF, &voice->envelope);
1243 if (drumInfo->randVolume != 0) {
1244 note->volume = note->noteVelocity * au_bgm_get_random_vol(player->randomValue1, drumInfo->volume, drumInfo->randVolume);
1245 } else {
1246 note->volume = note->noteVelocity * drumInfo->volume;
1247 }
1248 voice->clientVolume = ((
1249 ((player->masterVolume >> 0x15) * (track->subTrackVolume >> 0x15) * (track->unkVolume >> 0x15)) >> 0x14)
1250 * (track->segTrackVolume * note->volume)) >> 0x10;
1251 note->adjustedPitch =
1252 drumInfo->keyBase
1253 + track->subTrackCoarseTune
1254 + track->subTrackFineTune
1255 - note->ins->keyBase;
1256 temp = (note->adjustedPitch + track->segTrackTune) + player->detune;
1257 if (drumInfo->randTune != 0) {
1258 note->unk_14 = au_bgm_get_random_pitch(player->randomValue1, temp, drumInfo->randTune);
1259 temp = note->unk_14;
1260 }
1261 note->pitchRatio = au_compute_pitch_ratio(temp) * note->ins->pitchRatio;
1262 if (drumInfo->randPan != 0) {
1263 voice->pan = au_bgm_get_random_pan(player, drumInfo->pan, drumInfo->randPan);
1264 } else {
1265 voice->pan = drumInfo->pan;
1266 }
1267 if (drumInfo->randReverb != 0) {
1268 voice->reverb = au_bgm_get_random_reverb(player->randomValue1, drumInfo->reverb, drumInfo->randReverb);
1269 } else {
1270 voice->reverb = drumInfo->reverb;
1271 }
1272 } else {
1273 note->volume = ((
1274 ((player->masterVolume >> 0x15) * (track->subTrackVolume >> 0x15) * (track->unkVolume >> 0x15)) >> 0x14)
1275 * (track->segTrackVolume * note->noteVelocity)) >> 9;
1276 voice->clientVolume = note->volume;
1277 note->ins = track->instrument;
1278 note->adjustedPitch =
1279 (notePitch * 100)
1280 + track->subTrackCoarseTune
1281 + player->masterPitchShift
1282 + track->subTrackFineTune
1283 - note->ins->keyBase;
1285 note->adjustedPitch
1286 + track->segTrackTune
1287 + player->detune)
1288 * track->instrument->pitchRatio;
1289
1290 if (track->unk_57 != 0) {
1291 voice->pan = au_bgm_get_random_pan(player, track->subTrackPan, track->unk_57);
1292 } else {
1293 voice->pan = track->subTrackPan;
1294 }
1295 voice->reverb = track->subTrackReverb;
1296
1297 if (track->unk_4C != 0) {
1298 voice->envelope.cmdListPress = (u8*) player->unk_174[track->unk_4C - 1]; //TODO ???
1299 } else {
1301 }
1303 }
1304 voice->instrument = note->ins;
1305 voice->pitchRatio = note->pitchRatio;
1306 voice->busId = track->subtrackBusId;
1307 if (note->noteLength >= 2) {
1308 note->unk_note_17 = 1;
1309 note->tremoloTime = track->trackTremoloTime;
1310 note->unk_13 = 0;
1311 note->tremoloAmount = track->trackTremoloAmount;
1313 voice->priority = player->priority;
1314 voice->clientPriority = voice->priority;
1315 }
1316 }
1317 } else {
1318 //TODO variable is nargs, but reusing temp is required to match
1319 temp = SeqCmdArgCounts[opcode - 0xE0];
1320 if (temp != 0) {
1321 player->seqCmdArgs.raw[0] = *(track->bgmReadPos++);
1322 POST_BGM_READ();
1323 } else {
1324 goto bgm_args_done;
1325 }
1326 if (temp > 1) {
1327 player->seqCmdArgs.raw[1] = *(track->bgmReadPos++);
1328 POST_BGM_READ();
1329 } else {
1330 goto bgm_args_done;
1331 }
1332 if (temp > 2) {
1333 player->seqCmdArgs.raw[2] = *(track->bgmReadPos++);
1334 POST_BGM_READ();
1335 } else {
1336 goto bgm_args_done;
1337 }
1338 if (temp > 3) {
1339 player->seqCmdArgs.raw[3] = *(track->bgmReadPos++);
1340 POST_BGM_READ();
1341 }
1342 bgm_args_done:
1343 CurrentSeqCmdHandler = SeqCmdHandlers[opcode - 0xE0];
1344 CurrentSeqCmdHandler(player, track);
1345 }
1346 }
1347 } // end while
1348 }
1349
1350 for (voiceIdx = track->unk_52; voiceIdx < track->unk_53; voiceIdx++) {
1351 if (track->unk_5A == 0) {
1352 voice = &player->globals->voices[voiceIdx];
1353 if (voice->priority == player->priority) {
1354 note = &player->notes[voiceIdx];
1355 if (note->unk_note_17 == 0) {
1356 if (note->noteLength > 0) {
1357 note->noteLength--;
1358 if (note->noteLength == 0) {
1360 }
1361 }
1362 if (track->isDrumTrack) {
1363 if (track->changed.tune || (player->detune != 0)) {
1364 note->pitchRatio = au_compute_pitch_ratio(((note->adjustedPitch + note->unk_14) + track->segTrackTune) + player->detune) * note->ins->pitchRatio;
1365 if (voice->pitchRatio != note->pitchRatio) {
1366 voice->pitchRatio = note->pitchRatio;
1368 }
1369 }
1370 if (track->changed.volume) {
1371 voice->clientVolume = (
1372 ((((player->masterVolume >> 0x15)
1373 * (track->subTrackVolume >> 0x15))
1374 * (track->unkVolume >> 0x15)) >> 0x14)
1375 * (track->segTrackVolume * note->volume)) >> 0x10;
1377 }
1378 } else {
1379 if (note->tremoloTime != 0) {
1380 if (note->tremoloAmount != 0) {
1381 note->tremoloAmount--;
1382 } else {
1383 u8 temp_a0_6;
1384 u8 temp_a2_4;
1385 note->unk_13 += track->trackTremoloSpeed;
1386 opcode = (note->unk_13 << 2) + 3;
1387 temp_a2_4 = note->unk_13 >> 6;
1388
1389 if ((temp_a2_4 == 1) || (temp_a2_4 == 3)) {
1390 u8 temp2 = ~opcode;
1391 var_a1_5 = temp2 + 1;
1392 } else {
1393 var_a1_5 = opcode;
1394 }
1395
1396 var_a1_5 = (var_a1_5 * track->trackTremoloTime) >> 8;
1397
1398 if ((temp_a2_4 == 2) || (temp_a2_4 == 3)) {
1399 var_a1_5 = -var_a1_5;
1400 }
1401
1402 note->pitchRatio = au_compute_pitch_ratio(var_a1_5 + ((note->adjustedPitch + track->segTrackTune) + player->detune)) * note->ins->pitchRatio;
1403 if (voice->pitchRatio != note->pitchRatio) {
1404 voice->pitchRatio = note->pitchRatio;
1406 }
1407 }
1408 } else if (track->changed.tune || (player->detune != 0)) {
1409
1410 note->pitchRatio = au_compute_pitch_ratio((note->adjustedPitch + track->segTrackTune) + player->detune) * note->ins->pitchRatio;
1411 if (voice->pitchRatio != note->pitchRatio) {
1412 voice->pitchRatio = note->pitchRatio;
1414 }
1415 }
1416 if (track->changed.volume) {
1417 s32 tempVolume = ((player->masterVolume >> 0x15) * (track->subTrackVolume >> 0x15) * (track->unkVolume >> 0x15)) >> 0x14;
1418 note->volume = (tempVolume * (track->segTrackVolume * note->noteVelocity)) >> 9;
1419 voice->clientVolume = note->volume;
1421 voice->pan = track->subTrackPan;
1422 voice->reverb = track->subTrackReverb;
1423 } else if (track->changed.pan || track->changed.reverb) {
1424 voice->pan = track->subTrackPan;
1425 voice->reverb = track->subTrackReverb;
1427 }
1428 }
1429 }
1430 note->unk_note_17 = 0;
1431 }
1432 }
1433 }
1434 }
1435 }
1436
1437 if (bFinished) {
1439 }
1440}
void au_BGMCmd_F6_TrackVolumeFade(BGMPlayer *player, BGMPlayerTrack *track)
u8 SeqCmdArgCounts[]
Definition sfx_player.c:264
#define POST_BGM_READ()
BSS void(* CurrentSeqCmdHandler)(BGMPlayer *, BGMPlayerTrack *)
void(* SeqCmdHandlers[])(BGMPlayer *, BGMPlayerTrack *)
Definition sfx_player.c:229
s8 volumeChanged
Definition audio.h:1058
u8 randVolume
Definition audio.h:770
u8 raw[4]
Definition audio.h:263
u8 randPan
Definition audio.h:771
u8 unk_13
Definition audio.h:996
struct SeqArgs::@79 TrackVolumeFade
u16 tremoloAmount
Definition audio.h:994
EnvelopeData envelope
Definition audio.h:946
u8 randReverb
Definition audio.h:772
u8 randTune
Definition audio.h:769

Referenced by au_bgm_player_update_main().

◆ au_BGMCmd_E0_MasterTempo()

void au_BGMCmd_E0_MasterTempo ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1444 of file 28910_len_5090.c.

1444 {
1445 u32 bpm = player->seqCmdArgs.MasterTempo.value;
1446 s32 tempo;
1447
1448 player->masterTempoBPM = bpm;
1449 tempo = snd_bpm_to_tempo(player, bpm);
1450 player->masterTempo = tempo;
1451 player->nextUpdateStep = tempo * 10;
1452 player->masterTempoTime = 0;
1453 player->masterTempoTarget = 0;
1454 player->masterTempoStep = 0;
1455}
struct SeqArgs::@59 MasterTempo

◆ au_BGMCmd_E1_MasterVolume()

void au_BGMCmd_E1_MasterVolume ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1472 of file 28910_len_5090.c.

1472 {
1473 s32 volume = player->seqCmdArgs.MasterVolume.value & 0x7F;
1474
1475 if (volume != 0) {
1476 volume = volume << 0x18;
1477 }
1478
1479 player->masterVolume = volume;
1480 player->masterVolumeTime = 0;
1481 player->masterVolumeTarget = 0;
1482 player->masterVolumeStep = 0;
1483 player->volumeChanged = TRUE;
1484 track->changed.volume = TRUE;
1485}
struct SeqArgs::@60 MasterVolume

◆ au_BGMCmd_E2_MasterPitchShift()

void au_BGMCmd_E2_MasterPitchShift ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1487 of file 28910_len_5090.c.

1487 {
1488 player->masterPitchShift = (s8)player->seqCmdArgs.MasterPitchShift.cent * 100;
1489}
struct SeqArgs::@61 MasterPitchShift

◆ au_BGMCmd_E3()

void au_BGMCmd_E3 ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1491 of file 28910_len_5090.c.

1491 {
1492 player->globals->effectChanges[player->busId].type = player->seqCmdArgs.UnkCmdE3.effectType;
1493 player->globals->effectChanges[player->busId].changed = TRUE;
1494}
struct SeqArgs::@62 UnkCmdE3

◆ au_BGMCmd_E6_MasterEffect()

void au_BGMCmd_E6_MasterEffect ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1496 of file 28910_len_5090.c.

1496 {
1497 u8 index = player->seqCmdArgs.MasterEffect.index;
1498 u32 busId = player->effectIndices[index];
1499
1500 if ((index < 4) && (busId < 0x80)) {
1501 if (player->globals->effectChanges[busId].type != player->seqCmdArgs.MasterEffect.value) {
1502 player->globals->effectChanges[busId].type = player->seqCmdArgs.MasterEffect.value;
1503 player->globals->effectChanges[busId].changed = TRUE;
1504 }
1505 player->effectValues[index] = player->seqCmdArgs.MasterEffect.value;
1506 }
1507}

Referenced by func_8004DFD4().

◆ au_BGMCmd_E4_MasterTempoFade()

void au_BGMCmd_E4_MasterTempoFade ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1509 of file 28910_len_5090.c.

1509 {
1510 s32 time = player->seqCmdArgs.MasterTempoFade.time;
1511 s32 tempo = snd_bpm_to_tempo(player, player->seqCmdArgs.MasterTempoFade.value);
1512
1513 if (time <= 0) {
1514 time = 1;
1515 }
1516
1517 player->masterTempoTime = time;
1518 player->masterTempoTarget = tempo;
1519 player->masterTempoStep = (tempo - player->masterTempo) / time;
1520}
struct SeqArgs::@63 MasterTempoFade

◆ au_BGMCmd_E5_MasterVolumeFade()

void au_BGMCmd_E5_MasterVolumeFade ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1522 of file 28910_len_5090.c.

1522 {
1523 s32 time = player->seqCmdArgs.MasterVolumeFade.time;
1524 s32 volume = player->seqCmdArgs.MasterVolumeFade.value & 0x7F;
1525
1526 if (volume != 0) {
1527 volume = volume << 0x18;
1528 }
1529
1530 if (time <= 0) {
1531 time = 1;
1532 }
1533
1534 player->masterVolumeTime = time;
1535 player->masterVolumeTarget = volume;
1536 player->masterVolumeStep = (volume - player->masterVolume) / time;
1537}
struct SeqArgs::@64 MasterVolumeFade

◆ au_BGMCmd_E8_TrackOverridePatch()

void au_BGMCmd_E8_TrackOverridePatch ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1539 of file 28910_len_5090.c.

1539 {
1540 track->patch = player->seqCmdArgs.TrackOverridePatch.patch;
1541 track->instrument = au_get_instrument(player->globals, player->seqCmdArgs.TrackOverridePatch.bank, track->patch, &track->envelope);
1542}
struct SeqArgs::@66 TrackOverridePatch

◆ au_BGMCmd_E9_SubTrackVolume()

void au_BGMCmd_E9_SubTrackVolume ( BGMPlayer * arg0,
BGMPlayerTrack * track )

Definition at line 1544 of file 28910_len_5090.c.

1544 {
1545 u32 volume = arg0->seqCmdArgs.SubTrackVolume.value & 0x7F;
1546
1547 if (volume != 0) {
1548 volume = volume << 0x18;
1549 }
1550
1551 track->subTrackVolume = volume;
1552 track->changed.volume = TRUE;
1553}
struct SeqArgs::@67 SubTrackVolume

Referenced by func_80050970().

◆ au_BGMCmd_F6_TrackVolumeFade()

void au_BGMCmd_F6_TrackVolumeFade ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1555 of file 28910_len_5090.c.

1555 {
1556 s32 time = player->seqCmdArgs.TrackVolumeFade.time;
1557 s32 volume = player->seqCmdArgs.TrackVolumeFade.value & 0x7F;
1558
1559 if (volume != 0) {
1560 volume = volume << 0x18;
1561 }
1562
1563 if (volume != track->subTrackVolume) {
1564 if (time <= 0) {
1565 time = 1;
1566 }
1567
1568 track->subTrackVolumeTime = time;
1569 track->subTrackVolumeTarget = volume;
1570 track->subTrackVolumeStep = (volume - track->subTrackVolume) / time;
1571 }
1572}

Referenced by au_bgm_change_track_volume(), au_bgm_player_update_playing(), and func_80050970().

◆ au_BGMCmd_EA_SubTrackPan()

void au_BGMCmd_EA_SubTrackPan ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1574 of file 28910_len_5090.c.

1574 {
1575 track->subTrackPan = player->seqCmdArgs.SubTrackPan.value & 0x7F;
1576 track->unk_57 = 0;
1577 track->changed.pan = TRUE;
1578}
struct SeqArgs::@68 SubTrackPan

◆ au_BGMCmd_EB_SubTrackReverb()

void au_BGMCmd_EB_SubTrackReverb ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1580 of file 28910_len_5090.c.

1580 {
1581 track->subTrackReverb = player->seqCmdArgs.SubTrackReverb.value & 0x7F;
1582 track->changed.reverb = TRUE;
1583}
struct SeqArgs::@69 SubTrackReverb

◆ au_BGMCmd_EC_SegTrackVolume()

void au_BGMCmd_EC_SegTrackVolume ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1585 of file 28910_len_5090.c.

1585 {
1586 track->segTrackVolume = player->seqCmdArgs.SegTrackVolume.value & 0x7F;
1587 track->changed.volume = TRUE;
1588}
struct SeqArgs::@70 SegTrackVolume

◆ au_BGMCmd_ED_SubTrackCoarseTune()

void au_BGMCmd_ED_SubTrackCoarseTune ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1590 of file 28910_len_5090.c.

1590 {
1591 track->subTrackCoarseTune = (s8)player->seqCmdArgs.SubTrackCoarseTune.cent * 100;
1592}
struct SeqArgs::@71 SubTrackCoarseTune

◆ au_BGMCmd_EE_SubTrackFineTune()

void au_BGMCmd_EE_SubTrackFineTune ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1594 of file 28910_len_5090.c.

1594 {
1595 track->subTrackFineTune = player->seqCmdArgs.SubTrackFineTune.value;
1596}
struct SeqArgs::@72 SubTrackFineTune

◆ au_BGMCmd_EF_SegTrackTune()

void au_BGMCmd_EF_SegTrackTune ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1598 of file 28910_len_5090.c.

1598 {
1599 track->segTrackTune = player->seqCmdArgs.SegTrackTune.value;
1600 track->changed.tune = TRUE;
1601}
struct SeqArgs::@73 SegTrackTune

◆ au_BGMCmd_F0_TrackTremolo()

void au_BGMCmd_F0_TrackTremolo ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1603 of file 28910_len_5090.c.

1603 {
1604 track->trackTremoloAmount = player->seqCmdArgs.TrackTremolo.amount;
1605 track->trackTremoloSpeed = player->seqCmdArgs.TrackTremolo.speed;
1606 track->trackTremoloTime = player->seqCmdArgs.TrackTremolo.time;
1607}
struct SeqArgs::@74 TrackTremolo

◆ au_BGMCmd_F1_TrackTremoloSpeed()

void au_BGMCmd_F1_TrackTremoloSpeed ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1609 of file 28910_len_5090.c.

1609 {
1610 track->trackTremoloSpeed = player->seqCmdArgs.TrackTremoloSpeed.value;
1611}
struct SeqArgs::@75 TrackTremoloSpeed

◆ au_BGMCmd_F2_TrackTremoloTime()

void au_BGMCmd_F2_TrackTremoloTime ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1613 of file 28910_len_5090.c.

1613 {
1614 track->trackTremoloTime = player->seqCmdArgs.TrackTremoloTime.time;
1615}
struct SeqArgs::@76 TrackTremoloTime

◆ au_BGMCmd_F3_TrackTremoloStop()

void au_BGMCmd_F3_TrackTremoloStop ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1617 of file 28910_len_5090.c.

1617 {
1618 track->trackTremoloTime = 0;
1619}

◆ au_BGMCmd_F4()

void au_BGMCmd_F4 ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1621 of file 28910_len_5090.c.

1621 {
1622 track->subTrackPan = player->seqCmdArgs.UnkCmdF4.pan0 & 0x7F;
1623 track->unk_57 = player->seqCmdArgs.UnkCmdF4.pan1 & 0x7F;
1624}
struct SeqArgs::@77 UnkCmdF4

◆ au_BGMCmd_F5_TrackVoice()

void au_BGMCmd_F5_TrackVoice ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1626 of file 28910_len_5090.c.

1626 {
1627 BGMInstrumentInfo* instrument;
1628 s32 volume;
1629 u32 voiceIndex;
1630 u32 patch;
1631 u32 bank;
1632
1633 voiceIndex = player->seqCmdArgs.SetTrackVoice.index;
1634 if (voiceIndex < 0x80) {
1635 if (voiceIndex < player->bgmInstrumentCount) {
1636 instrument = &player->instrumentsInfo[voiceIndex];
1637 } else {
1638 instrument = &player->globals->defaultPRGEntry;
1639 }
1640 } else {
1641 voiceIndex -= 0x80;
1642 if (voiceIndex < 0x40) {
1643 instrument = &player->globals->dataPRG[voiceIndex];
1644 } else {
1645 instrument = &player->globals->defaultPRGEntry;
1646 }
1647 }
1648 bank = instrument->bankPatch >> 8;
1649 patch = (u8)instrument->bankPatch;
1650 volume = instrument->volume & 0x7F;
1651 track->patch = patch;
1652 track->instrument = au_get_instrument(player->globals, bank, patch, &track->envelope);
1653 if (volume != 0) {
1654 volume <<= 0x18;
1655 }
1656 track->subTrackVolume = volume;
1657 track->subTrackPan = instrument->pan & 0x7F;
1658 track->subTrackReverb = instrument->reverb & 0x7F;
1659 track->subTrackCoarseTune = instrument->coarseTune * 100;
1660 track->subTrackFineTune = instrument->fineTune;
1661 track->changed.all |= 0x10101;
1662}
struct SeqArgs::@78 SetTrackVoice

◆ au_BGMCmd_F7_SubTrackReverbType()

void au_BGMCmd_F7_SubTrackReverbType ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1664 of file 28910_len_5090.c.

1664 {
1665 u8 index = player->seqCmdArgs.SubTrackReverbType.index;
1666 s8 busId = player->effectIndices[index];
1667
1668 if ((index < 4) && (busId >= 0)) {
1669 track->subtrackBusId = busId;
1670 } else {
1671 track->subtrackBusId = player->busId;
1672 }
1673}
struct SeqArgs::@80 SubTrackReverbType

◆ au_BGMCmd_FD_EventTrigger()

void au_BGMCmd_FD_EventTrigger ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1675 of file 28910_len_5090.c.

1675 {
1676 bgm_trigger_music_event(player->priority, track->index, player->seqCmdArgs.EventTrigger.eventInfo >> 8);
1677}
void bgm_trigger_music_event(s32 playerID, s32 trackIndex, s32 eventInfo)
Definition 30450.c:812
struct SeqArgs::@82 EventTrigger

◆ au_BGMCmd_FE_Detour()

void au_BGMCmd_FE_Detour ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1680 of file 28910_len_5090.c.

1680 {
1681 AuFilePos readPos = AU_FILE_RELATIVE(player->bgmFile, player->seqCmdArgs.Detour.offset);
1682
1683 track->detourLength = player->seqCmdArgs.Detour.length;
1684 track->savedPos = track->bgmReadPos;
1685 track->bgmReadPos = readPos;
1686}
struct SeqArgs::@83 Detour

◆ au_BGMCmd_FC_Jump()

void au_BGMCmd_FC_Jump ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1689 of file 28910_len_5090.c.

1689 {
1690 AuFilePos args;
1691 u32 i;
1692
1693 // get jump table
1694 args = AU_FILE_RELATIVE(player->bgmFile, player->seqCmdArgs.Jump.unk_00);
1695 if (player->proxMixID < player->seqCmdArgs.Jump.unk_02) {
1696 args += player->proxMixID * 3;
1697 }
1698 // read new position from jump table
1699 track->prevReadPos = track->bgmReadPos;
1700 track->bgmReadPos = AU_FILE_RELATIVE(player->bgmFile, (args[0] << 8) + args[1]);
1701 track->isDrumTrack = args[2];
1702
1703 if (track->unk_4D != 0) {
1704 track->unk_4D = 0;
1705 track->unkVolume = 0;
1706 for (i = track->unk_52; i < track->unk_53; i++) {
1707 AuVoice* voice = &player->globals->voices[i];
1708 if ((voice->priority == player->priority) && (voice->cmdPtr != NULL)) {
1709 au_reset_voice(voice, i);
1710 }
1711 }
1712 }
1713 if (track->unk_4E != 0) {
1714 track->unk_4E = 0;
1715 func_80050888(player, track, player->proxMixVolume, 144);
1716 }
1717 track->subTrackCoarseTune = 0;
1718 track->subTrackFineTune = 0;
1719 track->unk_4C = 0;
1720 track->segTrackTune = 0;
1721 track->trackTremoloTime = 0;
1722 track->subTrackVolumeTime = 0;
1723 track->unk_57 = 0;
1724 track->subtrackBusId = player->busId;
1725}
void func_80050888(BGMPlayer *player, BGMPlayerTrack *track, s32 target, s32 duration)
struct SeqArgs::@81 Jump

◆ au_BGMCmd_FF()

void au_BGMCmd_FF ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1727 of file 28910_len_5090.c.

1727 {
1728 u32 i;
1729 u32 j;
1730 u8 temp_a1;
1731 u8 temp_a3;
1732
1733 u32 arg0 = player->seqCmdArgs.UnkCmdFF.unk_00;
1734 u32 arg1 = player->seqCmdArgs.UnkCmdFF.unk_01;
1735 u32 arg2 = player->seqCmdArgs.UnkCmdFF.unk_02;
1736
1737 switch (arg0) {
1738 case 1:
1739 if ((arg1 < ARRAY_COUNT(player->effectIndices)) && ((s8)player->effectIndices[arg1] >= 0)) {
1740 player->globals->channelDelayBusId = player->effectIndices[arg1];
1741 if (arg2 != 0) {
1742 temp_a3 = arg2 & 0xF;
1743 temp_a1 = ((arg2 >> 4) & 1) + 1;
1744 if ((player->globals->channelDelayTime != temp_a3) || (player->globals->channelDelaySide != temp_a1)) {
1745 player->globals->channelDelayTime = temp_a3;
1746 player->globals->channelDelaySide = temp_a1;
1747 player->globals->channelDelayPending = 1;
1748 }
1749 } else {
1750 if (player->globals->channelDelaySide != 0) {
1751 player->globals->channelDelaySide = 0;
1752 player->globals->channelDelayPending = 1;
1753 }
1754 }
1755 }
1756 break;
1757 case 2:
1758 if (arg1 - 1 < 8) {
1759 player->unk_211 = arg1;
1760 func_8004E844(player, arg1 - 1);
1761 } else {
1762 player->unk_211 = 0;
1763 }
1764 break;
1765 case 3:
1766 i = player->unk_211;
1767 if (i - 1 < 8) {
1768 i = i - 1; // needed to match
1769 j = player->unk_212[i];
1770 if (j < 8) {
1771 if (arg1 >= 40) {
1772 player->unk_174[i][j] = (arg1 << 8) + arg2;
1773 } else {
1774 player->unk_174[i][j] = (D_80078558[arg1] << 8) + arg2;
1775 }
1776 player->unk_212[i] = j + 1;
1777 }
1778 }
1779 break;
1780 case 4:
1781 if (arg1 < 9) {
1782 track->unk_4C = arg1;
1783 } else {
1784 track->unk_4C = 0;
1785 }
1786 break;
1787 case 5:
1788 if (player->soundManager != NULL) {
1789 for (i = 0; i < ARRAY_COUNT(player->soundManager->bgmSounds); i++) {
1790 if ((player->soundManager->bgmSounds[i].unk_0) == 0) {
1791 player->soundManager->bgmSounds[i].unk_0 = arg1;
1792 player->soundManager->bgmSounds[i].volume = ((player->fadeInfo.curVolume.u16 * player->fadeInfo.volScale.u16) + 0x7FFF) >> 0x17;
1793 break;
1794 }
1795 }
1796 }
1797 break;
1798 case 6:
1799 if (arg1 == 0) {
1800 if (track->unk_4E != 0) {
1801 track->unk_4E = 0;
1802 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
1803 BGMPlayerTrack* otherTrack = &player->tracks[i];
1804 if (player->proxMixVolume == 0x7F) {
1805 if (otherTrack->unk_4F != 0) {
1806 otherTrack->unk_4E = 0;
1807 func_80050888(player, otherTrack, otherTrack->unk_4F, 72);
1808 }
1809 } else {
1810 if (otherTrack->unk_50 != 0) {
1811 otherTrack->unk_4E = 0;
1812 func_80050888(player, otherTrack, otherTrack->unk_50, 72);
1813 }
1814 }
1815 }
1816 }
1817 } else {
1818 track->unk_4F = arg1;
1819 track->unk_50 = arg2;
1820 }
1821 break;
1822 }
1823}
u8 D_80078558[40]
Definition sfx_player.c:317
struct SeqArgs::@84 UnkCmdFF

◆ au_BGMCmd_NOP()

void au_BGMCmd_NOP ( BGMPlayer * player,
BGMPlayerTrack * track )

Definition at line 1825 of file 28910_len_5090.c.

1825 {
1826}

◆ au_bgm_set_proximity_mix()

void au_bgm_set_proximity_mix ( s32 songName,
u32 mix )

Definition at line 1905 of file 28910_len_5090.c.

1905 {
1906 BGMPlayer* player;
1907 BGMPlayerTrack* track;
1908 s32 changed = FALSE;
1909 u8 mixID = mix & 0xFF;
1910 s32 i;
1911
1912 if (songName != 0) {
1913 player = au_bgm_get_player_with_song_name(songName);
1914 if ((player != NULL) && (player->proxMixValue != mix)) {
1915 player->proxMixValue = mix;
1916 if (player->proxMixID != mixID) {
1917 player->proxMixID = mixID;
1918 changed = TRUE;
1919 }
1920 player->proxMixVolume = (mix >> 0x18) & 0x7F;
1921 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
1922 track = &player->tracks[i];
1923 if (changed) {
1924 track->unk_4D = 1;
1925 }
1926 track->unk_4E = 1;
1927 }
1928 }
1929 }
1930}

Referenced by bgm_set_proximity_mix_far(), bgm_set_proximity_mix_full(), and bgm_set_proximity_mix_near().

◆ au_bgm_set_playback_rate()

void au_bgm_set_playback_rate ( BGMPlayer * player,
f32 arg1 )

Definition at line 1932 of file 28910_len_5090.c.

1932 {
1933 if (rate > 2.0) {
1934 rate = 2.0f;
1935 } else if (rate < 0.25) {
1936 rate = 0.25f;
1937 }
1938
1939 player->playbackRate = rate;
1940 player->masterTempo = snd_bpm_to_tempo(player, player->masterTempoBPM);
1941 player->nextUpdateStep = player->masterTempo * 10;
1942 player->masterTempoTime = 0;
1943 player->masterTempoTarget = 0;
1944 player->masterTempoStep = 0;
1945}

Referenced by snd_song_set_playback_rate().

◆ au_bgm_player_set_detune()

void au_bgm_player_set_detune ( BGMPlayer * player,
s32 arg1 )

Definition at line 1947 of file 28910_len_5090.c.

1947 {
1948 if (detune > 1200) {
1949 detune = 1200;
1950 } else if (detune < -2400) {
1951 detune = -2400;
1952 }
1953
1954 player->detune = detune;
1955}

Referenced by snd_song_set_detune().

◆ au_bgm_change_track_volume()

void au_bgm_change_track_volume ( BGMPlayer * player,
s32 trackIdx,
s16 arg2,
u8 arg3 )

Definition at line 1957 of file 28910_len_5090.c.

1957 {
1958 BGMPlayerTrack* track = &player->tracks[trackIdx];
1959
1960 if (track->bgmReadPos != 0) {
1961 player->seqCmdArgs.TrackVolumeFade.time = time;
1962 player->seqCmdArgs.TrackVolumeFade.value = volume;
1963 au_BGMCmd_F6_TrackVolumeFade(player, track);
1964 }
1965}

◆ au_bgm_set_track_volumes()

void au_bgm_set_track_volumes ( BGMPlayer * player,
u8 * arg1,
s32 arg2 )

Definition at line 1967 of file 28910_len_5090.c.

1967 {
1968 player->trackVolsConfig = trackVols;
1969 player->bFadeConfigSetsVolume = mode;
1970}

Referenced by snd_song_clear_track_volumes(), and snd_song_set_track_volumes().

◆ func_80050888()

void func_80050888 ( BGMPlayer * player,
BGMPlayerTrack * track,
s32 target,
s32 duration )

Definition at line 1972 of file 28910_len_5090.c.

1972 {
1973 if (target != 0) {
1974 target = (target << 8) | 0xFF;
1975 }
1976 if (duration <= 0) {
1977 duration = 1;
1978 } else if (duration > 1000) {
1979 duration = 1000;
1980 }
1981 if (target == track->unkVolume) {
1982 track->unkVolumeTime = 0;
1983 return;
1984 }
1985 track->unkVolumeTime = duration;
1986 track->unkVolumeTarget = target;
1987 track->unkVolumeStep = ((target << 0x10) - track->unkVolume) / duration;
1988}

Referenced by au_BGMCmd_FC_Jump(), and au_BGMCmd_FF().

◆ func_80050900()

void func_80050900 ( BGMPlayer * player)

Definition at line 1990 of file 28910_len_5090.c.

1990 {
1991 u8 i;
1992
1993 for (i = 0; i < ARRAY_COUNT(player->globals->voices); i++) {
1994 AuVoice* voice = &player->globals->voices[i];
1995 if (voice->priority == player->priority) {
1996 au_reset_voice(voice, i);
1997 }
1998 }
1999}

Referenced by au_bgm_player_initialize(), au_bgm_player_update_stop(), and func_8004DCB8().

◆ func_80050970()

AuResult func_80050970 ( SongUpdateEvent * arg0)

Definition at line 2001 of file 28910_len_5090.c.

2001 {
2002 BGMPlayer* player;
2003 BGMPlayerTrack* track;
2004 BGMPlayerTrack* parentTrack;
2005 AuVoice* voice;
2006 s32 i;
2007 s32 j;
2008 s8 oldVolume;
2009
2010 s32 songName = update->songName;
2011 s32 variation = update->variation;
2012 AuResult status = AU_RESULT_OK;
2013
2014 if (songName != 0) {
2015 player = au_bgm_get_player_with_song_name(songName);
2016 if (player != NULL) {
2017 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
2018 track = &player->tracks[i];
2019 if (track->bgmReadPos != NULL) {
2020 if (track->parentTrackIdx != 0) {
2021 parentTrack = &player->tracks[track->parentTrackIdx - 1];
2022 if (variation != 0) {
2023 if (track->unk_5A != 0) {
2024 track->unk_5A = 0;
2025 parentTrack->unk_5A = 1;
2026 for (j = parentTrack->unk_52; j < parentTrack->unk_53; j++) {
2027 voice = &player->globals->voices[j];
2028 if (voice->priority == player->priority) {
2031 }
2032 }
2033 oldVolume = track->subTrackVolume >> 24;
2034 au_BGMCmd_E9_SubTrackVolume(player, track);
2035 player->seqCmdArgs.raw[0] = 0;
2036 player->seqCmdArgs.TrackVolumeFade.time = 96;
2037 player->seqCmdArgs.TrackVolumeFade.value = oldVolume;
2038 au_BGMCmd_F6_TrackVolumeFade(player, track);
2039 }
2040 } else {
2041 if (track->unk_5A == 0) {
2042 track->unk_5A = 1;
2043 parentTrack->unk_5A = 0;
2044 for (j = track->unk_52; j < track->unk_53; j++) {
2045 voice = &player->globals->voices[j];
2046 if (voice->priority == player->priority) {
2049 }
2050 }
2051 oldVolume = parentTrack->subTrackVolume >> 24;
2052 au_BGMCmd_E9_SubTrackVolume(player, parentTrack);
2053 player->seqCmdArgs.raw[0] = 0;
2054 player->seqCmdArgs.TrackVolumeFade.time = 96;
2055 player->seqCmdArgs.TrackVolumeFade.value = oldVolume;
2056 au_BGMCmd_F6_TrackVolumeFade(player, parentTrack);
2057 }
2058 }
2059 }
2060 }
2061 }
2062 } else {
2064 }
2065 } else {
2066 status = AU_ERROR_NULL_SONG_NAME;
2067 }
2068
2069 return status;
2070}
u8 EnvelopeReleaseDefaultFast[]
Definition sfx_player.c:309
void au_BGMCmd_E9_SubTrackVolume(BGMPlayer *arg0, BGMPlayerTrack *track)

Referenced by snd_set_song_variation().

◆ func_80055110()

void func_80055110 ( BGMPlayer * player)

Definition at line 133 of file 30450.c.

133 {
134 s32 i;
135
136 for (i = 0; i < ARRAY_COUNT(player->unk_238); i++) {
137 player->unk_238[i] = 0;
138 }
139
140 player->unk_25B = 0;
141 player->unk_25A = 0;
142 player->unk_259 = 0;
143 player->unk_258 = 0;
144}
u8 unk_25B
Definition audio.h:1080

Referenced by au_bgm_player_init().

◆ snd_song_get_playing_info()

AuResult snd_song_get_playing_info ( s32 songName,
BGMHeader ** outTrackData,
BGMPlayer ** outPlayer )

Definition at line 636 of file 30450.c.

636 {
637 AuResult status = AU_RESULT_OK;
638 BGMHeader* bgmFile;
639
640 bgmFile = gSoundGlobals->dataBGM[0];
641 if (songName == bgmFile->name) {
642 *outPlayer = gBGMPlayerA;
643 *outFile = bgmFile;
644 } else {
645 bgmFile = gSoundGlobals->dataBGM[1];
646 if (songName == bgmFile->name) {
647 *outPlayer = gBGMPlayerB;
648 *outFile = bgmFile;
649 } else {
650 status = AU_ERROR_1;
651 }
652 }
653 return status;
654}
AuGlobals * gSoundGlobals
@ AU_ERROR_1
Definition enums.h:1757

Referenced by snd_song_clear_track_volumes(), snd_song_set_detune(), snd_song_set_playback_rate(), and snd_song_set_track_volumes().

◆ au_register_callback()

void au_register_callback ( AuCallback arg0,
s32 arg1 )

Definition at line 835 of file 30450.c.

835 {
836 gSoundGlobals->audioThreadCallbacks[index] = func;
837}

◆ au_driver_init()

void au_driver_init ( AuSynDriver * driver,
ALConfig * config )

Definition at line 25 of file 31650.c.

25 {
26 ALHeap* heap = config->heap;
27 s32 i;
28
29 if (gActiveSynDriverPtr != NULL) {
30 return;
31 }
32
33 driver->num_pvoice = config->num_pvoice;
34 driver->num_bus = config->num_bus;
35 driver->curSamples = 0;
36 driver->unk_04 = 0;
37 driver->outputRate = config->outputRate;
38 driver->dmaNew = config->dmaNew;
39
40 gActiveSynDriverPtr = driver;
41 gSynDriverPtr = driver;
42 AuUseGlobalVolume = FALSE;
43 AuGlobalVolume = 0x7FFF;
44 AuSynStereoDirty = TRUE;
45
47
48 // this is inlined alN_PVoiceNew
49 for (i = 0; i < config->num_pvoice; i++) {
50 AuPVoice* voice = &gSynDriverPtr->pvoices[i];
51 voice->decoder.state = alHeapAlloc(heap, 1, sizeof(*voice->decoder.state));
52 voice->decoder.lstate = alHeapAlloc(heap, 1, sizeof(*voice->decoder.lstate));
54 voice->decoder.lastsam = 0;
55 voice->decoder.first = 1;
56 voice->decoder.memin = NULL;
57 voice->resampler.state = alHeapAlloc(heap, 1, sizeof(*voice->resampler.state));
58 voice->resampler.delta = 0;
59 voice->resampler.first = 1;
60 voice->resampler.ratio = 1.0f;
61 voice->envMixer.state = alHeapAlloc(heap, 1, sizeof(*voice->envMixer.state));
62 voice->envMixer.first = 1;
63 voice->envMixer.motion = AL_STOPPED;
64 voice->envMixer.volume = 1;
65 voice->envMixer.ltgt = 1;
66 voice->envMixer.rtgt = 1;
67 voice->envMixer.cvolL = 1;
68 voice->envMixer.cvolR = 1;
69 voice->envMixer.dryamt = 0;
70 voice->envMixer.wetamt = 0;
71 voice->envMixer.lratm = 1;
72 voice->envMixer.lratl = 0;
73 voice->envMixer.rratm = 1;
74 voice->envMixer.rratl = 0;
75 voice->envMixer.delta = 0;
76 voice->envMixer.segEnd = 0;
77 voice->envMixer.pan = 64;
78 voice->unk_74 = 0;
79 voice->next = NULL;
80 voice->busId = FX_BUS_BGMA_MAIN;
81 voice->index = i;
82 }
83
84 gSynDriverPtr->fxBus = alHeapAlloc(heap, config->num_bus, sizeof(*gSynDriverPtr->fxBus));
85
86 for (i = 0; i < config->num_bus; i++) {
87 AuFxBus* fxBus = &gSynDriverPtr->fxBus[i];
88 fxBus->head = NULL;
89 fxBus->tail = NULL;
90 fxBus->gain = 0x7FFF;
92 fxBus->fxL = alHeapAlloc(heap, 1, sizeof(*fxBus->fxL));
93 fxBus->fxR = alHeapAlloc(heap, 1, sizeof(*fxBus->fxR));
94 func_80058E84(fxBus->fxL, fxBus->curEffectType, heap);
95 func_80058E84(fxBus->fxR, fxBus->curEffectType, heap);
96 }
97
102 AuDelayCount = 4;
103
106 for (i = 0; i < 4 * AUDIO_SAMPLES; i++) {
108 }
109
110 gSynDriverPtr->heap = heap;
111}
BSS s16 AuDelayedChannel
Definition 31650.c:11
BSS u8 AuDelayedVoiceGroup
Definition 31650.c:10
AuSynDriver * gActiveSynDriverPtr
Definition 31650.c:14
BSS s16 * AuDelayBufferAux
Definition 31650.c:8
BSS s16 * AuDelayBufferMain
Definition 31650.c:7
u8 AuUseGlobalVolume
Definition 31650.c:16
AuSynDriver * gSynDriverPtr
Definition 31650.c:15
u16 AuGlobalVolume
Definition 31650.c:17
BSS s32 AuDelayCount
Definition 31650.c:12
u8 AuSynStereoDirty
Definition 31650.c:18
s32 unk_04
Definition audio.h:511
f32 delta
Definition audio.h:470
s32 * savedMainOut
Definition audio.h:519
s16 dryamt
Definition audio.h:481
u16 gain
Definition audio.h:437
f32 ratio
Definition audio.h:469
struct AuPVoice * next
Definition audio.h:497
s16 wetamt
Definition audio.h:482
s32 segEnd
Definition audio.h:490
s16 rtgt
Definition audio.h:488
s32 curSamples
Definition audio.h:510
s16 cvolR
Definition audio.h:480
ALDMANew2 dmaNew
Definition audio.h:515
s16 unk_74
Definition audio.h:501
s32 outputRate
Definition audio.h:512
u8 curEffectType
Definition audio.h:441
s16 lratm
Definition audio.h:484
s32 * savedAuxOut
Definition audio.h:520
AuLoadFilter decoder
Definition audio.h:498
ADPCM_STATE * state
Definition audio.h:453
s32 first
Definition audio.h:471
s16 rratm
Definition audio.h:487
s16 volume
Definition audio.h:478
AuPVoice * pvoices
Definition audio.h:517
s16 pan
Definition audio.h:477
s32 delta
Definition audio.h:489
ENVMIX_STATE * state
Definition audio.h:476
s32 lastsam
Definition audio.h:461
AuFxBus * fxBus
Definition audio.h:518
AuResampler resampler
Definition audio.h:499
s16 cvolL
Definition audio.h:479
s32 num_pvoice
Definition audio.h:513
s16 rratl
Definition audio.h:486
AuFX * fxR
Definition audio.h:440
s16 lratl
Definition audio.h:483
u8 index
Definition audio.h:504
struct AuPVoice * tail
Definition audio.h:444
ALDMAproc2 dmaFunc
Definition audio.h:458
s32 first
Definition audio.h:491
struct AuPVoice * head
Definition audio.h:443
u8 busId
Definition audio.h:503
s32 motion
Definition audio.h:492
ADPCM_STATE * lstate
Definition audio.h:454
NUDMAState * dmaState
Definition audio.h:459
s32 num_bus
Definition audio.h:514
AuEnvMixer envMixer
Definition audio.h:500
s32 memin
Definition audio.h:463
RESAMPLE_STATE * state
Definition audio.h:468
s16 ltgt
Definition audio.h:485
s32 first
Definition audio.h:462
AuFX * fxL
Definition audio.h:439
void func_80058E84(AuFX *fx, u8 mode, ALHeap *heap)
Definition reverb.c:137

Referenced by create_audio_system().

◆ au_driver_release()

void au_driver_release ( void )

Definition at line 113 of file 31650.c.

113 {
114 if (gActiveSynDriverPtr != NULL) {
115 gActiveSynDriverPtr = NULL;
116 }
117}

◆ au_use_global_volume()

void au_use_global_volume ( void )

Definition at line 250 of file 31650.c.

250 {
251 AuUseGlobalVolume = TRUE;
252}

Referenced by nuAuPreNMIProc().

◆ au_set_global_volume()

void au_set_global_volume ( s16 arg0)

Definition at line 254 of file 31650.c.

254 {
255 AuGlobalVolume = arg0;
256}

Referenced by nuAuPreNMIProc().

◆ au_get_global_volume()

s16 au_get_global_volume ( void )

Definition at line 258 of file 31650.c.

258 {
259 return AuGlobalVolume;
260}

Referenced by nuAuPreNMIProc().

◆ func_80056D5C()

void func_80056D5C ( u8 arg0)

Definition at line 262 of file 31650.c.

262 {
263 AuSynUseStereo = bStereoSound;
264 AuSynStereoDirty = TRUE;
265}
volatile u8 AuSynUseStereo

Referenced by audio_set_mono(), and audio_set_stereo().

◆ au_bus_set_volume()

void au_bus_set_volume ( u8 arg0,
u16 arg1 )

Definition at line 267 of file 31650.c.

267 {
268 AuFxBus* fxBus = &gSynDriverPtr->fxBus[index];
269
270 fxBus->gain = arg1 & 0x7FFF;
271}

Referenced by au_fade_set_volume().

◆ au_bus_get_volume()

u16 au_bus_get_volume ( u8 arg0,
u16 arg1 )

Definition at line 273 of file 31650.c.

273 {
274 AuFxBus* fxBus = &gSynDriverPtr->fxBus[index];
275
276 return fxBus->gain;
277}

◆ au_bus_set_effect()

void au_bus_set_effect ( u8 arg0,
u8 effectID )

Definition at line 279 of file 31650.c.

279 {
280 AuFxBus* fxBus = &gSynDriverPtr->fxBus[index];
281
282 fxBus->curEffectType = effectType;
283 func_8005904C(fxBus->fxL, effectType);
284 func_8005904C(fxBus->fxR, effectType);
285}
void func_8005904C(AuFX *fx, u8 effectType)
Definition reverb.c:180

Referenced by au_syn_update().

◆ au_bus_set_fx_params()

void au_bus_set_fx_params ( u8 arg0,
s16 arg1,
s16 arg2,
s32 arg3 )

Definition at line 287 of file 31650.c.

287 {
288 AuFxBus* fxBus = &gSynDriverPtr->fxBus[index];
289
290 au_fx_param_hdl(fxBus->fxL, delayIndex, paramID, value);
291 au_fx_param_hdl(fxBus->fxR, delayIndex, paramID, value);
292}
s32 au_fx_param_hdl(AuFX *fx, s16 index, s16 paramID, s32 value)
Definition reverb.c:384

◆ au_pvoice_set_bus()

void au_pvoice_set_bus ( u8 arg0,
s8 arg1 )

Definition at line 294 of file 31650.c.

294 {
295 AuPVoice* pvoice = &gSynDriverPtr->pvoices[index];
296
297 pvoice->busId = busId;
298}

Referenced by au_engine_init().

◆ au_syn_stop_voice()

void au_syn_stop_voice ( u8 voiceIdx)

Definition at line 301 of file 31650.c.

301 {
302 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
303 AuLoadFilter* decoder = &pvoice->decoder;
304
305 pvoice->envMixer.motion = AL_STOPPED;
306 pvoice->envMixer.first = 1;
307 pvoice->envMixer.volume = 1;
308 pvoice->resampler.delta = 0;
309 pvoice->resampler.first = 1;
310 decoder->lastsam = 0;
311 decoder->first = 1;
312 decoder->sample = 0;
313 if (decoder->instrument != NULL) {
314 decoder->memin = (s32)decoder->instrument->base;
315 if (decoder->instrument->type == AL_ADPCM_WAVE) {
316 if (decoder->instrument->loopEnd != 0){
317 decoder->loop.count = decoder->instrument->loopCount;
318 }
319 } else if (decoder->instrument->type == AL_RAW16_WAVE) {
320 if (decoder->instrument->loopEnd != 0){
321 decoder->loop.count = decoder->instrument->loopCount;
322 }
323 }
324 }
325}
s32 loopEnd
Definition audio.h:554
s32 loopCount
Definition audio.h:555
struct Instrument * instrument
Definition audio.h:456
ALRawLoop loop
Definition audio.h:455
u8 type
Definition audio.h:563
s32 sample
Definition audio.h:460

Referenced by au_syn_update(), and au_update_stopped_voices().

◆ au_syn_start_voice()

void au_syn_start_voice ( u8 index)

Definition at line 328 of file 31650.c.

328 {
329 AuPVoice* pvoice = (AuPVoice*)&gSynDriverPtr->pvoices[voiceIdx];
330
331 pvoice->envMixer.motion = AL_PLAYING;
332}

◆ au_syn_start_voice_params()

void au_syn_start_voice_params ( u8 index,
u8 reverbType,
Instrument * table,
f32 pitch,
s16 vol,
u8 pan,
u8 fxMix,
s32 delta )

Definition at line 335 of file 31650.c.

335 {
336 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
337 AuLoadFilter* decoder = &pvoice->decoder;
338 AuEnvMixer* envMixer = &pvoice->envMixer;
339 AuResampler* resampler = &pvoice->resampler;
340
341 pvoice->busId = busId;
342 decoder->instrument = instrument;
343
344 pvoice->decoder.memin = (s32)decoder->instrument->base;
345 pvoice->decoder.sample = 0;
346
347 switch (decoder->instrument->type) {
348 case AL_ADPCM_WAVE:
349 decoder->instrument->wavDataLength = (decoder->instrument->wavDataLength / ADPCMFBYTES) * ADPCMFBYTES;
350 pvoice->decoder.bookSize = decoder->instrument->dc_bookSize;
351 if (decoder->instrument->loopEnd == 0) {
352 decoder->loop.count = 0;
353 decoder->loop.end = 0;
354 decoder->loop.start = 0;
355 } else {
356 decoder->loop.start = decoder->instrument->loopStart;
357 decoder->loop.end = decoder->instrument->loopEnd;
358 decoder->loop.count = decoder->instrument->loopCount;
359 alCopy(decoder->instrument->loopPredictor, decoder->lstate, sizeof(ADPCM_STATE));
360 }
361 break;
362 case AL_RAW16_WAVE:
363 if (decoder->instrument->loopEnd != 0) {
364 decoder->loop.start = decoder->instrument->loopStart;
365 decoder->loop.end = decoder->instrument->loopEnd;
366 decoder->loop.count = decoder->instrument->loopCount;
367 } else {
368 decoder->loop.count = 0;
369 decoder->loop.end = 0;
370 decoder->loop.start = 0;
371 }
372 break;
373 }
374
375 envMixer->motion = AL_PLAYING;
376 envMixer->first = 1;
377 envMixer->delta = 0;
378 envMixer->segEnd = delta;
379 envMixer->pan = pan;
380 envMixer->volume = SQ(vol) >> 0xF;
381 envMixer->dryamt = AuEqPower[fxMix];
382 envMixer->wetamt = AuEqPower[AU_EQPOW_MAX_IDX - fxMix];
383 if (envMixer->segEnd != 0) {
384 envMixer->cvolL = 1;
385 envMixer->cvolR = 1;
386 } else {
387 if (!AuSynUseStereo) {
388 envMixer->cvolL = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
389 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
390 } else {
391 envMixer->cvolL = (envMixer->volume * AuEqPower[envMixer->pan]) >> 0xF;
392 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MAX_IDX - envMixer->pan]) >> 0xF;
393 }
394 }
395 resampler->ratio = pitch;
396}
#define AU_EQPOW_MID_IDX
Definition 31650.c:22
#define AU_EQPOW_MAX_IDX
Definition 31650.c:23
void alCopy(void *src, void *dst, s32 size)
Definition 31650.c:755
s16 AuEqPower[128]
Definition 33450.c:9
#define ADPCMFBYTES
Definition audio.h:47
#define SQ(x)
Definition macros.h:166

Referenced by au_syn_update().

◆ au_syn_set_wavetable()

void au_syn_set_wavetable ( u8 voiceIdx,
Instrument * table )

Definition at line 398 of file 31650.c.

398 {
399 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
400 AuLoadFilter* decoder = &pvoice->decoder;
401
402 pvoice->decoder.instrument = instrument;
403 pvoice->decoder.memin = (s32)decoder->instrument->base;
404 pvoice->decoder.sample = 0;
405
406 switch (decoder->instrument->type) {
407 case AL_ADPCM_WAVE:
408 decoder->instrument->wavDataLength = (decoder->instrument->wavDataLength / ADPCMFBYTES) * ADPCMFBYTES;
409 pvoice->decoder.bookSize = decoder->instrument->dc_bookSize;
410 if (decoder->instrument->loopEnd == 0) {
411 pvoice->decoder.loop.count = 0;
412 pvoice->decoder.loop.end = 0;
413 pvoice->decoder.loop.start = 0;
414 } else {
415 pvoice->decoder.loop.start = decoder->instrument->loopStart;
416 pvoice->decoder.loop.end = decoder->instrument->loopEnd;
417 pvoice->decoder.loop.count = decoder->instrument->loopCount;
418 alCopy(decoder->instrument->loopPredictor, pvoice->decoder.lstate, sizeof(ADPCM_STATE));
419 }
420 break;
421 case AL_RAW16_WAVE:
422 if (decoder->instrument->loopEnd != 0) {
423 pvoice->decoder.loop.start = decoder->instrument->loopStart;
424 pvoice->decoder.loop.end = decoder->instrument->loopEnd;
425 pvoice->decoder.loop.count = decoder->instrument->loopCount;
426 } else {
427 pvoice->decoder.loop.count = 0;
428 pvoice->decoder.loop.end = 0;
429 pvoice->decoder.loop.start = 0;
430 }
431 break;
432 }
433}

Referenced by au_engine_init().

◆ au_syn_set_pitch()

void au_syn_set_pitch ( u8 voiceIdx,
f32 pitchRatio )

Definition at line 436 of file 31650.c.

436 {
437 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
438
439 pvoice->resampler.ratio = pitch;
440}

Referenced by au_syn_update().

◆ au_syn_set_mixer_params()

void au_syn_set_mixer_params ( u8 voiceIdx,
s16 volume,
s32 arg2,
u8 arg3,
u8 arg4 )

Definition at line 442 of file 31650.c.

442 {
443 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
444 AuEnvMixer* envMixer = &pvoice->envMixer;
445
446 if (envMixer->delta >= envMixer->segEnd) {
447 envMixer->delta = envMixer->segEnd;
448 if (!AuSynUseStereo) {
449 envMixer->cvolL = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
450 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
451 } else {
452 envMixer->cvolL = (envMixer->volume * AuEqPower[envMixer->pan]) >> 0xF;
453 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MAX_IDX - envMixer->pan]) >> 0xF;
454 }
455 } else {
456 envMixer->cvolL = _getVol(envMixer->cvolL, envMixer->delta, envMixer->lratm, envMixer->lratl);
457 envMixer->cvolR = _getVol(envMixer->cvolR, envMixer->delta, envMixer->rratm, envMixer->rratl);
458 }
459 if (envMixer->cvolL == 0) {
460 envMixer->cvolL = 1;
461 }
462 if (envMixer->cvolR == 0) {
463 envMixer->cvolR = 1;
464 }
465
466 envMixer->delta = 0;
467 envMixer->segEnd = delta;
468 envMixer->pan = pan;
469 envMixer->volume = SQ(volume) >> 0xF;
470 envMixer->dryamt = AuEqPower[fxMix];
471 envMixer->wetamt = AuEqPower[AU_EQPOW_MAX_IDX - fxMix];
472 envMixer->first = 1;
473}

Referenced by au_syn_update().

◆ au_syn_set_pan_fxmix()

void au_syn_set_pan_fxmix ( u8 voiceIdx,
u8 arg1,
u8 arg2 )

Definition at line 475 of file 31650.c.

475 {
476 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
477 AuEnvMixer* envMixer = &pvoice->envMixer;
478
479 if (envMixer->delta >= envMixer->segEnd) {
480 envMixer->delta = envMixer->segEnd;
481 if (!AuSynUseStereo) {
482 envMixer->cvolL = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
483 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
484 } else {
485 envMixer->cvolL = (envMixer->volume * AuEqPower[envMixer->pan]) >> 0xF;
486 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MAX_IDX - envMixer->pan]) >> 0xF;
487 }
488 } else {
489 envMixer->cvolL = _getVol(envMixer->cvolL, envMixer->delta, envMixer->lratm, envMixer->lratl);
490 envMixer->cvolR = _getVol(envMixer->cvolR, envMixer->delta, envMixer->rratm, envMixer->rratl);
491 }
492 if (envMixer->cvolL == 0) {
493 envMixer->cvolL = 1;
494 }
495 if (envMixer->cvolR == 0) {
496 envMixer->cvolR = 1;
497 }
498
499 envMixer->pan = pan;
500 envMixer->dryamt = AuEqPower[fxMix];
501 envMixer->wetamt = AuEqPower[AU_EQPOW_MAX_IDX - fxMix];
502 envMixer->first = 1;
503}

Referenced by au_syn_update().

◆ au_syn_set_volume_delta()

void au_syn_set_volume_delta ( u8 voiceIdx,
s16 arg1,
s32 arg2 )

Definition at line 505 of file 31650.c.

505 {
506 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
507 AuEnvMixer* envMixer = &pvoice->envMixer;
508
509 if (envMixer->delta >= envMixer->segEnd) {
510 envMixer->delta = envMixer->segEnd;
511 if (!AuSynUseStereo) {
512 envMixer->cvolL = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
513 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
514 } else {
515 envMixer->cvolL = (envMixer->volume * AuEqPower[envMixer->pan]) >> 0xF;
516 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MAX_IDX - envMixer->pan]) >> 0xF;
517 }
518 } else {
519 envMixer->cvolL = _getVol(envMixer->cvolL, envMixer->delta, envMixer->lratm, envMixer->lratl);
520 envMixer->cvolR = _getVol(envMixer->cvolR, envMixer->delta, envMixer->rratm, envMixer->rratl);
521 }
522 if (envMixer->cvolL == 0) {
523 envMixer->cvolL = 1;
524 }
525 if (envMixer->cvolR == 0) {
526 envMixer->cvolR = 1;
527 }
528
529 envMixer->volume = SQ(vol) >> 0xF;
530 envMixer->delta = 0;
531 envMixer->segEnd = delta;
532 envMixer->first = 1;
533}

Referenced by au_reset_nonfree_voice(), and au_reset_voice().

◆ au_syn_set_pan()

void au_syn_set_pan ( u8 voiceIdx,
u8 pan )

Definition at line 535 of file 31650.c.

535 {
536 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
537 AuEnvMixer* envMixer = &pvoice->envMixer;
538
539 if (envMixer->delta >= envMixer->segEnd) {
540 envMixer->delta = envMixer->segEnd;
541 if (!AuSynUseStereo) {
542 envMixer->cvolL = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
543 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
544 } else {
545 envMixer->cvolL = (envMixer->volume * AuEqPower[envMixer->pan]) >> 0xF;
546 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MAX_IDX - envMixer->pan]) >> 0xF;
547 }
548 } else {
549 envMixer->cvolL = _getVol(envMixer->cvolL, envMixer->delta, envMixer->lratm, envMixer->lratl);
550 envMixer->cvolR = _getVol(envMixer->cvolR, envMixer->delta, envMixer->rratm, envMixer->rratl);
551 }
552 if (envMixer->cvolL == 0) {
553 envMixer->cvolL = 1;
554 }
555 if (envMixer->cvolR == 0) {
556 envMixer->cvolR = 1;
557 }
558
559 envMixer->pan = pan;
560 envMixer->first = 1;
561}

Referenced by alAudioFrame().

◆ au_syn_set_fxmix()

void au_syn_set_fxmix ( u8 voiceIdx,
u8 dryAmt )

Definition at line 563 of file 31650.c.

563 {
564 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
565 AuEnvMixer* envMixer = &pvoice->envMixer;
566
567 if (envMixer->delta >= envMixer->segEnd) {
568 envMixer->delta = envMixer->segEnd;
569 if (!AuSynUseStereo) {
570 envMixer->cvolL = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
571 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
572 } else {
573 envMixer->cvolL = (envMixer->volume * AuEqPower[envMixer->pan]) >> 0xF;
574 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MAX_IDX - envMixer->pan]) >> 0xF;
575 }
576 } else {
577 envMixer->cvolL = _getVol(envMixer->cvolL, envMixer->delta, envMixer->lratm, envMixer->lratl);
578 envMixer->cvolR = _getVol(envMixer->cvolR, envMixer->delta, envMixer->rratm, envMixer->rratl);
579 }
580 if (envMixer->cvolL == 0) {
581 envMixer->cvolL = 1;
582 }
583 if (envMixer->cvolR == 0) {
584 envMixer->cvolR = 1;
585 }
586
587 envMixer->dryamt = AuEqPower[fxMix];
588 envMixer->wetamt = AuEqPower[AU_EQPOW_MAX_IDX - fxMix];
589 envMixer->first = 1;
590}

◆ au_syn_get_playing()

s32 au_syn_get_playing ( u8 voiceIdx)

Definition at line 592 of file 31650.c.

592 {
593 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
594
595 return pvoice->envMixer.motion;
596}

◆ au_syn_get_bus()

s32 au_syn_get_bus ( u8 voiceIdx)

Definition at line 598 of file 31650.c.

598 {
599 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
600
601 return pvoice->busId;
602}

◆ au_syn_get_pitch()

f32 au_syn_get_pitch ( u8 voiceIdx)

Definition at line 604 of file 31650.c.

604 {
605 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
606
607 return pvoice->resampler.ratio;
608}

◆ au_syn_get_pan()

u8 au_syn_get_pan ( u8 voiceIdx)

Definition at line 610 of file 31650.c.

610 {
611 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
612
613 return pvoice->envMixer.pan;
614}

◆ au_syn_get_dryamt()

s16 au_syn_get_dryamt ( u8 voiceIdx)

Definition at line 616 of file 31650.c.

616 {
617 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
618
619 return pvoice->envMixer.dryamt;
620}

◆ au_syn_get_wetamt()

s16 au_syn_get_wetamt ( u8 voiceIdx)

Definition at line 622 of file 31650.c.

622 {
623 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
624
625 return pvoice->envMixer.wetamt;
626}

◆ au_syn_get_volume_left()

s32 au_syn_get_volume_left ( u8 voiceIdx)

Definition at line 628 of file 31650.c.

628 {
629 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
630 AuEnvMixer* envmixer = &pvoice->envMixer;
631 u32 retVal;
632
633 if (envmixer->delta >= envmixer->segEnd) {
634 if (!AuSynUseStereo) {
635 retVal = (envmixer->volume * AuEqPower[AU_EQPOW_MID_IDX] * 2) >> 0x10;
636 } else {
637 retVal = (envmixer->volume * AuEqPower[envmixer->pan] * 2) >> 0x10;
638 }
639 } else {
640 retVal = _getVol(envmixer->cvolL, envmixer->delta, envmixer->lratm, envmixer->lratl);
641 }
642 return retVal;
643}

◆ au_syn_get_volume_right()

s32 au_syn_get_volume_right ( u8 voiceIdx)

Definition at line 645 of file 31650.c.

645 {
646 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
647 AuEnvMixer* envmixer = &pvoice->envMixer;
648 u32 retVal;
649
650 if (envmixer->delta >= envmixer->segEnd) {
651 if (!AuSynUseStereo) {
652 retVal = (envmixer->volume * AuEqPower[AU_EQPOW_MID_IDX] * 2) >> 0x10;
653 } else {
654 retVal = (envmixer->volume * AuEqPower[AU_EQPOW_MAX_IDX - envmixer->pan] * 2) >> 0x10;
655 }
656 } else {
657 retVal = _getVol(envmixer->cvolL, envmixer->delta, envmixer->lratm, envmixer->lratl);
658 }
659 return retVal;
660}

◆ au_set_delay_time()

void au_set_delay_time ( s32 arg0)

Definition at line 662 of file 31650.c.

662 {
663 if (arg0 < 2) {
664 AuDelayCount = 0;
666 }
667
668 AuDelayCount = arg0;
669 if (arg0 > 4) {
670 AuDelayCount = 4;
671 }
672}

Referenced by au_syn_update().

◆ au_delay_left_channel()

void au_delay_left_channel ( u8 arg0)

Definition at line 674 of file 31650.c.

674 {
675 s32* phi_a1 = (s32*)AuDelayBufferMain;
676 s32* phi_v1 = (s32*)AuDelayBufferAux;
677 s32 i;
678
679 for (i = 0; i < 2 * AUDIO_SAMPLES; i++) {
680 *phi_a1++ = 0;
681 *phi_v1++ = 0;
682 }
683
684 AuDelayedVoiceGroup = groupIdx;
686 AuDelayCounter = 0;
687}
BSS s32 AuDelayCounter
Definition 31650.c:9

Referenced by au_syn_update().

◆ au_delay_right_channel()

void au_delay_right_channel ( u8 arg0)

Definition at line 689 of file 31650.c.

689 {
690 s32* phi_a1 = (s32*)AuDelayBufferMain;
691 s32* phi_v1 = (s32*)AuDelayBufferAux;
692 s32 i;
693
694 for (i = 0; i < 2 * AUDIO_SAMPLES; i++) {
695 *phi_a1++ = 0;
696 *phi_v1++ = 0;
697 }
698
699 AuDelayedVoiceGroup = groupIdx;
701 AuDelayCounter = 0;
702}

Referenced by au_syn_update().

◆ au_disable_channel_delay()

void au_disable_channel_delay ( void )

Definition at line 704 of file 31650.c.

704 {
707 AuDelayCounter = 0;
708}

Referenced by au_syn_update().

◆ au_delay_channel()

void au_delay_channel ( s16 arg0)

Definition at line 710 of file 31650.c.

710 {
711 s32* phi_a1 = (s32*)AuDelayBufferMain;
712 s32* phi_v1 = (s32*)AuDelayBufferAux;
713 s32 i;
714
715 for (i = 0; i < 2 * AUDIO_SAMPLES; i++) {
716 *phi_a1++ = 0;
717 *phi_v1++ = 0;
718 }
719
721 AuDelayedChannel = arg0;
722 AuDelayCounter = 0;
723}

Referenced by au_engine_init().

◆ alHeapAlloc()

void * alHeapAlloc ( ALHeap * heap,
s32 arg1,
s32 size )

Definition at line 743 of file 31650.c.

743 {
744 void* ret = NULL;
745 u8* newCur = &heap->cur[ALIGN16(count * size)];
746
747 if (&heap->base[heap->len] >= newCur) {
748 ret = heap->cur;
749 heap->cur = newCur;
750 }
751
752 return ret;
753}
#define ALIGN16(val)
Definition macros.h:20

Referenced by au_driver_init(), au_engine_init(), au_load_BK_to_bank(), au_load_INIT(), create_audio_system(), func_80054AA0(), func_80058E84(), and func_80058F88().

◆ au_pull_voice()

Acmd * au_pull_voice ( AuPVoice * pvoice,
Acmd * cmdBufPos )

Definition at line 32 of file 33450.c.

32 {
33 Acmd* ptr = cmdBufPos;
34 AuLoadFilter* decoder;
35 AuResampler* resampler;
36 AuEnvMixer* envMixer;
37 s16 inp;
38 f32 finCount;
39 s16 outp;
40 s32 startZero;
41 s32 outCount;
42 s32 incr;
43
44 envMixer = &pvoice->envMixer;
45 resampler = &pvoice->resampler;
46 decoder = &pvoice->decoder;
47
48 if (envMixer->motion != AL_PLAYING) {
49 return ptr;
50 }
51 outp = N_AL_DECODER_OUT;
52 if (resampler->ratio > MAX_RATIO) {
53 resampler->ratio = MAX_RATIO;
54 }
55
56 resampler->ratio = (s32)(resampler->ratio * UNITY_PITCH);
57 resampler->ratio = resampler->ratio / UNITY_PITCH;
58 finCount = resampler->delta + resampler->ratio * (f32)184;
59 outCount = (s32) finCount;
60 resampler->delta = finCount - (f32) outCount;
61 if (outCount != 0) {
62 if (decoder->instrument->type == AL_ADPCM_WAVE) {
63 s32 nSam;
64 s32 nbytes;
65 s32 nframes;
66 s32 op;
67 s32 tsam;
68 s32 nLeft;
69 s32 bEnd;
70 s32 nOver;
71 s32 overFlow;
72 s32 decoded = FALSE;
73 s32 looped = FALSE;
74 inp = N_AL_DECODER_IN;
75
76 aLoadADPCM(ptr++, decoder->bookSize, K0_TO_PHYS(decoder->instrument->predictor));
77
78 looped = (decoder->loop.end < outCount + decoder->sample) && (decoder->loop.count != 0);
79
80 if (looped) {
81 nSam = decoder->loop.end - decoder->sample;
82 } else {
83 nSam = outCount;
84 }
85 if (decoder->lastsam != 0) {
86 nLeft = ADPCMFSIZE - decoder->lastsam;
87 } else {
88 nLeft = 0;
89 }
90 tsam = nSam - nLeft;
91 if (tsam < 0) {
92 tsam = 0;
93 }
94 nframes = (tsam + ADPCMFSIZE - 1) >> LFSAMPLES;
95 nbytes = nframes * ADPCMFBYTES;
96 if (looped) {
97 ptr = _decodeChunk(ptr, decoder, tsam, nbytes, outp, inp, decoder->first);
98 if (decoder->lastsam != 0) {
99 outp += (decoder->lastsam << 1);
100 } else {
101 outp += (ADPCMFSIZE << 1);
102 }
103
104 decoder->lastsam = decoder->loop.start & 0xF;
105 decoder->memin = (s32)decoder->instrument->base + ADPCMFBYTES * ((s32)(decoder->loop.start >> LFSAMPLES) + 1);
106 decoder->sample = decoder->loop.start;
107 bEnd = outp;
108 while (outCount > nSam) {
109 outCount -= nSam;
110 op = (bEnd + ((nframes + 1) << (LFSAMPLES + 1)) + 16) & ~0x1f;
111 bEnd += nSam << 1;
112 if (decoder->loop.count != -1 && decoder->loop.count != 0) {
113 decoder->loop.count--;
114 }
115 nSam = MIN(outCount, decoder->loop.end - decoder->loop.start);
116 tsam = nSam - ADPCMFSIZE + decoder->lastsam;
117 if (tsam < 0) {
118 tsam = 0;
119 }
120 nframes = (tsam + ADPCMFSIZE - 1) >> LFSAMPLES;
121 nbytes = nframes * ADPCMFBYTES;
122 ptr = _decodeChunk(ptr, decoder, tsam, nbytes, op, inp, decoder->first | A_LOOP);
123 aDMEMMove(ptr++, op + (decoder->lastsam << 1), bEnd, nSam << 1);
124 }
125 decoder->lastsam = (outCount + decoder->lastsam) & 0xF;
126 decoder->sample += outCount;
127 decoder->memin += ADPCMFBYTES * nframes;
128 } else {
129 nSam = nframes << LFSAMPLES;
130 overFlow = decoder->memin + nbytes - ((s32)decoder->instrument->base + decoder->instrument->wavDataLength);
131
132 if (overFlow <= 0) {
133 overFlow = 0;
134 } else {
135 envMixer->motion = AL_STOPPED;
136 }
137 nOver = (overFlow / ADPCMFBYTES) << LFSAMPLES;
138 if (nOver > nSam + nLeft) {
139 nOver = nSam + nLeft;
140 }
141 nbytes -= overFlow;
142 if (nOver - (nOver & 0xF) < outCount) {
143 decoded = TRUE;
144 ptr = _decodeChunk(ptr, decoder, nSam - nOver, nbytes, outp, inp, decoder->first);
145 if (decoder->lastsam != 0) {
146 outp += decoder->lastsam << 1;
147 } else {
148 outp += ADPCMFSIZE << 1;
149 }
150 decoder->lastsam = (outCount + decoder->lastsam) & 0xF;
151 decoder->sample += outCount;
152 decoder->memin += ADPCMFBYTES * nframes;
153 } else {
154 decoder->lastsam = 0;
155 decoder->memin += ADPCMFBYTES * nframes;
156 }
157
158 if (nOver != 0) {
159 decoder->lastsam = 0;
160 if (decoded) {
161 startZero = (nLeft + nSam - nOver) << 1;
162 } else {
163 startZero = 0;
164 }
165 aClearBuffer(ptr++, startZero + outp, nOver << 1);
166 }
167 }
168 } else {
169 s32 nSam;
170 s32 nbytes;
171 s32 op;
172 s32 dramAlign;
173 s32 dramLoc;
174 s32 dmemAlign;
175 s32 overFlow;
176 if (decoder->loop.end < outCount + decoder->sample && decoder->loop.count != 0) {
177 nSam = decoder->loop.end - decoder->sample;
178 nbytes = nSam << 1;
179 if (nSam > 0) {
180 dramLoc = decoder->dmaFunc(decoder->memin, nbytes, decoder->dmaState, decoder->instrument->unk_25);
181 dramAlign = dramLoc & 7;
182 nbytes += dramAlign;
183 n_aLoadBuffer(ptr++, nbytes + 8 - (nbytes & 7), outp, dramLoc - dramAlign);
184 } else {
185 dramAlign = 0;
186 }
187 outp += dramAlign;
188 decoder->memin = (s32)decoder->instrument->base + (decoder->loop.start << 1);
189 decoder->sample = decoder->loop.start;
190 op = outp;
191 while (outCount > nSam){
192 op += nSam << 1;
193 outCount -= nSam;
194 if (decoder->loop.count != -1 && decoder->loop.count != 0) {
195 decoder->loop.count--;
196 }
197 nSam = MIN(outCount, decoder->loop.end - decoder->loop.start);
198 nbytes = nSam << 1;
199 dramLoc = decoder->dmaFunc(decoder->memin, nbytes, decoder->dmaState, decoder->instrument->unk_25);
200 dramAlign = dramLoc & 7;
201 nbytes += dramAlign;
202 if ((op & 7) != 0) {
203 dmemAlign = 8 - (op & 7);
204 } else {
205 dmemAlign = 0;
206 }
207 n_aLoadBuffer(ptr++, nbytes + 8 - (nbytes & 7), op + dmemAlign, dramLoc - dramAlign);
208
209 if (dramAlign != 0 || dmemAlign != 0) {
210 aDMEMMove(ptr++, op + dramAlign + dmemAlign, op, nSam * 2);
211 }
212 }
213 decoder->sample += outCount;
214 decoder->memin += outCount << 1;
215 } else {
216 nbytes = outCount << 1;
217 overFlow = decoder->memin + nbytes - ((s32)decoder->instrument->base + decoder->instrument->wavDataLength);
218 if (overFlow <= 0) {
219 overFlow = 0;
220 } else {
221 envMixer->motion = AL_STOPPED;
222 }
223 if (nbytes < overFlow) {
224 overFlow = nbytes;
225 }
226 if (overFlow < nbytes) {
227 if (outCount > 0) {
228 nbytes -= overFlow;
229 dramLoc = decoder->dmaFunc(decoder->memin, nbytes, decoder->dmaState, decoder->instrument->unk_25);
230 dramAlign = dramLoc & 7;
231 nbytes += dramAlign;
232 n_aLoadBuffer(ptr++, nbytes + 8 - (nbytes & 7), outp, dramLoc - dramAlign);
233 } else {
234 dramAlign = 0;
235 }
236 outp += dramAlign;
237 decoder->sample += outCount;
238 decoder->memin += outCount << 1;
239 } else {
240 decoder->memin += outCount << 1;
241 }
242
243 if (overFlow != 0) {
244 startZero = (outCount << 1) - overFlow;
245 if (startZero < 0) {
246 startZero = 0;
247 }
248 aClearBuffer(ptr++, startZero + outp, overFlow);
249 }
250 }
251 }
252 }
253 incr = (s32)(resampler->ratio * UNITY_PITCH);
254 n_aResample(ptr++, osVirtualToPhysical(resampler->state), resampler->first, incr, outp, 0);
255 resampler->first = 0;
256
257 if (envMixer->first != 0) {
258 envMixer->first = 0;
259 if (!AuSynUseStereo) {
260 envMixer->ltgt = (envMixer->volume * AuEqPower[AUEQPOWER_LENGTH / 2]) >> 15;
261 envMixer->rtgt = (envMixer->volume * AuEqPower[AUEQPOWER_LENGTH / 2]) >> 15;
262 } else {
263 envMixer->ltgt = (envMixer->volume * AuEqPower[envMixer->pan]) >> 15;
264 envMixer->rtgt = (envMixer->volume * AuEqPower[AUEQPOWER_LENGTH - envMixer->pan - 1]) >> 15;
265 }
266 envMixer->lratm = _getRate(envMixer->cvolL, envMixer->ltgt, envMixer->segEnd, &envMixer->lratl);
267 envMixer->rratm = _getRate(envMixer->cvolR, envMixer->rtgt, envMixer->segEnd, &envMixer->rratl);
268 n_aSetVolume(ptr++, A_RATE, envMixer->ltgt, envMixer->lratm, envMixer->lratl);
269 n_aSetVolume(ptr++, A_LEFT | A_VOL, envMixer->cvolL, envMixer->dryamt, envMixer->wetamt);
270 n_aSetVolume(ptr++, A_RIGHT | A_VOL, envMixer->rtgt, envMixer->rratm, envMixer->rratl);
271 n_aEnvMixer(ptr++, A_INIT, envMixer->cvolR, osVirtualToPhysical(envMixer->state));
272 } else {
273 n_aEnvMixer(ptr++, A_CONTINUE, 0, osVirtualToPhysical(envMixer->state));
274 }
275
276 envMixer->delta += AUDIO_SAMPLES;
277 if (envMixer->segEnd < envMixer->delta) {
278 envMixer->delta = envMixer->segEnd;
279 }
280 if (envMixer->motion == AL_STOPPED) {
281 envMixer->first = 1;
282 envMixer->volume = 1;
283 resampler->delta = 0.0f;
284 resampler->first = 1;
285 decoder->lastsam = 0;
286 decoder->first = 1;
287 decoder->sample = 0;
288 decoder->memin = (s32) decoder->instrument->base;
289 decoder->loop.count = decoder->instrument->loopCount;
290 func_80052E30(pvoice->index);
291 }
292 return ptr;
293}
void func_80052E30(u8 index)
#define LFSAMPLES
Definition 33450.c:4
#define AUEQPOWER_LENGTH
Definition 33450.c:5
s16 AuEqPower[128]
Definition 33450.c:9
#define N_AL_DECODER_OUT
Definition audio.h:31
s32 bookSize
Definition audio.h:457
u32 wavDataLength
Definition audio.h:551
#define N_AL_DECODER_IN
Definition audio.h:28

Referenced by alAudioFrame().

◆ func_80058E84()

void func_80058E84 ( AuFX * fx,
u8 effectType,
ALHeap * heap )
Parameters
effectTypefrom enum AuEffectType

Definition at line 137 of file reverb.c.

137 {
138 AuDelay* delay;
139 u16 i;
140
141 // allocate space for 4 AuDelay
142 fx->delays = alHeapAlloc(heap, AU_FX_DELAY_COUNT, sizeof(AuDelay));
143 fx->base = alHeapAlloc(heap, AU_FX_LENGTH, sizeof(s16));
144
145 for (i = 0; i < AU_FX_DELAY_COUNT; i++) {
146 delay = &fx->delays[i];
147 delay->resampler_2C = alHeapAlloc(heap, 1, sizeof(AuResampler));
148 delay->resampler_2C->state = alHeapAlloc(heap, 1, sizeof(RESAMPLE_STATE));
149 delay->lowpass_24 = alHeapAlloc(heap, 1, sizeof(AuLowPass));
150 delay->lowpass_24->fstate = alHeapAlloc(heap, 1, sizeof(POLEF_STATE));
151 }
152
153 func_8005904C(fx, effectType);
154}
#define AU_FX_LENGTH
Definition audio.h:20
struct AuLowPass * lowpass_24
Definition audio.h:401
AuDelay * delays
Definition audio.h:411
struct AuResampler * resampler_2C
Definition audio.h:403
POLEF_STATE * fstate
Definition audio.h:422
#define AU_FX_DELAY_COUNT
Definition audio.h:19
s16 * base
Definition audio.h:408
void func_8005904C(AuFX *fx, u8 effectType)
Definition reverb.c:180

Referenced by au_driver_init().

◆ func_80058F88()

void func_80058F88 ( AlUnkKappa * kappa,
ALHeap * heap )

Definition at line 157 of file reverb.c.

157 {
158 kappa->unk_00 = alHeapAlloc(heap, 0x1420, sizeof(s16));
159 kappa->lowpass_10 = alHeapAlloc(heap, 1, sizeof(AuLowPass));
160 kappa->lowpass_10->fstate = alHeapAlloc(heap, 1, sizeof(POLEF_STATE));
161 func_80059008(kappa, 0, 0, 0x5000);
162}
UNK_TYPE_PTR unk_00
Definition audio.h:427
AuLowPass * lowpass_10
Definition audio.h:433
void func_80059008(AlUnkKappa *kappa, s16 arg1, s16 arg2, s16 fc)
Definition reverb.c:165

◆ func_80059008()

void func_80059008 ( AlUnkKappa * kappa,
s16 arg1,
s16 arg2,
s16 fc )

Definition at line 165 of file reverb.c.

165 {
166 kappa->unk_06 = arg1;
167 kappa->unk_08 = arg2;
168
169 if (fc != 0) {
170 kappa->lowpass_0C = kappa->lowpass_10;
171 kappa->lowpass_0C->fc = fc;
172 _init_lpfilter(kappa->lowpass_0C);
173 return;
174 }
175
176 kappa->lowpass_0C = NULL;
177}
s16 fc
Definition audio.h:417
AuLowPass * lowpass_0C
Definition audio.h:432
s16 unk_06
Definition audio.h:429
s16 unk_08
Definition audio.h:430

Referenced by func_80058F88().

◆ func_8005904C()

void func_8005904C ( AuFX * fx,
u8 effectType )

Definition at line 180 of file reverb.c.

180 {
181 s32* params;
182 s32* clr;
183 s32 i, j;
184 clr = (s32*)fx->base;
185
186 switch (effectType) {
187 case AU_FX_SMALLROOM:
188 params = SMALL_ROOM_PARAMS;
189 break;
190 case AU_FX_BIGROOM:
191 params = BIG_ROOM_PARAMS;
192 break;
193 case AU_FX_ECHO:
194 params = ECHO_PARAMS;
195 break;
196 case AU_FX_CHORUS:
197 params = CHORUS_PARAMS;
198 break;
199 case AU_FX_FLANGE:
200 params = FLANGE_PARAMS;
201 break;
202 case AU_FX_CUSTOM_0:
203 params = AU_FX_CUSTOM_PARAMS[0];
204 break;
205 case AU_FX_CUSTOM_1:
206 params = AU_FX_CUSTOM_PARAMS[1];
207 break;
208 case AU_FX_CUSTOM_2:
209 params = AU_FX_CUSTOM_PARAMS[2];
210 break;
211 case AU_FX_CUSTOM_3:
212 params = AU_FX_CUSTOM_PARAMS[3];
213 break;
215 params = BIG_ROOM_PARAMS;
216 break;
217 default:
218 params = NULL_PARAMS;
219 break;
220 }
221
222 j = 0;
223 fx->delayCount = params[j++];
224 fx->length = params[j++] * AUDIO_SAMPLES;
225 fx->input = fx->base;
226
227 for (i = 0; i < AU_FX_LENGTH/2; i++) {
228 *clr++ = 0;
229 }
230
231 for (i = 0; i < fx->delayCount; i++) {
232 AuDelay* delay = &fx->delays[i];
233 delay->input = params[j++] * AUDIO_SAMPLES;
234 delay->output = params[j++] * AUDIO_SAMPLES;
235 delay->fbcoef = (u16) params[j++];
236 delay->ffcoef = (u16) params[j++];
237 delay->gain = (u16) params[j++];
238
239 if (params[j]) {
240 delay->rsinc = (2.0 * (params[j++] / 1000.0f)) / gActiveSynDriverPtr->outputRate;
241 delay->rsgain = ((f32)params[j++] / CONVERT) * (delay->output - delay->input);
242 delay->rsval = 1.0f;
243 delay->rsdelta = 0.0f;
244 delay->resampler_28 = delay->resampler_2C;
245 delay->resampler_2C->delta = 0.0;
246 delay->resampler_28->first = 1;
247 } else {
248 delay->resampler_28 = NULL;
249 j++;
250 j++;
251 }
252
253 if (params[j]) {
254 delay->lowpass_20 = delay->lowpass_24;
255 delay->lowpass_20->fc = params[j++];
256 _init_lpfilter(delay->lowpass_20);
257 } else {
258 delay->lowpass_20 = NULL;
259 j++;
260 }
261 }
262}
f32 rsval
Definition audio.h:397
s32 rsdelta
Definition audio.h:398
@ AU_FX_CUSTOM_3
Definition audio.h:96
@ AU_FX_FLANGE
Definition audio.h:91
@ AU_FX_CUSTOM_2
Definition audio.h:95
@ AU_FX_CUSTOM_1
Definition audio.h:94
@ AU_FX_ECHO
Definition audio.h:92
@ AU_FX_CHORUS
Definition audio.h:90
@ AU_FX_SMALLROOM
Definition audio.h:88
@ AU_FX_OTHER_BIGROOM
Definition audio.h:97
@ AU_FX_BIGROOM
Definition audio.h:89
AuSynDriver * gActiveSynDriverPtr
Definition 31650.c:14
struct AuResampler * resampler_28
Definition audio.h:402
u32 output
Definition audio.h:391
s16 fbcoef
Definition audio.h:393
s16 ffcoef
Definition audio.h:392
f32 rsgain
Definition audio.h:399
struct AuLowPass * lowpass_20
Definition audio.h:400
u8 delayCount
Definition audio.h:412
f32 rsinc
Definition audio.h:396
u32 input
Definition audio.h:390
s16 gain
Definition audio.h:394
s16 * input
Definition audio.h:409
s32 length
Definition audio.h:410
#define CONVERT
Definition reverb.c:27
s32 ECHO_PARAMS[]
Definition reverb.c:70
s32 CHORUS_PARAMS[]
Definition reverb.c:78
s32 * AU_FX_CUSTOM_PARAMS[]
Definition reverb.c:103
s32 BIG_ROOM_PARAMS[]
Definition reverb.c:47
s32 FLANGE_PARAMS[]
Definition reverb.c:86
s32 NULL_PARAMS[]
Definition reverb.c:94
s32 SMALL_ROOM_PARAMS[]
Definition reverb.c:37

Referenced by au_bus_set_effect(), and func_80058E84().

◆ au_pull_fx()

Acmd * au_pull_fx ( AuFX * fx,
Acmd * cmdBusPos,
s16 outputBuf,
s16 arg3 )

Definition at line 267 of file reverb.c.

267 {
268 Acmd* cmdBufPos = ptr;
269 s16 delayIdx;
270
271 s16* inPtr;
272 s16* outPtr;
273
274 s16 buff1 = arg3 + N_AL_TEMP_0;
275 s16 buff2 = arg3 + N_AL_TEMP_1;
276 s16 rbuff = arg3 + N_AL_TEMP_2;
277 s16* prevOutPtr = 0;
278 s16 outputBufCopy = outputBuf;
279
280 n_aSaveBuffer(cmdBufPos++, FIXED_SAMPLE<<1, outputBuf, osVirtualToPhysical(fx->input));
281 aClearBuffer(cmdBufPos++, outputBuf, FIXED_SAMPLE<<1);
282
283 for (delayIdx = 0; delayIdx < fx->delayCount; delayIdx++) {
284 AuDelay* delay = &fx->delays[delayIdx];
285 f32 fUnityPitch = UNITY_PITCH;
286
287 inPtr = &fx->input[-delay->input];
288 if (inPtr < fx->base) {
289 inPtr += fx->length;
290 }
291 outPtr = &fx->input[-delay->output];
292 if (outPtr < fx->base) {
293 outPtr += fx->length;
294 }
295 if (inPtr == prevOutPtr) {
296 SWAP16(buff1, buff2);
297 } else {
298 n_aLoadBuffer(cmdBufPos++, FIXED_SAMPLE<<1, buff1, osVirtualToPhysical(inPtr));
299 }
300 if (delay->resampler_28) {
301 // modified _n_loadOutputBuffer
302 s32 ratio;
303 s32 length, count;
304 f32 delta, fratio, fincount;
305 s32 ramAlign;
306 s16 tmp;
307 s16* rsOutPtr;
308
309 length = delay->output - delay->input;
310 delta = func_80059BD4(delay, AUDIO_SAMPLES);
311 delta /= length;
312 delta = (s32)(delta * fUnityPitch);
313 delta = delta / UNITY_PITCH;
314 fratio = 1.0 - delta;
315 fincount = delay->resampler_28->delta + (fratio * AUDIO_SAMPLES);
316 count = (s32) fincount;
317 delay->resampler_28->delta = fincount - count;
318
319 rsOutPtr = &fx->input[-(delay->output - delay->rsdelta)];
320 ramAlign = ((s32) rsOutPtr & 7) >> 1;
321
322 rsOutPtr -= ramAlign;
323 if (rsOutPtr < fx->base) {
324 rsOutPtr += fx->length;
325 }
326
327 cmdBufPos = _saveBuffer(fx, rsOutPtr, rbuff, count + ramAlign, cmdBufPos);
328 ratio = fratio * fUnityPitch;
329
330 tmp = buff2 >> 8;
331 n_aResample(cmdBufPos++, osVirtualToPhysical(delay->resampler_28->state),
332 delay->resampler_28->first, ratio, rbuff + (ramAlign<<1), tmp);
333
334 delay->resampler_28->first = 0;
335 delay->rsdelta += count - AUDIO_SAMPLES;
336 } else {
337 n_aLoadBuffer(cmdBufPos++, FIXED_SAMPLE<<1, buff2, osVirtualToPhysical(outPtr));
338 }
339 if (delay->ffcoef) {
340 aMix(cmdBufPos++, 0, (u16)delay->ffcoef, buff1, buff2);
341
342 if (delay->resampler_28 == NULL && delay->lowpass_20 == NULL) {
343 n_aSaveBuffer(cmdBufPos++, FIXED_SAMPLE<<1, buff2, osVirtualToPhysical(outPtr));
344 }
345 }
346 if (delay->fbcoef) {
347 aMix(cmdBufPos++, 0, (u16)delay->fbcoef, buff2, buff1);
348 n_aSaveBuffer(cmdBufPos++, FIXED_SAMPLE<<1, buff1, osVirtualToPhysical(inPtr));
349 }
350 if (delay->lowpass_20 != NULL) {
351 // modified _n_filterBuffer
352 s16 tmp = buff2 >> 8;
353 n_aLoadADPCM(cmdBufPos++, 32, osVirtualToPhysical(delay->lowpass_20->fccoef));
354 n_aPoleFilter(cmdBufPos++, delay->lowpass_20->first, delay->lowpass_20->fgain, tmp, osVirtualToPhysical(delay->lowpass_20->fstate));
355 delay->lowpass_20->first = 0;
356 }
357 if (!delay->resampler_28) {
358 n_aSaveBuffer(cmdBufPos++, FIXED_SAMPLE<<1, buff2, osVirtualToPhysical(outPtr));
359 }
360 if (delay->gain) {
361 aMix(cmdBufPos++, 0, (u16)delay->gain, buff2, outputBufCopy);
362 }
363 prevOutPtr = &fx->input[delay->output];
364 }
365
366 fx->input += AUDIO_SAMPLES;
367 if (fx->input >= &fx->base[fx->length]) {
368 fx->input = fx->base;
369 }
370 return cmdBufPos;
371}
s16 fccoef[16]
Definition audio.h:421
s32 first
Definition audio.h:423
#define N_AL_TEMP_1
Definition audio.h:32
#define N_AL_TEMP_0
Definition audio.h:30
#define FIXED_SAMPLE
Definition audio.h:26
#define N_AL_TEMP_2
Definition audio.h:33
s16 fgain
Definition audio.h:418
#define SWAP16(in, out)
Definition reverb.c:4

Referenced by alAudioFrame().

◆ au_fx_param_hdl()

s32 au_fx_param_hdl ( AuFX * fx,
s16 index,
s16 paramID,
s32 value )

Definition at line 384 of file reverb.c.

384 {
385 switch (paramID) {
386 case INPUT_PARAM:
387 fx->delays[index].input = value & 0xFFFFFFF8;
388 break;
389 case OUTPUT_PARAM:
390 fx->delays[index].output = value & 0xFFFFFFF8;
391 break;
392 case FFCOEF_PARAM:
393 fx->delays[index].ffcoef = value;
394 break;
395 case FBCOEF_PARAM:
396 fx->delays[index].fbcoef = value;
397 break;
398 case GAIN_PARAM:
399 fx->delays[index].gain = value;
400 break;
401 case CHORUSRATE_PARAM:
402 fx->delays[index].rsinc = (2.0 * (value / 1000.0f)) / gActiveSynDriverPtr->outputRate;
403 break;
405 fx->delays[index].rsgain = ((f32)value / CONVERT) * (fx->delays[index].output - fx->delays[index].input);
406 break;
407 case LPFILT_PARAM:
408 if (fx->delays[index].lowpass_20) {
409 fx->delays[index].lowpass_20->fc = value;
410 _init_lpfilter(fx->delays[index].lowpass_20);
411 }
412 break;
413 }
414 return 0;
415}
#define FBCOEF_PARAM
Definition reverb.c:376
#define INPUT_PARAM
Definition reverb.c:374
#define CHORUSRATE_PARAM
Definition reverb.c:379
#define OUTPUT_PARAM
Definition reverb.c:375
#define CHORUSDEPTH_PARAM
Definition reverb.c:380
#define GAIN_PARAM
Definition reverb.c:378
#define FFCOEF_PARAM
Definition reverb.c:377
#define LPFILT_PARAM
Definition reverb.c:381

Referenced by au_bus_set_fx_params().

◆ sfx_get_env_sound_instance()

SoundInstance * sfx_get_env_sound_instance ( s32 soundID)

Definition at line 379 of file sfx.c.

379 {
381 s32 i;
382
383 for (i = 0; i < MAX_SOUND_INSTANCES; i++, sound++) {
384 if (sound->flags & SOUND_INSTANCE_FLAG_ACTIVE && sound->soundID == soundID) {
385 return sound;
386 }
387 }
388
389 return NULL;
390}
@ SOUND_INSTANCE_FLAG_ACTIVE
Definition audio.h:242
s32 soundID
Definition audio.h:698
#define MAX_SOUND_INSTANCES
Definition sfx.c:4
BSS SoundInstance * gCurrentEnvSounds
Definition sfx.c:214

Referenced by sfx_adjust_env_sound_params(), sfx_adjust_env_sound_pos(), and snd_stop_tracking_env_sound_pos().