Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
bgm_control.c File Reference

Go to the source code of this file.

Functions

void bgm_update_volume (void)
 
void bgm_set_target_volume (s32 volume)
 
s32 bgm_get_map_default_variation (s32 songID)
 If the given song ID is present in SongsUsingVariationFlag, returns the current map's songVariation & 1 value.
 
void bgm_reset_sequence_players (void)
 
void bgm_reset_volume (void)
 
void bgm_update_music_control (void)
 
s32 _bgm_set_song (s32 playerIndex, s32 songID, s32 variation, s32 fadeOutTime, s16 volume)
 
s32 bgm_set_song (s32 playerIndex, s32 songID, s32 variation, s32 fadeOutTime, s16 volume)
 
b32 bgm_fade_in_song (s32 playerIndex, s32 songID, s32 variation, s32 fadeInTime, s16 fadeStartVolume, s16 fadeEndVolume)
 
s32 bgm_adjust_proximity (s32 playerIndex, s32 mix, s16 state)
 
AuResult bgm_set_track_volumes (s32 playerIndex, s16 trackVolSet)
 
AuResult bgm_clear_track_volumes (s32 playerIndex, s16 trackVolSet)
 
AuResult bgm_set_linked_mode (s32 playerIndex, b16 mode)
 
s32 bgm_init_music_players (void)
 
void bgm_quiet_max_volume (void)
 
void bgm_reset_max_volume (void)
 
b32 bgm_is_any_song_playing (void)
 
void bgm_pop_song (void)
 
void bgm_push_song (s32 songID, s32 variation)
 
void bgm_pop_battle_song (void)
 
void bgm_push_battle_song (void)
 
void bgm_set_battle_song (s32 songID, s32 variation)
 
void bgm_NOOP (void)
 

Variables

BSS s16 MusicDefaultVolume
 
BSS s16 MusicTargetVolume
 
BSS s16 MusicMaxVolume
 
BSS s16 MusicCurrentVolume
 
MusicControlData gMusicControlData [2]
 
MusicControlData BlankMusicControlData
 
s32 SongsUsingVariationFlag []
 Lists the songs that are forced to use the variation determined by map.songVariation & 1.
 
s16 NextVolumeUpdateTimer = 0
 

Function Documentation

◆ bgm_update_volume()

void bgm_update_volume ( void )

Definition at line 343 of file bgm_control.c.

343 {
345
346 if (NextVolumeUpdateTimer != 0) {
348 return;
349 }
350
352 if (toVolume > MusicMaxVolume) {
354 }
355
359 } else {
361 }
364 }
365}
BSS s32 PopupMenu_SelectedIndex
s16 NextVolumeUpdateTimer
Definition bgm_control.c:43
BSS s16 MusicMaxVolume
Definition bgm_control.c:10
BSS s16 MusicCurrentVolume
Definition bgm_control.c:11
BSS s16 MusicTargetVolume
Definition bgm_control.c:9
void snd_set_bgm_volume(VolumeLevels volume)

Referenced by bgm_update_music_control().

◆ bgm_set_target_volume()

void bgm_set_target_volume ( s32 volume)

Definition at line 339 of file bgm_control.c.

339 {
340 MusicTargetVolume = volume;
341}

Referenced by _bgm_set_song(), and bgm_update_music_control().

◆ bgm_get_map_default_variation()

s32 bgm_get_map_default_variation ( s32 songID)

If the given song ID is present in SongsUsingVariationFlag, returns the current map's songVariation & 1 value.

Otherwise, returns -1.

See also
SongsUsingVariationFlag
Returns
-1: no override; 0: override to variation 0; 1 override to variation 1

Definition at line 50 of file bgm_control.c.

50 {
51 u32 i;
52
53 for (i = 0; i < ARRAY_COUNT(SongsUsingVariationFlag); i++) {
54 if (SongsUsingVariationFlag[i] == songID) {
56
57 return map->songVariation & 1;
58 }
59 }
60
61 return -1;
62}
s32 SongsUsingVariationFlag[]
Lists the songs that are forced to use the variation determined by map.songVariation & 1.
Definition bgm_control.c:34
#define ARRAY_COUNT(arr)
Definition macros.h:40
s8 songVariation
0 or 1.
Definition map.h:50
AreaConfig gAreas[29]
Zero-terminated.
Definition world.c:868
MapConfig * maps
Definition map.h:56
GameStatus * gGameStatusPtr
Definition main_loop.c:31

Referenced by _bgm_set_song(), and bgm_fade_in_song().

◆ bgm_reset_sequence_players()

void bgm_reset_sequence_players ( void )

