Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
audio_api.c
Go to the documentation of this file.
1#include "common.h"
2
3API_CALLABLE(PollMusicEvents);
4
6extern Evt* RunningMusicEvents[10];
7extern s32 RunningMusicEventIDs[10];
8
10
11static EvtScript EVS_MusicEventMonitor = {
13 Return
14 End
15};
16
17API_CALLABLE(PollMusicEvents) {
19 s32 musicEventID, scriptSelector;
20 u32 count;
21 s32 i;
22
23 bgm_poll_music_events(&list, &count);
24
25 for (i = 0; i < count; i++, list++) {
27 musicEventID = (*list & 0xFF0000) >> 0x10;
28 scriptSelector = *list & 0xFF;
29 while (cur->musicEventID != -1) {
30 if (cur->musicEventID == musicEventID) {
31 break;
32 }
33 cur++;
34 }
37 if (cur != NULL) {
38 EvtScript* newSource = cur->scripts[scriptSelector];
39 if (RunningMusicEvents[musicEventID] != NULL) {
41 }
42 if (newSource != NULL) {
43 Evt* newEvt = start_script(newSource, EVT_PRIORITY_1, 0);
44 RunningMusicEvents[musicEventID] = newEvt;
45 RunningMusicEventIDs[musicEventID] = newEvt->id;
46 }
47 }
48 }
51 return ApiStatus_BLOCK;
52}
53
54API_CALLABLE(RegisterMusicEvents) {
55 Bytecode* args = script->ptrReadPos;
56 s32 i;
57
58 // expects a list of MusicEvent, terminated by -1 0 0 0 0
59 MusicEventList = (MusicEvent*) evt_get_variable(script, *args++);
60
61 for (i = 0; i < ARRAY_COUNT(RunningMusicEvents); i++) {
62 RunningMusicEvents[i] = NULL;
64 }
65
66 start_script(&EVS_MusicEventMonitor, EVT_PRIORITY_1, 0);
67 return ApiStatus_DONE2;
68}
69
70API_CALLABLE(FadeOutMusic) {
71 Bytecode* args = script->ptrReadPos;
72 s32 musicPlayer = evt_get_variable(script, *args++);
73 s32 fadeTime = evt_get_variable(script, *args++);
74
75 if (bgm_set_song(musicPlayer, -1, 0, fadeTime, 8)) {
76 return ApiStatus_DONE2;
77 } else {
78 return ApiStatus_BLOCK;
79 }
80}
81
82API_CALLABLE(SetMusicTrack) {
83 Bytecode* args = script->ptrReadPos;
84 s32 musicPlayer = evt_get_variable(script, *args++);
85 s32 songID = evt_get_variable(script, *args++);
86 s32 variation = evt_get_variable(script, *args++);
87 s16 volume = evt_get_variable(script, *args++);
88
89 if (bgm_set_song(musicPlayer, songID, variation, 500, volume)) {
90 return ApiStatus_DONE2;
91 } else {
92 return ApiStatus_BLOCK;
93 }
94}
95
96API_CALLABLE(FadeInMusic) {
97 Bytecode* args = script->ptrReadPos;
98 s32 musicPlayer = evt_get_variable(script, *args++);
99 s32 songID = evt_get_variable(script, *args++);
100 s32 variation = evt_get_variable(script, *args++);
101 s32 fadeTime = evt_get_variable(script, *args++);
102 s16 fadeStartVolume = evt_get_variable(script, *args++);
103 s16 fadeEndVolume = evt_get_variable(script, *args++);
104
105 if (func_8014A964(musicPlayer, songID, variation, fadeTime, fadeStartVolume, fadeEndVolume)) {
106 return ApiStatus_DONE2;
107 } else {
108 return ApiStatus_BLOCK;
109 }
110}
111
112API_CALLABLE(EnableMusicProximityMix) {
113 Bytecode* args = script->ptrReadPos;
114 s32 playerIndex = evt_get_variable(script, *args++);
115
117 return ApiStatus_DONE2;
118}
119
120API_CALLABLE(AdjustMusicProximityMix) {
121 Bytecode* args = script->ptrReadPos;
122 s32 playerIndex = evt_get_variable(script, *args++);
123 s32 mix = evt_get_variable(script, *args++);
124 s32 state = evt_get_variable(script, *args++);
125
126 bgm_adjust_proximity(playerIndex, mix, state);
127 return ApiStatus_DONE2;
128}
129
130API_CALLABLE(SetMusicTrackVolumes) {
131 Bytecode* args = script->ptrReadPos;
132 s16 trackVolSet = evt_get_variable(script, *args++);
133
134 bgm_set_track_volumes(0, trackVolSet);
135 return ApiStatus_DONE2;
136}
137
138API_CALLABLE(PopSong) {
139 bgm_pop_song();
140 return ApiStatus_DONE2;
141}
142
143API_CALLABLE(PushSong) {
144 Bytecode* args = script->ptrReadPos;
145 s32 songID = evt_get_variable(script, *args++);
146 s32 variation = evt_get_variable(script, *args++);
147
148 bgm_push_song(songID, variation);
149 return ApiStatus_DONE2;
150}
151
152API_CALLABLE(PopBattleSong) {
154 return ApiStatus_DONE2;
155}
156
157API_CALLABLE(PushBattleSong) {
159 return ApiStatus_DONE2;
160}
161
162API_CALLABLE(SetBattleSong) {
163 Bytecode* args = script->ptrReadPos;
164 s32 songID = evt_get_variable(script, *args++);
165 s32 variation = evt_get_variable(script, *args++);
166
167 bgm_set_battle_song(songID, variation);
168 return ApiStatus_DONE2;
169}
170
171API_CALLABLE(ClearAmbientSounds) {
172 Bytecode* args = script->ptrReadPos;
173 s32 time = evt_get_variable(script, *args++);
174
175 if (play_ambient_sounds(-1, time)) {
176 return ApiStatus_DONE2;
177 } else {
178 return ApiStatus_BLOCK;
179 }
180}
181
182API_CALLABLE(PlayAmbientSounds) {
183 Bytecode* args = script->ptrReadPos;
184 s32 soundID = evt_get_variable(script, *args++);
185
186 if (play_ambient_sounds(soundID, 250)) {
187 return ApiStatus_DONE2;
188 } else {
189 return ApiStatus_BLOCK;
190 }
191}
192
193API_CALLABLE(PlaySound) {
194 Bytecode* args = script->ptrReadPos;
195 s32 soundID = evt_get_variable(script, *args++);
196
197 sfx_play_sound(soundID);
198 return ApiStatus_DONE2;
199}
200
201API_CALLABLE(PlaySoundWithVolume) {
202 Bytecode* args = script->ptrReadPos;
203 s32 soundID = evt_get_variable(script, *args++);
204 s32 volume = evt_get_variable(script, *args++);
205
206 sfx_play_sound_with_params(soundID, volume, 0, 0);
207 return ApiStatus_DONE2;
208}
209
210API_CALLABLE(PlaySoundAt) {
211 Bytecode* args = script->ptrReadPos;
212 s32 soundID = evt_get_variable(script, *args++);
213 s32 flags = evt_get_variable(script, *args++);
214 s32 x = evt_get_variable(script, *args++);
215 s32 y = evt_get_variable(script, *args++);
216 s32 z = evt_get_variable(script, *args++);
217
218 sfx_play_sound_at_position(soundID, flags, x, y, z);
219 return ApiStatus_DONE2;
220}
221
222API_CALLABLE(StopSound) {
223 Bytecode* args = script->ptrReadPos;
224 s32 soundID = evt_get_variable(script, *args++);
225
226 sfx_stop_sound(soundID);
227 return ApiStatus_DONE2;
228}
229
230API_CALLABLE(StopTrackingSoundPos) {
231 Bytecode* args = script->ptrReadPos;
232 s32 soundID = evt_get_variable(script, *args++);
233
234 snd_stop_tracking_env_sound_pos(soundID, TRUE);
235 return ApiStatus_DONE2;
236}
237
238API_CALLABLE(UseDoorSounds) {
239 Bytecode* args = script->ptrReadPos;
240
241 gCurrentDoorSounds = evt_get_variable(script, *args++);
242 return ApiStatus_DONE2;
243}
244
245API_CALLABLE(UseRoomDoorSounds) {
246 Bytecode* args = script->ptrReadPos;
247
248 gCurrentRoomDoorSounds = evt_get_variable(script, *args++);
249 return ApiStatus_DONE2;
250}
251
252API_CALLABLE(PlaySoundAtF) {
253 Bytecode* args = script->ptrReadPos;
254 Bytecode soundID = *args++;
255 u16 spatializationFlags = evt_get_variable(script, *args++);
256 f32 x = evt_get_float_variable(script, *args++);
257 f32 y = evt_get_float_variable(script, *args++);
258 f32 z = evt_get_float_variable(script, *args++);
259
260 sfx_play_sound_at_position(soundID, spatializationFlags, x, y, z);
261 return ApiStatus_DONE2;
262}
void bgm_flush_music_events(void)
Definition 30450.c:808
void bgm_poll_music_events(MusicEventTrigger **musicEvents, s32 *count)
Definition 30450.c:801
MusicEvent * MusicEventList
Definition script_list.c:50
Evt * RunningMusicEvents[10]
Definition script_list.c:51
s32 RunningMusicEventIDs[10]
Definition script_list.c:52
s32 MusicEventPollCount
Definition audio_api.c:9
EvtScript * scripts[4]
u32 MusicEventTrigger
Bytecode EvtScript[]
s8 flags
Definition demo_api.c:15
#define sfx_play_sound_at_position
@ MUSIC_SETTINGS_FLAG_ENABLE_PROXIMITY_MIX
Definition enums.h:4661
@ EVT_PRIORITY_1
Definition evt.h:152
#define ApiStatus_DONE2
Definition evt.h:118
s32 Bytecode
Definition evt.h:7
#define ApiStatus_BLOCK
Definition evt.h:116
s32 bgm_adjust_proximity(s32 playerIndex, s32 arg1, s16 arg2)
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
s32 play_ambient_sounds(s32 fadeInTime, s32 fadeOutTime)
Definition ambience.c:72
void bgm_pop_song(void)
s32 bgm_set_song(s32 playerIndex, s32 songID, s32 variation, s32 fadeOutTime, s16 volume)
enum AuResult bgm_set_track_volumes(s32 playerIndex, s16 trackVolSet)
void bgm_pop_battle_song(void)
Evt * start_script(EvtScript *source, s32 priority, s32 initialState)
s32 func_8014A964(s32 playerIndex, s32 songID, s32 variation, s32 fadeInTime, s16 arg4, s16 arg5)
void kill_script_by_ID(s32 id)
f32 evt_get_float_variable(Evt *script, Bytecode var)
Definition evt.c:1930
void bgm_push_song(s32 songID, s32 variation)
void bgm_set_battle_song(s32, s32)
void bgm_push_battle_song(void)
void sfx_stop_sound(s32 soundID)
Definition sfx.c:507
void sfx_play_sound_with_params(s32 soundID, u8 volume, u8 pan, s16 pitchShift)
Definition sfx.c:458
void snd_stop_tracking_env_sound_pos(s32 soundID, s32 keepPlaying)
Definition sfx.c:447
void sfx_play_sound(s32 soundID)
Definition sfx.c:517
ApiStatus FadeOutMusic(Evt *script, b32 isInitialCall)
ApiStatus FadeInMusic(Evt *script, b32 isInitialCall)
ApiStatus PopBattleSong(Evt *script, b32 isInitialCall)
ApiStatus PlaySound(Evt *script, b32 isInitialCall)
ApiStatus PushSong(Evt *script, b32 isInitialCall)
ApiStatus PlaySoundAtF(Evt *script, b32 isInitialCall)
ApiStatus SetMusicTrack(Evt *script, b32 isInitialCall)
ApiStatus UseRoomDoorSounds(Evt *script, b32 isInitialCall)
ApiStatus PushBattleSong(Evt *script, b32 isInitialCall)
ApiStatus PopSong(Evt *script, b32 isInitialCall)
ApiStatus SetMusicTrackVolumes(Evt *script, b32 isInitialCall)
ApiStatus SetBattleSong(Evt *script, b32 isInitialCall)
ApiStatus RegisterMusicEvents(Evt *script, b32 isInitialCall)
ApiStatus StopSound(Evt *script, b32 isInitialCall)
ApiStatus StopTrackingSoundPos(Evt *script, b32 isInitialCall)
ApiStatus PlayAmbientSounds(Evt *script, b32 isInitialCall)
ApiStatus PollMusicEvents(Evt *script, b32 isInitialCall)
ApiStatus UseDoorSounds(Evt *script, b32 isInitialCall)
ApiStatus EnableMusicProximityMix(Evt *script, b32 isInitialCall)
ApiStatus AdjustMusicProximityMix(Evt *script, b32 isInitialCall)
ApiStatus PlaySoundWithVolume(Evt *script, b32 isInitialCall)
ApiStatus ClearAmbientSounds(Evt *script, b32 isInitialCall)
ApiStatus PlaySoundAt(Evt *script, b32 isInitialCall)
#define End
Signals the end of EVT script data. A script missing this will likely crash on load.
Definition macros.h:213
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define Call(FUNC, ARGS...)
Calls a given C EVT API function with any number of arguments.
Definition macros.h:576
#define Return
Kills the current EVT thread.
Definition macros.h:217
MusicSettings gMusicSettings[2]
u16 gCurrentDoorSounds
Definition sfx.c:6
u16 gCurrentRoomDoorSounds
Definition sfx.c:7