Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
ambience.c
Go to the documentation of this file.
1#include "common.h"
2//#include "audio/public.h"
3
4typedef struct {
5 /* 0x0 */ s16 flags;
6 /* 0x2 */ s16 fadeState;
7 /* 0x4 */ s32 fadeTime;
8 /* 0x8 */ s32 soundID;
9 /* 0xC */ s32 unkC;
11
12typedef enum AmbientSoundState {
14 AMBIENCE_STATE_FADE_OUT = 1, // fade out old sounds
15 AMBIENCE_STATE_FADE_IN = 2 // fade in new sounds
17
21
23 .flags = 0,
24 .fadeState = 0,
25 .fadeTime = 0,
26 .soundID = -1,
27 .unkC = -1
28};
29
31
35
37 AmbientSoundSettings* ambientSoundState = &AmbientSoundData;
38 s32 error;
39
40 switch (ambientSoundState->fadeState) {
42 break;
44 if (ambientSoundState->flags & 1) {
45 if (ambientSoundState->fadeTime < 250) {
46 error = snd_ambient_stop_quick(0);
47 } else {
48 error = snd_ambient_stop_slow(0, ambientSoundState->fadeTime);
49 }
50
51 if (error != AU_RESULT_OK) {
52 return;
53 }
54 }
55 ambientSoundState->fadeState = AMBIENCE_STATE_FADE_IN;
56 break;
58 if (ambientSoundState->flags & AMBIENCE_FLAG_PLAYING) {
60 return;
61 }
62 ambientSoundState->flags &= ~AMBIENCE_FLAG_PLAYING;
63 }
64 if (ambientSoundState->soundID < 0) {
65 ambientSoundState->fadeState = AMBIENCE_STATE_IDLE;
66 } else if (snd_load_ambient(ambientSoundState->soundID) == AU_RESULT_OK) {
67 if (snd_ambient_play(0, 0) == AU_RESULT_OK) {
68 ambientSoundState->fadeState = AMBIENCE_STATE_IDLE;
69 ambientSoundState->flags |= AMBIENCE_FLAG_PLAYING;
70 }
71 }
72 break;
73 }
74}
75
76s32 play_ambient_sounds(s32 soundID, s32 fadeTime) {
78
81 state->flags &= ~AMBIENCE_FLAG_PLAYING;
82 return 1;
83 }
84
85 if (state->soundID == soundID) {
86 return 2;
87 }
88
89 state->soundID = soundID;
90 state->fadeTime = fadeTime;
92 return 1;
93}
void update_ambient_sounds(void)
Definition ambience.c:36
AmbientSoundFlag
Definition ambience.c:18
@ AMBIENCE_FLAG_PLAYING
Definition ambience.c:19
AmbientSoundSettings AmbientSoundData
Definition ambience.c:30
AmbientSoundState
Definition ambience.c:12
@ AMBIENCE_STATE_IDLE
Definition ambience.c:13
@ AMBIENCE_STATE_FADE_IN
Definition ambience.c:15
@ AMBIENCE_STATE_FADE_OUT
Definition ambience.c:14
s32 play_ambient_sounds(s32 soundID, s32 fadeTime)
Definition ambience.c:76
void reset_ambient_sounds(void)
Definition ambience.c:32
AmbientSoundSettings DefaultAmbientSoundData
Definition ambience.c:22
@ AU_RESULT_OK
Definition enums.h:1759
AuResult snd_ambient_play(s32 arg0, s32 arg1)
AuResult snd_load_ambient(s32 arg0)
AuResult snd_ambient_stop_slow(s32 arg0, s32 arg1)
AuResult snd_ambient_stop_quick(s32 arg0)
AuResult snd_ambient_is_stopped(s32 arg0)
GameStatus * gGameStatusPtr
Definition main_loop.c:31