Definition at line 64 of file bgm_control.c.

64 {
65 s32 i;
66
67 for (i = 0; i < ARRAY_COUNT(gMusicControlData); i++) {
69 }
70
75}
MusicControlData gMusicControlData[2]
Definition bgm_control.c:13
MusicControlData BlankMusicControlData
Definition bgm_control.c:15
@ VOL_LEVEL_FULL
Definition enums.h:1822

Referenced by load_engine_data().

◆ bgm_reset_volume()

void bgm_reset_volume ( void )

Definition at line 77 of file bgm_control.c.

Referenced by state_step_startup().

◆ bgm_update_music_control()

void bgm_update_music_control ( void )
Bug
this is called even if we are trying to fade in, immediately overriding any fade parameters

Definition at line 83 of file bgm_control.c.

83 {
85 s32 i = 0;
88 s32 flags;
89
90 for (i; i < ARRAY_COUNT(gMusicControlData); i++, music++) {
91 switch (music->state) {
93 break;
95 if (music->flags & MUSIC_FLAG_PLAYING) {
96 if (music->fadeOutTime < 250) {
97 if (!(music->flags & MUSIC_FLAG_PUSHING)) {
98 if (snd_song_stop(music->songName) == AU_RESULT_OK) {
100 }
101 } else {
102 if (snd_song_push_stop(music->songName) == AU_RESULT_OK) {
103 music->state = stateFadeOut;
104 }
105 }
106 } else if (!(music->flags & MUSIC_FLAG_PUSHING)) {
107 if (snd_song_request_fade_out(music->songName, music->fadeOutTime, NULL) == AU_RESULT_OK) {
108 music->state = stateFadeOut;
109 }
110 } else {
111 if (snd_song_request_push_fade_out(music->songName, 250) == AU_RESULT_OK) {
112 music->state = stateFadeOut;
113 }
114 }
115 } else {
116 if (music->flags & MUSIC_FLAG_PUSHING) {
117 // nothing was playing in this case, so remember to skip the next pop
119 }
120 music->flags &= ~pushedFlag;
122 }
123 break;
125 flags = music->flags;
126 music->flags &= ~pushedFlag;
128 if (snd_song_is_playing(music->songName) == AU_RESULT_OK) {
129 music->flags &= ~MUSIC_FLAG_PLAYING;
130 music->state = MUSIC_STATE_DELAY_2;
131 }
132 } else {
134 }
135 break;
137 music->state = MUSIC_STATE_DELAY_1;
138 break;
141 break;
143 if (!(music->flags & MUSIC_FLAG_POPPING)) {
144 if (music->requestedSongID <= AU_SONG_NONE) {
145 // new song is AU_SONG_NONE, play nothing
146 music->state = MUSIC_STATE_IDLE;
147 } else {
148 music->songName = snd_song_load(music->requestedSongID, i);
149 // snd_song_lond may return either songName or an AuResult error code.
150 // since song names are 4-character big-endian identifiers packed into an s32, we require
151 // the upper half of the return value to be nonzero for songs which loaded without error.
152 // this reserves return values from 0 to 0xFFFF for AuResult codes.
153 if (music->songName > 0xFFFFU) {
154 if ((music->flags & MUSIC_FLAG_FADE_IN_NEXT)) {
155 snd_song_request_fade_in(music->songName, music->variation,
156 music->fadeInTime, music->fadeStartVolume, music->fadeEndVolume);
158 } else {
159 // if we aren't fading in, just start at the default volume level
161 }
163 if (snd_song_request_play(music->songName, music->variation) == AU_RESULT_OK) {
164 music->flags |= MUSIC_FLAG_PLAYING;
165 music->state = MUSIC_STATE_IDLE;
166 }
167 }
168 }
169 } else {
170 if (music->flags & MUSIC_FLAG_IGNORE_POP) {
171 music->state = MUSIC_STATE_IDLE;
173 } else if (snd_song_request_pop(music->savedSongName) == AU_RESULT_OK) {
174 music->requestedSongID = music->savedSongID;
175 music->variation = music->savedVariation;
176 music->songName = music->savedSongName;
177 music->state = MUSIC_STATE_IDLE;
178 music->flags |= MUSIC_FLAG_PLAYING;
179 music->flags &= ~MUSIC_FLAG_POPPING;
180 }
181 }
182 break;
183 }
184 }
186}
@ MUSIC_STATE_PLAY_NEXT
Definition audio.h:179
@ MUSIC_STATE_IDLE
Definition audio.h:174
@ MUSIC_STATE_STOP_CURRENT
Definition audio.h:175
@ MUSIC_STATE_AWAIT_FADEOUT
Definition audio.h:176
@ MUSIC_STATE_DELAY_2
Definition audio.h:177
@ MUSIC_STATE_DELAY_1
Definition audio.h:178
#define AU_SONG_NONE
Definition audio.h:105
@ MUSIC_FLAG_PUSHING
Definition audio.h:185
@ MUSIC_FLAG_PLAYING
Definition audio.h:183
@ MUSIC_FLAG_POPPING
Definition audio.h:186
@ MUSIC_FLAG_FADE_IN_NEXT
Definition audio.h:188
@ MUSIC_FLAG_IGNORE_POP
Definition audio.h:187
void bgm_update_volume(void)
void bgm_set_target_volume(s32 volume)
BSS s16 MusicDefaultVolume
Definition bgm_control.c:8
s8 flags
Definition demo_api.c:15
@ AU_RESULT_OK
Definition enums.h:1759
AuResult snd_song_push_stop(s32 songName)
AuResult snd_song_request_fade_out(s32 songName, s32 fadeTime, AuCallback callback)
AuResult snd_song_request_play(s32 songName, s32 variation)
Called from bgm_control to start playing a particular song + variation.
AuResult snd_song_request_push_fade_out(s32 songName, s32 fadeTime)
AuResult snd_song_load(s32 songID, s32 playerIndex)
return value may be either an AuResult error code OR a valid songName
AuResult snd_song_request_pop(s32 songName)
AuResult snd_song_request_fade_in(s32 songName, s32 variation, s32 fadeInTime, s32 startVolume, s32 endVolume)
Called from bgm_control to fade in a particular song + variation.
AuResult snd_song_is_playing(s32 songName)
AuResult snd_song_stop(s32 songName)

