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 AMBIENT_SOUND_FADE_OUT = 1, // fade out old sounds
15 AMBIENT_SOUND_FADE_IN = 2 // fade in new sounds
17
19 .flags = 0,
20 .fadeState = 0,
21 .fadeTime = 0,
22 .soundID = -1,
23 .unkC = -1
24};
25
27
31
33 AmbientSoundSettings* ambientSoundState = &AmbientSoundData;
34 s32 error;
35
36 switch (ambientSoundState->fadeState) {
38 break;
40 if (ambientSoundState->flags & 1) {
41 if (ambientSoundState->fadeTime < 250) {
42 error = snd_ambient_stop_quick(0);
43 } else {
44 error = snd_ambient_stop_slow(0, ambientSoundState->fadeTime);
45 }
46
47 if (error != AU_RESULT_OK) {
48 return;
49 }
50 }
51 ambientSoundState->fadeState = AMBIENT_SOUND_FADE_IN;
52 break;
54 if (ambientSoundState->flags & 1) {
56 return;
57 }
58 ambientSoundState->flags &= ~1;
59 }
60 if (ambientSoundState->soundID < 0) {
61 ambientSoundState->fadeState = AMBIENT_SOUND_IDLE;
62 } else if (snd_load_ambient(ambientSoundState->soundID) == AU_RESULT_OK) {
63 if (snd_ambient_play(0, 0) == AU_RESULT_OK) {
64 ambientSoundState->fadeState = AMBIENT_SOUND_IDLE;
65 ambientSoundState->flags |= 1;
66 }
67 }
68 break;
69 }
70}
71
72s32 play_ambient_sounds(s32 soundID, s32 fadeTime) {
74
77 state->flags &= ~1;
78 return 1;
79 }
80
81 if (state->soundID == soundID) {
82 return 2;
83 }
84
85 state->soundID = soundID;
86 state->fadeTime = fadeTime;
88 return 1;
89}
AuResult snd_load_ambient(s32 ambSoundID)
Definition 30450.c:272
AuResult snd_ambient_stop_slow(s32 index, s32 fadeOutTime)
Definition 30450.c:295
AuResult snd_ambient_stop_quick(s32 index)
Definition 30450.c:285
AuResult snd_ambient_play(s32 index, s32 fadeInTime)
Definition 30450.c:276
AuResult snd_ambient_is_stopped(s32 index)
Definition 30450.c:325
void update_ambient_sounds(void)
Definition ambience.c:32
AmbientSoundSettings AmbientSoundData
Definition ambience.c:26
AmbientSoundState
Definition ambience.c:12
@ AMBIENT_SOUND_FADE_OUT
Definition ambience.c:14
@ AMBIENT_SOUND_IDLE
Definition ambience.c:13
@ AMBIENT_SOUND_FADE_IN
Definition ambience.c:15
s32 play_ambient_sounds(s32 soundID, s32 fadeTime)
Definition ambience.c:72
void reset_ambient_sounds(void)
Definition ambience.c:28
AmbientSoundSettings DefaultAmbientSoundData
Definition ambience.c:18
@ AU_RESULT_OK
Definition enums.h:1756
GameStatus * gGameStatusPtr
Definition main_loop.c:32