Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
sfx_player.c
Go to the documentation of this file.
1#include "common.h"
2#include "audio.h"
3
4static void au_sfx_play_sound(SoundManager* manager, SoundPlayer* player, s8* readPos, SoundSFXEntry* sfxEntry, s32 arg4, s32 arg5);
5static void au_sfx_set_triggers(SoundManager* manager, u32 soundID);
6static void au_sfx_stop_by_id(SoundManager* manager, u32 soundID);
7static void au_sfx_stop_by_exlusive_id(SoundManager* manager, u32 soundID);
8static void au_sfx_set_modifiers(SoundManager* manager, SoundSFXEntry* sfxEntry);
9static void au_sfx_set_player_modifiers(SoundPlayer* player, SoundSFXEntry* sfxEntry);
10
11static void au_sfx_update_basic(SoundManager* manager, SoundPlayer* player, AuVoice* arg2, u8 arg3);
12static s16 au_sfx_get_scaled_volume(SoundManager* manager, SoundPlayer* player);
13static void au_sfx_update_sequence(SoundManager* manager, SoundPlayer* player, AuVoice* arg2, u8 arg3);
14static void snd_set_voice_volume(AuVoice* voice, SoundManager* manager, SoundPlayer* player);
15static u8 au_sfx_get_random_pan(s32 arg0, s32 arg1, s32 arg2);
16static void au_SEFCmd_00_SetVolume(SoundManager* manager, SoundPlayer* player);
17static void au_SEFCmd_01_SetPan(SoundManager* manager, SoundPlayer* player);
18static void au_SEFCmd_02_SetInstrument(SoundManager* manager, SoundPlayer* player);
19static void au_SEFCmd_03_SetReverb(SoundManager* manager, SoundPlayer* player);
20static void au_SEFCmd_04_SetEnvelope(SoundManager* manager, SoundPlayer* player);
21static void au_SEFCmd_05_CoarseTune(SoundManager* manager, SoundPlayer* player);
22static void au_SEFCmd_06_FineTune(SoundManager* manager, SoundPlayer* player);
23static void au_SEFCmd_07_WaitForEnd(SoundManager* manager, SoundPlayer* player);
24static void au_SEFCmd_08_PitchSweep(SoundManager* manager, SoundPlayer* player);
25static void au_SEFCmd_09_StartLoop(SoundManager* manager, SoundPlayer* player);
26static void au_SEFCmd_0A_EndLoop(SoundManager* manager, SoundPlayer* player);
27static void au_SEFCmd_0B_WaitForRelease(SoundManager* manager, SoundPlayer* player);
28static void au_SEFCmd_0C_SetCurrentVolume(SoundManager* manager, SoundPlayer* player);
29static void au_SEFCmd_0D_VolumeRamp(SoundManager* manager, SoundPlayer* player);
30static void au_SEFCmd_0E_SetAlternativeSound(SoundManager* manager, SoundPlayer* player);
31static void au_SEFCmd_0F_Stop(SoundManager* manager, SoundPlayer* player);
32static void au_SEFCmd_10_Jump(SoundManager* manager, SoundPlayer* player);
33static void au_SEFCmd_11_Restart(SoundManager* manager, SoundPlayer* player);
34static void au_SEFCmd_12_NOP(SoundManager* manager, SoundPlayer* player);
35static void au_SEFCmd_13_SetRandomPitch(SoundManager* manager, SoundPlayer* player);
36static void au_SEFCmd_14_SetRandomVelocity(SoundManager* manager, SoundPlayer* player);
37static void au_SEFCmd_15_SetUnkA3(SoundManager* manager, SoundPlayer* player);
38static void au_SEFCmd_16_SetEnvelopePress(SoundManager* manager, SoundPlayer* player);
39static void au_SEFCmd_17_PlaySound(SoundManager* manager, SoundPlayer* player);
40static void au_SEFCmd_18_SetAlternativeVolume(SoundManager* manager, SoundPlayer* player);
41static s32 au_sfx_get_random_pitch(s32 arg0, s32 arg1, s32 arg2);
42static u8 au_sfx_get_random_vol(s32 arg0, s32 arg1, s32 arg2);
43static void au_sfx_reset_players(SoundManager* manager);
44
46 // 8 bytes: flags, instrument, volume, pan, reverb, pitch, randomPitch
48 // arbitrary sequence of commands
50 // 4 bytes: flags, instrument, volume and randomPitch
52 SFX_PARAM_FLAG_MODE = 0x00000003,
53 // when flags below are set, these params can't be changed from api functions like sfx_play_sound_with_params
55 SFX_PARAM_FLAG_PAN = 0x00000008,
57 // prevents from changing reverb amount via SetReverb command
59};
60
62 0xF803, 0x0125, 0x07D0, 0xFDBC, 0xF886, 0x0355, 0x06FC, 0xFBAB,
63 0xFEDA, 0xF82D, 0x0245, 0x077D, 0xFCA9, 0xF901, 0x0456, 0x065D,
64 0xFC33, 0xFBB2, 0xFCEF, 0xFE94, 0xFFD8, 0x0080, 0x00A4, 0x007D,
65 0x090E, 0x0673, 0x02FF, 0x0053, 0xFEF2, 0xFEA7, 0xFEF9, 0xFF7B
66};
67
69 0xB1, 0x01, 0x11, 0x10, 0x00, 0xFF, 0xFE, 0x34, 0xBB, 0x90, 0xE2, 0x1E, 0x00, 0xFB, 0x10, 0xEF,
70 0xF2, 0xD1, 0x80, 0xC4, 0xB3, 0xB1, 0xD3, 0xCF, 0xD1, 0xFD, 0xFE, 0x80, 0x1D, 0x2D, 0x3D, 0x3B,
71 0x2C, 0x3B, 0xFC, 0x1D, 0x80, 0xDE, 0xF0, 0xD0, 0xD3, 0xD2, 0xB3, 0xD1, 0xF4, 0x80, 0xA2, 0x03,
72 0xD0, 0x0D, 0xA9, 0xEA, 0xCB, 0x72, 0x90, 0x41, 0x4E, 0x1D, 0x2D, 0x0C, 0x1E, 0x10, 0x2F, 0x90,
73 0xF2, 0x12, 0x03, 0xF0, 0xC2, 0xD1, 0xD4, 0xF3, 0x80, 0xB0, 0xA1, 0xBF, 0xD2, 0x1E, 0x12, 0x70,
74 0x4D, 0x80, 0x4C, 0x39, 0x2C, 0x7E, 0x30, 0x6D, 0xB9, 0xCF, 0x90, 0xE1, 0xF2, 0xF3, 0xF2, 0xE1,
75 0xE2, 0x16, 0x22, 0xC1, 0xE7, 0x28, 0xF4, 0xF0, 0x21, 0x10, 0x10, 0xFF, 0xA1, 0xED, 0x9F, 0x2F,
76 0xF5, 0x61, 0x33, 0x3C, 0xD0, 0xA1, 0xDA, 0xC2, 0xFF, 0x14, 0x41, 0x22, 0x2D, 0xEF, 0xA1, 0xFA,
77 0xE1, 0x0E, 0x23, 0x30, 0x32, 0x0E, 0xF0, 0x91, 0x9A, 0xF2, 0xCF, 0x55, 0x13, 0x61, 0xEE, 0x1C,
78 0x91, 0x9D, 0x0F, 0xD2, 0x52, 0x06, 0x4D, 0xE1, 0x09, 0x91, 0xD0, 0x1B, 0x15, 0x2E, 0x36, 0xFD,
79 0x12, 0xCB, 0x81, 0x22, 0xBC, 0x65, 0xF0, 0x73, 0xCE, 0x3F, 0xAE, 0x71, 0x4E, 0x93, 0x70, 0xF5,
80 0x6E, 0xD2, 0x1B, 0xD1, 0x61, 0x0A, 0x5D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
81};
82
83// copy of SMALL_ROOM_PARAMS
85 /* sections length */
86 3, 11,
87 /* chorus chorus filter
88 input output fbcoef ffcoef gain rate depth coef */
89 0, 9, 9830, -9830, 0, 0, 0, 0,
90 3, 7, 3276, -3276, 0x3FFF, 0, 0, 0,
91 0, 10, 5000, 0, 0, 0, 0, 0x5000
92};
93
94// modified ECHO_PARAMS -- length and output changed
96 /* sections length */
97 1, 11,
98 /* chorus chorus filter
99 input output fbcoef ffcoef gain rate depth coef */
100 0, 10, 20000, 0, 0x7FFF, 0, 0, 0x7FFF
101};
102
103// modified ECHO_PARAMS -- length and output changed
105 /* sections length */
106 1, 13,
107 /* chorus chorus filter
108 input output fbcoef ffcoef gain rate depth coef */
109 0, 12, 20000, 0, 0x7FFF, 0, 0, 0x7FFF
110};
111
112// modified ECHO_PARAMS -- length and output changed
114 /* sections length */
115 1, 14,
116 /* chorus chorus filter
117 input output fbcoef ffcoef gain rate depth coef */
118 0, 13, 20000, 0, 0x7FFF, 0, 0, 0x7FFF
119};
120
122 {
124 .sound2 = SOUND_LRAW_CHEERING,
125 .flags = 1
126 }
127};
128
129// TODO: figure out how to make struct properly
131 .count = 1,
132 .offsets = { { 0x08, 0x12 } },
133};
134
136 // press
137 ENV_TIME_290MS, 127,
138 ENV_TIME_900MS, 127,
139 ENV_TIME_1S, 95,
140 ENV_TIME_3S, 0,
141 ENV_CMD_END, 0,
142 // release
144 ENV_CMD_END, 0
145};
146
148 .count = 1,
149 .offsets = { { 0x08, 0x1A } },
150};
151
153 // press
154 ENV_TIME_290MS, 127,
155 ENV_TIME_1800MS, 127,
156 ENV_TIME_290MS, 63,
157 ENV_TIME_1100MS, 31,
158 ENV_TIME_1100MS, 15,
162 ENV_CMD_END, 0,
163 // release
165 ENV_CMD_END, 0,
166};
167
168// looks like envelope data, but it's not aligned and not used
169s32 D_800783B0[] = {
170 0x34337F26, 0x3F1600FF, 0x343B7F3B, 0x3FFF0000
171};
172
191
193 au_SEFCmd_00_SetVolume,
194 au_SEFCmd_01_SetPan,
195 au_SEFCmd_02_SetInstrument,
196 au_SEFCmd_03_SetReverb,
197 au_SEFCmd_04_SetEnvelope,
198 au_SEFCmd_05_CoarseTune,
199 au_SEFCmd_06_FineTune,
200 au_SEFCmd_07_WaitForEnd,
201 au_SEFCmd_08_PitchSweep,
202 au_SEFCmd_09_StartLoop,
203 au_SEFCmd_0A_EndLoop,
204 au_SEFCmd_0B_WaitForRelease,
205 au_SEFCmd_0C_SetCurrentVolume,
206 au_SEFCmd_0D_VolumeRamp,
207 au_SEFCmd_0E_SetAlternativeSound,
208 au_SEFCmd_0F_Stop,
209 au_SEFCmd_10_Jump,
210 au_SEFCmd_11_Restart,
211 au_SEFCmd_12_NOP,
212 au_SEFCmd_13_SetRandomPitch,
213 au_SEFCmd_14_SetRandomVelocity,
214 au_SEFCmd_15_SetUnkA3,
215 au_SEFCmd_16_SetEnvelopePress,
216 au_SEFCmd_17_PlaySound,
217 au_SEFCmd_18_SetAlternativeVolume
218};
219
221 0x00, 0x00, 0x00, 0x00,
222 0x00, 0x00, 0x00, 0x00,
223 0x00, 0x00, 0x00, 0x00
224};
225
226// --------------------------------------------
227// the following are only referenced in audio/28910_len_5090
228
263
265 2, 1, 1, 1, 4, 3, 2, 0,
266 2, 1, 1, 1, 1, 1, 1, 2,
267 3, 1, 1, 0, 2, 1, 3, 1,
268 0, 0, 0, 0, 3, 3, 3, 3
269};
270
272 48, 24, 32, 40, 48, 56, 64, 48,
273 0, 0, 0, 0, 0, 0, 0, 0
274};
275
276// --------------------------------------------
277// the following are only referenced in audio/2BF90
278
280 0x00, 0x00, 0x00, 0x00,
281 0x00, 0x00, 0x00, 0x00,
282 0x00, 0x00, 0x00, 0x00,
283 0x00, 0x00, 0x00, 0x00
284};
285
286// --------------------------------------------
287// the following are only referenced in audio/2e230_len_2190
288
289s16 D_80078530[] = {
290 0x0000, 0x0200, 0x0800, 0x1200, 0x2000, 0x3200, 0x4800, 0x6200, 0x8000
291};
292
293// TODO: figure out how to make struct properly
295 .count = 1,
296 .offsets = { { 0x8, 0xC } }, // EnvelopePressDefault, EnvelopePressDefault
297};
298
300 ENV_TIME_280MS, 127,
301 ENV_CMD_END, 0
302};
303
308
313
314// --------------------------------------------
315// the following are only referenced in 28910_len_5090
316
318 0x5E, 0x5D, 0x5C, 0x5B, 0x5A, 0x58, 0x56, 0x53,
319 0x51, 0x4F, 0x4A, 0x45, 0x40, 0x3B, 0x37, 0x35,
320 0x33, 0x31, 0x2F, 0x2D, 0x2B, 0x29, 0x27, 0x26,
321 0x25, 0x23, 0x21, 0x20, 0x1F, 0x1E, 0x1D, 0x1C,
322 0x1B, 0x1A, 0x19, 0x18, 0x17, 0x16, 0x15, 0x14
323};
324
325// --------------------------------------------
326// the following are only referenced in audio/2e230_len_2190
327
329 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
330 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12,
331 0x13, 0x14, 0x15, 0x16, 0x17, 0x00, 0x00, 0x00,
332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
333};
334
335// --------------------------------------------
336// the following are only referenced in audio/2d9a0_len_890
337
338// convert seconds to microseconds and round to number multiple to 5750
339#define SEC(x) ((s32)(x * 1000000) / AU_5750 * AU_5750)
340
342 SEC(60), SEC(55), SEC(50), SEC(45), SEC(40), SEC(35), SEC(30), SEC(27.5), SEC(25), SEC(22.5),
343 SEC(20), SEC(19), SEC(18), SEC(17), SEC(16), SEC(15), SEC(14), SEC(13), SEC(12), SEC(11),
344 SEC(10), SEC(9), SEC(8), SEC(7), SEC(6), SEC(5), SEC(4.5), SEC(4), SEC(3.5), SEC(3),
345 SEC(2.75), SEC(2.5), SEC(2.25), SEC(2), SEC(1.9), SEC(1.8), SEC(1.7), SEC(1.6), SEC(1.5), SEC(1.4),
346 SEC(1.3), SEC(1.2), SEC(1.1), SEC(1), SEC(0.95), SEC(0.9), SEC(0.85), SEC(0.8), SEC(0.75), SEC(0.7),
347 SEC(0.65), SEC(0.6), SEC(0.55), SEC(0.5), SEC(0.45), SEC(0.4), SEC(0.375), SEC(0.35), SEC(0.325), SEC(0.3),
348 SEC(0.29), SEC(0.28), SEC(0.27), SEC(0.26), SEC(0.25), SEC(0.24), SEC(0.23), SEC(0.22), SEC(0.21), SEC(0.2),
349 SEC(0.19), SEC(0.18), SEC(0.17), SEC(0.16), SEC(0.15), SEC(0.14), SEC(0.13), SEC(0.12), SEC(0.11), SEC(0.1),
350 16 * AU_5750, 14 * AU_5750, 12 * AU_5750, 11 * AU_5750, 10 * AU_5750,
351 9 * AU_5750, 8 * AU_5750, 7 * AU_5750, 6 * AU_5750, 5 * AU_5750,
352 4 * AU_5750, 3 * AU_5750, 2 * AU_5750, 1 * AU_5750, 0, 0, 0, 0, 0, 0,
353};
354
355#undef SEC
356
357// --------------------------------------------
358// the following are only referenced in audio/2e230_len_2190
359
361 // TUNE_SCALING_ARR_AMPLIFY_FINE
362 1.00000000f, 1.00057781f, 1.00115597f, 1.00173450f, 1.00231326f, 1.00289237f, 1.00347185f, 1.00405169f,
363 1.00463188f, 1.00521231f, 1.00579309f, 1.00637424f, 1.00695574f, 1.00753760f, 1.00811982f, 1.00870228f,
364 1.00928509f, 1.00986826f, 1.01045179f, 1.01103568f, 1.01161981f, 1.01220429f, 1.01278913f, 1.01337433f,
365 1.01395988f, 1.01454580f, 1.01513207f, 1.01571858f, 1.01630545f, 1.01689267f, 1.01748025f, 1.01806819f,
366 1.01865649f, 1.01924503f, 1.01983392f, 1.02042317f, 1.02101278f, 1.02160275f, 1.02219307f, 1.02278376f,
367 1.02337468f, 1.02396595f, 1.02455759f, 1.02514958f, 1.02574193f, 1.02633464f, 1.02692771f, 1.02752113f,
368 1.02811480f, 1.02870882f, 1.02930319f, 1.02989793f, 1.03049302f, 1.03108847f, 1.03168428f, 1.03228045f,
369 1.03287685f, 1.03347361f, 1.03407073f, 1.03466821f, 1.03526604f, 1.03586423f, 1.03646278f, 1.03706169f,
370 1.03766096f, 1.03826058f, 1.03886044f, 1.03946066f, 1.04006124f, 1.04066217f, 1.04126346f, 1.04186511f,
371 1.04246712f, 1.04306948f, 1.04367220f, 1.04427528f, 1.04487872f, 1.04548252f, 1.04608655f, 1.04669094f,
372 1.04729569f, 1.04790080f, 1.04850626f, 1.04911208f, 1.04971826f, 1.05032480f, 1.05093169f, 1.05153894f,
373 1.05214655f, 1.05275452f, 1.05336285f, 1.05397153f, 1.05458057f, 1.05518997f, 1.05579972f, 1.05640972f,
374 1.05702007f, 1.05763078f, 1.05824184f, 1.05885327f, 1.05946505f, 1.06007719f, 1.06068969f, 1.06130254f,
375 1.06191576f, 1.06252933f, 1.06314325f, 1.06375754f, 1.06437218f, 1.06498718f, 1.06560254f, 1.06621826f,
376 1.06683433f, 1.06745076f, 1.06806755f, 1.06868470f, 1.06930220f, 1.06992006f, 1.07053828f, 1.07115686f,
377 1.07177579f, 1.07239509f, 1.07301474f, 1.07363474f, 1.07425511f, 1.07487583f, 1.07549691f, 1.07611835f,
378 // TUNE_SCALING_ARR_AMPLIFY_COARSE
379 1.00000000f, 1.07674015f, 1.15936935f, 1.24833953f, 1.34413731f, 1.44728661f, 1.55835164f, 1.67793977f,
380 1.80670512f, 1.94535196f, 2.09463859f, 2.25538135f, 2.42845964f, 2.61482000f, 2.81548166f, 3.03154206f,
381 3.26418304f, 3.51467681f, 3.78439355f, 4.07480860f, 4.38750982f, 4.72420788f, 5.08674431f, 5.47710180f,
382 5.89741516f, 6.34998369f, 6.83728218f, 7.36197615f, 7.92693520f, 8.53524971f, 9.19024563f, 9.89550686f,
383 // TUNE_SCALING_ARR_ATTENUATE_FINE
384 1.00000000f, 0.99942255f, 0.99884546f, 0.99826866f, 0.99769223f, 0.99711609f, 0.99654031f, 0.99596488f,
385 0.99538976f, 0.99481499f, 0.99424052f, 0.99366641f, 0.99309260f, 0.99251914f, 0.99194598f, 0.99137318f,
386 0.99080074f, 0.99022859f, 0.98965681f, 0.98908532f, 0.98851418f, 0.98794335f, 0.98737288f, 0.98680270f,
387 0.98623288f, 0.98566335f, 0.98509419f, 0.98452532f, 0.98395681f, 0.98338860f, 0.98282075f, 0.98225319f,
388 0.98168600f, 0.98111910f, 0.98055255f, 0.97998631f, 0.97942042f, 0.97885484f, 0.97828960f, 0.97772467f,
389 0.97716010f, 0.97659582f, 0.97603190f, 0.97546828f, 0.97490501f, 0.97434205f, 0.97377944f, 0.97321713f,
390 0.97265512f, 0.97209346f, 0.97153211f, 0.97097111f, 0.97041041f, 0.96985006f, 0.96929002f, 0.96873033f,
391 0.96817094f, 0.96761185f, 0.96705312f, 0.96649468f, 0.96593660f, 0.96537882f, 0.96482134f, 0.96426421f,
392 0.96370739f, 0.96315092f, 0.96259475f, 0.96203887f, 0.96148336f, 0.96092814f, 0.96037328f, 0.95981872f,
393 0.95926446f, 0.95871055f, 0.95815694f, 0.95760363f, 0.95705068f, 0.95649803f, 0.95594567f, 0.95539367f,
394 0.95484197f, 0.95429057f, 0.95373952f, 0.95318878f, 0.95263839f, 0.95208830f, 0.95153850f, 0.95098901f,
395 0.95043987f, 0.94989103f, 0.94934249f, 0.94879431f, 0.94824642f, 0.94769883f, 0.94715160f, 0.94660467f,
396 0.94605803f, 0.94551176f, 0.94496578f, 0.94442010f, 0.94387472f, 0.94332969f, 0.94278497f, 0.94224054f,
397 0.94169647f, 0.94115269f, 0.94060922f, 0.94006604f, 0.93952322f, 0.93898070f, 0.93843848f, 0.93789655f,
398 0.93735498f, 0.93681371f, 0.93627274f, 0.93573207f, 0.93519175f, 0.93465173f, 0.93411201f, 0.93357259f,
399 0.93303353f, 0.93249476f, 0.93195629f, 0.93141812f, 0.93088025f, 0.93034273f, 0.92980552f, 0.92926860f,
400 // TUNE_SCALING_ARR_ATTENUATE_COARSE
401 1.00000000f, 0.92873198f, 0.86254311f, 0.80107135f, 0.74398059f, 0.69095856f, 0.64171529f, 0.59598154f,
402 0.55350709f, 0.51405972f, 0.47742370f, 0.44339865f, 0.41179851f, 0.38245043f, 0.35519394f, 0.32987997f,
403 0.30637008f, 0.28453568f, 0.26425737f, 0.24542427f, 0.22793336f, 0.21168900f, 0.19660234f, 0.18259089f,
404 0.16957800f, 0.15749252f, 0.14626834f, 0.13584408f, 0.12616274f, 0.11717137f, 0.10882080f, 0.10106535f,
405 0.09386262f, 0.08717322f, 0.08096056f, 0.07519066f, 0.06983197f, 0.06485518f, 0.06023308f, 0.05594039f,
406 0.05195362f, 0.04825099f, 0.04481224f, 0.04161856f, 0.03865249f, 0.03589780f, 0.03333944f, 0.03096340f,
407 0.02875670f, 0.02670727f, 0.02480390f, 0.02303617f, 0.02139443f, 0.01986969f, 0.01845361f, 0.01713846f,
408 0.01591704f, 0.01478266f, 0.01372913f, 0.01275068f, 0.01184197f, 0.01099801f, 0.01021421f, 0.00948626f,
409 0.00881019f, 0.00818231f, 0.00759917f, 0.00705759f, 0.00655461f, 0.00608748f, 0.00565364f, 0.00525071f,
410 0.00487650f, 0.00452897f, 0.00420620f, 0.00390643f, 0.00362802f, 0.00336946f, 0.00312933f, 0.00290631f,
411 0.00269918f, 0.00250681f, 0.00232816f, 0.00216224f, 0.00200814f, 0.00186502f, 0.00173211f, 0.00160866f,
412 0.00149402f, 0.00138754f, 0.00128865f, 0.00119681f, 0.00111152f, 0.00103230f, 0.00095873f, 0.00089041f,
413 0.00082695f, 0.00076801f, 0.00071328f, 0.00066244f, 0.00061523f, 0.00057139f, 0.00053067f, 0.00049285f,
414 0.00045772f, 0.00042510f, 0.00039480f, 0.00036667f, 0.00034054f, 0.00031627f, 0.00029373f, 0.00027279f,
415 0.00025335f, 0.00023530f, 0.00021853f, 0.00020295f, 0.00018849f, 0.00017506f, 0.00016258f, 0.00015099f,
416 0.00014023f, 0.00013024f, 0.00012096f, 0.00011234f, 0.00010433f, 0.00009689f, 0.00008999f, 0.00008358f
417};
418
419extern s32* AU_FX_CUSTOM_PARAMS[0]; // points to 80078290
420
422
423void au_sfx_init(SoundManager* manager, u8 priority, u8 busId, AuGlobals* globals, u8 minVoiceIdx) {
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}
505
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}
525
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}
542
543void au_sfx_enqueue_event(SoundManager* manager, u32 soundID, s16 volume, s16 pitchShift, u8 pan) {
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}
568
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}
662
663// also affects ambience because it uses same fx bus
664s32 au_sfx_set_reverb_type(SoundManager* manager, s32 arg1) {
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}
683
684void au_sfx_set_state(SoundManager* manager, s32 state) {
685 if (state == SND_MANAGER_STATE_ENABLED) {
687 } else if (state == SND_MANAGER_STATE_DISABLED) {
689 }
690}
691
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}
939
940static void au_sfx_play_sound(SoundManager* manager, SoundPlayer* player, s8* readPos, SoundSFXEntry* sfxEntry, s32 priority, s32 exclusiveID) {
941 if (manager->state == SND_MANAGER_STATE_ENABLED) {
942 player->sefDataReadPos = readPos;
943 player->sefReadStart = readPos;
944 player->sfxInstrumentRef = manager->globals->defaultInstrument;
945 player->sfxPan = 0x40;
946 player->sfxVolume = 0x7FFF;
947 player->alternativeVolume = 0x7FFF;
948 player->reverb = 0;
949 player->instrumentIndex = 0;
950 player->envelopePreset = 0;
951 player->playVelocity = 0x7F;
952 player->coarseTune = 0;
953 player->fineTune = 0;
954 player->loopStartPos = NULL;
955 player->loopIterCount = 0;
956 player->delay = 1;
957 player->playLength = 0;
958 player->curSoundID = sfxEntry->soundID & SOUND_ID_LOWER;
959 player->priority = priority;
960 player->exclusiveID = exclusiveID;
961 player->envelopCustomPressProfile = NULL;
962 player->changed.all = 0;
963 player->unk_A0 = 0;
964 player->randomPitch = 0;
965 player->randomVelocity = 0;
966 player->unk_A3 = 0;
967 player->volumeLerp.current = 0x7FFFFFFF;
968 player->volumeLerp.time = 0;
969 player->volumeLerp.step = 0;
970 player->volumeLerp.goal = 0;
971 player->tuneLerp.current = 0;
972 player->tuneLerp.time = 0;
973 player->tuneLerp.step = 0;
974 player->tuneLerp.goal = 0;
975 player->alternativeDataPos = NULL;
976 player->alternativeType = 0;
977 player->triggers = 0;
978 player->sfxParamsFlags = *player->sefDataReadPos++;
979 switch (player->sfxParamsFlags & SFX_PARAM_FLAG_MODE) {
982 break;
985 break;
987 player->sfxParamsFlags = (player->sfxParamsFlags & ~SFX_PARAM_FLAG_MODE) | SFX_PARAM_MODE_ADVANCED;
989 player->cmdList_mode2[0] = player->sefDataReadPos[0]; // instrument bank
990 player->cmdList_mode2[1] = player->sefDataReadPos[1]; // instrument patch
991 // volume and random pitch may overlap
992 player->cmdList_mode2[2] = (player->sefDataReadPos[2] >> 1) | 3; // volume
993 player->cmdList_mode2[6] = player->sefDataReadPos[2] & 7; // random pitch
994 player->sefDataReadPos = player->cmdList_mode2;
995 break;
996 }
997 au_sfx_set_player_modifiers(player, sfxEntry);
998 }
999}
1000
1001static void au_sfx_set_triggers(SoundManager* manager, u32 soundID) {
1002 s32 triggers = (soundID & SOUND_ID_TRIGGER_MASK) >> 0xA;
1003 s32 i;
1004
1005 for (i = 0; i < ARRAY_COUNT(manager->players); i++) {
1006 SoundPlayer* player = &manager->players[i];
1007 if (player->curSoundID == (soundID & SOUND_ID_LOWER)) {
1008 player->triggers = triggers;
1009 }
1010 }
1011}
1012
1013static void au_sfx_stop_by_id(SoundManager* manager, u32 soundID) {
1014 s32 i;
1015
1016 for (i = 0; i < ARRAY_COUNT(manager->players); i++) {
1017 SoundPlayer* player = &manager->players[i];
1018 if (player->curSoundID == (soundID & SOUND_ID_LOWER)) {
1019 player->sefDataReadPos = BlankSEFData;
1020 player->alternativeDataPos = NULL;
1023 player->delay = 1;
1024 player->priority = 0;
1025 player->exclusiveID = 0;
1026 }
1027 }
1028}
1029
1030static void au_sfx_stop_by_exlusive_id(SoundManager* manager, u32 exclusiveID) {
1031 s32 i;
1032
1033 for (i = 0; i < ARRAY_COUNT(manager->players); i++) {
1034 SoundPlayer* player = &manager->players[i];
1035 if (exclusiveID == player->exclusiveID) {
1036 player->sefDataReadPos = BlankSEFData;
1037 player->alternativeDataPos = NULL;
1040 player->delay = 1;
1041 player->priority = 0;
1042 player->exclusiveID = 0;
1043 }
1044 }
1045}
1046
1047static void au_sfx_set_modifiers(SoundManager* manager, SoundSFXEntry* sfxEntry) {
1048 s32 soundID = sfxEntry->soundID & SOUND_ID_LOWER;
1049 s32 i;
1050
1051 for (i = 0; i < ARRAY_COUNT(manager->players); i++) {
1052 SoundPlayer* player = &manager->players[i];
1053 if (player->curSoundID == soundID) {
1054 au_sfx_set_player_modifiers(player, sfxEntry);
1055 }
1056 }
1057}
1058
1059static void au_sfx_set_player_modifiers(SoundPlayer* player, SoundSFXEntry* sfxEntry) {
1060 if (player->sfxParamsFlags & SFX_PARAM_FLAG_VOLUME) {
1061 player->masterVolume = 0;
1062 } else {
1063 player->masterVolume = sfxEntry->volume;
1064 player->changed.volume = TRUE;
1065 }
1066 if (player->sfxParamsFlags & SFX_PARAM_FLAG_PAN) {
1067 player->masterPan = 0;
1068 } else {
1069 player->masterPan = sfxEntry->pan;
1070 player->changed.pan = TRUE;
1071 }
1072 if (player->sfxParamsFlags & SFX_PARAM_FLAG_PITCH) {
1073 player->masterPitchShift = 0;
1074 } else {
1075 player->masterPitchShift = sfxEntry->pitchShift;
1076 player->changed.tune = TRUE;
1077 }
1078}
1079
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}
1117
1118static void au_sfx_update_basic(SoundManager* manager, SoundPlayer* player, AuVoice* voice, u8 voiceIdx) {
1119 s16 volume;
1120 s32 tune;
1121 s32 pan;
1122 s32 a;
1123 s32 b;
1124
1125 switch (player->state) {
1127 if (voice->priority != manager->priority) {
1128 player->sefDataReadPos = NULL;
1129 player->curSoundID = 0;
1130 player->priority = 0;
1131 } else {
1132 if (!(player->sfxParamsFlags & SFX_PARAM_FLAG_PITCH)) {
1134 ((player->tuneLerp.current >> 0x10) - player->sfxInstrumentRef->keyBase) + player->masterPitchShift) * player->sfxInstrumentRef->pitchRatio;
1135 if (voice->pitchRatio != player->pitchRatio) {
1137 voice->pitchRatio = player->pitchRatio;
1138 }
1139 }
1140
1141 if (!(player->sfxParamsFlags & SFX_PARAM_FLAG_PAN) && player->masterPan != 0) {
1142 pan = player->masterPan;
1143 } else {
1144 pan = player->sfxPan;
1145 }
1146 if (voice->pan != pan) {
1147 voice->pan = pan;
1149 }
1150
1151 volume = au_sfx_get_scaled_volume(manager, player);
1152 if (voice->clientVolume != volume) {
1153 voice->clientVolume = volume;
1155 }
1156 }
1157 break;
1159 au_SEFCmd_02_SetInstrument(manager, player); // 2 bytes
1160 au_SEFCmd_00_SetVolume(manager, player); // 1 byte
1161 au_SEFCmd_01_SetPan(manager, player); // 1 byte
1162 au_SEFCmd_03_SetReverb(manager, player); // 1 byte
1163 a = (*player->sefDataReadPos++ & 0x7F); // 1 byte
1164 b = (*player->sefDataReadPos & 0xF) << 3; // 1 byte
1165 tune = a * 100;
1166 player->randomPitch = b;
1167 if (player->randomPitch != 0) {
1168 player->tuneLerp.current = au_sfx_get_random_pitch(manager->randomValue, player->randomPitch, tune) << 0x10;
1169 } else {
1170 player->tuneLerp.current = tune << 0x10;
1171 }
1172 if (player->sfxParamsFlags & SFX_PARAM_FLAG_PITCH) {
1173 tune = (player->tuneLerp.current >> 0x10) - player->sfxInstrumentRef->keyBase;
1174 } else {
1175 tune = ((player->tuneLerp.current >> 0x10) - player->sfxInstrumentRef->keyBase) + player->masterPitchShift;
1176 }
1177 player->pitchRatio = au_compute_pitch_ratio(tune) * player->sfxInstrumentRef->pitchRatio;
1178 if (voice->priority <= manager->priority) {
1179 au_reset_nonfree_voice(voice, voiceIdx);
1180 if (!(player->sfxParamsFlags & SFX_PARAM_FLAG_PAN) && player->masterPan != 0) {
1181 voice->pan = player->masterPan;
1182 } else {
1183 voice->pan = player->sfxPan;
1184 }
1185
1186 voice->reverb = player->reverb;
1187 voice->clientVolume = au_sfx_get_scaled_volume(manager, player);
1188 voice->envelope.cmdListPress = player->envelope.cmdListPress;
1190 voice->instrument = player->sfxInstrumentRef;
1191 voice->pitchRatio = player->pitchRatio;
1193 voice->priority = manager->priority;
1194 voice->clientPriority = voice->priority;
1195 voice->busId = manager->busId;
1196 }
1198 break;
1199 default:
1200 player->sefDataReadPos = NULL;
1201 player->curSoundID = 0;
1202 player->priority = 0;
1203 break;
1204 }
1205}
1206
1207static s16 au_sfx_get_scaled_volume(SoundManager* manager, SoundPlayer* player) {
1208 s32 outVolume;
1209
1210 outVolume = (manager->baseVolume * player->sfxVolume) >> 15;
1211 if (!(player->sfxParamsFlags & SFX_PARAM_FLAG_VOLUME) && (player->masterVolume != 0)) {
1212 outVolume = (outVolume * player->masterVolume) >> 15;
1213 }
1214 return outVolume;
1215}
1216
1217static void au_sfx_update_sequence(SoundManager* manager, SoundPlayer* player, AuVoice* voice, u8 voiceIdx) {
1218 s32* var_v0_3;
1219 s32 pitchShift;
1220 s32 temp_a0;
1221 u8 opcode;
1222 u32 playLength;
1223 s32 startedNewVoice;
1224 void (**CmdHandlers)(SoundManager*, SoundPlayer*);
1225
1226 startedNewVoice = FALSE;
1227 if (player->state == SND_PLAYER_STATE_INIT) {
1229 if (voice->priority == manager->priority) {
1230 au_reset_voice(voice, voiceIdx);
1231 }
1232 }
1233
1234 if (player->alternativeDataPos != NULL) {
1235 if (player->triggers == 1) {
1236 player->sefDataReadPos = player->alternativeDataPos;
1237 player->alternativeDataPos = NULL;
1238 player->triggers = 0;
1239 player->delay = 1;
1240 }
1241 }
1242 if (player->triggers == 2) {
1243 player->changed.volume = TRUE;
1244 player->sfxVolume = player->alternativeVolume;
1245 }
1246 player->delay--;
1247 while (player->delay == 0) {
1248 CmdHandlers = SefCmdHandlers;
1249 opcode = *player->sefDataReadPos++;
1250 if (opcode < 0x80) {
1251 if (opcode == 0) {
1252 if (voice->priority == manager->priority) {
1253 au_reset_voice(voice, voiceIdx);
1254 }
1255 player->sefDataReadPos = NULL;
1256 player->curSoundID = 0;
1257 player->priority = 0;
1258 player->exclusiveID = 0;
1259 return;
1260 }
1261 if (opcode >= 0x78) {
1262 // long delay
1263 player->delay = (u8)(*player->sefDataReadPos++) + ((opcode & 7) << 8) + 0x78;
1264 } else {
1265 // short delay
1266 player->delay = opcode;
1267 }
1268 } else if (opcode < 0xD8) {
1269 // play sound
1270 // (opcode & 0x7F) = pitch
1271 if (player->randomPitch != 0) {
1272 player->tuneLerp.current = au_sfx_get_random_pitch(manager->randomValue, player->randomPitch, (opcode & 0x7F) * 100) << 0x10;
1273 } else {
1274 player->tuneLerp.current = ((opcode & 0x7F) * 100) << 0x10;
1275 }
1276
1277 if (player->randomVelocity != 0) {
1278 player->playVelocity = au_sfx_get_random_vol(manager->randomValue, player->randomVelocity, player->sefDataReadPos[0] & 0x7F);
1279 } else {
1280 player->playVelocity = player->sefDataReadPos[0] & 0x7F;
1281 }
1282
1283 playLength = player->sefDataReadPos[1];
1284 if (playLength >= 0xC0) {
1285 playLength = player->sefDataReadPos[2] + ((playLength & 0x3F) << 8) + 0xC0;
1286 player->sefDataReadPos += 3;
1287 } else {
1288 player->sefDataReadPos += 2;
1289 }
1290 player->playLength = playLength;
1291
1292 if (voice->priority <= manager->priority) {
1293 au_reset_nonfree_voice(voice, voiceIdx);
1294 if ((player->sfxParamsFlags & SFX_PARAM_FLAG_PAN) || (player->masterPan == 0)) {
1295 voice->pan = player->sfxPan;
1296 } else {
1297 voice->pan = player->masterPan;
1298 }
1299
1300 voice->reverb = player->reverb;
1301 snd_set_voice_volume(voice, manager, player);
1302 if (player->envelopCustomPressProfile == NULL) {
1303 voice->envelope.cmdListPress = player->envelope.cmdListPress;
1305 } else {
1308 }
1309
1310 voice->instrument = player->sfxInstrumentRef;
1311 voice->busId = manager->busId;
1312
1313 voice->priority = manager->priority;
1315 startedNewVoice = TRUE;
1316 voice->clientPriority = manager->priority;
1317 player->changed.tune = TRUE;
1318 }
1319 } else {
1320 s32 index = opcode - 0xE0;
1321 CurrentSefCmdHandler = CmdHandlers[index];
1322 CurrentSefCmdHandler(manager, player);
1323 }
1324 }
1325
1326 if (player->volumeLerp.time != 0) {
1327 player->volumeLerp.time--;
1328 if (player->volumeLerp.time != 0) {
1329 player->volumeLerp.current += player->volumeLerp.step;
1330 } else {
1331 player->volumeLerp.current = player->volumeLerp.goal << 0x10;
1332 }
1333 player->changed.volume = TRUE;
1334 }
1335
1336 if (!startedNewVoice) {
1337 if (player->playLength != 0) {
1338 player->playLength--;
1339 if ((player->playLength == 0) && (voice->priority == manager->priority)) {
1341 }
1342 }
1343 if (player->tuneLerp.time != 0) {
1344 player->tuneLerp.time--;
1345 if (player->tuneLerp.time != 0) {
1346 player->tuneLerp.current += player->tuneLerp.step;
1347 } else {
1348 player->tuneLerp.current = player->tuneLerp.goal << 0x10;
1349 }
1350 player->changed.tune = TRUE;
1351 }
1352 if (player->changed.pan || player->changed.reverb) {
1353 if ((player->sfxParamsFlags & SFX_PARAM_FLAG_PAN) || (player->masterPan == 0)) {
1354 voice->pan = player->sfxPan;
1355 } else {
1356 voice->pan = player->masterPan;
1357 }
1359 voice->reverb = player->reverb;
1360 }
1361 }
1362 if (player->changed.volume && voice->priority == manager->priority) {
1363 snd_set_voice_volume(voice, manager, player);
1365 }
1366 if (player->changed.tune) {
1367 f32 adjustedPitchRatio;
1368 if (player->sfxParamsFlags & SFX_PARAM_FLAG_PITCH) {
1369 pitchShift = (player->coarseTune + (s16)(player->tuneLerp.current >> 0x10)) - player->sfxInstrumentRef->keyBase;
1370 adjustedPitchRatio = au_compute_pitch_ratio(pitchShift + player->fineTune) * player->sfxInstrumentRef->pitchRatio;
1371 player->pitchRatio = adjustedPitchRatio;
1372 } else {
1373 pitchShift = ((player->coarseTune + (s16)(player->tuneLerp.current >> 0x10)) - player->sfxInstrumentRef->keyBase) + player->fineTune;
1374 adjustedPitchRatio = au_compute_pitch_ratio(pitchShift + player->masterPitchShift) * player->sfxInstrumentRef->pitchRatio;
1375 player->pitchRatio = adjustedPitchRatio;
1376 }
1377 if ((voice->priority == manager->priority) && (voice->pitchRatio != adjustedPitchRatio)) {
1379 voice->pitchRatio = player->pitchRatio;
1380 }
1381 }
1382 player->changed.all = 0;
1383}
1384
1385static void snd_set_voice_volume(AuVoice* voice, SoundManager* manager, SoundPlayer* player) {
1386 s32 x = ((((manager->baseVolume
1387 * player->sfxVolume) >> 0xF)
1388 * player->playVelocity) >> 7)
1389 * (player->volumeLerp.current >> 0x10) >> 0xF;
1390
1391 if (player->sfxParamsFlags & SFX_PARAM_FLAG_VOLUME || player->masterVolume == 0) {
1392 voice->clientVolume = x;
1393 } else {
1394 voice->clientVolume = (x * player->masterVolume) >> 0xF;
1395 }
1396}
1397
1398/*
1399Uses bit masks:
14001F00 = 0001 1111 0000 0000 -> 0001 1111
1401001C = 0000 0000 0001 1100 -> 1110 0000
1402*/
1403static u8 au_sfx_get_random_pan(s32 seed, s32 pan, s32 amplitude) {
1404 s32 tap5, tap3, parity;
1405 s32 lo, hi, random;
1406 s32 retPan;
1407
1408 pan = pan & 0xFF;
1409 tap5 = seed >> 5;
1410 tap3 = seed >> 3;
1411 parity = (tap5 + tap3) & 1;
1412
1413 lo = (seed >> 8) & 0x1F; // bitmask 0x1F00
1414 hi = (seed << 3) & 0xE0; // bitmask 0x001C
1415 random = lo + hi;
1416
1417 if (parity) {
1418 retPan = pan + (((amplitude & 0xFF) * random) >> 8);
1419 } else {
1420 retPan = pan - (((amplitude & 0xFF) * random) >> 8);
1421 }
1422 if (retPan < 0) {
1423 retPan = 0;
1424 } else if (retPan > 0x7F) {
1425 retPan = 0x7F;
1426 }
1427 return retPan;
1428}
1429
1430static void au_SEFCmd_00_SetVolume(SoundManager* manager, SoundPlayer* player) {
1431 player->sfxVolume = *player->sefDataReadPos++;
1432 if (player->sfxVolume != 0) {
1433 player->sfxVolume = player->sfxVolume << 8 | 0xFF;
1434 }
1435 player->changed.volume = TRUE;
1436}
1437
1438static void au_SEFCmd_01_SetPan(SoundManager* manager, SoundPlayer* player) {
1439 s32 sfxPan = *player->sefDataReadPos++;
1440
1441 player->changed.pan = TRUE;
1442 player->sfxPan = sfxPan;
1443}
1444
1445static void au_SEFCmd_02_SetInstrument(SoundManager* manager, SoundPlayer* player) {
1446 AuFilePos buf = player->sefDataReadPos;
1447 s32 bank = buf[0];
1448 s32 patch = buf[1];
1449 player->sefDataReadPos += 2;
1450
1451 player->instrumentIndex = patch;
1452 player->sfxInstrumentRef = au_get_instrument(manager->globals, bank, patch, &player->envelope);
1453}
1454
1455static void au_SEFCmd_03_SetReverb(SoundManager* manager, SoundPlayer* player) {
1456 u8 reverb = *player->sefDataReadPos++;
1457
1459 reverb = manager->defaultReverbAmt;
1460 }
1461 player->reverb = reverb;
1462 player->changed.reverb = TRUE;
1463}
1464
1465static void au_SEFCmd_04_SetEnvelope(SoundManager* manager, SoundPlayer* player) {
1466 Instrument* other;
1467 EnvelopePreset* envPreset;
1468
1469 u8 envelope = *player->sefDataReadPos++;
1470
1471 player->envelopePreset = envelope & 0x7F;
1472 other = player->sfxInstrumentRef;
1473
1474 player->sfxInstrument.base = other->base;
1475 player->sfxInstrument.wavDataLength = other->wavDataLength;
1476 player->sfxInstrument.loopPredictor = other->loopPredictor;
1477 player->sfxInstrument.loopStart = other->loopStart;
1478 player->sfxInstrument.loopEnd = other->loopEnd;
1479 player->sfxInstrument.loopCount = other->loopCount;
1480 player->sfxInstrument.predictor = other->predictor;
1481 player->sfxInstrument.dc_bookSize = other->dc_bookSize;
1482 player->sfxInstrument.keyBase = other->keyBase;
1483 player->sfxInstrument.pitchRatio = other->pitchRatio;
1484 player->sfxInstrument.type = other->type;
1485 player->sfxInstrument.unk_25 = other->unk_25;
1486
1488 player->sfxInstrumentRef = &player->sfxInstrument;
1489
1490 envPreset = player->sfxInstrument.envelopes;
1491 if (envPreset != NULL && envPreset->count != 0) {
1492 player->envelope.cmdListPress = AU_FILE_RELATIVE(envPreset, envPreset->offsets[0].offsetPress);
1493 player->envelope.cmdListRelease = AU_FILE_RELATIVE(envPreset, envPreset->offsets[0].offsetRelease);
1494 }
1495}
1496
1497static void au_SEFCmd_05_CoarseTune(SoundManager* manager, SoundPlayer* player) {
1498 player->coarseTune = (*(s8*)player->sefDataReadPos++) * 100;
1499}
1500
1501static void au_SEFCmd_06_FineTune(SoundManager* manager, SoundPlayer* player) {
1502 player->fineTune = *player->sefDataReadPos++;
1503}
1504
1505static void au_SEFCmd_07_WaitForEnd(SoundManager* manager, SoundPlayer* player) {
1506 if (manager->curVoice->priority == manager->priority) {
1507 player->delay = 2;
1508 player->sefDataReadPos--;
1509 }
1510}
1511
1512static void au_SEFCmd_08_PitchSweep(SoundManager* manager, SoundPlayer* player) {
1513 s32 hi = player->sefDataReadPos[0];
1514 s32 lo = player->sefDataReadPos[1];
1515 s16 newValue = (player->sefDataReadPos[2] & 0x7F) * 100;
1516 s16 time = lo + (hi << 8);
1517 player->sefDataReadPos += 3;
1518
1519 if (time <= 0) {
1520 time = 1;
1521 }
1522
1523 player->tuneLerp.time = time;
1524 player->tuneLerp.goal = newValue;
1525 player->tuneLerp.step = ((newValue << 0x10) - player->tuneLerp.current) / time;
1526}
1527
1528static void au_SEFCmd_09_StartLoop(SoundManager* manager, SoundPlayer* player) {
1529 s32 loopIterCount = *player->sefDataReadPos++;
1530
1531 player->loopStartPos = player->sefDataReadPos;
1532 player->loopIterCount = loopIterCount;
1533}
1534
1535static void au_SEFCmd_0A_EndLoop(SoundManager* manager, SoundPlayer* player) {
1536 if (player->loopIterCount == 0 || --player->loopIterCount != 0) {
1537 player->sefDataReadPos = player->loopStartPos;
1538 }
1539}
1540
1541static void au_SEFCmd_0B_WaitForRelease(SoundManager* manager, SoundPlayer* player) {
1542 if (player->playLength != 0) {
1543 player->delay = 3;
1544 player->sefDataReadPos--;
1545 }
1546}
1547
1548static void au_SEFCmd_0C_SetCurrentVolume(SoundManager* manager, SoundPlayer* player) {
1549 s32 vol = *player->sefDataReadPos++;
1550
1551 if (vol != 0) {
1552 vol = (vol << 0x18) | 0xFFFFFF;
1553 }
1554 player->volumeLerp.current = vol;
1555 player->changed.volume = TRUE;
1556}
1557
1558static void au_SEFCmd_0D_VolumeRamp(SoundManager* manager, SoundPlayer* player) {
1559 s32 hi = player->sefDataReadPos[0];
1560 s32 lo = player->sefDataReadPos[1];
1561 s32 newValue = player->sefDataReadPos[2];
1562 s16 time = lo + (hi << 8);
1563 player->sefDataReadPos += 3;
1564
1565 if (newValue != 0) {
1566 newValue = (newValue << 8) | 0xFF;
1567 }
1568 if (time <= 0) {
1569 time = 1;
1570 }
1571
1572 player->volumeLerp.time = time;
1573 player->volumeLerp.goal = newValue;
1574 player->volumeLerp.step = ((newValue << 0x10) - player->volumeLerp.current) / time;
1575}
1576
1577static void au_SEFCmd_0E_SetAlternativeSound(SoundManager* manager, SoundPlayer* player) {
1578 s32 hi = player->sefDataReadPos[1];
1579 s32 lo = player->sefDataReadPos[2];
1580 AuFilePos pos = AU_FILE_RELATIVE(manager->sefData, (hi << 8) + lo);
1581 u8 type = player->sefDataReadPos[0];
1582 player->sefDataReadPos += 3;
1583
1584 player->alternativeType = type;
1585 switch (type) {
1586 case 1:
1587 player->alternativeDataPos = pos;
1588 break;
1589 case 2:
1590 player->alternativeDataPos = pos;
1591 break;
1592 case 3:
1593 player->alternativeDataPos = pos;
1594 break;
1595 default:
1596 player->alternativeDataPos = NULL;
1597 break;
1598 }
1599}
1600
1601static void au_SEFCmd_0F_Stop(SoundManager* manager, SoundPlayer* player) {
1602 AuVoice* voice = manager->curVoice;
1603 if (voice->priority == manager->priority) {
1604 au_reset_voice(voice, manager->curVoiceIndex);
1605 }
1606}
1607
1608static void au_SEFCmd_10_Jump(SoundManager* manager, SoundPlayer* player) {
1609 AuFilePos buf = player->sefDataReadPos;
1610 player->sefReadStart = &buf[2];
1611 player->sefDataReadPos = AU_FILE_RELATIVE(manager->sefData, (buf[0] << 8) + buf[1]);
1612}
1613
1614static void au_SEFCmd_11_Restart(SoundManager* manager, SoundPlayer* player) {
1615 player->sefDataReadPos = player->sefReadStart;
1616}
1617
1618static void au_SEFCmd_12_NOP(SoundManager* manager, SoundPlayer* player) {
1619}
1620
1621static void au_SEFCmd_13_SetRandomPitch(SoundManager* manager, SoundPlayer* player) {
1622 player->randomPitch = *player->sefDataReadPos++;
1623}
1624
1625static void au_SEFCmd_14_SetRandomVelocity(SoundManager* manager, SoundPlayer* player) {
1626 player->randomVelocity = *player->sefDataReadPos++;
1627}
1628
1629static void au_SEFCmd_15_SetUnkA3(SoundManager* manager, SoundPlayer* player) {
1630 player->unk_A3 = *player->sefDataReadPos++;;
1631}
1632
1633static void au_SEFCmd_16_SetEnvelopePress(SoundManager* manager, SoundPlayer* player) {
1634 AuFilePos buf = player->sefDataReadPos;
1635 s32 offset = (buf[0] << 8) + buf[1];
1636
1637 if (offset != 0) {
1638 player->envelopCustomPressProfile = AU_FILE_RELATIVE(manager->sefData, offset);
1639 } else {
1640 player->envelopCustomPressProfile = NULL;
1641 }
1642
1643 player->sefDataReadPos = &buf[2];
1644}
1645
1646static void au_SEFCmd_17_PlaySound(SoundManager* manager, SoundPlayer* player) {
1647 AuFilePos buf = player->sefDataReadPos;
1648 u32 i;
1649
1650 for (i = 0; i < ARRAY_COUNT(manager->customCmdList); i++) {
1651 if (manager->customCmdList[i].data[0] == 0) {
1652 manager->customCmdList[i].data[0] = buf[1] + (buf[0] << 8);
1653 manager->customCmdList[i].data[1] = buf[3] + (buf[2] << 8);
1654 break;
1655 }
1656 }
1657 player->sefDataReadPos = &buf[4];
1658}
1659
1660static void au_SEFCmd_18_SetAlternativeVolume(SoundManager* manager, SoundPlayer* player) {
1661 player->alternativeVolume = *player->sefDataReadPos++;
1662 if (player->alternativeVolume != 0) {
1663 player->alternativeVolume = player->alternativeVolume << 8 | 0xFF;
1664 }
1665}
1666
1667/*
1668Uses bit masks:
1669780 = 0111 1000 0000 -> 0000 1111
167001E = 0000 0001 1110 -> 1111 0000
1671*/
1672static s32 au_sfx_get_random_pitch(s32 seed, s32 amplitude, s32 pitch) {
1673 s32 lo = (seed >> 7) & 0xF; // bitmask 0x780
1674 s32 hi = (seed << 3) & 0xF0; // bitmask 0x01E
1675 s32 random = (lo + hi);
1676 s32 tap5 = (seed >> 5);
1677 s32 tap2 = (seed >> 2);
1678 s32 parity = (tap5 + tap2) & 1;
1679
1680 if (parity) {
1681 return pitch + ((amplitude * 5 * random) >> 8);
1682 } else {
1683 return pitch - ((amplitude * 5 * random) >> 8);
1684 }
1685}
1686
1687/*
1688Uses bit masks:
1689CC = 1100 1100 -> 0011 0011
169013 = 0001 0011 -> 0100 1100
1691*/
1692static u8 au_sfx_get_random_vol(s32 seed, s32 amplitude, s32 volume) {
1693 s32 lo = (seed & 0xCC) >> 2;
1694 s32 hi = (seed & 0x13) << 2;
1695 s32 random = lo + hi;
1696
1697 return volume * (0x8000 - (amplitude * random)) >> 0xF;
1698}
1699
1700static void au_sfx_reset_players(SoundManager* manager) {
1701 s32 i;
1702
1703 for (i = 0; i < ARRAY_COUNT(manager->players); i++) {
1704 SoundPlayer* player = &manager->players[i];
1705 player->sefDataReadPos = BlankSEFData;
1706 player->alternativeDataPos = NULL;
1709 player->delay = 1;
1710 player->priority = 0;
1711 player->exclusiveID = 0;
1712 }
1713}
void au_BGMCmd_EB_SubTrackReverb(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_F6_TrackVolumeFade(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_F4(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_FD_EventTrigger(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_F7_SubTrackReverbType(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_FC_Jump(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_EE_SubTrackFineTune(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_FE_Detour(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_E3(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_EA_SubTrackPan(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_F2_TrackTremoloTime(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_E5_MasterVolumeFade(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_F1_TrackTremoloSpeed(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_E0_MasterTempo(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_E8_TrackOverridePatch(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_F0_TrackTremolo(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_EC_SegTrackVolume(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_E9_SubTrackVolume(BGMPlayer *arg0, BGMPlayerTrack *track)
void au_BGMCmd_NOP(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_E2_MasterPitchShift(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_F5_TrackVoice(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_E6_MasterEffect(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_FF(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_ED_SubTrackCoarseTune(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_E1_MasterVolume(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_F3_TrackTremoloStop(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_E4_MasterTempoFade(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_EF_SegTrackTune(BGMPlayer *player, BGMPlayerTrack *track)
void au_reset_voice(AuVoice *voice, u8 voiceIdx)
Instrument * au_get_instrument(AuGlobals *globals, u32 bank, u32 patch, EnvelopeData *envData)
void au_fade_set_volume(u8 busId, u16 volume, s32 busVolume)
f32 au_compute_pitch_ratio(s32 pitch)
void au_fade_init(Fade *fade, s32 time, s32 startValue, s32 endValue)
void au_reset_nonfree_voice(AuVoice *voice, u8 index)
s32 * extraSounds
Definition audio.h:663
u8 randomVelocity
Definition audio.h:633
@ SND_MANAGER_STATE_DISABLED
Definition audio.h:238
@ SND_MANAGER_STATE_ENABLED
Definition audio.h:237
f32 pitchRatio
Definition audio.h:604
u8 * sefData
Definition audio.h:661
u8 * cmdListPress
Definition audio.h:533
VolumeField curVolume
Definition audio.h:366
Instrument * sfxInstrumentRef
Definition audio.h:600
u8 instrumentIndex
Definition audio.h:628
u16 * predictor
Definition audio.h:556
u8 curVoiceIndex
Definition audio.h:683
s32 * customReverbParams[8]
Definition audio.h:671
u8 lastCustomEffectIdx
Definition audio.h:673
u16 soundID
Definition audio.h:524
u16 playLength
Definition audio.h:618
AuVoice voices[24]
Definition audio.h:938
AuFilePos sefDataReadPos
Definition audio.h:596
@ AU_FX_CUSTOM_0
Definition audio.h:93
s8 alternativeType
Definition audio.h:611
u8 * cmdListRelease
Definition audio.h:534
EnvelopeData envelope
Definition audio.h:721
@ ENV_CMD_END
Definition audio.h:130
Instrument * defaultInstrument
Definition audio.h:891
s16 pitchShift
Definition audio.h:527
SoundLerp volumeLerp
Definition audio.h:608
struct AuGlobals * globals
Definition audio.h:659
u8 randomPitch
Definition audio.h:632
s32 nextUpdateInterval
Definition audio.h:666
struct Fade fadeInfo
Definition audio.h:668
u16 sound1
Definition audio.h:1174
s16 coarseTune
Definition audio.h:619
s32 loopEnd
Definition audio.h:554
s16 masterPitchShift
Definition audio.h:635
u8 masterPan
Definition audio.h:637
SoundPlayChange changed
Definition audio.h:603
SoundManager90 bgmSounds[4]
Definition audio.h:676
SoundLerp tuneLerp
Definition audio.h:607
s32 step
Definition audio.h:578
EnvelopeOffset offsets[1]
Definition audio.h:545
u16 baseVolume
Definition audio.h:678
s32 current
Definition audio.h:577
u8 reverb
Definition audio.h:627
u16 offsetPress
Definition audio.h:538
s16 alternativeVolume
Definition audio.h:606
AuFilePos alternativeDataPos
Definition audio.h:610
u8 envelopePreset
Definition audio.h:629
s32 * normalSounds[8]
Definition audio.h:662
#define AU_FILE_RELATIVE(base, offset)
Definition audio.h:40
f32 pitchRatio
Definition audio.h:714
SoundPlayer players[8]
Definition audio.h:693
s32 playCounter
Definition audio.h:664
u32 wavDataLength
Definition audio.h:551
s32 randomValue
Definition audio.h:670
s32 loopCount
Definition audio.h:555
Instrument sfxInstrument
Definition audio.h:601
u16 dc_bookSize
Definition audio.h:557
s16 masterVolume
Definition audio.h:636
u8 cmdList_mode2[8]
Definition audio.h:609
@ 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
s32 busVolume
Definition audio.h:669
u8 * base
Definition audio.h:550
s8 clientPriority
Definition audio.h:740
s32 nextUpdateStep
Definition audio.h:665
s32 loopStart
Definition audio.h:553
s16 clientVolume
Definition audio.h:737
u8 priority
Definition audio.h:623
SoundManagerCustomCmdList customCmdList[4]
Definition audio.h:677
@ FX_BUS_SOUND
Definition audio.h:120
u8 pan
Definition audio.h:717
s16 time
Definition audio.h:579
u8 sfxQueueNextPos
Definition audio.h:689
u8 triggers
Definition audio.h:612
u8 syncFlags
Definition audio.h:739
u8 sfxPlayerSelector
Definition audio.h:681
u16 u16
Definition audio.h:360
u8 exclusiveID
Definition audio.h:624
EnvelopeData envelope
Definition audio.h:598
u8 sfxParamsFlags
Definition audio.h:625
UNK_PTR loopPredictor
Definition audio.h:552
u16 curSoundID
Definition audio.h:622
u16 sections[8]
Definition audio.h:810
Instrument * instrument
Definition audio.h:713
@ SND_PLAYER_STATE_INIT
Definition audio.h:233
@ SND_PLAYER_STATE_CONTINUE
Definition audio.h:232
EnvelopePreset * envelopes
Definition audio.h:571
u8 envelopeFlags
Definition audio.h:734
u16 section2000
Definition audio.h:811
s16 sfxVolume
Definition audio.h:605
s32 nextUpdateCounter
Definition audio.h:667
s8 fineTune
Definition audio.h:620
s8 unk_A3
Definition audio.h:634
u8 reverb
Definition audio.h:718
u8 sfxQueuePosOffset
Definition audio.h:688
u16 keyBase
Definition audio.h:558
SoundSFXEntry soundQueue[16]
Definition audio.h:686
u16 offsetRelease
Definition audio.h:539
#define AU_5750
Definition audio.h:22
u16 delay
Definition audio.h:617
s8 customReverbAmounts[8]
Definition audio.h:672
s8 * loopStartPos
Definition audio.h:614
u8 loopIterCount
Definition audio.h:615
u8 unk_25
Definition audio.h:564
s16 goal
Definition audio.h:580
u8 priority
Definition audio.h:680
u16 upperSoundID
Definition audio.h:525
s32 resetPending
Definition audio.h:692
AuEffectChange effectChanges[4]
Definition audio.h:903
u8 unk_A0
Definition audio.h:631
u8 * AuFilePos
Definition audio.h:14
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 * envelopCustomPressProfile
Definition audio.h:599
@ ENV_TIME_280MS
Definition audio.h:195
@ ENV_TIME_1100MS
Definition audio.h:176
@ ENV_TIME_1800MS
Definition audio.h:169
@ ENV_TIME_2UNITS
Definition audio.h:226
@ ENV_TIME_1400MS
Definition audio.h:173
@ ENV_TIME_3S
Definition audio.h:163
@ ENV_TIME_1S
Definition audio.h:177
@ ENV_TIME_450MS
Definition audio.h:188
@ ENV_TIME_900MS
Definition audio.h:179
@ ENV_TIME_550MS
Definition audio.h:186
@ ENV_TIME_290MS
Definition audio.h:194
u8 playVelocity
Definition audio.h:630
s8 defaultReverbAmt
Definition audio.h:674
AuFilePos sefReadStart
Definition audio.h:602
u8 type
Definition audio.h:563
u8 priority
Definition audio.h:741
SEFHeader * dataSEF
Definition audio.h:924
struct AuVoice * curVoice
Definition audio.h:660
u8 hasExtraSection
Definition audio.h:808
u16 sound2
Definition audio.h:1175
u8 sfxPan
Definition audio.h:626
Vec3s pos
Definition demo_api.c:17
@ SOUND_ID_ADJUST
Definition enums.h:529
@ SOUND_ID_UNK_INDEX_MASK
Definition enums.h:535
@ SOUND_ID_TRIGGER_MASK
Definition enums.h:530
@ SOUND_ID_STOP
Definition enums.h:526
@ SOUND_ID_UNK
Definition enums.h:528
@ SOUND_ID_LOWER
Definition enums.h:527
@ SOUND_LRAW_CHEERING
Definition enums.h:1151
@ SOUND_NONE
Definition enums.h:547
@ SOUND_SHORT_CLAP
Definition enums.h:1152
#define ARRAY_COUNT(arr)
Definition macros.h:40
s8 D_80078558[]
Definition sfx_player.c:317
s32 CUSTOM_ECHO_PARAMS_1[]
Definition sfx_player.c:95
u8 EnvelopeReleaseDefault[]
Definition sfx_player.c:304
u8 EnvelopePressDefault[]
Definition sfx_player.c:299
s32 CUSTOM_SMALL_ROOM_PARAMS[]
Definition sfx_player.c:84
void au_sfx_set_state(SoundManager *manager, s32 state)
Definition sfx_player.c:684
EnvelopePreset DummyInstrumentEnvelope
Definition sfx_player.c:294
void(* SefCmdHandlers[])(SoundManager *, SoundPlayer *)
Definition sfx_player.c:192
s32 AuEnvelopeIntervals[]
Definition sfx_player.c:341
u8 EnvelopeReleaseDefaultFast[]
Definition sfx_player.c:309
s8 BgmDivisors[]
Definition sfx_player.c:271
#define SEC(x)
Definition sfx_player.c:339
u8 AmbientSoundIDtoMSEQFileIndex[]
Definition sfx_player.c:328
s16 D_80078530[]
Definition sfx_player.c:289
s16 au_sfx_manager_update(SoundManager *manager)
u8 SFXEnvelopeFastData[]
Definition sfx_player.c:135
s32 CUSTOM_ECHO_PARAMS_3[]
Definition sfx_player.c:113
void au_sfx_load_sound(SoundManager *manager, SoundSFXEntry *entry, SoundManagerCustomCmdList *customSEF)
Definition sfx_player.c:692
EnvelopePreset * SFXEnvelopePresets[]
Definition sfx_player.c:173
#define NEXT_CMD
EnvelopePreset SFXEnvelopeFast
Definition sfx_player.c:130
s8 SeqCmdArgCounts[]
Definition sfx_player.c:264
f32 AlTuneScaling[]
Definition sfx_player.c:360
s32 * AU_FX_CUSTOM_PARAMS[0]
Definition reverb.c:103
u16 DummyInstrumentPredictor[32]
Definition sfx_player.c:61
u8 SFXEnvelopeSlowData[]
Definition sfx_player.c:152
u8 DummyInstrumentBase[190]
Definition sfx_player.c:68
void au_sfx_update_main(SoundManager *manager)
Definition sfx_player.c:569
EnvelopePreset SFXEnvelopeSlow
Definition sfx_player.c:147
s32 CUSTOM_ECHO_PARAMS_2[]
Definition sfx_player.c:104
void au_sfx_enqueue_event(SoundManager *manager, u32 soundID, s16 volume, s16 pitchShift, u8 pan)
Definition sfx_player.c:543
u8 BlankMseqData[]
Definition sfx_player.c:279
s32 D_800783B0[]
Definition sfx_player.c:169
SoundEffectParamFlags
Definition sfx_player.c:45
@ SFX_PARAM_MODE_SEQUENCE
Definition sfx_player.c:49
@ SFX_PARAM_FLAG_FIXED_REVERB
Definition sfx_player.c:58
@ SFX_PARAM_FLAG_MODE
Definition sfx_player.c:52
@ SFX_PARAM_FLAG_PITCH
Definition sfx_player.c:56
@ SFX_PARAM_FLAG_PAN
Definition sfx_player.c:55
@ SFX_PARAM_MODE_ADVANCED
Definition sfx_player.c:47
@ SFX_PARAM_MODE_BASIC
Definition sfx_player.c:51
@ SFX_PARAM_FLAG_VOLUME
Definition sfx_player.c:54
void au_sfx_clear_queue(SoundManager *manager)
Definition sfx_player.c:526
void(* CurrentSefCmdHandler)(SoundManager *, SoundPlayer *)
Definition sfx_player.c:421
void au_sfx_init(SoundManager *manager, u8 priority, u8 busId, AuGlobals *globals, u8 minVoiceIdx)
Definition sfx_player.c:423
s32 au_sfx_set_reverb_type(SoundManager *manager, s32 arg1)
Definition sfx_player.c:664
void(* SeqCmdHandlers[])(BGMPlayer *, BGMPlayerTrack *)
Definition sfx_player.c:229
AlUnkGemini D_80078370[]
Definition sfx_player.c:121
void au_sfx_load_groups_from_SEF(SoundManager *manager)
Definition sfx_player.c:506
u8 BlankSEFData[]
Definition sfx_player.c:220