Referenced by step_game_loop().

◆ _bgm_set_song()

s32 _bgm_set_song ( s32 playerIndex,
s32 songID,
s32 variation,
s32 fadeOutTime,
s16 volume )

Definition at line 188 of file bgm_control.c.

188 {
191
193 return 1;
194 }
195
196 music = &gMusicControlData[playerIndex];
197
199 snd_song_stop(music->songName);
200 music->flags &= ~MUSIC_FLAG_PLAYING;
201 return 1;
202 }
203
205 if (mapSongVariation >= 0) {
206 variation = mapSongVariation;
207 }
208
209 if (music->requestedSongID == songID && music->variation == variation) {
210 bgm_set_target_volume(volume);
211
212 if (music->flags & MUSIC_FLAG_PUSHING) {
214 music->flags &= ~MUSIC_FLAG_PUSHING;
215 }
216
217 return 2;
218 }
219
220 MusicDefaultVolume = volume;
221 music->requestedSongID = songID;
222 music->variation = variation;
223 music->fadeOutTime = fadeOutTime;
226
227 return 1;
228}
s32 bgm_get_map_default_variation(s32 songID)
If the given song ID is present in SongsUsingVariationFlag, returns the current map's songVariation &...
Definition bgm_control.c:50
@ DEMO_STATE_NONE
Definition enums.h:3568
AuResult snd_song_request_snapshot(s32 songName)

Referenced by bgm_pop_battle_song(), bgm_pop_song(), and bgm_set_song().

◆ bgm_set_song()

s32 bgm_set_song ( s32 playerIndex,
s32 songID,
s32 variation,
s32 fadeOutTime,
s16 volume )

Definition at line 230 of file bgm_control.c.

230 {
232
233 return _bgm_set_song(playerIndex, songID, variation, fadeOutTime, volume);
234}
s32 _bgm_set_song(s32 playerIndex, s32 songID, s32 variation, s32 fadeOutTime, s16 volume)

Referenced by bgm_init_music_players(), bgm_push_battle_song(), bgm_push_song(), btl_state_update_celebration(), btl_state_update_defeat(), btl_state_update_end_training_battle(), btl_state_update_run_away(), btl_state_update_victory(), state_init_exit_file_select(), state_init_title_screen(), and state_step_title_screen().

◆ bgm_fade_in_song()

b32 bgm_fade_in_song ( s32 playerIndex,
s32 songID,
s32 variation,
s32 fadeInTime,
s16 fadeStartVolume,
s16 fadeEndVolume )

Definition at line 236 of file bgm_control.c.

