Set names for sndp functions

This commit is contained in:
Ryan Dwyer 2025-01-21 20:20:18 +10:00
parent 9839a54b55
commit 9550c72151
25 changed files with 333 additions and 310 deletions

View File

@ -931,7 +931,7 @@ typedef struct {
s32 maxEvents;
s32 maxSounds;
ALHeap *heap;
u16 unk10;
u16 maxVolumes;
} ALSndpConfig;
typedef struct {

View File

@ -19,8 +19,8 @@ void bcutscene_init(void)
for (j = 0; j < 1; j++) {
struct hand *hand = &g_Vars.players[i]->hands[j];
if (hand->audiohandle && sndGetState(hand->audiohandle) != AL_STOPPED) {
audioStop(hand->audiohandle);
if (hand->audiohandle && sndp_get_state(hand->audiohandle) != AL_STOPPED) {
sndp_stop_sound(hand->audiohandle);
hand->audiohandle = NULL;
}

View File

@ -684,7 +684,7 @@ void bgun_tick_anim(struct hand *hand, struct modeldef *modeldef)
if (hasspeed && audiohandle) {
hasspeed = false;
audioPostEvent(audiohandle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
sndp_post_event(audiohandle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
}
#endif
break;
@ -1806,12 +1806,12 @@ void bgun0f09a6f8(struct handweaponinfo *info, s32 handnum, struct hand *hand, s
osSetThreadPri(0, osGetThreadPri(&g_AudioManager.thread) + 1);
#endif
if (hand->audiohandle2 && sndGetState(hand->audiohandle2) != AL_STOPPED) {
audioStop(hand->audiohandle2);
if (hand->audiohandle2 && sndp_get_state(hand->audiohandle2) != AL_STOPPED) {
sndp_stop_sound(hand->audiohandle2);
}
if (hand->audiohandle3 && sndGetState(hand->audiohandle3) != AL_STOPPED) {
audioStop(hand->audiohandle3);
if (hand->audiohandle3 && sndp_get_state(hand->audiohandle3) != AL_STOPPED) {
sndp_stop_sound(hand->audiohandle3);
}
if (gset_get_single_shoot_sound(&hand->gset)) {
@ -1836,7 +1836,7 @@ void bgun0f09a6f8(struct handweaponinfo *info, s32 handnum, struct hand *hand, s
tmp = 1.0f - frac * 0.4f;
audioPostEvent(handle, AL_SNDP_PITCH_EVT, *(s32 *) &tmp);
sndp_post_event(handle, AL_SNDP_PITCH_EVT, *(s32 *) &tmp);
}
}
@ -2455,7 +2455,7 @@ s32 bgun_tick_inc_attackempty(struct handweaponinfo *info, s32 handnum, struct h
handle = snd_start(var80095200, SFX_HIT_WATER, NULL, -1, -1, -1, -1, -1);
if (handle) {
audioPostEvent(handle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
sndp_post_event(handle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
}
#if VERSION >= VERSION_NTSC_1_0
@ -2481,7 +2481,7 @@ s32 bgun_tick_inc_attackempty(struct handweaponinfo *info, s32 handnum, struct h
handle = snd_start(var80095200, SFX_FIREEMPTY, NULL, -1, -1, -1, -1, -1);
if (handle) {
audioPostEvent(handle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
sndp_post_event(handle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
}
#if VERSION >= VERSION_NTSC_1_0
@ -2865,7 +2865,7 @@ s32 bgun_tick_inc_changegun(struct handweaponinfo *info, s32 handnum, struct han
handle1 = snd_start(var80095200, SFX_EQUIP_HORIZONSCANNER, 0, -1, -1, -1, -1, -1);
if (handle1) {
audioPostEvent(handle1, AL_SNDP_PITCH_EVT, *(s32 *)&speed1);
sndp_post_event(handle1, AL_SNDP_PITCH_EVT, *(s32 *)&speed1);
}
#if VERSION >= VERSION_NTSC_1_0
@ -2908,7 +2908,7 @@ s32 bgun_tick_inc_changegun(struct handweaponinfo *info, s32 handnum, struct han
handle2 = snd_start(var80095200, SFX_PICKUP_GUN, 0, -1, -1, -1, -1, -1);
if (handle2) {
audioPostEvent(handle2, AL_SNDP_PITCH_EVT, *(s32 *)&speed2);
sndp_post_event(handle2, AL_SNDP_PITCH_EVT, *(s32 *)&speed2);
}
#if VERSION >= VERSION_NTSC_1_0
@ -2926,7 +2926,7 @@ s32 bgun_tick_inc_changegun(struct handweaponinfo *info, s32 handnum, struct han
handle3 = snd_start(var80095200, SFX_PICKUP_GUN, 0, -1, -1, -1, -1, -1);
if (handle3) {
audioPostEvent(handle3, AL_SNDP_PITCH_EVT, *(s32 *)&speed3);
sndp_post_event(handle3, AL_SNDP_PITCH_EVT, *(s32 *)&speed3);
}
#if VERSION >= VERSION_NTSC_1_0
@ -5372,8 +5372,8 @@ void bgun_tick_switch2(void)
anim_init(&player->hands[i].anim);
if (player->hands[i].audiohandle && sndGetState(player->hands[i].audiohandle) != AL_STOPPED) {
audioStop(player->hands[i].audiohandle);
if (player->hands[i].audiohandle && sndp_get_state(player->hands[i].audiohandle) != AL_STOPPED) {
sndp_stop_sound(player->hands[i].audiohandle);
}
}
@ -6798,14 +6798,14 @@ void bgun_update_reaper(struct hand *hand, struct modeldef *modeldef)
s32 volume = AL_VOL_FULL;
if (hand->mm_reaperspeedcur < 0.1f) {
audioStop(hand->audiohandle);
sndp_stop_sound(hand->audiohandle);
} else {
if (hand->mm_reaperspeedcur < 0.6f) {
volume = (hand->mm_reaperspeedcur - 0.1f) * AL_VOL_FULL / 0.5f;
}
audioPostEvent(hand->audiohandle, AL_SNDP_VOL_EVT, volume);
audioPostEvent(hand->audiohandle, AL_SNDP_PITCH_EVT, *(s32 *)&sp34);
sndp_post_event(hand->audiohandle, AL_SNDP_VOL_EVT, volume);
sndp_post_event(hand->audiohandle, AL_SNDP_PITCH_EVT, *(s32 *)&sp34);
}
}
@ -6955,8 +6955,8 @@ void bgun_update_laser(struct hand *hand)
hand->mm_lasertype = 1;
} else if (hand->mm_lasertype > 0) {
hand->mm_lasertype -= LVUPDATE60FREAL() / 10.0f;
} else if (hand->audiohandle != NULL && sndGetState(hand->audiohandle) != AL_STOPPED) {
audioStop(hand->audiohandle);
} else if (hand->audiohandle != NULL && sndp_get_state(hand->audiohandle) != AL_STOPPED) {
sndp_stop_sound(hand->audiohandle);
}
}
@ -7928,7 +7928,7 @@ void bgun_tick_mauler_charge(void)
* its speed is adjusted, the game raises the priority of the main
* thread (this thread) to above the audio thread's priority so that
* the audio thread cannot execute and start playing the audio
* between the calls to snd_start and audioPostEvent. But this pattern
* between the calls to snd_start and sndp_post_event. But this pattern
* is not done here.
*
* There is a known issue where the Mauler charge sound is played
@ -7950,9 +7950,9 @@ void bgun_tick_mauler_charge(void)
f32 speed = 0.5f + hand->mm_maulercharge / 3.0f + sinf(g_20SecIntervalFrac * DTOR(180) * 32.0f) * 0.03f;
if (hand->mm_maulercharge < 0.1f || !charging) {
audioStop(hand->audiohandle);
sndp_stop_sound(hand->audiohandle);
} else {
audioPostEvent(hand->audiohandle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
sndp_post_event(hand->audiohandle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
}
}
}
@ -8040,7 +8040,7 @@ void bgun_tick_gameplay2(void)
hand = &player->hands[i];
if (hand->audiohandle) {
audioStop(hand->audiohandle);
sndp_stop_sound(hand->audiohandle);
}
}
}
@ -8124,12 +8124,12 @@ s8 bgun_free_fireslot_wrapper(s32 slotnum)
{
#if VERSION < VERSION_NTSC_1_0
if (slotnum >= 0) {
if (g_Fireslots[slotnum].unk04nb && sndGetState(g_Fireslots[slotnum].unk04nb) != AL_STOPPED) {
audioStop(g_Fireslots[slotnum].unk04nb);
if (g_Fireslots[slotnum].unk04nb && sndp_get_state(g_Fireslots[slotnum].unk04nb) != AL_STOPPED) {
sndp_stop_sound(g_Fireslots[slotnum].unk04nb);
}
if (g_Fireslots[slotnum].unk08nb && sndGetState(g_Fireslots[slotnum].unk08nb) != AL_STOPPED) {
audioStop(g_Fireslots[slotnum].unk08nb);
if (g_Fireslots[slotnum].unk08nb && sndp_get_state(g_Fireslots[slotnum].unk08nb) != AL_STOPPED) {
sndp_stop_sound(g_Fireslots[slotnum].unk08nb);
}
}
#endif

View File

@ -16,8 +16,8 @@ void bgun_stop(void)
for (j = 0; j < 2; j++) {
struct hand *hand = &g_Vars.players[i]->hands[j];
if (hand->audiohandle2 && sndGetState(hand->audiohandle2) != AL_STOPPED) {
audioStop(hand->audiohandle2);
if (hand->audiohandle2 && sndp_get_state(hand->audiohandle2) != AL_STOPPED) {
sndp_stop_sound(hand->audiohandle2);
}
}
}

View File

@ -48,7 +48,7 @@ void casing_tick(struct casing *casing)
snd_start(var80095200, SFX_8051, &g_CasingAudioHandles[i], -1, -1, -1.0f, -1, -1);
if (g_CasingAudioHandles[i]) {
audioPostEvent(g_CasingAudioHandles[i], AL_SNDP_PITCH_EVT, *(s32 *)&sp58);
sndp_post_event(g_CasingAudioHandles[i], AL_SNDP_PITCH_EVT, *(s32 *)&sp58);
}
}

View File

@ -9274,7 +9274,7 @@ bool ai_chr_begin_or_end_teleport(void)
handle = snd_start(var80095200, SFX_RELOAD_FARSIGHT, NULL, -1, -1, -1, -1, -1);
if (handle) {
audioPostEvent(handle, AL_SNDP_PITCH_EVT, *(u32 *)&fvalue);
sndp_post_event(handle, AL_SNDP_PITCH_EVT, *(u32 *)&fvalue);
}
#if VERSION >= VERSION_NTSC_1_0
@ -9325,7 +9325,7 @@ bool ai_if_chr_teleport_full_white(void)
handle = snd_start(var80095200, SFX_FIRE_SHOTGUN, NULL, -1, -1, -1, -1, -1);
if (handle) {
audioPostEvent(handle, AL_SNDP_PITCH_EVT, *(u32 *)&fvalue);
sndp_post_event(handle, AL_SNDP_PITCH_EVT, *(u32 *)&fvalue);
}
#if VERSION >= VERSION_NTSC_1_0

View File

@ -2122,22 +2122,22 @@ void lights_update_goggle_sounds(void)
} else {
// Room is dark enough for night vision - stop overload sound if active
if (g_Vars.currentplayer->nvoverload != NULL) {
if (sndGetState(g_Vars.currentplayer->nvoverload) != AL_STOPPED) {
audioStop(g_Vars.currentplayer->nvoverload);
if (sndp_get_state(g_Vars.currentplayer->nvoverload) != AL_STOPPED) {
sndp_stop_sound(g_Vars.currentplayer->nvoverload);
}
}
}
} else {
// Paused or not wearing night vision - stop both sounds
if (g_Vars.currentplayer->nvhum != NULL) {
if (sndGetState(g_Vars.currentplayer->nvhum) != NULL) {
audioStop(g_Vars.currentplayer->nvhum);
if (sndp_get_state(g_Vars.currentplayer->nvhum) != AL_STOPPED) {
sndp_stop_sound(g_Vars.currentplayer->nvhum);
}
}
if (g_Vars.currentplayer->nvoverload != NULL) {
if (sndGetState(g_Vars.currentplayer->nvoverload) != NULL) {
audioStop(g_Vars.currentplayer->nvoverload);
if (sndp_get_state(g_Vars.currentplayer->nvoverload) != AL_STOPPED) {
sndp_stop_sound(g_Vars.currentplayer->nvoverload);
}
}
}

View File

@ -1608,8 +1608,8 @@ void hudmsgs_stop(void)
}
#if VERSION < VERSION_NTSC_1_0
if (var800736b0nb && sndGetState(var800736b0nb) != AL_STOPPED) {
audioStop(var800736b0nb);
if (var800736b0nb && sndp_get_state(var800736b0nb) != AL_STOPPED) {
sndp_stop_sound(var800736b0nb);
}
#endif
}

View File

@ -194,7 +194,7 @@ void lv_set_misc_sfx_state(u32 type, bool play)
s32 index = lv_get_misc_sfx_index(type);
if (index != -1) {
audioStop(g_MiscSfxAudioHandles[index]);
sndp_stop_sound(g_MiscSfxAudioHandles[index]);
#if VERSION < VERSION_NTSC_1_0
g_MiscSfxAudioHandles[index] = 0;
#endif
@ -231,8 +231,8 @@ void lv_update_misc_sfx(void)
lv_set_misc_sfx_state(MISCSFX_SLAYERROCKETBEEP, usingrocket);
}
if (g_Vars.lvupdate240 == 0 && g_MiscAudioHandle && sndGetState(g_MiscAudioHandle) != AL_STOPPED) {
audioStop(g_MiscAudioHandle);
if (g_Vars.lvupdate240 == 0 && g_MiscAudioHandle && sndp_get_state(g_MiscAudioHandle) != AL_STOPPED) {
sndp_stop_sound(g_MiscAudioHandle);
}
}
@ -1434,7 +1434,7 @@ Gfx *lv_render(Gfx *gdl)
}
if (g_CutsceneStaticAudioHandle && !cutscenehasstatic) {
audioStop(g_CutsceneStaticAudioHandle);
sndp_stop_sound(g_CutsceneStaticAudioHandle);
}
// Slayer rocket shows static when flying out of bounds
@ -2376,8 +2376,8 @@ void lv_stop(void)
{
paks_stop(true);
if (g_MiscAudioHandle && sndGetState(g_MiscAudioHandle)) {
audioStop(g_MiscAudioHandle);
if (g_MiscAudioHandle && sndp_get_state(g_MiscAudioHandle) != AL_STOPPED) {
sndp_stop_sound(g_MiscAudioHandle);
}
if (g_Vars.stagenum < STAGE_TITLE) {
@ -2407,7 +2407,7 @@ void lv_stop(void)
bg_stop();
}
func00033dd8();
sndp_stop_all();
if (g_FileState == FILESTATE_CHANGINGAGENT) {
menu_play_sound(MENUSOUND_EXPLOSION);

View File

@ -195,11 +195,11 @@ void menu_play_sound(s32 menusound)
handle = snd_start(var80095200, sound, NULL, -1, -1, -1, -1, -1);
if (handle && setpitch) {
audioPostEvent(handle, AL_SNDP_PITCH_EVT, *(s32 *)&pitch);
sndp_post_event(handle, AL_SNDP_PITCH_EVT, *(s32 *)&pitch);
}
if (handle && setvol) {
audioPostEvent(handle, AL_SNDP_VOL_EVT, 0x4000);
sndp_post_event(handle, AL_SNDP_VOL_EVT, 0x4000);
}
#if VERSION >= VERSION_NTSC_1_0

View File

@ -1935,7 +1935,7 @@ void mp_calculate_awards(void)
duration60 = player_get_mission_time();
func00033dd8();
sndp_stop_all();
numchrs = mp_get_player_rankings(playerrankings);
#if VERSION >= VERSION_NTSC_1_0

View File

@ -607,32 +607,32 @@ void nbombs_tick(void)
volume = 0;
}
audioPostEvent(g_NbombAudioHandle, AL_SNDP_VOL_EVT, volume);
audioPostEvent(g_NbombAudioHandle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
sndp_post_event(g_NbombAudioHandle, AL_SNDP_VOL_EVT, volume);
sndp_post_event(g_NbombAudioHandle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
}
} else {
if (g_NbombAudioHandle && sndGetState(g_NbombAudioHandle) != AL_STOPPED) {
audioStop(g_NbombAudioHandle);
if (g_NbombAudioHandle && sndp_get_state(g_NbombAudioHandle) != AL_STOPPED) {
sndp_stop_sound(g_NbombAudioHandle);
}
}
} else {
if (g_NbombAudioHandle && sndGetState(g_NbombAudioHandle) != AL_STOPPED) {
audioStop(g_NbombAudioHandle);
if (g_NbombAudioHandle && sndp_get_state(g_NbombAudioHandle) != AL_STOPPED) {
sndp_stop_sound(g_NbombAudioHandle);
}
}
if (g_Vars.lvupdate240 == 0) {
for (i = 0; i < ARRAYCOUNT(g_Nbombs); i++) {
if (g_Nbombs[i].age240 >= 0) {
if (g_Nbombs[i].audiohandle20 && sndGetState(g_Nbombs[i].audiohandle20) != AL_STOPPED) {
audioStop(g_Nbombs[i].audiohandle20);
if (g_Nbombs[i].audiohandle20 && sndp_get_state(g_Nbombs[i].audiohandle20) != AL_STOPPED) {
sndp_stop_sound(g_Nbombs[i].audiohandle20);
#if VERSION < VERSION_NTSC_1_0
g_Nbombs[i].audiohandle20 = NULL;
#endif
}
if (g_Nbombs[i].audiohandle24 && sndGetState(g_Nbombs[i].audiohandle24) != AL_STOPPED) {
audioStop(g_Nbombs[i].audiohandle24);
if (g_Nbombs[i].audiohandle24 && sndp_get_state(g_Nbombs[i].audiohandle24) != AL_STOPPED) {
sndp_stop_sound(g_Nbombs[i].audiohandle24);
#if VERSION < VERSION_NTSC_1_0
g_Nbombs[i].audiohandle24 = NULL;
#endif
@ -706,7 +706,7 @@ void nbomb_create_storm(struct coord *pos, struct prop *ownerprop)
if (g_Nbombs[index].audiohandle20) {
union audioparam param;
param.f32 = 0.4f;
audioPostEvent(g_Nbombs[index].audiohandle20, AL_SNDP_PITCH_EVT, param.s32);
sndp_post_event(g_Nbombs[index].audiohandle20, AL_SNDP_PITCH_EVT, param.s32);
}
}
@ -716,7 +716,7 @@ void nbomb_create_storm(struct coord *pos, struct prop *ownerprop)
if (g_Nbombs[index].audiohandle24) {
union audioparam param;
param.f32 = 0.4f;
audioPostEvent(g_Nbombs[index].audiohandle24, AL_SNDP_PITCH_EVT, param.s32);
sndp_post_event(g_Nbombs[index].audiohandle24, AL_SNDP_PITCH_EVT, param.s32);
}
}
#else
@ -728,7 +728,7 @@ void nbomb_create_storm(struct coord *pos, struct prop *ownerprop)
if (g_Nbombs[index].audiohandle20) {
union audioparam param;
param.f32 = 0.4f;
audioPostEvent(g_Nbombs[index].audiohandle20, AL_SNDP_PITCH_EVT, param.s32);
sndp_post_event(g_Nbombs[index].audiohandle20, AL_SNDP_PITCH_EVT, param.s32);
}
snd_start(var80095200, SFX_LAUNCH_ROCKET, &g_Nbombs[index].audiohandle24, -1, -1, -1, -1, -1);
@ -736,7 +736,7 @@ void nbomb_create_storm(struct coord *pos, struct prop *ownerprop)
if (g_Nbombs[index].audiohandle24) {
union audioparam param;
param.f32 = 0.4f;
audioPostEvent(g_Nbombs[index].audiohandle24, AL_SNDP_PITCH_EVT, param.s32);
sndp_post_event(g_Nbombs[index].audiohandle24, AL_SNDP_PITCH_EVT, param.s32);
}
#endif
}

View File

@ -2156,8 +2156,8 @@ void player_stop_audio_for_pause(void)
for (i = 0; i < 2; i++) {
hand = &g_Vars.currentplayer->hands[i];
if (hand->audiohandle2 && sndGetState(hand->audiohandle2) != AL_STOPPED) {
audioStop(hand->audiohandle2);
if (hand->audiohandle2 && sndp_get_state(hand->audiohandle2) != AL_STOPPED) {
sndp_stop_sound(hand->audiohandle2);
}
}
}

View File

@ -479,7 +479,7 @@ void weapon_play_melee_miss_sound(s32 weaponnum, struct prop *prop)
handle = snd_start(var80095200, soundnum, NULL, -1, -1, -1, -1, -1);
if (handle) {
audioPostEvent(handle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
sndp_post_event(handle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
}
osSetThreadPri(0, prevpri);
@ -487,7 +487,7 @@ void weapon_play_melee_miss_sound(s32 weaponnum, struct prop *prop)
handle = snd_start(var80095200, soundnum, NULL, -1, -1, -1, -1, -1);
if (handle) {
audioPostEvent(handle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
sndp_post_event(handle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
}
#endif
} else {
@ -542,7 +542,7 @@ void weapon_play_melee_hit_sound(s32 weaponnum, struct prop *prop)
handle = snd_start(var80095200, soundnum, 0, -1, -1, -1, -1, -1);
if (handle) {
audioPostEvent(handle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
sndp_post_event(handle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
}
osSetThreadPri(0, prevpri);
@ -550,7 +550,7 @@ void weapon_play_melee_hit_sound(s32 weaponnum, struct prop *prop)
handle = snd_start(var80095200, soundnum, 0, -1, -1, -1, -1, -1);
if (handle) {
audioPostEvent(handle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
sndp_post_event(handle, AL_SNDP_PITCH_EVT, *(s32 *)&speed);
}
#endif
} else {

View File

@ -19751,8 +19751,8 @@ void alarm_activate(void)
void alarm_stop_audio(void)
{
if (g_AlarmAudioHandle && sndGetState(g_AlarmAudioHandle) != AL_STOPPED) {
audioStop(g_AlarmAudioHandle);
if (g_AlarmAudioHandle && sndp_get_state(g_AlarmAudioHandle) != AL_STOPPED) {
sndp_stop_sound(g_AlarmAudioHandle);
}
}
@ -19790,8 +19790,8 @@ void gas_release_from_pos(struct coord *pos)
void gas_stop_audio(void)
{
if (g_GasAudioHandle && sndGetState(g_GasAudioHandle)) {
audioStop(g_GasAudioHandle);
if (g_GasAudioHandle && sndp_get_state(g_GasAudioHandle) != AL_STOPPED) {
sndp_stop_sound(g_GasAudioHandle);
}
}
@ -19844,8 +19844,8 @@ void gas_tick(void)
if (g_GasAudioHandle) {
ps_apply_vol_pan(g_GasAudioHandle, &g_GasPos, 400, 2500, 3000, g_Vars.currentplayer->prop->rooms, soundnum, AL_VOL_FULL, 0);
}
} else if (g_GasAudioHandle && sndGetState(g_GasAudioHandle)) {
audioStop(g_GasAudioHandle);
} else if (g_GasAudioHandle && sndp_get_state(g_GasAudioHandle) != AL_STOPPED) {
sndp_stop_sound(g_GasAudioHandle);
}
}
}

View File

@ -175,8 +175,8 @@ void ps_stop_channel(s32 channelnum)
if (channel->flags & PSFLAG_ISMP3) {
snd_stop_mp3(channel->soundnum26);
} else if (channel->audiohandle && sndGetState(channel->audiohandle) != AL_STOPPED) {
audioStop(channel->audiohandle);
} else if (channel->audiohandle && sndp_get_state(channel->audiohandle) != AL_STOPPED) {
sndp_stop_sound(channel->audiohandle);
}
#if VERSION < VERSION_NTSC_1_0
@ -224,12 +224,12 @@ void ps_tick_channel(s32 channelnum)
#if VERSION >= VERSION_NTSC_1_0
if ((channel->flags2 & PSFLAG2_STOPPED) == 0
&& channel->type != PSTYPE_MARKER
&& ((channel->audiohandle != NULL && sndGetState(channel->audiohandle) != AL_STOPPED)
&& ((channel->audiohandle != NULL && sndp_get_state(channel->audiohandle) != AL_STOPPED)
|| (channel->flags & PSFLAG_REPEATING)
|| (channel->flags & PSFLAG_FIRSTTICK)
|| ((channel->flags & PSFLAG_ISMP3) && snd_is_playing_mp3())))
#else
if ((channel->audiohandle != NULL && sndGetState(channel->audiohandle) != AL_STOPPED)
if ((channel->audiohandle != NULL && sndp_get_state(channel->audiohandle) != AL_STOPPED)
|| (channel->flags & PSFLAG_REPEATING)
|| (channel->flags & PSFLAG_FIRSTTICK)
|| ((channel->flags & PSFLAG_ISMP3) && snd_is_playing_mp3()))
@ -408,12 +408,12 @@ void ps_tick_channel(s32 channelnum)
}
} else {
if ((channel->flags & PSFLAG_OUTOFRANGE) == 0) {
if (channel->audiohandle != NULL && sndGetState(channel->audiohandle) != AL_STOPPED) {
if (channel->audiohandle != NULL && sndp_get_state(channel->audiohandle) != AL_STOPPED) {
#if VERSION >= VERSION_NTSC_1_0
audioStop(channel->audiohandle);
sndp_stop_sound(channel->audiohandle);
#else
osSyncPrintf("PS_AUTO : Pausing %d\n", channelnum);
audioStop(channel->audiohandle);
sndp_stop_sound(channel->audiohandle);
channel->audiohandle = NULL;
#endif
}

View File

@ -15,8 +15,8 @@ void ps_stop(void)
snd_stop_mp3(g_PsChannels[i].soundnum26);
g_PsChannels[i].flags &= ~PSFLAG_ISMP3;
g_PsChannels[i].flags &= ~PSFLAG_REPEATING;
} else if (g_PsChannels[i].audiohandle && sndGetState(g_PsChannels[i].audiohandle) != AL_STOPPED) {
audioStop(g_PsChannels[i].audiohandle);
} else if (g_PsChannels[i].audiohandle && sndp_get_state(g_PsChannels[i].audiohandle) != AL_STOPPED) {
sndp_stop_sound(g_PsChannels[i].audiohandle);
g_PsChannels[i].flags &= ~PSFLAG_REPEATING;
}
}

View File

@ -1648,7 +1648,7 @@ void title_init_rare_presents(void)
void title_exit_rare_presents(void)
{
if (g_TitleAudioHandle) {
audioStop(g_TitleAudioHandle);
sndp_stop_sound(g_TitleAudioHandle);
}
g_TitleAudioHandle = NULL;
@ -1743,7 +1743,7 @@ Gfx *title_render_rare_presents(Gfx *gdl)
}
} else {
if (g_TitleAudioHandle) {
audioStop(g_TitleAudioHandle);
sndp_stop_sound(g_TitleAudioHandle);
}
g_TitleAudioHandle = NULL;

View File

@ -320,14 +320,14 @@ void weather_tick_rain(struct weatherdata *weather)
}
if (weather->audiohandles[i] != 0) {
if (sndGetState(weather->audiohandles[i]) != AL_STOPPED) {
if (sndp_get_state(weather->audiohandles[i]) != AL_STOPPED) {
snd_adjust(&weather->audiohandles[i], 0, iVar10 * 3 / 4, -1,
weather->unkf8, 1, 1, -1, 1);
}
}
} else {
if (weather->audiohandles[i] != 0) {
audioStop(weather->audiohandles[i]);
sndp_stop_sound(weather->audiohandles[i]);
}
}
}
@ -1039,7 +1039,7 @@ Gfx *weather_render_rain(Gfx *gdl, struct weatherdata *weather, s32 arg2)
}
snd_adjust(&weather->audiohandles[3], 0, volume, -1, weather->unkf8, 1.00f, 1, -1, 1);
audioPostEvent(weather->audiohandles[3], AL_SNDP_PITCH_EVT, *(s32 *)&pitch);
sndp_post_event(weather->audiohandles[3], AL_SNDP_PITCH_EVT, *(s32 *)&pitch);
}
}
}
@ -1882,19 +1882,19 @@ void weather_stop(void)
{
if (g_WeatherData) {
if (g_WeatherData->audiohandles[0]) {
audioStop(g_WeatherData->audiohandles[0]);
sndp_stop_sound(g_WeatherData->audiohandles[0]);
}
if (g_WeatherData->audiohandles[1]) {
audioStop(g_WeatherData->audiohandles[1]);
sndp_stop_sound(g_WeatherData->audiohandles[1]);
}
if (g_WeatherData->audiohandles[2]) {
audioStop(g_WeatherData->audiohandles[2]);
sndp_stop_sound(g_WeatherData->audiohandles[2]);
}
if (g_WeatherData->audiohandles[3]) {
audioStop(g_WeatherData->audiohandles[3]);
sndp_stop_sound(g_WeatherData->audiohandles[3]);
}
g_WeatherData = NULL;

View File

@ -3800,11 +3800,11 @@
#define SMOKETYPE_DEBRIS 21 // Crash site cockpit, Skedar Ruins outro
#define SMOKETYPE_UFO 22 // AF1 outro
#define SNDSTATEFLAG_01 0x01
#define SNDSTATEFLAG_02 0x02
#define SNDSTATEFLAG_04 0x04
#define SNDSTATEFLAG_10 0x10
#define SNDSTATEFLAG_20 0x20
#define SNDSTATEFLAG_LEAF 0x01
#define SNDSTATEFLAG_NO_DECAY 0x02
#define SNDSTATEFLAG_HAS_VOICE 0x04
#define SNDSTATEFLAG_10 0x10
#define SNDSTATEFLAG_HAS_DETUNE_PITCH 0x20
#define SOLOSTAGEINDEX_DEFECTION 0x00
#define SOLOSTAGEINDEX_INVESTIGATION 0x01

View File

@ -4,17 +4,17 @@
#include "data.h"
#include "types.h"
void sndpSetAddRefCallback(void *fn);
void sndpSetRemoveRefCallback(void *fn);
s32 sndGetState(struct sndstate *handle);
struct sndstate *func00033820(s32 arg0, s16 soundnum, u16 vol, ALPan pan, f32 pitch, u8 fxmix, u8 fxbus, struct sndstate **handleptr);
void audioStop(struct sndstate *handle);
void func00033db0(void);
void func00033dd8(void);
void audioPostEvent(struct sndstate *handle, s16 type, s32 data);
u16 func00033ec4(u8 index);
struct sndstate *sndpGetHeadState(void);
ALMicroTime sndpGetCurTime(void);
void func00033f44(u8 index, u16 volume);
void sndp_set_addref_callback(void *fn);
void sndp_set_removeref_callback(void *fn);
s32 sndp_get_state(struct sndstate *handle);
struct sndstate *sndp_play_sound(s32 arg0, s16 soundnum, u16 vol, ALPan pan, f32 pitch, u8 fxmix, u8 fxbus, struct sndstate **handleptr);
void sndp_stop_sound(struct sndstate *handle);
void sndp_cleanup(void);
void sndp_stop_all(void);
void sndp_post_event(struct sndstate *handle, s16 type, s32 data);
u16 sndp_get_volume_entry(u8 index);
struct sndstate *sndp_get_head_state(void);
ALMicroTime sndp_get_curtime(void);
void sndp_set_volume_entry(u8 index, u16 volume);
#endif

View File

@ -1994,7 +1994,7 @@ struct sndstate {
/*0x45*/ u8 state;
#if VERSION >= VERSION_NTSC_1_0
/*0x46*/ u16 soundnum;
/*0x48*/ ALMicroTime unk48;
/*0x48*/ ALMicroTime cleanuptime;
#endif
};

View File

@ -34,21 +34,21 @@
#define MIN_RATIO 0.0001
typedef enum {
AL_SNDP_PLAY_EVT = 0x0001,
AL_SNDP_STOP_EVT = 0x0002,
AL_SNDP_PAN_EVT = 0x0004,
AL_SNDP_VOL_EVT = 0x0008,
AL_SNDP_PITCH_EVT = 0x0010,
AL_SNDP_API_EVT = 0x0020,
AL_SNDP_DECAY_EVT = 0x0040,
AL_SNDP_END_EVT = 0x0080,
AL_SNDP_FX_EVT = 0x0100,
AL_SNDP_0200_EVT = 0x0200,
AL_SNDP_0400_EVT = 0x0400,
AL_SNDP_0800_EVT = 0x0800,
AL_SNDP_1000_EVT = 0x1000,
AL_SNDP_FXBUS_EVT = 0x2000,
AL_SNDP_4000_EVT = 0x4000
AL_SNDP_PLAY_EVT = 0x0001,
AL_SNDP_STOP_EVT = 0x0002,
AL_SNDP_PAN_EVT = 0x0004,
AL_SNDP_VOL_EVT = 0x0008,
AL_SNDP_PITCH_EVT = 0x0010,
AL_SNDP_API_EVT = 0x0020,
AL_SNDP_DECAY_EVT = 0x0040,
AL_SNDP_END_EVT = 0x0080,
AL_SNDP_FX_EVT = 0x0100,
AL_SNDP_PLAYNEXT_EVT = 0x0200,
AL_SNDP_STOPALL_EVT = 0x0400,
AL_SNDP_VOLTBL_EVT = 0x0800,
AL_SNDP_STOP2_EVT = 0x1000,
AL_SNDP_FXBUS_EVT = 0x2000,
AL_SNDP_FX2_EVT = 0x4000
} ALSndpMsgType;
typedef struct {

View File

@ -9,25 +9,25 @@
#include "types.h"
u32 var8009c330;
s16 *var8009c334;
s16 *g_SndpVolumeTable;
struct sndstate *g_SndpAllocStatesHead = NULL;
struct sndstate *g_SndpAllocStatesTail = NULL;
struct sndstate *g_SndpFreeStatesHead = NULL;
N_ALSndPlayer *g_SndPlayer = &var8009c2d0;
s16 var8005f130 = 0;
s32 var8005f134 = 0;
s32 var8005f138 = 0;
s16 g_SndpNumPlaying = 0;
s32 g_SndpNumAlloced = 0;
s32 g_SndpMostAlloced = 0;
void (*g_SndpAddRefCallback)(ALSound *) = NULL;
void (*g_SndpRemoveRefCallback)(ALSound *) = NULL;
void sndpSetAddRefCallback(void *fn);
void sndpSetRemoveRefCallback(void *fn);
void sndpFreeState(struct sndstate *state);
u16 sndpCountStates(s16 *numfreeptr, s16 *numallocedptr);
void func00033090(struct sndstate *state);
void func00033100(struct sndstate *state);
void func00033bc0(struct sndstate *state);
void sndp_set_addref_callback(void *fn);
void sndp_set_removeref_callback(void *fn);
void sndp_free_state2(struct sndstate *state);
u16 sndp_count_states(s16 *numfreeptr, s16 *numallocedptr);
void sndp_free_state(struct sndstate *state);
void sndp_apply_detune_pitch(struct sndstate *state);
void sndp_post_end_event(struct sndstate *state);
void n_alSndpNew(ALSndpConfig *config)
{
@ -54,13 +54,13 @@ void n_alSndpNew(ALSndpConfig *config)
alLink(&sndstate[i].node, &sndstate[i - 1].node);
}
sndpSetAddRefCallback(NULL);
sndpSetRemoveRefCallback(NULL);
sndp_set_addref_callback(NULL);
sndp_set_removeref_callback(NULL);
var8009c334 = alHeapAlloc(config->heap, sizeof(s16), config->unk10);
g_SndpVolumeTable = alHeapAlloc(config->heap, sizeof(s16), config->maxVolumes);
for (i = 0; i < config->unk10; i++) {
var8009c334[i] = 0x7fff;
for (i = 0; i < config->maxVolumes; i++) {
g_SndpVolumeTable[i] = 0x7fff;
}
// Add ourselves to the driver
@ -118,8 +118,8 @@ void _n_handleEvent(N_ALSndpEvent *event)
s32 fxmix;
s32 vol;
s32 tmppan;
s32 sp70;
s32 isspecial;
bool isfull;
bool isspecial;
bool done = true;
bool hasvoice = false;
struct sndstate *state = NULL;
@ -147,7 +147,7 @@ void _n_handleEvent(N_ALSndpEvent *event)
sound = state->sound;
if (sound == NULL) {
sndpCountStates(&numfree, &numalloced);
sndp_count_states(&numfree, &numalloced);
return;
}
@ -163,25 +163,25 @@ void _n_handleEvent(N_ALSndpEvent *event)
config.fxBus = state->fxbus;
config.priority = state->priority;
config.unityPitch = 0;
sp70 = var8005f130 >= g_SndPlayer->maxSounds;
isfull = g_SndpNumPlaying >= g_SndPlayer->maxSounds;
if (!sp70 || (state->flags & SNDSTATEFLAG_10)) {
if (!isfull || (state->flags & SNDSTATEFLAG_10)) {
hasvoice = n_alSynAllocVoice(&state->voice, &config);
}
if (!hasvoice) {
if (state->flags & (SNDSTATEFLAG_02 | SNDSTATEFLAG_10) || state->unk34 > 0) {
if (state->flags & (SNDSTATEFLAG_NO_DECAY | SNDSTATEFLAG_10) || state->unk34 > 0) {
state->state = AL_STATE4;
state->unk34--;
n_alEvtqPostEvent(&g_SndPlayer->evtq, &event->msg, 33333, 0);
} else if (sp70) {
} else if (isfull) {
iterstate = g_SndpAllocStatesTail;
do {
if ((iterstate->flags & (SNDSTATEFLAG_02 | SNDSTATEFLAG_10)) == 0
&& (iterstate->flags & SNDSTATEFLAG_04)
if ((iterstate->flags & (SNDSTATEFLAG_NO_DECAY | SNDSTATEFLAG_10)) == 0
&& (iterstate->flags & SNDSTATEFLAG_HAS_VOICE)
&& iterstate->state != AL_STATE3) {
sp70 = 0;
isfull = false;
sp44.common.type = AL_SNDP_END_EVT;
sp44.common.state = (N_ALSoundState *)iterstate;
iterstate->state = AL_STATE3;
@ -191,16 +191,16 @@ void _n_handleEvent(N_ALSndpEvent *event)
}
iterstate = (struct sndstate *)iterstate->node.prev;
} while (sp70 && iterstate);
} while (isfull && iterstate);
if (sp70 == 0) {
if (!isfull) {
state->unk34 = 2;
n_alEvtqPostEvent(&g_SndPlayer->evtq, &event->msg, 1001, 0);
} else {
func00033090(state);
sndp_free_state(state);
}
} else {
func00033090(state);
sndp_free_state(state);
}
return;
}
@ -208,8 +208,8 @@ void _n_handleEvent(N_ALSndpEvent *event)
#if VERSION >= VERSION_NTSC_1_0
delta = sound->envelope->attackTime / state->pitch / state->basepitch;
if (state->flags & SNDSTATEFLAG_02) {
state->unk48 = 0;
if (state->flags & SNDSTATEFLAG_NO_DECAY) {
state->cleanuptime = 0;
} else {
sp40 = sound->envelope->decayTime / state->pitch / state->basepitch;
@ -217,32 +217,32 @@ void _n_handleEvent(N_ALSndpEvent *event)
sp40 = 5500000;
}
state->unk48 = 1000000 + sp40 + g_SndPlayer->curTime;
state->cleanuptime = 1000000 + sp40 + g_SndPlayer->curTime;
if (state->unk48 < 0) {
state->unk48 = 0;
if (state->cleanuptime < 0) {
state->cleanuptime = 0;
}
}
if (delta > 5500000) {
func00033090(state);
sndp_free_state(state);
return;
}
state->flags |= SNDSTATEFLAG_04;
state->flags |= SNDSTATEFLAG_HAS_VOICE;
state->envvol = sound->envelope->attackVolume;
state->fxbus = config.fxBus;
state->endtime = g_SndPlayer->curTime + delta;
#else
// This is the same as above, but delta is calculated later
state->flags |= SNDSTATEFLAG_04;
state->flags |= SNDSTATEFLAG_HAS_VOICE;
state->envvol = sound->envelope->attackVolume;
state->fxbus = config.fxBus;
delta = sound->envelope->attackTime / state->pitch / state->basepitch;
state->endtime = g_SndPlayer->curTime + delta;
#endif
vol = MAX(0, (var8009c334[keymap->keyMin & 0x1f] * (state->envvol * state->vol * sound->sampleVolume / 0x3f01)) / 0x7fff - 1);
vol = MAX(0, (g_SndpVolumeTable[keymap->keyMin & 0x1f] * (state->envvol * state->vol * sound->sampleVolume / 0x3f01)) / 0x7fff - 1);
tmppan = state->pan + sound->samplePan - AL_PAN_CENTER;
pan = MIN(MAX(tmppan, 0), 127);
@ -252,19 +252,19 @@ void _n_handleEvent(N_ALSndpEvent *event)
n_alSynStartVoiceParams(&state->voice, sound->wavetable, state->pitch * state->basepitch, vol, pan, fxmix, 0, 0, 0, delta);
state->state = AL_PLAYING;
var8005f130++;
g_SndpNumPlaying++;
if ((state->flags & SNDSTATEFLAG_02) == 0) {
if ((state->flags & SNDSTATEFLAG_NO_DECAY) == 0) {
if (delta == 0) {
state->envvol = sound->envelope->decayVolume;
vol = MAX(0, (var8009c334[keymap->keyMin & 0x1f] * (state->envvol * state->vol * sound->sampleVolume / 0x3f01)) / 0x7fff - 1);
vol = MAX(0, (g_SndpVolumeTable[keymap->keyMin & 0x1f] * (state->envvol * state->vol * sound->sampleVolume / 0x3f01)) / 0x7fff - 1);
delta = sound->envelope->decayTime / state->basepitch / state->pitch;
#if VERSION >= VERSION_NTSC_1_0
if (delta > 5500000) {
func00033090(state);
sndp_free_state(state);
return;
}
#endif
@ -278,8 +278,8 @@ void _n_handleEvent(N_ALSndpEvent *event)
n_alEvtqPostEvent(&g_SndPlayer->evtq, &sp94.msg, delta, 0);
if (state->flags & SNDSTATEFLAG_20) {
func00033100(state);
if (state->flags & SNDSTATEFLAG_HAS_DETUNE_PITCH) {
sndp_apply_detune_pitch(state);
}
} else {
sp94.common.type = AL_SNDP_DECAY_EVT;
@ -288,7 +288,7 @@ void _n_handleEvent(N_ALSndpEvent *event)
#if VERSION >= VERSION_NTSC_1_0
if (delta > 5500000) {
func00033090(state);
sndp_free_state(state);
return;
}
#endif
@ -297,10 +297,29 @@ void _n_handleEvent(N_ALSndpEvent *event)
}
}
break;
/**
* AL_SNDP_STOP_EVT:
* - Executed once a decay has finished.
* - cleanup() the given sound.
* - For subsequent sounds in the chain, post STOP2.
*
* AL_SNDP_STOP2_EVT:
* - If the given sound has no decay, cleanup()
*
* AL_SNDP_STOPALL_EVT:
* - Posted and executed on lv stop.
* - For all sounds in the chain, cleanup()
*
* The cleanup logic:
* - Remove any scheduled decay events from the given sound
* - If the sound has a releaseTime, enter AL_STOPPING and schedule an END event
* - If the sound has no releaseTime, free it immediately
*/
case AL_SNDP_STOP_EVT:
case AL_SNDP_0400_EVT:
case AL_SNDP_1000_EVT:
if (event->common.type != AL_SNDP_1000_EVT || (state->flags & SNDSTATEFLAG_02)) {
case AL_SNDP_STOPALL_EVT:
case AL_SNDP_STOP2_EVT:
if (event->common.type != AL_SNDP_STOP2_EVT || (state->flags & SNDSTATEFLAG_NO_DECAY)) {
switch (state->state) {
case AL_PLAYING:
_removeEvents(&g_SndPlayer->evtq, (N_ALSoundState *)state, AL_SNDP_DECAY_EVT);
@ -308,7 +327,7 @@ void _n_handleEvent(N_ALSndpEvent *event)
#if VERSION >= VERSION_NTSC_1_0
if (delta > 5500000) {
func00033090(state);
sndp_free_state(state);
break;
}
#endif
@ -321,19 +340,19 @@ void _n_handleEvent(N_ALSndpEvent *event)
n_alEvtqPostEvent(&g_SndPlayer->evtq, &sp94.msg, delta, 0);
state->state = AL_STOPPING;
} else {
func00033090(state);
sndp_free_state(state);
}
break;
case AL_STATE4:
case AL_STATE5:
func00033090(state);
sndp_free_state(state);
break;
default:
break;
}
if (event->common.type == AL_SNDP_STOP_EVT) {
event->common.type = AL_SNDP_1000_EVT;
event->common.type = AL_SNDP_STOP2_EVT;
}
}
break;
@ -353,8 +372,8 @@ void _n_handleEvent(N_ALSndpEvent *event)
if (state->state == AL_PLAYING) {
n_alSynSetPitch(&state->voice, state->pitch * state->basepitch);
if (state->flags & SNDSTATEFLAG_20) {
func00033100(state);
if (state->flags & SNDSTATEFLAG_HAS_DETUNE_PITCH) {
sndp_apply_detune_pitch(state);
}
}
break;
@ -369,7 +388,7 @@ void _n_handleEvent(N_ALSndpEvent *event)
n_alSynSetFXMix(&state->voice, fxmix);
}
break;
case AL_SNDP_4000_EVT:
case AL_SNDP_FX2_EVT:
state->fxmix = (u8)(state->fxmix & 0x7f) | (u8)(event->common.unk08 & 0x80);
if (state->state == AL_PLAYING) {
@ -395,36 +414,36 @@ void _n_handleEvent(N_ALSndpEvent *event)
state->vol = event->common.unk08;
if (state->state == AL_PLAYING) {
vol = MAX(0, (var8009c334[keymap->keyMin & 0x1f] * (state->envvol * state->vol * sound->sampleVolume / 0x3f01)) / 0x7fff - 1);
vol = MAX(0, (g_SndpVolumeTable[keymap->keyMin & 0x1f] * (state->envvol * state->vol * sound->sampleVolume / 0x3f01)) / 0x7fff - 1);
n_alSynSetVol(&state->voice, vol, MAX(1000, state->endtime - g_SndPlayer->curTime));
}
break;
case AL_SNDP_0800_EVT:
case AL_SNDP_VOLTBL_EVT:
if (state->state == AL_PLAYING) {
delta = sound->envelope->releaseTime / state->basepitch / state->pitch;
#if VERSION >= VERSION_NTSC_1_0
if (delta > 5500000) {
func00033090(state);
sndp_free_state(state);
break;
}
#endif
vol = MAX(0, var8009c334[keymap->keyMin & 0x1f] * (state->envvol * state->vol * sound->sampleVolume / 0x3f01) / 0x7fff - 1);
vol = MAX(0, g_SndpVolumeTable[keymap->keyMin & 0x1f] * (state->envvol * state->vol * sound->sampleVolume / 0x3f01) / 0x7fff - 1);
n_alSynSetVol(&state->voice, vol, delta);
}
break;
case AL_SNDP_DECAY_EVT:
if ((state->flags & SNDSTATEFLAG_02) == 0) {
if ((state->flags & SNDSTATEFLAG_NO_DECAY) == 0) {
state->envvol = sound->envelope->decayVolume;
vol = MAX(0, var8009c334[keymap->keyMin & 0x1f] * (state->envvol * state->vol * sound->sampleVolume / 0x3f01) / 0x7fff - 1);
vol = MAX(0, g_SndpVolumeTable[keymap->keyMin & 0x1f] * (state->envvol * state->vol * sound->sampleVolume / 0x3f01) / 0x7fff - 1);
delta = sound->envelope->decayTime / state->basepitch / state->pitch;
#if VERSION >= VERSION_NTSC_1_0
if (delta > 5500000) {
func00033090(state);
sndp_free_state(state);
break;
}
#endif
@ -438,17 +457,17 @@ void _n_handleEvent(N_ALSndpEvent *event)
n_alEvtqPostEvent(&g_SndPlayer->evtq, &sp94.msg, delta, 0);
if (state->flags & SNDSTATEFLAG_20) {
func00033100(state);
if (state->flags & SNDSTATEFLAG_HAS_DETUNE_PITCH) {
sndp_apply_detune_pitch(state);
}
}
break;
case AL_SNDP_END_EVT:
func00033090(state);
sndp_free_state(state);
break;
case AL_SNDP_0200_EVT:
case AL_SNDP_PLAYNEXT_EVT:
if (state->flags & SNDSTATEFLAG_10) {
func00033820(event->msg.msg.generic.data2, event->msg.msg.generic.data, state->vol, state->pan,
sndp_play_sound(event->msg.msg.generic.data2, event->msg.msg.generic.data, state->vol, state->pan,
state->pitch, state->fxmix, state->fxbus, state->unk30);
}
break;
@ -456,32 +475,29 @@ void _n_handleEvent(N_ALSndpEvent *event)
break;
}
isspecial = event->common.type & (AL_SNDP_PLAY_EVT
| AL_SNDP_PITCH_EVT
| AL_SNDP_DECAY_EVT
| AL_SNDP_END_EVT
| AL_SNDP_0200_EVT);
isspecial = event->common.type
& (AL_SNDP_PLAY_EVT | AL_SNDP_PITCH_EVT | AL_SNDP_DECAY_EVT | AL_SNDP_END_EVT | AL_SNDP_PLAYNEXT_EVT);
if ((state = nextstate) && !isspecial) {
done = state->flags & SNDSTATEFLAG_01;
done = state->flags & SNDSTATEFLAG_LEAF;
}
} while (!done && state && !isspecial);
}
void func00033090(struct sndstate *state)
void sndp_free_state(struct sndstate *state)
{
if (state->flags & SNDSTATEFLAG_04) {
if (state->flags & SNDSTATEFLAG_HAS_VOICE) {
n_alSynStopVoice(&state->voice);
n_alSynFreeVoice(&state->voice);
}
sndpFreeState(state);
sndp_free_state2(state);
// @todo: Remove cast
_removeEvents(&g_SndPlayer->evtq, (N_ALSoundState *)state, 0xffff);
}
void func00033100(struct sndstate *state)
void sndp_apply_detune_pitch(struct sndstate *state)
{
N_ALSndpEvent evt;
f32 pitch = alCents2Ratio(state->sound->keyMap->detune) * state->pitch;
@ -527,7 +543,7 @@ void _removeEvents(ALEventQueue *evtq, N_ALSoundState *state, u16 typemask)
osSetIntMask(mask);
}
u16 sndpCountStates(s16 *numfreeptr, s16 *numallocedptr)
u16 sndp_count_states(s16 *numfreeptr, s16 *numallocedptr)
{
OSIntMask mask = osSetIntMask(1);
u16 numalloced;
@ -549,12 +565,12 @@ u16 sndpCountStates(s16 *numfreeptr, s16 *numallocedptr)
return numalloced2;
}
void sndpSetAddRefCallback(void *fn)
void sndp_set_addref_callback(void *fn)
{
g_SndpAddRefCallback = fn;
}
struct sndstate *func00033390(s32 arg0, ALSound *sound)
struct sndstate *sndp_alloc_state(s32 arg0, ALSound *sound)
{
struct sndstate *state;
ALKeyMap *keymap;
@ -563,10 +579,10 @@ struct sndstate *func00033390(s32 arg0, ALSound *sound)
keymap = sound->keyMap;
if (++var8005f134 > var8005f138) {
var8005f138 = var8005f134;
if (++g_SndpNumAlloced > g_SndpMostAlloced) {
g_SndpMostAlloced = g_SndpNumAlloced;
if (var8005f134 > 16) {
if (g_SndpNumAlloced > 16) {
// empty
}
}
@ -602,14 +618,14 @@ struct sndstate *func00033390(s32 arg0, ALSound *sound)
state->flags = keymap->keyMax & 0xf0;
state->unk30 = NULL;
if (state->flags & SNDSTATEFLAG_20) {
if (state->flags & SNDSTATEFLAG_HAS_DETUNE_PITCH) {
state->basepitch = alCents2Ratio(keymap->keyBase * 100 - 6000);
} else {
state->basepitch = alCents2Ratio(keymap->keyBase * 100 + keymap->detune - 6000);
}
if (sp18) {
state->flags |= SNDSTATEFLAG_02;
state->flags |= SNDSTATEFLAG_NO_DECAY;
}
state->fxmix = 0;
@ -626,14 +642,14 @@ struct sndstate *func00033390(s32 arg0, ALSound *sound)
return state;
}
void sndpSetRemoveRefCallback(void *fn)
void sndp_set_removeref_callback(void *fn)
{
g_SndpRemoveRefCallback = fn;
}
void sndpFreeState(struct sndstate *state)
void sndp_free_state2(struct sndstate *state)
{
var8005f134--;
g_SndpNumAlloced--;
if (g_SndpAllocStatesHead == state) {
g_SndpAllocStatesHead = (struct sndstate *)state->node.next;
@ -655,8 +671,8 @@ void sndpFreeState(struct sndstate *state)
g_SndpFreeStatesHead = state;
}
if (state->flags & SNDSTATEFLAG_04) {
var8005f130--;
if (state->flags & SNDSTATEFLAG_HAS_VOICE) {
g_SndpNumPlaying--;
}
state->state = AL_STOPPED;
@ -674,14 +690,14 @@ void sndpFreeState(struct sndstate *state)
}
}
void sndSetPriority(struct sndstate *state, u8 priority)
void sndp_set_priority(struct sndstate *state, u8 priority)
{
if (state) {
state->priority = (s16)priority;
}
}
s32 sndGetState(struct sndstate *state)
s32 sndp_get_state(struct sndstate *state)
{
if (state) {
return state->state;
@ -690,16 +706,16 @@ s32 sndGetState(struct sndstate *state)
}
}
struct sndstate *func00033820(s32 arg0, s16 soundnum, u16 vol, ALPan pan, f32 pitch, u8 fxmix, u8 fxbus, struct sndstate **handleptr)
struct sndstate *sndp_play_sound(s32 arg0, s16 soundnum, u16 vol, ALPan pan, f32 pitch, u8 fxmix, u8 fxbus, struct sndstate **handleptr)
{
struct sndstate *state;
struct sndstate *state2 = NULL;
struct sndstate *leafstate = NULL;
ALKeyMap *keymap;
ALSound *sound;
s16 sp4e = 0;
s32 sp48;
s32 sp44;
s32 sp40 = 0;
s32 thisdelay;
s32 sumdelay = 0;
s32 abspan;
N_ALEvent evt;
N_ALEvent evt2;
@ -711,7 +727,7 @@ struct sndstate *func00033820(s32 arg0, s16 soundnum, u16 vol, ALPan pan, f32 pi
if (soundnum != 0) {
do {
sound = snd_load_sound(soundnum);
state = func00033390(arg0, sound);
state = sndp_alloc_state(arg0, sound);
if (state != NULL) {
g_SndPlayer->target = state;
@ -732,37 +748,37 @@ struct sndstate *func00033820(s32 arg0, s16 soundnum, u16 vol, ALPan pan, f32 pi
state->fxbus = fxbus;
#if VERSION >= VERSION_NTSC_1_0
state->soundnum = soundnum;
state->unk48 = 0;
state->cleanuptime = 0;
#endif
sp44 = sound->keyMap->velocityMax * 33333;
thisdelay = sound->keyMap->velocityMax * 33333;
if (state->flags & SNDSTATEFLAG_10) {
state->flags &= ~SNDSTATEFLAG_10;
n_alEvtqPostEvent(&g_SndPlayer->evtq, &evt, sp40 + 1, 0);
sp48 = sp44 + 1;
n_alEvtqPostEvent(&g_SndPlayer->evtq, &evt, sumdelay + 1, 0);
sp48 = thisdelay + 1;
sp4e = soundnum;
} else {
n_alEvtqPostEvent(&g_SndPlayer->evtq, &evt, sp44 + 1, 0);
n_alEvtqPostEvent(&g_SndPlayer->evtq, &evt, thisdelay + 1, 0);
}
state2 = state;
leafstate = state;
}
sp40 += sp44;
sumdelay += thisdelay;
keymap = sound->keyMap;
soundnum = keymap->velocityMin + (keymap->keyMin & 0xc0) * 4;
soundnum = keymap->velocityMin + ((keymap->keyMin & 0xc0) << 2);
} while (soundnum && state);
if (state2 != NULL) {
state2->flags |= SNDSTATEFLAG_01;
state2->unk30 = handleptr;
if (leafstate != NULL) {
leafstate->flags |= SNDSTATEFLAG_LEAF;
leafstate->unk30 = handleptr;
if (sp4e != 0) {
state2->flags |= SNDSTATEFLAG_10;
leafstate->flags |= SNDSTATEFLAG_10;
evt2.type = AL_SNDP_0200_EVT;
evt2.msg.generic.sndstate = state2;
evt2.type = AL_SNDP_PLAYNEXT_EVT;
evt2.msg.generic.sndstate = leafstate;
evt2.msg.generic.data = sp4e;
evt2.msg.generic.data2 = arg0;
@ -772,21 +788,21 @@ struct sndstate *func00033820(s32 arg0, s16 soundnum, u16 vol, ALPan pan, f32 pi
}
if (handleptr != NULL) {
*handleptr = state2;
*handleptr = leafstate;
}
return state2;
return leafstate;
}
void audioStop(struct sndstate *state)
void sndp_stop_sound(struct sndstate *state)
{
N_ALEvent evt;
#if VERSION >= VERSION_NTSC_FINAL
if (state && (state->flags & SNDSTATEFLAG_02)) {
func00033bc0(state);
if (state && (state->flags & SNDSTATEFLAG_NO_DECAY)) {
sndp_post_end_event(state);
} else {
evt.type = AL_SNDP_0400_EVT;
evt.type = AL_SNDP_STOPALL_EVT;
evt.msg.generic.sndstate = state;
if (state != NULL) {
@ -797,10 +813,10 @@ void audioStop(struct sndstate *state)
}
#elif VERSION >= VERSION_NTSC_1_0
// NTSC 1.0 lacks the null state check
if (state->flags & SNDSTATEFLAG_02) {
func00033bc0(state);
if (state->flags & SNDSTATEFLAG_NO_DECAY) {
sndp_post_end_event(state);
} else {
evt.type = AL_SNDP_0400_EVT;
evt.type = AL_SNDP_STOPALL_EVT;
evt.msg.generic.sndstate = state;
if (state != NULL) {
@ -810,7 +826,7 @@ void audioStop(struct sndstate *state)
}
}
#else
evt.type = AL_SNDP_0400_EVT;
evt.type = AL_SNDP_STOPALL_EVT;
evt.msg.generic.sndstate = state;
if (state != NULL) {
@ -822,7 +838,7 @@ void audioStop(struct sndstate *state)
}
#if VERSION >= VERSION_NTSC_1_0
void func00033bc0(struct sndstate *state)
void sndp_post_end_event(struct sndstate *state)
{
N_ALEvent evt;
@ -837,14 +853,14 @@ void func00033bc0(struct sndstate *state)
}
#endif
void func00033c30(u8 flags)
void sndp_post_stopall_event_bulk(u8 flags)
{
OSIntMask mask = osSetIntMask(1);
N_ALEvent evt;
struct sndstate *state = g_SndpAllocStatesHead;
while (state) {
evt.type = AL_SNDP_0400_EVT;
evt.type = AL_SNDP_STOPALL_EVT;
evt.msg.generic.sndstate = state;
if ((state->flags & flags) == flags) {
@ -859,7 +875,7 @@ void func00033c30(u8 flags)
}
#if VERSION >= VERSION_NTSC_1_0
void func00033cf0(u8 flags)
void sndp_post_end_event_bulk(u8 flags)
{
OSIntMask mask = osSetIntMask(1);
N_ALEvent evt;
@ -882,28 +898,28 @@ void func00033cf0(u8 flags)
#endif
#if VERSION >= VERSION_NTSC_1_0
void func00033db0(void)
void sndp_cleanup(void)
{
func00033cf0(SNDSTATEFLAG_01);
sndp_post_end_event_bulk(SNDSTATEFLAG_LEAF);
}
#endif
void func00033dd8(void)
void sndp_stop_all(void)
{
func00033c30(SNDSTATEFLAG_01);
sndp_post_stopall_event_bulk(SNDSTATEFLAG_LEAF);
}
void func00033e00(void)
void sndp_stop_specials(void)
{
func00033c30(SNDSTATEFLAG_01 | SNDSTATEFLAG_10);
sndp_post_stopall_event_bulk(SNDSTATEFLAG_LEAF | SNDSTATEFLAG_10);
}
void func00033e28(void)
void sndp_stop_nodecays(void)
{
func00033c30(SNDSTATEFLAG_01 | SNDSTATEFLAG_02);
sndp_post_stopall_event_bulk(SNDSTATEFLAG_LEAF | SNDSTATEFLAG_NO_DECAY);
}
void audioPostEvent(struct sndstate *state, s16 type, s32 data)
void sndp_post_event(struct sndstate *state, s16 type, s32 data)
{
N_ALEvent evt;
@ -918,38 +934,43 @@ void audioPostEvent(struct sndstate *state, s16 type, s32 data)
}
}
u16 func00033ec4(u8 index)
u16 sndp_get_volume_entry(u8 index)
{
return var8009c334 ? var8009c334[index] : 0;
return g_SndpVolumeTable ? g_SndpVolumeTable[index] : 0;
}
#if VERSION >= VERSION_NTSC_1_0
struct sndstate *sndpGetHeadState(void)
struct sndstate *sndp_get_head_state(void)
{
return g_SndpAllocStatesHead;
}
#endif
#if VERSION >= VERSION_NTSC_1_0
ALMicroTime sndpGetCurTime(void)
ALMicroTime sndp_get_curtime(void)
{
return g_SndPlayer->curTime;
}
#endif
void func00033f44(u8 index, u16 volume)
/**
* Set the given entry in the volume table to the specified volume,
* then find all active sounds which use this entry and notify them
* that the entry has changed.
*/
void sndp_set_volume_entry(u8 index, u16 volume)
{
if (var8009c334) {
if (g_SndpVolumeTable) {
OSIntMask mask = osSetIntMask(1);
struct sndstate *state = g_SndpAllocStatesHead;
s32 i;
N_ALEvent evt;
var8009c334[index] = volume;
g_SndpVolumeTable[index] = volume;
for (i = 0; state != NULL; i++, state = (struct sndstate *)state->node.next) {
if ((state->sound->keyMap->keyMin & 0x1f) == index) {
evt.type = AL_SNDP_0800_EVT;
evt.type = AL_SNDP_VOLTBL_EVT;
evt.msg.generic.sndstate = state;
n_alEvtqPostEvent(&g_SndPlayer->evtq, &evt, 0, 0);
}

View File

@ -27,7 +27,7 @@
#define MAX_SEQ_SIZE_8MB 1024 * 18
#define NUM_CACHE_SLOTS 45
#define NUM_KEYTHINGS 9
#define NUM_VOLUMES 9
struct sndcache {
/*0x0000*/ u16 *indexes; // indexed by sfxnum, value is cache index (0-44) or 0xffff
@ -877,20 +877,20 @@ bool snd_is_playing_mp3(void)
return g_SndCurMp3.playing;
}
u16 snd0000e9dc(void)
u16 snd_get_sfx_volume(void)
{
#if VERSION >= VERSION_NTSC_1_0
s32 result;
if (func00033ec4(0) < 0x5000) {
result = func00033ec4(0);
if (sndp_get_volume_entry(0) < 0x5000) {
result = sndp_get_volume_entry(0);
} else {
result = 0x5000;
}
return result;
#else
return func00033ec4(0);
return sndp_get_volume_entry(0);
#endif
}
@ -904,14 +904,14 @@ void snd_set_sfx_volume(u16 volume)
}
#endif
for (i = 0; i < NUM_KEYTHINGS; i++) {
func00033f44(i, volume);
for (i = 0; i < NUM_VOLUMES; i++) {
sndp_set_volume_entry(i, volume);
}
g_SfxVolume = volume;
}
void snd0000ea80(u16 volume)
void snd_set_sfx_volume_untracked(u16 volume)
{
u8 i;
@ -921,8 +921,8 @@ void snd0000ea80(u16 volume)
}
#endif
for (i = 0; i < NUM_KEYTHINGS; i++) {
func00033f44(i, volume);
for (i = 0; i < NUM_VOLUMES; i++) {
sndp_set_volume_entry(i, volume);
}
}
@ -1536,7 +1536,7 @@ void snd_init(void)
sndpconfig.maxEvents = 64;
sndpconfig.maxStates = 64;
sndpconfig.maxSounds = 20;
sndpconfig.unk10 = NUM_KEYTHINGS;
sndpconfig.maxVolumes = NUM_VOLUMES;
sndpconfig.heap = &g_SndHeap;
#if VERSION >= VERSION_PAL_BETA
@ -1569,8 +1569,8 @@ void snd_init(void)
osSyncPrintf("Set the sample callbacks\n");
sndpSetAddRefCallback(snd_add_ref);
sndpSetRemoveRefCallback(snd_remove_ref);
sndp_set_addref_callback(snd_add_ref);
sndp_set_removeref_callback(snd_remove_ref);
amgr_start_thread();
@ -1736,7 +1736,7 @@ void snd_tick(void)
struct sndstate *state;
#endif
OSPri prevpri;
s32 s0;
s32 volume;
union soundnumhack sp50;
s32 index;
s32 stack;
@ -1749,8 +1749,8 @@ void snd_tick(void)
prevpri = osGetThreadPri(NULL);
osSetThreadPri(0, osGetThreadPri(&g_AudioManager.thread) + 1);
curtime = sndpGetCurTime();
state = sndpGetHeadState();
curtime = sndp_get_curtime();
state = sndp_get_head_state();
g_SndNumPlaying = 0;
i = 0;
@ -1761,12 +1761,12 @@ void snd_tick(void)
g_SndNumPlaying++;
if ((state->flags & SNDSTATEFLAG_02) == 0
if ((state->flags & SNDSTATEFLAG_NO_DECAY) == 0
&& stateptrs[i]->state == AL_PLAYING
&& stateptrs[i]->unk48 > 0
&& stateptrs[i]->unk48 < curtime) {
state->unk48 = 0;
func00033db0();
&& stateptrs[i]->cleanuptime > 0
&& stateptrs[i]->cleanuptime < curtime) {
state->cleanuptime = 0;
sndp_cleanup();
break;
}
@ -1792,18 +1792,20 @@ void snd_tick(void)
snd_tick_ufo();
}
// In cutscenes, force sfx volume to at least the same as music
if (g_Vars.tickmode == TICKMODE_CUTSCENE) {
s0 = music_get_volume() > g_SfxVolume ? music_get_volume() : g_SfxVolume;
volume = music_get_volume() > g_SfxVolume ? music_get_volume() : g_SfxVolume;
if (s0 != snd0000e9dc()) {
snd0000ea80(s0);
if (volume != snd_get_sfx_volume()) {
snd_set_sfx_volume_untracked(volume);
}
} else {
if (g_SfxVolume != snd0000e9dc()) {
snd0000ea80(g_SfxVolume);
if (g_SfxVolume != snd_get_sfx_volume()) {
snd_set_sfx_volume_untracked(g_SfxVolume);
}
}
// Check for sound heap overflow
if (g_SndGuardStringPtr != NULL) {
if (strcmp(g_SndGuardStringPtr, g_SndGuardString) != 0) {
#if VERSION < VERSION_NTSC_1_0
@ -2004,7 +2006,7 @@ void snd_adjust(struct sndstate **handle, bool ismp3, s32 vol, s32 pan, s32 soun
if (ismp3) {
if (vol != -1) {
vol = vol * snd0000e9dc() / AL_VOL_FULL;
vol = vol * snd_get_sfx_volume() / AL_VOL_FULL;
func00037f08(vol, true);
}
@ -2015,19 +2017,19 @@ void snd_adjust(struct sndstate **handle, bool ismp3, s32 vol, s32 pan, s32 soun
if (*handle != NULL) {
if (vol != -1) {
audioPostEvent(*handle, AL_SNDP_VOL_EVT, vol);
sndp_post_event(*handle, AL_SNDP_VOL_EVT, vol);
}
if (pan != -1) {
audioPostEvent(*handle, AL_SNDP_PAN_EVT, pan & 0x7f);
sndp_post_event(*handle, AL_SNDP_PAN_EVT, pan & 0x7f);
}
if (pitch != -1.0f) {
audioPostEvent(*handle, AL_SNDP_PITCH_EVT, *(s32 *)&pitch);
sndp_post_event(*handle, AL_SNDP_PITCH_EVT, *(s32 *)&pitch);
}
if (fxmix != -1) {
audioPostEvent(*handle, AL_SNDP_FX_EVT, fxmix);
sndp_post_event(*handle, AL_SNDP_FX_EVT, fxmix);
}
}
}
@ -2135,12 +2137,12 @@ struct sndstate *snd_start(s32 arg0, s16 sound, struct sndstate **handle, s32 vo
#if VERSION >= VERSION_NTSC_1_0
if (sp40.id < (u32)g_NumSounds) {
return func00033820(arg0, sp40.id, volume, pan & 0x7f, pitch, fxmix, IS4MB() ? 0 : fxbus, handle);
return sndp_play_sound(arg0, sp40.id, volume, pan & 0x7f, pitch, fxmix, IS4MB() ? 0 : fxbus, handle);
}
return NULL;
#else
return func00033820(arg0, sp40.id, volume, pan & 0x7f, pitch, fxmix, IS4MB() ? 0 : fxbus, handle);
return sndp_play_sound(arg0, sp40.id, volume, pan & 0x7f, pitch, fxmix, IS4MB() ? 0 : fxbus, handle);
#endif
}
@ -2191,7 +2193,7 @@ void snd_start_mp3(s16 soundnum, s32 volume, s32 pan, s32 responseflags)
}
}
volume = volume * snd0000e9dc() / AL_VOL_FULL;
volume = volume * snd_get_sfx_volume() / AL_VOL_FULL;
g_SndCurMp3.romaddr = file_get_rom_address(sp20.id);
g_SndCurMp3.romsize = file_get_rom_size(sp20.id);
@ -2262,7 +2264,7 @@ void snd_tick_nosedive(void)
if (g_SndNosediveVolume) {
snd_adjust(&g_SndNosediveHandle, 0, g_SndNosediveVolume, AL_PAN_CENTER, -1, percentage, 0, -1, 1);
} else if (g_SndNosediveHandle != NULL) {
audioStop(g_SndNosediveHandle);
sndp_stop_sound(g_SndNosediveHandle);
g_SndNosediveHandle = NULL;
}
} else {
@ -2295,7 +2297,7 @@ void snd_tick_nosedive(void)
if (g_SndNosediveVolume) {
snd_adjust(&g_SndNosediveHandle, 0, g_SndNosediveVolume, AL_PAN_CENTER, -1, -1, 0, -1, 1);
} else if (g_SndNosediveHandle != NULL) {
audioStop(g_SndNosediveHandle);
sndp_stop_sound(g_SndNosediveHandle);
g_SndNosediveHandle = NULL;
}
}
@ -2346,7 +2348,7 @@ void snd_tick_ufo(void)
if (g_SndUfoVolume) {
snd_adjust(&g_SndUfoHandle, 0, g_SndUfoVolume, AL_PAN_CENTER, -1, percentage, 0, -1, 1);
} else if (g_SndUfoHandle != NULL) {
audioStop(g_SndUfoHandle);
sndp_stop_sound(g_SndUfoHandle);
g_SndUfoHandle = NULL;
}
} else {
@ -2379,7 +2381,7 @@ void snd_tick_ufo(void)
if (g_SndUfoVolume) {
snd_adjust(&g_SndUfoHandle, 0, g_SndUfoVolume, AL_PAN_CENTER, -1, -1, 0, -1, 1);
} else if (g_SndUfoHandle != NULL) {
audioStop(g_SndUfoHandle);
sndp_stop_sound(g_SndUfoHandle);
g_SndUfoHandle = NULL;
}
}