236 {
239
241 return TRUE;
242 }
243
244 music = &gMusicControlData[playerIndex];
245
247 snd_song_stop(music->songName);
248 music->flags &= ~MUSIC_FLAG_PLAYING;
249 return TRUE;
250 }
251
253 if (mapSongVariation >= 0) {
254 variation = mapSongVariation;
255 }
256
257 music->fadeInTime = fadeInTime;
258 music->fadeStartVolume = fadeStartVolume;
259 music->fadeEndVolume = fadeEndVolume;
260 music->requestedSongID = songID;
261 music->variation = variation;
265
266 return TRUE;
267}

◆ bgm_adjust_proximity()

s32 bgm_adjust_proximity ( s32 playerIndex,
s32 mix,
s16 state )

Definition at line 269 of file bgm_control.c.

269 {
271
272 if (!(music->flags & MUSIC_FLAG_PLAYING)) {
273 return FALSE;
274 }
275
276 if (!(music->flags & MUSIC_FLAG_ENABLE_PROX_MIX)) {
277 return FALSE;
278 }
279
280 switch (state) {
283 break;
286 break;
289 break;
290 }
291 return TRUE;
292}
@ MUSIC_FLAG_ENABLE_PROX_MIX
Definition audio.h:184
@ MUSIC_PROXIMITY_NEAR
Definition enums.h:1789
@ MUSIC_PROXIMITY_FULL
Definition enums.h:1790
@ MUSIC_PROXIMITY_FAR
Definition enums.h:1788
void snd_song_set_proximity_mix_far(s32 songName, s32 mix)
void snd_song_set_proximity_mix_near(s32 songName, s32 mix)
void snd_song_set_proximity_mix_full(s32 songName, s32 mix)

◆ bgm_set_track_volumes()

AuResult bgm_set_track_volumes ( s32 playerIndex,
s16 trackVolSet )

Definition at line 294 of file bgm_control.c.

294 {
296
297 if (!(music->flags & MUSIC_FLAG_PLAYING)) {
298 return AU_RESULT_OK;
299 }
300
302}
AuResult snd_song_set_track_volumes(s32 songName, MusicTrackVols arg1)

◆ bgm_clear_track_volumes()

AuResult bgm_clear_track_volumes ( s32 playerIndex,
s16 trackVolSet )

Definition at line 304 of file bgm_control.c.

304 {
306
307 if (!(music->flags & MUSIC_FLAG_PLAYING)) {
308 return AU_RESULT_OK;
309 }
310
312}
AuResult snd_song_clear_track_volumes(s32 songName, MusicTrackVols arg1)

◆ bgm_set_linked_mode()

AuResult bgm_set_linked_mode ( s32 playerIndex,
b16 mode )

Definition at line 314 of file bgm_control.c.

314 {
316
317 if (!(music->flags & MUSIC_FLAG_PLAYING)) {
318 return AU_RESULT_OK;
319 }
320
321 return snd_song_set_linked_mode(music->songName, mode);
322}
AuResult snd_song_set_linked_mode(s32 songName, b32 mode)

◆ bgm_init_music_players()

s32 bgm_init_music_players ( void )

Definition at line 324 of file bgm_control.c.

324 {
327
328 return 1;
329}
s32 bgm_set_song(s32 playerIndex, s32 songID, s32 variation, s32 fadeOutTime, s16 volume)

Referenced by state_step_startup().

◆ bgm_quiet_max_volume()

void bgm_quiet_max_volume ( void )

Definition at line 331 of file bgm_control.c.

331 {
333}
@ VOL_LEVEL_4
Definition enums.h:1818

Referenced by state_step_pause().

◆ bgm_reset_max_volume()

void bgm_reset_max_volume ( void )

Definition at line 335 of file bgm_control.c.

335 {
337}

Referenced by state_step_unpause().

◆ bgm_is_any_song_playing()

b32 bgm_is_any_song_playing ( void )

Definition at line 367 of file bgm_control.c.

367 {
369 s32 i;
370
371 for (i = 0; i < ARRAY_COUNT(gMusicControlData); i++, music++) {
372 if (music->flags & MUSIC_FLAG_PLAYING) {
373 if (snd_song_is_playing(music->songName)) {
374 return TRUE;
375 }
376 }
377 }
378 return FALSE;
379}

◆ bgm_pop_song()

void bgm_pop_song ( void )

Definition at line 381 of file bgm_control.c.

381 {
383
386 _bgm_set_song(0, music->savedSongID, music->savedVariation, 0, VOL_LEVEL_FULL);
387 }
388}

◆ bgm_push_song()

void bgm_push_song ( s32 songID,
s32 variation )

Definition at line 390 of file bgm_control.c.

390 {
392
394 music->savedSongID = music->requestedSongID;
395 music->savedVariation = music->variation;
396 music->savedSongName = music->songName;
397 music->flags |= MUSIC_FLAG_PUSHING;
398 bgm_set_song(0, songID, variation, 500, VOL_LEVEL_FULL);
399 }
400}

◆ bgm_pop_battle_song()

void bgm_pop_battle_song ( void )

Definition at line 402 of file bgm_control.c.

402 {
404
408 } else {
410 _bgm_set_song(0, music->savedSongID, music->savedVariation, 0, VOL_LEVEL_FULL);
411 snd_ambient_resume(0, 250);
412 }
413 }
414}
@ GLOBAL_OVERRIDES_DONT_RESUME_SONG_AFTER_BATTLE
Definition enums.h:3921
AuResult snd_ambient_resume(s32 arg0, s32 arg1)
s32 gOverrideFlags
Definition main_loop.c:10

Referenced by update_encounters_post_battle().

◆ bgm_push_battle_song()

void bgm_push_battle_song ( void )

Definition at line 416 of file bgm_control.c.

416 {
418
421 snd_ambient_pause(0, 250);
422 music->savedSongID = music->requestedSongID;
423 music->savedVariation = music->variation;
424 music->savedSongName = music->songName;
425 music->flags |= MUSIC_FLAG_PUSHING;
426 bgm_set_song(0, music->battleSongID, music->battleVariation, 500, VOL_LEVEL_FULL);
427 }
428 }
429}
AuResult snd_ambient_pause(s32 arg0, s32 arg1)

Referenced by update_encounters_pre_battle().

◆ bgm_set_battle_song()

void bgm_set_battle_song ( s32 songID,
s32 variation )

Definition at line 431 of file bgm_control.c.

431 {
433
434 music->battleSongID = songID;
435 music->battleVariation = variation;
436}
s32 battleSongID
name or handle of currently playing song

Referenced by update_encounters_pre_battle().

◆ bgm_NOOP()

void bgm_NOOP ( void )

Definition at line 438 of file bgm_control.c.

438 {
439}

Variable Documentation

◆ MusicDefaultVolume

BSS s16 MusicDefaultVolume

Definition at line 8 of file bgm_control.c.

Referenced by _bgm_set_song(), and bgm_update_music_control().

◆ MusicTargetVolume

BSS s16 MusicTargetVolume

◆ MusicMaxVolume

◆ MusicCurrentVolume

BSS s16 MusicCurrentVolume

Definition at line 11 of file bgm_control.c.

Referenced by bgm_reset_sequence_players(), and bgm_update_volume().

◆ gMusicControlData

◆ BlankMusicControlData

MusicControlData BlankMusicControlData
Initial value:
= {
.flags = 0,
.state = MUSIC_STATE_IDLE,
.fadeOutTime = -1,
.fadeInTime = 0,
.fadeStartVolume = 0,
.fadeEndVolume = 0,
.requestedSongID = AU_SONG_NONE,
.variation = -1,
.songName = -1,
.battleSongID = 0,
.battleVariation = 0,
.savedSongID = 0,
.savedVariation = 0,
.savedSongName = 0
}

Definition at line 15 of file bgm_control.c.

15 {
16 .flags = 0,
17 .state = MUSIC_STATE_IDLE,
18 .fadeOutTime = -1,
19 .fadeInTime = 0,
20 .fadeStartVolume = 0,
21 .fadeEndVolume = 0,
22 .requestedSongID = AU_SONG_NONE,
23 .variation = -1,
24 .songName = -1,
25 .battleSongID = 0,
26 .battleVariation = 0,
27 .savedSongID = 0,
28 .savedVariation = 0,
29 .savedSongName = 0
30};

Referenced by bgm_reset_sequence_players().

◆ SongsUsingVariationFlag

s32 SongsUsingVariationFlag[]
Initial value:
= {
}
@ SONG_NEW_PARTNER
Definition enums.h:412
@ SONG_TUBBA_BLUBBA_BATTLE
Definition enums.h:293
@ SONG_YOSHI_KIDS_FOUND
Definition enums.h:360
@ SONG_SPECIAL_BATTLE
Definition enums.h:285
@ SONG_JR_TROOPA_BATTLE
Definition enums.h:286
@ SONG_ITEM_UPGRADE
Definition enums.h:348

Lists the songs that are forced to use the variation determined by map.songVariation & 1.

See also
bgm_get_map_default_variation

Definition at line 34 of file bgm_control.c.

Referenced by bgm_get_map_default_variation().

◆ NextVolumeUpdateTimer

s16 NextVolumeUpdateTimer = 0

Definition at line 43 of file bgm_control.c.

Referenced by bgm_update_volume().