fix archive creation, must be o2r

This commit is contained in:
Demur Rumed 2025-04-20 21:25:39 +00:00
commit 17d2e39a57
9 changed files with 1598 additions and 1765 deletions

View file

@ -13,61 +13,56 @@
#include "overlays/actors/ovl_Boss_Goma/z_boss_goma.h" #include "overlays/actors/ovl_Boss_Goma/z_boss_goma.h"
std::vector<uint32_t> buttonList = { BTN_A, BTN_B, BTN_CUP, BTN_CDOWN, BTN_CLEFT, BTN_CRIGHT, BTN_L, std::vector<uint32_t> buttonList = { BTN_A, BTN_B, BTN_CUP, BTN_CDOWN, BTN_CLEFT, BTN_CRIGHT, BTN_L,
BTN_Z, BTN_R, BTN_START, BTN_DUP, BTN_DDOWN, BTN_DLEFT, BTN_DRIGHT }; BTN_Z, BTN_R, BTN_START, BTN_DUP, BTN_DDOWN, BTN_DLEFT, BTN_DRIGHT };
//Declarations specific to chests. // Declarations specific to chests.
#include "overlays/actors/ovl_En_Box/z_en_box.h" #include "overlays/actors/ovl_En_Box/z_en_box.h"
extern "C" { extern "C" {
void EnBox_WaitOpen(EnBox*, PlayState*); void EnBox_WaitOpen(EnBox*, PlayState*);
} }
//Declarations specific to Babas. // Declarations specific to Babas.
#include "overlays/actors/ovl_En_Karebaba/z_en_karebaba.h" #include "overlays/actors/ovl_En_Karebaba/z_en_karebaba.h"
extern "C" { extern "C" {
void EnKarebaba_DeadItemDrop(EnKarebaba*, PlayState*); void EnKarebaba_DeadItemDrop(EnKarebaba*, PlayState*);
} }
//Declarations specific to Torches // Declarations specific to Torches
#include "overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.h" #include "overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.h"
//Declarations specific to dogs // Declarations specific to dogs
#include "overlays/actors/ovl_En_Dog/z_en_dog.h" #include "overlays/actors/ovl_En_Dog/z_en_dog.h"
extern "C" { extern "C" {
void EnDog_FollowPlayer(EnDog*, PlayState*); void EnDog_FollowPlayer(EnDog*, PlayState*);
s8 EnDog_CanFollow(EnDog*, PlayState*); s8 EnDog_CanFollow(EnDog*, PlayState*);
} }
//User data for the general helper VA. // User data for the general helper VA.
typedef struct typedef struct {
{
s16 currentScene; s16 currentScene;
s8 currentRoom; s8 currentRoom;
bool currentRoomClear; bool currentRoomClear;
}GeneralHelperData; } GeneralHelperData;
typedef struct typedef struct {
{
f32 linearVelocity; f32 linearVelocity;
int framesUntilChime; int framesUntilChime;
}AudioCompassData; } AudioCompassData;
typedef struct typedef struct {
{
int framesUntilAboveChime; int framesUntilAboveChime;
}SwitchData; } SwitchData;
// Begin actor-specific policy callbacks. // Begin actor-specific policy callbacks.
void accessible_en_ishi(AccessibleActor* actor) { void accessible_en_ishi(AccessibleActor* actor) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_OCTAROCK_ROCK, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_OCTAROCK_ROCK, false);
//ActorAccessibility_PlaySpecialSound(actor, NA_SE_EN_OCTAROCK_ROCK); // ActorAccessibility_PlaySpecialSound(actor, NA_SE_EN_OCTAROCK_ROCK);
} }
void accessible_en_NPC_Gen(AccessibleActor* actor) { void accessible_en_NPC_Gen(AccessibleActor* actor) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_VO_NB_LAUGH, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_VO_NB_LAUGH, false);
} }
void accessible_en_chest(AccessibleActor* actor) { void accessible_en_chest(AccessibleActor* actor) {
Player* player = GET_PLAYER(actor->play); Player* player = GET_PLAYER(actor->play);
EnBox* chest = (EnBox*)actor->actor; EnBox* chest = (EnBox*)actor->actor;
if (chest->actionFunc != EnBox_WaitOpen) if (chest->actionFunc != EnBox_WaitOpen)
@ -77,12 +72,13 @@ void accessible_en_chest(AccessibleActor* actor) {
if (chest->type <= 8 && chest->type >= 5) { if (chest->type <= 8 && chest->type >= 5) {
size = 15; // small size = 15; // small
} else { } else {
size = 30;//large size = 30; // large
} }
if (!(treasureFlag >= 20 && treasureFlag < 32)) { if (!(treasureFlag >= 20 && treasureFlag < 32)) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_TBOX_UNLOCK, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_TBOX_UNLOCK, false);
} }
//Only chests that are "waiting to be opened" should play a sound. Chests which have not yet appeared (because some enemy has not been killed, switch has not been hit, etc) will not be in this action mode. // Only chests that are "waiting to be opened" should play a sound. Chests which have not yet appeared (because some
// enemy has not been killed, switch has not been hit, etc) will not be in this action mode.
f32 leftAngle = actor->actor->world.rot.y - 16384; f32 leftAngle = actor->actor->world.rot.y - 16384;
f32 velocityXRight = Math_SinS(leftAngle); f32 velocityXRight = Math_SinS(leftAngle);
f32 velocityZRight = Math_CosS(leftAngle); f32 velocityZRight = Math_CosS(leftAngle);
@ -92,22 +88,19 @@ void accessible_en_chest(AccessibleActor* actor) {
f32 velocityZFront = Math_CosS(frontAngle); f32 velocityZFront = Math_CosS(frontAngle);
f32 xdist = (player->actor.world.pos.x - actor->actor->world.pos.x) * velocityXFront + f32 xdist = (player->actor.world.pos.x - actor->actor->world.pos.x) * velocityXFront +
(player->actor.world.pos.z-actor->actor->world.pos.z) * velocityZFront; (player->actor.world.pos.z - actor->actor->world.pos.z) * velocityZFront;
f32 zdist = fabs((player->actor.world.pos.x - actor->actor->world.pos.x) * velocityXRight + f32 zdist = fabs((player->actor.world.pos.x - actor->actor->world.pos.x) * velocityXRight +
(player->actor.world.pos.z-actor->actor->world.pos.z) * velocityZRight); (player->actor.world.pos.z - actor->actor->world.pos.z) * velocityZRight);
if ((xdist - size / 2) < 0) { if ((xdist - size / 2) < 0) {
ActorAccessibility_SetSoundPitch(actor, 0, 0.5); ActorAccessibility_SetSoundPitch(actor, 0, 0.5);
} else if ((xdist + size / 2) > 0 && zdist < size / 2 && xdist < 150.0) { } else if ((xdist + size / 2) > 0 && zdist < size / 2 && xdist < 150.0) {
ActorAccessibility_PlaySoundForActor(actor, 1, NA_SE_EV_DIAMOND_SWITCH, false); ActorAccessibility_PlaySoundForActor(actor, 1, NA_SE_EV_DIAMOND_SWITCH, false);
} }
} }
void accessible_en_gerudo(AccessibleActor* actor) { void accessible_en_gerudo(AccessibleActor* actor) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_VO_NB_LAUGH, false);//update sound for ones that detect you ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_VO_NB_LAUGH, false); // update sound for ones that detect you
} }
void accessible_en_Sign(AccessibleActor* actor) { void accessible_en_Sign(AccessibleActor* actor) {
@ -154,7 +147,7 @@ void accessible_torches(AccessibleActor* actor) {
return; return;
} }
//unlit permanent torches // unlit permanent torches
if ((actor->actor->params) == 8192) { if ((actor->actor->params) == 8192) {
if (torche->litTimer == 0) { if (torche->litTimer == 0) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_IT_BOMB_IGNIT, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_IT_BOMB_IGNIT, false);
@ -162,7 +155,7 @@ void accessible_torches(AccessibleActor* actor) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_ANUBIS_FIRE, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_ANUBIS_FIRE, false);
} }
} }
//lit permanent torches // lit permanent torches
if ((actor->actor->params) == 9216 || (actor->actor->params) == 962) { if ((actor->actor->params) == 9216 || (actor->actor->params) == 962) {
actor->policy.volume = 0.5; actor->policy.volume = 0.5;
@ -187,20 +180,17 @@ bool accessible_switch_init(AccessibleActor* actor) {
SwitchData* data = (SwitchData*)malloc(sizeof(SwitchData)); SwitchData* data = (SwitchData*)malloc(sizeof(SwitchData));
data->framesUntilAboveChime = 0; data->framesUntilAboveChime = 0;
if (data == NULL) if (data == NULL)
return false;//failure to allocate memory. return false; // failure to allocate memory.
actor->userData = (void*) data; actor->userData = (void*)data;
return true; return true;
} }
void accessible_switch_cleanup(AccessibleActor* actor) void accessible_switch_cleanup(AccessibleActor* actor) {
{
free(actor->userData); free(actor->userData);
} }
void accessible_switch(AccessibleActor * actor) { void accessible_switch(AccessibleActor* actor) {
SwitchData* data = (SwitchData*)actor->userData; SwitchData* data = (SwitchData*)actor->userData;
Player* player = GET_PLAYER(actor->play); Player* player = GET_PLAYER(actor->play);
ObjSwitch* sw = (ObjSwitch*)actor->actor; ObjSwitch* sw = (ObjSwitch*)actor->actor;
@ -211,26 +201,24 @@ void accessible_switch_cleanup(AccessibleActor* actor)
} }
if (scale.y >= 33.0f / 200.0f) { if (scale.y >= 33.0f / 200.0f) {
if (actor->play->sceneNum == 0 && actor->play->roomCtx.curRoom.num == 5 && actor->xzDistToPlayer < 20) { if (actor->play->sceneNum == 0 && actor->play->roomCtx.curRoom.num == 5 && actor->xzDistToPlayer < 20) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_DIAMOND_SWITCH, false);//Should result in same behaviour. ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_DIAMOND_SWITCH,
false); // Should result in same behaviour.
} }
if (actor->frameCount % 30 != 0) { if (actor->frameCount % 30 != 0) {
return; return;
} }
ActorAccessibility_PlaySoundForActor(actor, 1, NA_SE_EV_FOOT_SWITCH, false); ActorAccessibility_PlaySoundForActor(actor, 1, NA_SE_EV_FOOT_SWITCH, false);
} }
} } else if (actor->frameCount % 30 != 0) {
else if (actor->frameCount % 30 != 0) {
return; return;
} } else if ((actor->actor->params & 7) == 1) {
else if ((actor->actor->params & 7) == 1) {
if (actor->xyzDistToPlayer > 800) { if (actor->xyzDistToPlayer > 800) {
return; return;
} }
if (scale.y >= 33.0f / 200.0f) { //(!(Flags_GetSwitch(actor->play, (actor->params >> 8 & 0x3F)))) { if (scale.y >= 33.0f / 200.0f) { //(!(Flags_GetSwitch(actor->play, (actor->params >> 8 & 0x3F)))) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_IT_HAMMER_HIT, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_IT_HAMMER_HIT, false);
} }
} } else if ((actor->actor->params & 7) == 2) {
else if ((actor->actor->params & 7) == 2) {
if (sw->eyeTexIndex == 0) { //(!(Flags_GetSwitch(actor->play, (actor->params >> 8 & 0x3F)))) if (sw->eyeTexIndex == 0) { //(!(Flags_GetSwitch(actor->play, (actor->params >> 8 & 0x3F))))
// make it only play for open eye // make it only play for open eye
actor->policy.aimAssist.isProvider = true; actor->policy.aimAssist.isProvider = true;
@ -243,9 +231,7 @@ void accessible_switch_cleanup(AccessibleActor* actor)
return; return;
} }
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_DIAMOND_SWITCH, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_DIAMOND_SWITCH, false);
} }
} }
void accessible_larva(AccessibleActor* actor) { void accessible_larva(AccessibleActor* actor) {
@ -261,7 +247,6 @@ void accessible_va_prototype(AccessibleActor* actor) {
Player* player = GET_PLAYER(actor->play); Player* player = GET_PLAYER(actor->play);
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_IT_BOMB_EXPLOSION, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_IT_BOMB_EXPLOSION, false);
} }
void accessible_maruta(AccessibleActor* actor) { void accessible_maruta(AccessibleActor* actor) {
@ -288,8 +273,8 @@ void accessible_area_change(AccessibleActor* actor) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_FANTOM_WARP_L, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_FANTOM_WARP_L, false);
}*/ }*/
//hyrule field attenuation // hyrule field attenuation
if (actor->play->sceneNum == 81) { if (actor->play->sceneNum == 81) {
if (actor->xzDistToPlayer > 700) { if (actor->xzDistToPlayer > 700) {
actor->policy.distance = actor->xzDistToPlayer * 1.2; actor->policy.distance = actor->xzDistToPlayer * 1.2;
if (actor->xzDistToPlayer > 8000) { if (actor->xzDistToPlayer > 8000) {
@ -302,54 +287,52 @@ void accessible_area_change(AccessibleActor* actor) {
} }
} }
} }
//kakariko village attenuation // kakariko village attenuation
else if (actor->play->sceneNum == 82) { else if (actor->play->sceneNum == 82) {
if (actor->sceneIndex == 83 || actor->sceneIndex == 81 || actor->sceneIndex == 96) { if (actor->sceneIndex == 83 || actor->sceneIndex == 81 || actor->sceneIndex == 96) {
actor->policy.runsAlways = true; actor->policy.runsAlways = true;
actor->policy.ydist = 5000; actor->policy.ydist = 5000;
if (actor->xzDistToPlayer > 700) { if (actor->xzDistToPlayer > 700) {
if (actor->sceneIndex == 81) { if (actor->sceneIndex == 81) {
actor->policy.distance = actor->xyzDistToPlayer * 1.4; actor->policy.distance = actor->xyzDistToPlayer * 1.4;
} else {
actor->policy.distance = actor->xyzDistToPlayer * 1.2;
}
if (actor->xzDistToPlayer > 8000) {
return;
}
} else { } else {
actor->policy.distance = 1500; actor->policy.distance = actor->xyzDistToPlayer * 1.2;
if (actor->xzDistToPlayer > 1500) {
return;
}
} }
} else if (actor->sceneIndex == 8) { if (actor->xzDistToPlayer > 8000) {
if (!(((gSaveContext.eventChkInf[6]) >> (7)) & 1))
return;
}
else {
actor->policy.ydist = 500;
actor->policy.distance = 1000;
if (actor->xzDistToPlayer > 1000) {
return; return;
} }
} else {
actor->policy.distance = 1500;
if (actor->xzDistToPlayer > 1500) {
return;
} }
} }
} else if (actor->sceneIndex == 8) {
if (!(((gSaveContext.eventChkInf[6]) >> (7)) & 1))
else if (actor->play->sceneNum == 91 || actor->play->sceneNum == 69 || actor->play->sceneNum == 70) { return;
} else {
actor->policy.ydist = 500;
actor->policy.distance = 1000; actor->policy.distance = 1000;
if (actor->xzDistToPlayer > 1000) { if (actor->xzDistToPlayer > 1000) {
return; return;
} }
} }
/* if (actor->play->sceneNum <= 11) { }
actor->policy.distance = 500;
}*/ else if (actor->play->sceneNum == 91 || actor->play->sceneNum == 69 || actor->play->sceneNum == 70) {
else { actor->policy.distance = 1000;
if (actor->xzDistToPlayer > 1500) { if (actor->xzDistToPlayer > 1000) {
return; return;
}
} }
}
/* if (actor->play->sceneNum <= 11) {
actor->policy.distance = 500;
}*/
else {
if (actor->xzDistToPlayer > 1500) {
return;
}
}
if (actor->sceneIndex == 85 || actor->sceneIndex == 91) { if (actor->sceneIndex == 85 || actor->sceneIndex == 91) {
if (actor->play->sceneNum == 91 && gSaveContext.entranceIndex != 1504 && gSaveContext.entranceIndex != 1246) { if (actor->play->sceneNum == 91 && gSaveContext.entranceIndex != 1504 && gSaveContext.entranceIndex != 1246) {
return; return;
@ -360,26 +343,26 @@ void accessible_area_change(AccessibleActor* actor) {
} else { } else {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_SARIA_MELODY, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_SARIA_MELODY, false);
} }
//kokiri forest and lost woods // kokiri forest and lost woods
} else if (actor->play->sceneNum >= 17 && actor->play->sceneNum <= 25) { } else if (actor->play->sceneNum >= 17 && actor->play->sceneNum <= 25) {
return; // dont check for entrances while in boss rooms return; // dont check for entrances while in boss rooms
} else if (actor->sceneIndex == 81) { } else if (actor->sceneIndex == 81) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_HORSE_RUN_LEVEL, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_HORSE_RUN_LEVEL, false);
//hyrule field // hyrule field
} else if (actor->sceneIndex == 10 && actor->play->sceneNum != 85) {//temp } else if (actor->sceneIndex == 10 && actor->play->sceneNum != 85) { // temp
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_OC_DOOR_OPEN, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_OC_DOOR_OPEN, false);
} else if (actor->sceneIndex <= 11) { } else if (actor->sceneIndex <= 11) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_FANTOM_WARP_L, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_FANTOM_WARP_L, false);
//dungeons // dungeons
} else if (actor->sceneIndex >= 27 && actor->sceneIndex <= 29) { } else if (actor->sceneIndex >= 27 && actor->sceneIndex <= 29) {
if (actor->play->sceneNum >= 32 && actor->play->sceneNum <= 34) { if (actor->play->sceneNum >= 32 && actor->play->sceneNum <= 34) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_HORSE_RUN_LEVEL, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_HORSE_RUN_LEVEL, false);
} else { } else {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_SMALL_DOG_BARK, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_SMALL_DOG_BARK, false);
} }
} else if (actor->sceneIndex >= 30 && actor->sceneIndex <= 33) { } else if (actor->sceneIndex >= 30 && actor->sceneIndex <= 33) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_SMALL_DOG_BARK, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_SMALL_DOG_BARK, false);
//market sound // market sound
} else if ((actor->sceneIndex >= 34 && actor->sceneIndex <= 36) || actor->sceneIndex == 67) { } else if ((actor->sceneIndex >= 34 && actor->sceneIndex <= 36) || actor->sceneIndex == 67) {
if (actor->play->sceneNum == 67) { if (actor->play->sceneNum == 67) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_SMALL_DOG_BARK, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_SMALL_DOG_BARK, false);
@ -387,55 +370,54 @@ void accessible_area_change(AccessibleActor* actor) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_STONE_BOUND, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_STONE_BOUND, false);
} }
//ToT sound // ToT sound
} else if (actor->sceneIndex == 69 || actor->sceneIndex == 70) { } else if (actor->sceneIndex == 69 || actor->sceneIndex == 70) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_MUSI_SINK, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_MUSI_SINK, false);
} else if (actor->sceneIndex == 82) { } else if (actor->sceneIndex == 82) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_CHICKEN_CRY_M, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_CHICKEN_CRY_M, false);
//kakariko sound // kakariko sound
} else if (actor->sceneIndex == 83) { } else if (actor->sceneIndex == 83) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_PO_APPEAR, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_PO_APPEAR, false);
//graveyard sound // graveyard sound
} else if (actor->sceneIndex == 84 || actor->sceneIndex == 88 || actor->sceneIndex == 89) { //last one is zora fountain maybe seperate? } else if (actor->sceneIndex == 84 || actor->sceneIndex == 88 ||
actor->sceneIndex == 89) { // last one is zora fountain maybe seperate?
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_RIVER_STREAM_S, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_RIVER_STREAM_S, false);
//zora sound // zora sound
} else if (actor->sceneIndex == 86) {//might not need to exist } else if (actor->sceneIndex == 86) { // might not need to exist
//forest medow sound // forest medow sound
} else if (actor->sceneIndex == 87) { } else if (actor->sceneIndex == 87) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_WATER_WALL, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_WATER_WALL, false);
//Lake Hylia sound // Lake Hylia sound
} else if (actor->sceneIndex == 90 || actor->sceneIndex == 93) { //gerudo valley and fortress } else if (actor->sceneIndex == 90 || actor->sceneIndex == 93) { // gerudo valley and fortress
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_GERUDOFT_BREATH, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_GERUDOFT_BREATH, false);
//gerudo valley sound // gerudo valley sound
} else if (actor->sceneIndex == 92 || actor->sceneIndex == 94) {//haunted wasteland and desert colosus } else if (actor->sceneIndex == 92 || actor->sceneIndex == 94) { // haunted wasteland and desert colosus
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_SAND_STORM, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_SAND_STORM, false);
} else if (actor->sceneIndex == 100 || actor->sceneIndex ==95) { } else if (actor->sceneIndex == 100 || actor->sceneIndex == 95) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_BRIDGE_OPEN, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_BRIDGE_OPEN, false);
//Hyrule Castle sound // Hyrule Castle sound
} else if (actor->sceneIndex == 96) { } else if (actor->sceneIndex == 96) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_DODO_K_ROLL, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_DODO_K_ROLL, false);
//DMT sound // DMT sound
} else if (actor->sceneIndex == 97) { } else if (actor->sceneIndex == 97) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_DODO_K_LAVA, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_DODO_K_LAVA, false);
//DMC sound // DMC sound
} else if (actor->sceneIndex == 98) { } else if (actor->sceneIndex == 98) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_DARUNIA_HIT_BREAST, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_DARUNIA_HIT_BREAST, false);
//Goron City // Goron City
} else if (actor->sceneIndex == 99) { } else if (actor->sceneIndex == 99) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_COW_CRY, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_COW_CRY, false);
//Lon Lon // Lon Lon
} else if (actor->sceneIndex >= 17 && actor->sceneIndex <= 25) { } else if (actor->sceneIndex >= 17 && actor->sceneIndex <= 25) {
return;//boss rooms return; // boss rooms
} } else {
else {
actor->policy.distance = 500; actor->policy.distance = 500;
if (actor->play->sceneNum == 83) { if (actor->play->sceneNum == 83) {
actor->policy.ydist = 0; actor->policy.ydist = 0;
} }
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_OC_DOOR_OPEN, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_OC_DOOR_OPEN, false);
} }
} }
@ -455,7 +437,6 @@ void accessible_231_dekus(AccessibleActor* actor) {
} else { } else {
return; return;
} }
} }
void accessible_hana(AccessibleActor* actor) { void accessible_hana(AccessibleActor* actor) {
@ -464,7 +445,6 @@ void accessible_hana(AccessibleActor* actor) {
} else if (actor->actor->params == 0) { } else if (actor->actor->params == 0) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_DIG_UP, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_DIG_UP, false);
} }
} }
void accessible_climable(AccessibleActor* actor) { void accessible_climable(AccessibleActor* actor) {
@ -482,35 +462,36 @@ void accessible_en_guard(AccessibleActor* actor) {
f32 guardsfx = NA_SE_IT_SWORD_IMPACT; f32 guardsfx = NA_SE_IT_SWORD_IMPACT;
if (fabs(actor->actor->world.pos.x - player->actor.world.pos.x) > if (fabs(actor->actor->world.pos.x - player->actor.world.pos.x) >
fabs(actor->actor->world.pos.z - player->actor.world.pos.z)) { fabs(actor->actor->world.pos.z - player->actor.world.pos.z)) {
if (fabs(actor->actor->shape.rot.y - 16384) <1000) { if (actor->actor->world.pos.x < player->actor.world.pos.x) { if (fabs(actor->actor->shape.rot.y - 16384) < 1000) {
ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false); if (actor->actor->world.pos.x < player->actor.world.pos.x) {
ActorAccessibility_SetSoundPitch(actor, 0, 2.0);
} else {
ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false);
ActorAccessibility_SetSoundPitch(actor, 0, 0.2);
}
} else if ((actor->actor->shape.rot.y + 16384)<1000) {
if (actor->actor->world.pos.x < player->actor.world.pos.x) {
ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false);
ActorAccessibility_SetSoundPitch(actor, 0, 0.2);
} else {
ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false);
ActorAccessibility_SetSoundPitch(actor, 0, 2.0);
}
} else {
ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false);
ActorAccessibility_SetSoundPitch(actor, 0, 1.0);
}
} else {
if (fabs(actor->actor->shape.rot.y) < 1000) {
if (actor->actor->world.pos.z < player->actor.world.pos.z) {
ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false); ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false);
ActorAccessibility_SetSoundPitch(actor, 0, 2.0); ActorAccessibility_SetSoundPitch(actor, 0, 2.0);
} else { } else {
ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false); ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false);
ActorAccessibility_SetSoundPitch(actor, 0, 0.2); ActorAccessibility_SetSoundPitch(actor, 0, 0.2);
} }
} else if (fabs(actor->actor->shape.rot.y+32768)<1000) { } else if ((actor->actor->shape.rot.y + 16384) < 1000) {
if (actor->actor->world.pos.x < player->actor.world.pos.x) {
ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false);
ActorAccessibility_SetSoundPitch(actor, 0, 0.2);
} else {
ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false);
ActorAccessibility_SetSoundPitch(actor, 0, 2.0);
}
} else {
ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false);
ActorAccessibility_SetSoundPitch(actor, 0, 1.0);
}
} else {
if (fabs(actor->actor->shape.rot.y) < 1000) {
if (actor->actor->world.pos.z < player->actor.world.pos.z) {
ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false);
ActorAccessibility_SetSoundPitch(actor, 0, 2.0);
} else {
ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false);
ActorAccessibility_SetSoundPitch(actor, 0, 0.2);
}
} else if (fabs(actor->actor->shape.rot.y + 32768) < 1000) {
if (actor->actor->world.pos.z < player->actor.world.pos.z) { if (actor->actor->world.pos.z < player->actor.world.pos.z) {
ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false); ActorAccessibility_PlaySoundForActor(actor, 0, guardsfx, false);
ActorAccessibility_SetSoundPitch(actor, 0, 0.2); ActorAccessibility_SetSoundPitch(actor, 0, 0.2);
@ -523,8 +504,6 @@ void accessible_en_guard(AccessibleActor* actor) {
ActorAccessibility_SetSoundPitch(actor, 0, 1.0); ActorAccessibility_SetSoundPitch(actor, 0, 1.0);
} }
} }
} }
void accessible_en_dogs(AccessibleActor* actor) { void accessible_en_dogs(AccessibleActor* actor) {
@ -533,14 +512,12 @@ void accessible_en_dogs(AccessibleActor* actor) {
dog->actionFunc = EnDog_FollowPlayer; dog->actionFunc = EnDog_FollowPlayer;
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_DIAMOND_SWITCH, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_DIAMOND_SWITCH, false);
ActorAccessibility_SetSoundPitch(actor, 0, 1.0); ActorAccessibility_SetSoundPitch(actor, 0, 1.0);
} }
if (actor->frameCount % 30 != 0) { if (actor->frameCount % 30 != 0) {
return; return;
} }
if (actor->actor->params == 608 || actor->actor->params == 336 || actor->actor->params == 304 || if (actor->actor->params == 608 || actor->actor->params == 336 || actor->actor->params == 304 ||
actor->actor->params == 3088 || actor->actor->params == 3088 || actor->actor->params == 2576 || actor->actor->params < 0) {
actor->actor->params == 2576 || actor->actor->params <0) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_SMALL_DOG_BARK, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_SMALL_DOG_BARK, false);
ActorAccessibility_SetSoundPitch(actor, 0, 2.0); ActorAccessibility_SetSoundPitch(actor, 0, 2.0);
@ -548,7 +525,6 @@ void accessible_en_dogs(AccessibleActor* actor) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_SMALL_DOG_BARK, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_SMALL_DOG_BARK, false);
ActorAccessibility_SetSoundPitch(actor, 0, 0.5); ActorAccessibility_SetSoundPitch(actor, 0, 0.5);
} }
} }
void accessible_goma(AccessibleActor* actor) { void accessible_goma(AccessibleActor* actor) {
@ -562,7 +538,7 @@ void accessible_door_of_time(AccessibleActor* actor) {
ActorAccessibility_PlaySampleForActor(actor, 0, "Chanting", false); ActorAccessibility_PlaySampleForActor(actor, 0, "Chanting", false);
ActorAccessibility_SetSoundPitch(actor, 0, 1.0); ActorAccessibility_SetSoundPitch(actor, 0, 1.0);
//ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_DIAMOND_SWITCH, false); // ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_DIAMOND_SWITCH, false);
} }
void accessible_sticks(AccessibleActor* actor) { void accessible_sticks(AccessibleActor* actor) {
@ -574,7 +550,6 @@ void accessible_sticks(AccessibleActor* actor) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_NUTS_DAMAGE, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_NUTS_DAMAGE, false);
} }
} }
void accessible_graveyard_soil(AccessibleActor* actor) { void accessible_graveyard_soil(AccessibleActor* actor) {
@ -602,40 +577,31 @@ bool accessible_general_helper_init(AccessibleActor* actor) {
actor->userData = data; actor->userData = data;
return true; return true;
} }
void accessible_general_helper_cleanup(AccessibleActor* actor) void accessible_general_helper_cleanup(AccessibleActor* actor) {
{
free(actor->userData); free(actor->userData);
actor->userData = NULL; actor->userData = NULL;
} }
void accessible_va_general_helper(AccessibleActor* actor) void accessible_va_general_helper(AccessibleActor* actor) {
{
GeneralHelperData* data = (GeneralHelperData*)actor->userData; GeneralHelperData* data = (GeneralHelperData*)actor->userData;
if (data->currentScene == actor->play->sceneNum && data->currentRoom != actor->play->roomCtx.curRoom.num) if (data->currentScene == actor->play->sceneNum && data->currentRoom != actor->play->roomCtx.curRoom.num) {
{
ActorAccessibility_AnnounceRoomNumber(actor->play); ActorAccessibility_AnnounceRoomNumber(actor->play);
data->currentRoom = actor->play->roomCtx.curRoom.num; data->currentRoom = actor->play->roomCtx.curRoom.num;
data->currentRoomClear = Flags_GetClear(actor->play, data->currentRoom); data->currentRoomClear = Flags_GetClear(actor->play, data->currentRoom);
} }
if (data->currentScene != actor->play->sceneNum) if (data->currentScene != actor->play->sceneNum) {
{
ActorAccessibility_InterpretCurrentScene(actor->play); ActorAccessibility_InterpretCurrentScene(actor->play);
data->currentScene = actor->play->sceneNum; data->currentScene = actor->play->sceneNum;
data->currentRoom = actor->play->roomCtx.curRoom.num; data->currentRoom = actor->play->roomCtx.curRoom.num;
data->currentRoomClear = Flags_GetClear(actor->play, data->currentRoom); data->currentRoomClear = Flags_GetClear(actor->play, data->currentRoom);
} }
//Report when a room is completed. // Report when a room is completed.
if (!data->currentRoomClear && Flags_GetClear(actor->play, data->currentRoom)) if (!data->currentRoomClear && Flags_GetClear(actor->play, data->currentRoom)) {
{
data->currentRoomClear = Flags_GetClear(actor->play, data->currentRoom); data->currentRoomClear = Flags_GetClear(actor->play, data->currentRoom);
ActorAccessibility_AnnounceRoomNumber(actor->play); ActorAccessibility_AnnounceRoomNumber(actor->play);
} }
} }
bool accessible_audio_compass_init(AccessibleActor* actor) bool accessible_audio_compass_init(AccessibleActor* actor) {
{
AudioCompassData* data = (AudioCompassData*)malloc(sizeof(AudioCompassData)); AudioCompassData* data = (AudioCompassData*)malloc(sizeof(AudioCompassData));
if (data == NULL) if (data == NULL)
return false; return false;
@ -644,73 +610,68 @@ bool accessible_audio_compass_init(AccessibleActor* actor)
actor->userData = data; actor->userData = data;
return true; return true;
} }
void accessible_audio_compass_cleanup(AccessibleActor* actor) void accessible_audio_compass_cleanup(AccessibleActor* actor) {
{
free(actor->userData); free(actor->userData);
} }
void accessible_audio_compass(AccessibleActor* actor) { void accessible_audio_compass(AccessibleActor* actor) {
Player* player = GET_PLAYER(actor->play); Player* player = GET_PLAYER(actor->play);
if (player->stateFlags1 & PLAYER_STATE1_Z_TARGETING || player->stateFlags1 & PLAYER_STATE1_CLIMBING_LADDER) if (player->stateFlags1 & PLAYER_STATE1_Z_TARGETING || player->stateFlags1 & PLAYER_STATE1_CLIMBING_LADDER)
return; return;
OSContPad* trackerButtonsPressed = std::dynamic_pointer_cast<LUS::ControlDeck>(Ship::Context::GetInstance()->GetControlDeck())->GetPads(); OSContPad* trackerButtonsPressed =
std::dynamic_pointer_cast<LUS::ControlDeck>(Ship::Context::GetInstance()->GetControlDeck())->GetPads();
AudioCompassData* data = (AudioCompassData*)actor->userData; AudioCompassData* data = (AudioCompassData*)actor->userData;
bool compassCombo = trackerButtonsPressed != nullptr && trackerButtonsPressed[0].button & buttonList[11] && bool compassCombo = trackerButtonsPressed != nullptr && trackerButtonsPressed[0].button & buttonList[11] &&
trackerButtonsPressed[0].button & buttonList[6]; trackerButtonsPressed[0].button & buttonList[6];
actor->world.pos = player->actor.world.pos; actor->world.pos = player->actor.world.pos;
actor->world.pos.z -= 50; actor->world.pos.z -= 50;
if (data->framesUntilChime > 0) if (data->framesUntilChime > 0)
data->framesUntilChime--; data->framesUntilChime--;
if (compassCombo && data->framesUntilChime <= 0) { if (compassCombo && data->framesUntilChime <= 0) {
ActorAccessibility_PlaySoundForActor(actor, 0, actor->policy.sound, false); ActorAccessibility_PlaySoundForActor(actor, 0, actor->policy.sound, false);
data->framesUntilChime = 30; data->framesUntilChime = 30;
}
/* Player* player = GET_PLAYER(actor->play);
if (player->stateFlags1 & PLAYER_STATE1_Z_TARGETING || player->stateFlags1 & PLAYER_STATE1_CLIMBING_LADDER)
return;
actor->world.pos = player->actor.world.pos;
actor->world.pos.z -= 50;
bool shouldChime = false;
if (actor->world.rot.y != player->actor.world.rot.y) {
actor->world.rot.y = player->actor.world.rot.y;
if (player->linearVelocity == 0)
shouldChime = true;
} }
AudioCompassData* data = (AudioCompassData*)actor->userData;
if (data->linearVelocity == 0.0 && player->linearVelocity > 0.0) {
shouldChime = true;
} /* Player* player = GET_PLAYER(actor->play);
data->linearVelocity = player->linearVelocity; if (player->stateFlags1 & PLAYER_STATE1_Z_TARGETING || player->stateFlags1 & PLAYER_STATE1_CLIMBING_LADDER)
if (data->framesUntilChime > 0) return;
data->framesUntilChime--;
if (shouldChime && data->framesUntilChime <= 0) {
ActorAccessibility_PlaySoundForActor(actor, 0, actor->policy.sound, false); actor->world.pos = player->actor.world.pos;
data->framesUntilChime = 10; actor->world.pos.z -= 50;
bool shouldChime = false;
if (actor->world.rot.y != player->actor.world.rot.y) {
actor->world.rot.y = player->actor.world.rot.y;
if (player->linearVelocity == 0)
shouldChime = true;
}
AudioCompassData* data = (AudioCompassData*)actor->userData;
if (data->linearVelocity == 0.0 && player->linearVelocity > 0.0) {
shouldChime = true;
}*/ }
data->linearVelocity = player->linearVelocity;
if (data->framesUntilChime > 0)
data->framesUntilChime--;
if (shouldChime && data->framesUntilChime <= 0) {
ActorAccessibility_PlaySoundForActor(actor, 0, actor->policy.sound, false);
data->framesUntilChime = 10;
}*/
} }
void accessible_stick_warning(AccessibleActor* actor) { void accessible_stick_warning(AccessibleActor* actor) {
Player* player = GET_PLAYER(actor->play); Player* player = GET_PLAYER(actor->play);
actor->world.pos = player->actor.world.pos; actor->world.pos = player->actor.world.pos;
actor->world.pos.z -= 50; actor->world.pos.z -= 50;
if (fabs(player->unk_860 - 25) < 24.0 && player->heldItemId==0) { if (fabs(player->unk_860 - 25) < 24.0 && player->heldItemId == 0) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_SY_WARNING_COUNT_N, false); ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_SY_WARNING_COUNT_N, false);
} }
} }
void ActorAccessibility_InitActors() { void ActorAccessibility_InitActors() {
const int Npc_Frames = 35; const int Npc_Frames = 35;
ActorAccessibilityPolicy policy; ActorAccessibilityPolicy policy;
ActorAccessibility_InitPolicy(&policy, "Rock", accessible_en_ishi, 0); ActorAccessibility_InitPolicy(&policy, "Rock", accessible_en_ishi, 0);
@ -826,7 +787,7 @@ void accessible_stick_warning(AccessibleActor* actor) {
policy.distance = 800; policy.distance = 800;
ActorAccessibility_AddSupportedActor(ACTOR_EN_KANBAN, policy); ActorAccessibility_AddSupportedActor(ACTOR_EN_KANBAN, policy);
//ACTOR_EN_A_OBJ has exactly the same configuration. // ACTOR_EN_A_OBJ has exactly the same configuration.
ActorAccessibility_AddSupportedActor(ACTOR_EN_A_OBJ, policy); ActorAccessibility_AddSupportedActor(ACTOR_EN_A_OBJ, policy);
ActorAccessibility_InitPolicy(&policy, "Large Crate", NULL, NA_SE_EV_WOODBOX_BREAK); ActorAccessibility_InitPolicy(&policy, "Large Crate", NULL, NA_SE_EV_WOODBOX_BREAK);
ActorAccessibility_AddSupportedActor(ACTOR_OBJ_KIBAKO2, policy); ActorAccessibility_AddSupportedActor(ACTOR_OBJ_KIBAKO2, policy);
@ -882,7 +843,6 @@ void accessible_stick_warning(AccessibleActor* actor) {
policy.ydist = 200; policy.ydist = 200;
policy.pitch = 1.1; policy.pitch = 1.1;
ActorAccessibility_AddSupportedActor(ACTOR_OBJ_SWITCH, policy); ActorAccessibility_AddSupportedActor(ACTOR_OBJ_SWITCH, policy);
ActorAccessibility_InitPolicy(&policy, "Ocarina Spots", NULL, NA_SE_EV_DIAMOND_SWITCH); ActorAccessibility_InitPolicy(&policy, "Ocarina Spots", NULL, NA_SE_EV_DIAMOND_SWITCH);
policy.n = 30; policy.n = 30;
@ -902,14 +862,14 @@ void accessible_stick_warning(AccessibleActor* actor) {
policy.distance = 800; policy.distance = 800;
ActorAccessibility_AddSupportedActor(ACTOR_OBJ_SYOKUDAI, policy); ActorAccessibility_AddSupportedActor(ACTOR_OBJ_SYOKUDAI, policy);
ActorAccessibility_InitPolicy(&policy, "Deku Tree Moving Platform", accessible_hasi, 0); ActorAccessibility_InitPolicy(&policy, "Deku Tree Moving Platform", accessible_hasi, 0);
//policy.volume = 1.3; // policy.volume = 1.3;
policy.distance = 1000; policy.distance = 1000;
ActorAccessibility_AddSupportedActor(ACTOR_BG_YDAN_HASI, policy); ActorAccessibility_AddSupportedActor(ACTOR_BG_YDAN_HASI, policy);
ActorAccessibility_InitPolicy(&policy, "Pot", NULL, NA_SE_EV_POT_BROKEN); ActorAccessibility_InitPolicy(&policy, "Pot", NULL, NA_SE_EV_POT_BROKEN);
ActorAccessibility_AddSupportedActor(ACTOR_OBJ_TSUBO, policy); ActorAccessibility_AddSupportedActor(ACTOR_OBJ_TSUBO, policy);
//ActorAccessibility_InitPolicy(&policy, "Deku Tree Entrance", NULL, NA_SE_EV_FANTOM_WARP_L); // ActorAccessibility_InitPolicy(&policy, "Deku Tree Entrance", NULL, NA_SE_EV_FANTOM_WARP_L);
//policy.distance = 5000; // policy.distance = 5000;
//ActorAccessibility_AddSupportedActor(ACTOR_BG_TREEMOUTH, policy); // ActorAccessibility_AddSupportedActor(ACTOR_BG_TREEMOUTH, policy);
ActorAccessibility_InitPolicy(&policy, "Platform collapsable", NULL, NA_SE_EV_BLOCK_SHAKE); ActorAccessibility_InitPolicy(&policy, "Platform collapsable", NULL, NA_SE_EV_BLOCK_SHAKE);
ActorAccessibility_AddSupportedActor(ACTOR_OBJ_LIFT, policy); ActorAccessibility_AddSupportedActor(ACTOR_OBJ_LIFT, policy);
ActorAccessibility_InitPolicy(&policy, "Ladder in Slingshot Room", accessible_maruta, 0); ActorAccessibility_InitPolicy(&policy, "Ladder in Slingshot Room", accessible_maruta, 0);
@ -964,9 +924,9 @@ void accessible_stick_warning(AccessibleActor* actor) {
policy.distance = 2000; policy.distance = 2000;
ActorAccessibility_AddSupportedActor(VA_CRAWLSPACE, policy); ActorAccessibility_AddSupportedActor(VA_CRAWLSPACE, policy);
ActorAccessibility_InitPolicy(&policy, "Ladder/climable", accessible_climable, 0); ActorAccessibility_InitPolicy(&policy, "Ladder/climable", accessible_climable, 0);
//policy.volume = 1.5; // policy.volume = 1.5;
policy.pitch = 1.3; policy.pitch = 1.3;
//policy.distance = 2000; // policy.distance = 2000;
ActorAccessibility_AddSupportedActor(VA_CLIMB, policy); ActorAccessibility_AddSupportedActor(VA_CLIMB, policy);
ActorAccessibility_InitPolicy(&policy, "Door", NULL, NA_SE_OC_DOOR_OPEN); ActorAccessibility_InitPolicy(&policy, "Door", NULL, NA_SE_OC_DOOR_OPEN);
policy.n = 30; policy.n = 30;
@ -978,15 +938,14 @@ void accessible_stick_warning(AccessibleActor* actor) {
policy.n = 60; policy.n = 60;
policy.distance = 100000; policy.distance = 100000;
ActorAccessibility_AddSupportedActor(VA_AREA_CHANGE, policy); ActorAccessibility_AddSupportedActor(VA_AREA_CHANGE, policy);
ActorAccessibility_InitPolicy(&policy, "marker", NULL, ActorAccessibility_InitPolicy(&policy, "marker", NULL, NA_SE_EV_DIAMOND_SWITCH);
NA_SE_EV_DIAMOND_SWITCH);
policy.distance = 1000; policy.distance = 1000;
policy.pitch = 1.7; policy.pitch = 1.7;
ActorAccessibility_AddSupportedActor(VA_MARKER, policy); ActorAccessibility_AddSupportedActor(VA_MARKER, policy);
//ActorAccessibility_InitPolicy(&policy, "Spike", NULL, NA_SE_EV_DIAMOND_SWITCH); // ActorAccessibility_InitPolicy(&policy, "Spike", NULL, NA_SE_EV_DIAMOND_SWITCH);
//policy.distance = 200; // policy.distance = 200;
//policy.pitch = 0.5; // policy.pitch = 0.5;
//ActorAccessibility_AddSupportedActor(VA_SPIKE, policy); // ActorAccessibility_AddSupportedActor(VA_SPIKE, policy);
ActorAccessibility_InitPolicy(&policy, "Stick Burnout Warning", accessible_stick_warning, 0); ActorAccessibility_InitPolicy(&policy, "Stick Burnout Warning", accessible_stick_warning, 0);
policy.n = 1; policy.n = 1;
policy.runsAlways = true; policy.runsAlways = true;
@ -1002,27 +961,27 @@ void accessible_stick_warning(AccessibleActor* actor) {
policy.cleanupUserData = accessible_audio_compass_cleanup; policy.cleanupUserData = accessible_audio_compass_cleanup;
policy.initUserData = accessible_audio_compass_init; policy.initUserData = accessible_audio_compass_init;
policy.runsAlways = true; policy.runsAlways = true;
policy.sound = NA_SE_EV_SHIP_BELL;//Setting this here so it's easy to change if we ever decide to change it. policy.sound = NA_SE_EV_SHIP_BELL; // Setting this here so it's easy to change if we ever decide to change it.
policy.pitch = 0.5; policy.pitch = 0.5;
ActorAccessibility_AddSupportedActor(VA_AUDIO_COMPASS, policy); ActorAccessibility_AddSupportedActor(VA_AUDIO_COMPASS, policy);
// Now query a list of virtual actors for a given // Now query a list of virtual actors for a given
// location (scene // location (scene
// and room // and room
// number). // number).
VirtualActorList* list = (VirtualActorList*)ActorAccessibility_GetVirtualActorList(EVERYWHERE, 0);//Global/ omnipresent. VirtualActorList* list =
(VirtualActorList*)ActorAccessibility_GetVirtualActorList(EVERYWHERE, 0); // Global/ omnipresent.
// Now place the actor. // Now place the actor.
ActorAccessibility_AddVirtualActor(list, VA_GENERAL_HELPER, { { 0.0, 0.0, 0.0 }, { 0, 0, 0 } }); ActorAccessibility_AddVirtualActor(list, VA_GENERAL_HELPER, { { 0.0, 0.0, 0.0 }, { 0, 0, 0 } });
ActorAccessibility_AddVirtualActor(list, VA_AUDIO_COMPASS, { { 0.0, 0.0, 0.0}, { 0, 0, 0 } }); ActorAccessibility_AddVirtualActor(list, VA_AUDIO_COMPASS, { { 0.0, 0.0, 0.0 }, { 0, 0, 0 } });
ActorAccessibility_AddVirtualActor(list, VA_STICK_WARNING, { { 0.0, 0.0, 0.0 }, { 0, 0, 0 } }); ActorAccessibility_AddVirtualActor(list, VA_STICK_WARNING, { { 0.0, 0.0, 0.0 }, { 0, 0, 0 } });
list = ActorAccessibility_GetVirtualActorList(85, 0); // Kokiri Forest list = ActorAccessibility_GetVirtualActorList(85, 0); // Kokiri Forest
ActorAccessibility_AddVirtualActor(list, VA_CRAWLSPACE, { { -784.0, 120.0, 1046.00 }, { 0, 14702, 0 } }); ActorAccessibility_AddVirtualActor(list, VA_CRAWLSPACE, { { -784.0, 120.0, 1046.00 }, { 0, 14702, 0 } });
ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { 2146.5, 1.0, -142.8 } }); ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { 2146.5, 1.0, -142.8 } });
//ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -547.0, 60.0, -1036.00 }, { 0, 14702, 0 } }); // ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -547.0, 60.0, -1036.00 }, { 0, 14702, 0 } });
//ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -29.0, -80.0, 983.00 }, { 0, 14702, 0 } }); // ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -29.0, -80.0, 983.00 }, { 0, 14702, 0 } });
/*ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { -448.0, 0.0, -528.00 }, { 0, 14702, 0 } }); /*ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { -448.0, 0.0, -528.00 }, { 0, 14702, 0 } });
ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { -1082.0, 120.0, 383.00 }, { 0, 14702, 0 } }); ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { -1082.0, 120.0, 383.00 }, { 0, 14702, 0 } });
ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { -27.0, 100.0, 1117.00 }, { 0, 14702, 0 } }); ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { -27.0, 100.0, 1117.00 }, { 0, 14702, 0 } });
@ -1030,50 +989,52 @@ void accessible_stick_warning(AccessibleActor* actor) {
ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { 1046.0, 0.0, 549.00 }, { 0, 14702, 0 } }); ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { 1046.0, 0.0, 549.00 }, { 0, 14702, 0 } });
ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { 848.0, 0.0, -323.00 }, { 0, 14702, 0 } }); ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { 848.0, 0.0, -323.00 }, { 0, 14702, 0 } });
*/ */
//ActorAccessibility_AddVirtualActor(list, VA_AREA_CHANGE,{ { -317.0, 373.2, -1542.00 }, {0, 14702, 0 }}, AREA_KORIRI); // ActorAccessibility_AddVirtualActor(list, VA_AREA_CHANGE,{ { -317.0, 373.2, -1542.00 }, {0, 14702, 0 }},
// AREA_KORIRI);
//ActorAccessibility_AddVirtualActor(list, VA_AREA_CHANGE, { { -1380.0, -67.0, -288.00 }, { 0, 14702, 0 } }, AREA_HYRULE_FIELD); // ActorAccessibility_AddVirtualActor(list, VA_AREA_CHANGE, { { -1380.0, -67.0, -288.00 }, { 0, 14702, 0 } },
// AREA_HYRULE_FIELD);
list = ActorAccessibility_GetVirtualActorList(85, 2); // Kokiri Forest Room with boulder and kokiri sword list = ActorAccessibility_GetVirtualActorList(85, 2); // Kokiri Forest Room with boulder and kokiri sword
ActorAccessibility_AddVirtualActor(list, VA_CRAWLSPACE, { { -788.0, 120.0, 1392.00 }, { 0, 14702, 0 } }); ActorAccessibility_AddVirtualActor(list, VA_CRAWLSPACE, { { -788.0, 120.0, 1392.00 }, { 0, 14702, 0 } });
//list = ActorAccessibility_GetVirtualActorList(38, 0); //know-it-all house // list = ActorAccessibility_GetVirtualActorList(38, 0); //know-it-all house
//ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { 12.0, 0.0, -131.00 }, { 0, 14702, 0 } }); // ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { 12.0, 0.0, -131.00 }, { 0, 14702, 0 } });
//list = ActorAccessibility_GetVirtualActorList(40, 0); // mido house // list = ActorAccessibility_GetVirtualActorList(40, 0); // mido house
//ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { -6.6, 0.0, -179.00 }, { 0, 14702, 0 } }); // ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { -6.6, 0.0, -179.00 }, { 0, 14702, 0 } });
//list = ActorAccessibility_GetVirtualActorList(52, 0); // link's house // list = ActorAccessibility_GetVirtualActorList(52, 0); // link's house
//ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { 2.3, 0.0, -134.00 }, { 0, 14702, 0 } }); // ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { 2.3, 0.0, -134.00 }, { 0, 14702, 0 } });
//list = ActorAccessibility_GetVirtualActorList(41, 0); // saria's house // list = ActorAccessibility_GetVirtualActorList(41, 0); // saria's house
//ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { 1.7, 0.0, -188.00 }, { 0, 14702, 0 } }); // ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { 1.7, 0.0, -188.00 }, { 0, 14702, 0 } });
//list = ActorAccessibility_GetVirtualActorList(39, 0); // twins house // list = ActorAccessibility_GetVirtualActorList(39, 0); // twins house
//ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { 3.0, 0.0, -179.00 }, { 0, 14702, 0 } }); // ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { 3.0, 0.0, -179.00 }, { 0, 14702, 0 } });
//list = ActorAccessibility_GetVirtualActorList(45, 0); // Kokiri Shop // list = ActorAccessibility_GetVirtualActorList(45, 0); // Kokiri Shop
//ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { 0.0, 0.0, 150.00 }, { 0, 14702, 0 } }); // ActorAccessibility_AddVirtualActor(list, VA_DOOR, { { 0.0, 0.0, 150.00 }, { 0, 14702, 0 } });
list = ActorAccessibility_GetVirtualActorList(0, 0);//deku tree main room list = ActorAccessibility_GetVirtualActorList(0, 0); // deku tree main room
//ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -226.7, 0, 197.0 } }); // ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -226.7, 0, 197.0 } });
//ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { 118.6, 0, -286.6 } }); // ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { 118.6, 0, -286.6 } });
//ActorAccessibility_AddVirtualActor(list, VA_AREA_CHANGE, { {0, 0, 640} }, AREA_KORIRI); // ActorAccessibility_AddVirtualActor(list, VA_AREA_CHANGE, { {0, 0, 640} }, AREA_KORIRI);
//ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { 287.4, 368.0, 347.0 } }); // ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { 287.4, 368.0, 347.0 } });
//ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { 419.4, 368.0, 173.6 } }); // ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { 419.4, 368.0, 173.6 } });
//ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { 323, 567.0, 314.6 } }); // ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { 323, 567.0, 314.6 } });
//ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { 127.5, 897.0, 433.6 } }); // ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { 127.5, 897.0, 433.6 } });
//ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { 440.9, 897.0, 101.6 } }); // ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { 440.9, 897.0, 101.6 } });
list = ActorAccessibility_GetVirtualActorList(0, 2); // deku tree slingshot room list = ActorAccessibility_GetVirtualActorList(0, 2); // deku tree slingshot room
//ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -1159, 288.0, 1403.0 } }); // ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -1159, 288.0, 1403.0 } });
//ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -1179.6, 480.0, 1463.6 } }); // ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -1179.6, 480.0, 1463.6 } });
//ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -1398.9, 288.0, 1161.6 } }); // ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -1398.9, 288.0, 1161.6 } });
list = ActorAccessibility_GetVirtualActorList(0, 10); // deku tree compass room list = ActorAccessibility_GetVirtualActorList(0, 10); // deku tree compass room
//ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -762, 733.0, 151.0 } }); // ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -762, 733.0, 151.0 } });
/*ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { -935, 780.0, -113 } }); /*ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { -935, 780.0, -113 } });
ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { -1031.0, 800.0, 109.7 } }); ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { -1031.0, 800.0, 109.7 } });
ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { -1184, 820.0, -103.4 } });*/ ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { -1184, 820.0, -103.4 } });*/
@ -1084,14 +1045,14 @@ void accessible_stick_warning(AccessibleActor* actor) {
list = ActorAccessibility_GetVirtualActorList(0, 3); // deku tree basement 1 lobby list = ActorAccessibility_GetVirtualActorList(0, 3); // deku tree basement 1 lobby
ActorAccessibility_AddVirtualActor(list, VA_CRAWLSPACE, { { -901, -820.0, 0.5 } }); ActorAccessibility_AddVirtualActor(list, VA_CRAWLSPACE, { { -901, -820.0, 0.5 } });
ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { -181.761, -905.0, -28.3 } }); ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { -181.761, -905.0, -28.3 } });
//ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { 108, -919.5, 5.0 } }); // ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { 108, -919.5, 5.0 } });
list = ActorAccessibility_GetVirtualActorList(0, 9); // deku tree b2 lobby list = ActorAccessibility_GetVirtualActorList(0, 9); // deku tree b2 lobby
//ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -639, -1912.5, 188.0 } }); // ActorAccessibility_AddVirtualActor(list, VA_CLIMB, { { -639, -1912.5, 188.0 } });
//Install cues for walls, ledges etc. // Install cues for walls, ledges etc.
list = ActorAccessibility_GetVirtualActorList(1, 2);//dodongo bombflower stairs room list = ActorAccessibility_GetVirtualActorList(1, 2); // dodongo bombflower stairs room
ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { -1958, 20, -1297 } }); ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { -1958, 20, -1297 } });
list = ActorAccessibility_GetVirtualActorList(69, 0);//hyrule courtyard list = ActorAccessibility_GetVirtualActorList(69, 0); // hyrule courtyard
ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { 1734.0, 0.0, 140.514 } }); ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { 1734.0, 0.0, 140.514 } });
AccessibleActor* temp = ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { 1734.0, 0.0, 140.514 } }); AccessibleActor* temp = ActorAccessibility_AddVirtualActor(list, VA_MARKER, { { 1734.0, 0.0, 140.514 } });
temp->policy.pitch = 0.3; temp->policy.pitch = 0.3;
@ -1117,5 +1078,4 @@ void accessible_stick_warning(AccessibleActor* actor) {
temp->policy.pitch = 1.8; temp->policy.pitch = 1.8;
temp->policy.volume = 0.5; temp->policy.volume = 0.5;
ActorAccessibility_InitCues(); ActorAccessibility_InitCues();
} }

View file

@ -7,11 +7,11 @@
#define AAE_MAX_BUFFER_SIZE AAE_SAMPLE_RATE / 10 #define AAE_MAX_BUFFER_SIZE AAE_SAMPLE_RATE / 10
#define AAE_PREP_CHUNK_SIZE 64 #define AAE_PREP_CHUNK_SIZE 64
#define AAE_MIX_CHUNK_SIZE 64 #define AAE_MIX_CHUNK_SIZE 64
#define AAE_GC_INTERVAL 20 * 60//How often, in frames, do we clean up sound handles that are no longer active. #define AAE_GC_INTERVAL 20 * 60 // How often, in frames, do we clean up sound handles that are no longer active.
#define AAE_MAX_DB_REDUCTION -20 #define AAE_MAX_DB_REDUCTION -20
#define AAE_LPF_ORDER 4 #define AAE_LPF_ORDER 4
#define NOMINMAX//because Windows is a joke. #define NOMINMAX // because Windows is a joke.
#include "AccessibleAudioEngine.h" #include "AccessibleAudioEngine.h"
extern "C" { extern "C" {
@ -25,25 +25,25 @@ enum AAE_COMMANDS {
AAE_STOP, AAE_STOP,
AAE_STOP_ALL, AAE_STOP_ALL,
AAE_PITCH, AAE_PITCH,
AAE_PITCH_BEHIND,//Specify how much to change the pitch when the sound is behind the listener. AAE_PITCH_BEHIND, // Specify how much to change the pitch when the sound is behind the listener.
AAE_VOLUME, AAE_VOLUME,
AAE_PAN, AAE_PAN,
AAE_FILTER, AAE_FILTER,
AAE_SEEK, AAE_SEEK,
AAE_LISTENER, //Set the listener's position and direction. AAE_LISTENER, // Set the listener's position and direction.
AAE_POS,//Set the sound source's position and direction. AAE_POS, // Set the sound source's position and direction.
AAE_PREPARE, AAE_PREPARE,
AAE_TERMINATE, AAE_TERMINATE,
}; };
typedef float f32; typedef float f32;
typedef int8_t s8; typedef int8_t s8;
typedef uint8_t u8; typedef uint8_t u8;
//Processing for our custom audio positioning. // Processing for our custom audio positioning.
static float lerp_aae(float x, float y, float z) { static float lerp_aae(float x, float y, float z) {
return (1.0 - z) * x + z * y; return (1.0 - z) * x + z * y;
} }
static float computeGain(SoundExtras * extras) { static float computeGain(SoundExtras* extras) {
if (extras->maxDistance == 0) if (extras->maxDistance == 0)
return 0; return 0;
float leftover = ma_volume_db_to_linear(AAE_MAX_DB_REDUCTION); float leftover = ma_volume_db_to_linear(AAE_MAX_DB_REDUCTION);
@ -53,23 +53,24 @@ static float lerp_aae(float x, float y, float z) {
gain -= lerp_aae(0, leftover, normDist); gain -= lerp_aae(0, leftover, normDist);
return gain; return gain;
} }
//Borrow the pan calculation from the game itself. Todo: this is technical debt, so copy/ revise it or something at some point. // Borrow the pan calculation from the game itself. Todo: this is technical debt, so copy/ revise it or something at
extern "C" int8_t Audio_ComputeSoundPanSigned(float x, float z, uint8_t token); // some point.
static void positioner_process_pcm_frames(ma_node * pNode, const float** ppFramesIn, ma_uint32* pFrameCountIn, extern "C" int8_t Audio_ComputeSoundPanSigned(float x, float z, uint8_t token);
float** ppFramesOut, static void positioner_process_pcm_frames(ma_node* pNode, const float** ppFramesIn, ma_uint32* pFrameCountIn,
ma_uint32* pFrameCountOut) float** ppFramesOut, ma_uint32* pFrameCountOut) {
{
const float* framesIn = ppFramesIn[0]; const float* framesIn = ppFramesIn[0];
float* framesOut = ppFramesOut[0]; float* framesOut = ppFramesOut[0];
ma_copy_pcm_frames(framesOut, framesIn, *pFrameCountIn, ma_format_f32, 2); ma_copy_pcm_frames(framesOut, framesIn, *pFrameCountIn, ma_format_f32, 2);
*pFrameCountOut = *pFrameCountIn; *pFrameCountOut = *pFrameCountIn;
SoundExtras* extras = (SoundExtras*)pNode; SoundExtras* extras = (SoundExtras*)pNode;
//Pan the sound based on its projected position. // Pan the sound based on its projected position.
float pan; float pan;
//Use the game's panning mechanism, which returns a signed 8-bit integer between 0 (far-left) and 127 (far-right). // Use the game's panning mechanism, which returns a signed 8-bit integer between 0 (far-left) and 127 (far-right).
//It would appear that the correct thing to do is interpret this value as a gain factor in decibels. In practice, values below 38 or above 90 are never seen, so a sound that's panned far to one side or the other amounts to about -25DB worth of attenuation. // It would appear that the correct thing to do is interpret this value as a gain factor in decibels. In practice,
//Also: lie about the value of Z and give it a constant value to prevent weird behaviour when Z is far away. // values below 38 or above 90 are never seen, so a sound that's panned far to one side or the other amounts to
// about -25DB worth of attenuation. Also: lie about the value of Z and give it a constant value to prevent weird
// behaviour when Z is far away.
s8 panSigned = Audio_ComputeSoundPanSigned(extras->x, extras->z, 4); s8 panSigned = Audio_ComputeSoundPanSigned(extras->x, extras->z, 4);
int db; int db;
if (panSigned < 64) if (panSigned < 64)
@ -82,36 +83,38 @@ static float lerp_aae(float x, float y, float z) {
ma_panner_set_pan(&extras->panner, pan); ma_panner_set_pan(&extras->panner, pan);
ma_panner_process_pcm_frames(&extras->panner, framesOut, framesOut, *pFrameCountIn); ma_panner_process_pcm_frames(&extras->panner, framesOut, framesOut, *pFrameCountIn);
//Next we'll apply the gain based on the object's distance relationship to the player. The strategy here is to use a combination of decibel-based and linear attenuation, so that the gain reaches 0 at the exact point when the object is at exactly the maximum distance from the player. // Next we'll apply the gain based on the object's distance relationship to the player. The strategy here is to use
// a combination of decibel-based and linear attenuation, so that the gain reaches 0 at the exact point when the
// object is at exactly the maximum distance from the player.
float gain = computeGain(extras); float gain = computeGain(extras);
ma_gainer_set_gain(&extras->gainer, gain); ma_gainer_set_gain(&extras->gainer, gain);
ma_gainer_process_pcm_frames(&extras->gainer, framesOut, framesOut, *pFrameCountIn); ma_gainer_process_pcm_frames(&extras->gainer, framesOut, framesOut, *pFrameCountIn);
//Run LPF only when necessary because we can't afford to run a 4th-order lowpass on every single sound. This probably causes minor glitches when the filter switches on and off. Todo: cross that bridge. // Run LPF only when necessary because we can't afford to run a 4th-order lowpass on every single sound. This
// probably causes minor glitches when the filter switches on and off. Todo: cross that bridge.
if (extras->cutoff != 1.0) if (extras->cutoff != 1.0)
ma_lpf_process_pcm_frames(&extras->filter, framesOut, framesOut, *pFrameCountIn); ma_lpf_process_pcm_frames(&extras->filter, framesOut, framesOut, *pFrameCountIn);
} }
static ma_node_vtable positioner_vtable = { static ma_node_vtable positioner_vtable = { positioner_process_pcm_frames, NULL, 1, 1, 0 };
positioner_process_pcm_frames, NULL, 1, 1, 0};
static ma_uint32 positioner_channels[1] = { 2 }; static ma_uint32 positioner_channels[1] = { 2 };
void AccessibleAudioEngine::destroy() { void AccessibleAudioEngine::destroy() {
switch (initialized){ switch (initialized) {
case 3: case 3:
ma_engine_uninit(&engine); ma_engine_uninit(&engine);
case 2: case 2:
ma_pcm_rb_uninit(&preparedOutput); ma_pcm_rb_uninit(&preparedOutput);
case 1: case 1:
ma_resource_manager_uninit(&resourceManager); ma_resource_manager_uninit(&resourceManager);
} }
} }
void AccessibleAudioEngine::destroyAndThrow(const char* exceptionText) { void AccessibleAudioEngine::destroyAndThrow(const char* exceptionText) {
destroy(); destroy();
throw std::runtime_error(exceptionText); throw std::runtime_error(exceptionText);
} }
uint32_t AccessibleAudioEngine::retrieve(float* buffer, uint32_t nFrames) { uint32_t AccessibleAudioEngine::retrieve(float* buffer, uint32_t nFrames) {
uint32_t framesAvailable = ma_pcm_rb_available_read(&preparedOutput); uint32_t framesAvailable = ma_pcm_rb_available_read(&preparedOutput);
if (nFrames > framesAvailable) if (nFrames > framesAvailable)
nFrames = framesAvailable; nFrames = framesAvailable;
@ -128,16 +131,13 @@ throw std::runtime_error(exceptionText);
memcpy(buffer, readBuffer, sizeof(float) * framesObtained * AAE_CHANNELS); memcpy(buffer, readBuffer, sizeof(float) * framesObtained * AAE_CHANNELS);
buffer += framesObtained * AAE_CHANNELS; buffer += framesObtained * AAE_CHANNELS;
nFrames -= framesObtained; nFrames -= framesObtained;
ma_pcm_rb_commit_read(&preparedOutput, framesObtained); ma_pcm_rb_commit_read(&preparedOutput, framesObtained);
} }
return ogNFrames; return ogNFrames;
} }
void AccessibleAudioEngine::doPrepare(SoundAction& action) void AccessibleAudioEngine::doPrepare(SoundAction& action) {
{
framesUntilGC--; framesUntilGC--;
int nFrames = ma_pcm_rb_available_write(&preparedOutput); int nFrames = ma_pcm_rb_available_write(&preparedOutput);
if (nFrames <= 0) if (nFrames <= 0)
@ -145,19 +145,19 @@ void AccessibleAudioEngine::doPrepare(SoundAction& action)
float* chunk; float* chunk;
while (nFrames > 0) { while (nFrames > 0) {
//This should not loop more than twice. // This should not loop more than twice.
uint32_t nextChunk = nFrames; uint32_t nextChunk = nFrames;
ma_pcm_rb_acquire_write(&preparedOutput, &nextChunk, (void**)&chunk);//Might reduce nextChunk if there isn't enough buffer space available to accommodate the request. ma_pcm_rb_acquire_write(&preparedOutput, &nextChunk,
(void**)&chunk); // Might reduce nextChunk if there isn't enough buffer space available
// to accommodate the request.
ma_uint64 framesRead = 0; ma_uint64 framesRead = 0;
ma_engine_read_pcm_frames(&engine, chunk, nextChunk, &framesRead); ma_engine_read_pcm_frames(&engine, chunk, nextChunk, &framesRead);
//Even if we get fewer frames than expected, we should still submit a full buffer of silence. // Even if we get fewer frames than expected, we should still submit a full buffer of silence.
if (framesRead < nextChunk) if (framesRead < nextChunk)
ma_silence_pcm_frames(chunk + (framesRead * 2), (nextChunk - framesRead), ma_format_f32, 2); ma_silence_pcm_frames(chunk + (framesRead * 2), (nextChunk - framesRead), ma_format_f32, 2);
ma_pcm_rb_commit_write(&preparedOutput, (uint32_t) nextChunk); ma_pcm_rb_commit_write(&preparedOutput, (uint32_t)nextChunk);
nFrames -= nextChunk; nFrames -= nextChunk;
} }
} }
int AccessibleAudioEngine::getSoundActions(SoundAction* dest, int limit) { int AccessibleAudioEngine::getSoundActions(SoundAction* dest, int limit) {
std::unique_lock<std::mutex> lock(mtx); std::unique_lock<std::mutex> lock(mtx);
@ -171,9 +171,8 @@ int AccessibleAudioEngine::getSoundActions(SoundAction* dest, int limit) {
limit--; limit--;
} }
return actionsOut; return actionsOut;
} }
void AccessibleAudioEngine::postSoundActions(){ void AccessibleAudioEngine::postSoundActions() {
{ {
std::scoped_lock<std::mutex> lock(mtx); std::scoped_lock<std::mutex> lock(mtx);
for (int i = 0; i < nextOutgoingSoundAction; i++) for (int i = 0; i < nextOutgoingSoundAction; i++)
@ -187,284 +186,263 @@ void AccessibleAudioEngine::postHighPrioritySoundAction(SoundAction& action) {
soundActions.push_front(action); soundActions.push_front(action);
cv.notify_one(); cv.notify_one();
} }
SoundAction& AccessibleAudioEngine::getNextOutgoingSoundAction() { SoundAction& AccessibleAudioEngine::getNextOutgoingSoundAction() {
if (nextOutgoingSoundAction >= AAE_SOUND_ACTION_BATCH_SIZE) if (nextOutgoingSoundAction >= AAE_SOUND_ACTION_BATCH_SIZE)
postSoundActions(); postSoundActions();
nextOutgoingSoundAction++; nextOutgoingSoundAction++;
return outgoingSoundActions[nextOutgoingSoundAction - 1]; return outgoingSoundActions[nextOutgoingSoundAction - 1];
} }
void AccessibleAudioEngine::runThread() { void AccessibleAudioEngine::runThread() {
bool shouldTerminate = false; bool shouldTerminate = false;
SoundAction incomingSoundActions[AAE_SOUND_ACTION_BATCH_SIZE]; SoundAction incomingSoundActions[AAE_SOUND_ACTION_BATCH_SIZE];
while (true) { while (true) {
processAudioJobs(); processAudioJobs();
if (framesUntilGC <= 0) if (framesUntilGC <= 0)
garbageCollect(); garbageCollect();
int batchSize = getSoundActions(incomingSoundActions, AAE_SOUND_ACTION_BATCH_SIZE); int batchSize = getSoundActions(incomingSoundActions, AAE_SOUND_ACTION_BATCH_SIZE);
for (int i = 0; i < batchSize; i++) { for (int i = 0; i < batchSize; i++) {
SoundAction& action = incomingSoundActions[i]; SoundAction& action = incomingSoundActions[i];
switch (action.command) { switch (action.command) {
case AAE_TERMINATE: case AAE_TERMINATE:
return; return;
case AAE_START: case AAE_START:
doPlaySound(action); doPlaySound(action);
break; break;
case AAE_STOP: case AAE_STOP:
doStopSound(action); doStopSound(action);
break; break;
case AAE_STOP_ALL: case AAE_STOP_ALL:
doStopAllSounds(action); doStopAllSounds(action);
break; break;
case AAE_PITCH: case AAE_PITCH:
doSetPitch(action); doSetPitch(action);
break; break;
case AAE_PITCH_BEHIND: case AAE_PITCH_BEHIND:
doSetPitchBehindModifier(action); doSetPitchBehindModifier(action);
break; break;
case AAE_VOLUME: case AAE_VOLUME:
doSetVolume(action); doSetVolume(action);
break; break;
case AAE_PAN: case AAE_PAN:
doSetPan(action); doSetPan(action);
break; break;
case AAE_FILTER: case AAE_FILTER:
doSetFilter(action); doSetFilter(action);
break; break;
case AAE_SEEK: case AAE_SEEK:
doSeekSound(action); doSeekSound(action);
break; break;
case AAE_LISTENER: case AAE_LISTENER:
doSetListenerPos(action); doSetListenerPos(action);
break; break;
case AAE_POS: case AAE_POS:
doSetSoundPos(action); doSetSoundPos(action);
break; break;
case AAE_PREPARE: case AAE_PREPARE:
doPrepare(action); doPrepare(action);
break; break;
}
} }
}
} }
} }
SoundSlot* AccessibleAudioEngine::findSound(SoundAction& action) SoundSlot* AccessibleAudioEngine::findSound(SoundAction& action) {
{
if (action.slot < 0 || action.slot >= AAE_SLOTS_PER_HANDLE) if (action.slot < 0 || action.slot >= AAE_SLOTS_PER_HANDLE)
return NULL; return NULL;
auto i = sounds.find(action.handle); auto i = sounds.find(action.handle);
if (i == sounds.end()) if (i == sounds.end())
return NULL; return NULL;
SoundSlot& target = i->second[action.slot]; SoundSlot& target = i->second[action.slot];
if (!target.active) if (!target.active)
return NULL; return NULL;
return &target; return &target;
}
} void AccessibleAudioEngine::doPlaySound(SoundAction& action) {
void AccessibleAudioEngine::doPlaySound(SoundAction& action) {
SoundSlot* sound; SoundSlot* sound;
if (sounds.contains(action.handle)) { if (sounds.contains(action.handle)) {
sound = &sounds[action.handle][action.slot]; sound = &sounds[action.handle][action.slot];
if (sound->active) { if (sound->active) {
ma_sound_stop(&sound->sound); ma_sound_stop(&sound->sound);
destroySound(sound); destroySound(sound);
} }
} }
else { else {
SoundSlots temp; SoundSlots temp;
for (int i = 0; i < AAE_SLOTS_PER_HANDLE; i++) for (int i = 0; i < AAE_SLOTS_PER_HANDLE; i++)
temp[i].active = false; temp[i].active = false;
sounds[action.handle] = temp; sounds[action.handle] = temp;
sound = &sounds[action.handle][action.slot]; sound = &sounds[action.handle][action.slot];
} }
if (ma_sound_init_from_file(&engine, action.path.c_str(), MA_SOUND_FLAG_NO_SPATIALIZATION|MA_SOUND_FLAG_NO_DEFAULT_ATTACHMENT, NULL, NULL, if (ma_sound_init_from_file(&engine, action.path.c_str(),
MA_SOUND_FLAG_NO_SPATIALIZATION | MA_SOUND_FLAG_NO_DEFAULT_ATTACHMENT, NULL, NULL,
&sound->sound) != MA_SUCCESS) &sound->sound) != MA_SUCCESS)
return; return;
initSoundExtras(sound); initSoundExtras(sound);
ma_sound_set_looping(&sound->sound, action.looping); ma_sound_set_looping(&sound->sound, action.looping);
//We actually attach the extras to the engine, not the sound itself. // We actually attach the extras to the engine, not the sound itself.
ma_node_attach_output_bus(&sound->extras, 0, ma_node_graph_get_endpoint(&engine.nodeGraph), 0); ma_node_attach_output_bus(&sound->extras, 0, ma_node_graph_get_endpoint(&engine.nodeGraph), 0);
ma_sound_start(&sound->sound); ma_sound_start(&sound->sound);
sound->active = true; sound->active = true;
}
void AccessibleAudioEngine::doStopSound(SoundAction& action) {
SoundSlot* slot = findSound(action);
if (slot == NULL)
return;
destroySound(slot);
}
void AccessibleAudioEngine::doStopAllSounds(SoundAction& action) {
auto it = sounds.find(action.handle);
if (it == sounds.end())
return;
SoundSlots& slots = it->second;
for (int i = 0; i < AAE_SLOTS_PER_HANDLE; i++) {
if (slots[i].active)
destroySound(&slots[i]);
} }
void AccessibleAudioEngine::doStopSound(SoundAction& action) { sounds.erase(it);
SoundSlot* slot = findSound(action); }
if (slot == NULL) void AccessibleAudioEngine::doSetPitch(SoundAction& action) {
return; SoundSlot* slot = findSound(action);
destroySound(slot); if (slot == NULL)
} return;
void AccessibleAudioEngine::doStopAllSounds(SoundAction& action) slot->extras.pitch = action.pitch;
{ float pitch = action.pitch;
auto it = sounds.find(action.handle); if (slot->extras.z < 0)
if (it == sounds.end()) pitch *= (1.0 - slot->extras.pitchBehindModifier);
return; ma_sound_set_pitch(&slot->sound, pitch);
SoundSlots& slots = it->second; }
for (int i = 0; i < AAE_SLOTS_PER_HANDLE; i++)
{
if (slots[i].active)
destroySound(&slots[i]);
}
sounds.erase(it);
} void AccessibleAudioEngine::doSetPitchBehindModifier(SoundAction& action) {
void AccessibleAudioEngine::doSetPitch(SoundAction& action) SoundSlot* slot = findSound(action);
{ if (slot == NULL)
SoundSlot* slot = findSound(action); return;
if (slot == NULL) slot->extras.pitchBehindModifier = action.pitch;
return; }
slot->extras.pitch = action.pitch; void AccessibleAudioEngine::doSetVolume(SoundAction& action) {
float pitch = action.pitch; SoundSlot* slot = findSound(action);
if (slot->extras.z < 0) if (slot == NULL)
pitch *= (1.0 - slot->extras.pitchBehindModifier); return;
ma_sound_set_pitch(&slot->sound, pitch); ma_sound_set_volume(&slot->sound, action.pitch);
}
} void AccessibleAudioEngine::doSetPan(SoundAction& action) {
SoundSlot* slot = findSound(action);
void AccessibleAudioEngine::doSetPitchBehindModifier(SoundAction& action) if (slot == NULL)
{ return;
SoundSlot* slot = findSound(action); ma_sound_set_pan(&slot->sound, action.pan);
if (slot == NULL) }
return; void AccessibleAudioEngine::doSetFilter(SoundAction& action) {
slot->extras.pitchBehindModifier = action.pitch; SoundSlot* slot = findSound(action);
} if (slot == NULL)
void AccessibleAudioEngine::doSetVolume(SoundAction& action) return;
{ slot->extras.cutoff = action.cutoff;
SoundSlot* slot = findSound(action); ma_lpf_config config = ma_lpf_config_init(ma_format_f32, AAE_CHANNELS, AAE_SAMPLE_RATE,
if (slot == NULL) lerp_aae(0.0, AAE_SAMPLE_RATE / 2, action.cutoff), AAE_LPF_ORDER);
return; ma_lpf_reinit(&config, &slot->extras.filter);
ma_sound_set_volume(&slot->sound, action.pitch); }
void AccessibleAudioEngine::doSeekSound(SoundAction& action) {
} SoundSlot* slot = findSound(action);
void AccessibleAudioEngine::doSetPan(SoundAction& action) if (slot == NULL)
{ return;
SoundSlot* slot = findSound(action); ma_sound_seek_to_pcm_frame(&slot->sound, action.offset);
if (slot == NULL) }
return; void AccessibleAudioEngine::doSetListenerPos(SoundAction& action) {
ma_sound_set_pan(&slot->sound, action.pan); }
} void AccessibleAudioEngine::doSetSoundPos(SoundAction& action) {
void AccessibleAudioEngine::doSetFilter(SoundAction& action) SoundSlot* slot = findSound(action);
{ if (slot == NULL)
SoundSlot* slot = findSound(action); return;
if (slot == NULL) slot->extras.x = action.posX;
return; slot->extras.y = action.posY;
slot->extras.cutoff = action.cutoff; slot->extras.z = action.posZ;
ma_lpf_config config = slot->extras.distToPlayer = action.distToPlayer;
ma_lpf_config_init(ma_format_f32, AAE_CHANNELS, AAE_SAMPLE_RATE, lerp_aae(0.0, AAE_SAMPLE_RATE / 2, action.cutoff), AAE_LPF_ORDER); slot->extras.maxDistance = action.maxDistance;
ma_lpf_reinit(&config, &slot->extras.filter); float pitch = slot->extras.pitch;
if (action.posZ < 0)
} pitch *= (1.0 - slot->extras.pitchBehindModifier);
void AccessibleAudioEngine::doSeekSound(SoundAction& action) ma_sound_set_pitch(&slot->sound, pitch);
{ }
SoundSlot* slot = findSound(action); void AccessibleAudioEngine::garbageCollect() {
if (slot == NULL) for (auto i = sounds.begin(); i != sounds.end();) {
return; int deadSlots = 0;
ma_sound_seek_to_pcm_frame(&slot->sound, action.offset); for (int x = 0; x < AAE_SLOTS_PER_HANDLE; x++) {
} if (!i->second[x].active)
void AccessibleAudioEngine::doSetListenerPos(SoundAction& action) deadSlots++;
{ else if (!ma_sound_is_playing(&i->second[x].sound)) {
destroySound(&i->second[x]);
} i->second[x].active = false;
void AccessibleAudioEngine::doSetSoundPos(SoundAction& action) deadSlots++;
{
SoundSlot* slot = findSound(action);
if (slot == NULL)
return;
slot->extras.x = action.posX;
slot->extras.y = action.posY;
slot->extras.z = action.posZ;
slot->extras.distToPlayer = action.distToPlayer;
slot->extras.maxDistance = action.maxDistance;
float pitch = slot->extras.pitch;
if (action.posZ < 0)
pitch *= (1.0 - slot->extras.pitchBehindModifier);
ma_sound_set_pitch(&slot->sound, pitch);
}
void AccessibleAudioEngine::garbageCollect()
{
for (auto i = sounds.begin(); i != sounds.end(); ) {
int deadSlots = 0;
for (int x = 0; x < AAE_SLOTS_PER_HANDLE; x++) {
if (!i->second[x].active)
deadSlots++;
else if (!ma_sound_is_playing(&i->second[x].sound)) {
destroySound(&i->second[x]);
i->second[x].active = false;
deadSlots++;
}
} }
if (deadSlots == AAE_SLOTS_PER_HANDLE) // Entire batch is garbage.
i = sounds.erase(i);
else
i++;
} }
framesUntilGC = AAE_GC_INTERVAL; if (deadSlots == AAE_SLOTS_PER_HANDLE) // Entire batch is garbage.
i = sounds.erase(i);
else
i++;
} }
void AccessibleAudioEngine::processAudioJobs() framesUntilGC = AAE_GC_INTERVAL;
{ }
ma_job job; void AccessibleAudioEngine::processAudioJobs() {
while (ma_resource_manager_next_job(&resourceManager, &job) == MA_SUCCESS) ma_job job;
ma_job_process(&job); while (ma_resource_manager_next_job(&resourceManager, &job) == MA_SUCCESS)
ma_job_process(&job);
}
bool AccessibleAudioEngine::initSoundExtras(SoundSlot* slot) {
ma_node_config config = ma_node_config_init();
config.inputBusCount = 1;
config.outputBusCount = 1;
config.pInputChannels = positioner_channels;
config.pOutputChannels = positioner_channels;
config.vtable = &positioner_vtable;
memset(&slot->extras, 0, sizeof(SoundExtras));
if (ma_node_init(&engine.nodeGraph, &config, NULL, &slot->extras) != MA_SUCCESS)
return false;
ma_panner_config pc = ma_panner_config_init(ma_format_f32, AAE_CHANNELS);
pc.mode = ma_pan_mode_balance;
ma_panner_init(&pc, &slot->extras.panner);
ma_gainer_config gc = ma_gainer_config_init(
AAE_CHANNELS,
AAE_SAMPLE_RATE / 20); // Allow one in-game frame for the gain to work its way towards the target value.
if (ma_gainer_init(&gc, NULL, &slot->extras.gainer) != MA_SUCCESS)
return false;
ma_lpf_config fc =
ma_lpf_config_init(ma_format_f32, AAE_CHANNELS, AAE_SAMPLE_RATE, AAE_SAMPLE_RATE / 2, AAE_LPF_ORDER);
ma_lpf_init(&fc, NULL, &slot->extras.filter);
slot->extras.cutoff = 1.0f;
slot->extras.pitch = 1.0f;
slot->extras.pitchBehindModifier = 0.0f;
// ma_node_attach_output_bus(&slot->sound, 0, &slot->extras.filter, 0);
ma_node_attach_output_bus(&slot->sound, 0, &slot->extras, 0);
return true;
}
void AccessibleAudioEngine::destroySound(SoundSlot* slot) {
ma_node_detach_all_output_buses(&slot->extras);
ma_sound_uninit(&slot->sound);
ma_gainer_uninit(&slot->extras.gainer, NULL);
} slot->active = false;
bool AccessibleAudioEngine::initSoundExtras(SoundSlot* slot) { }
ma_node_config config = ma_node_config_init();
config.inputBusCount = 1;
config.outputBusCount = 1;
config.pInputChannels = positioner_channels;
config.pOutputChannels = positioner_channels;
config.vtable = &positioner_vtable;
memset(&slot->extras, 0, sizeof(SoundExtras));
if (ma_node_init(&engine.nodeGraph, &config, NULL, &slot->extras) != MA_SUCCESS)
return false;
ma_panner_config pc = ma_panner_config_init(ma_format_f32, AAE_CHANNELS);
pc.mode = ma_pan_mode_balance;
ma_panner_init(&pc, &slot->extras.panner);
ma_gainer_config gc = ma_gainer_config_init(AAE_CHANNELS, AAE_SAMPLE_RATE / 20);//Allow one in-game frame for the gain to work its way towards the target value.
if (ma_gainer_init(&gc, NULL, &slot->extras.gainer) != MA_SUCCESS)
return false;
ma_lpf_config fc = ma_lpf_config_init(ma_format_f32, AAE_CHANNELS, AAE_SAMPLE_RATE, AAE_SAMPLE_RATE / 2, AAE_LPF_ORDER);
ma_lpf_init(&fc, NULL, &slot->extras.filter);
slot->extras.cutoff = 1.0f;
slot->extras.pitch = 1.0f;
slot->extras.pitchBehindModifier = 0.0f;
//ma_node_attach_output_bus(&slot->sound, 0, &slot->extras.filter, 0);
ma_node_attach_output_bus(&slot->sound, 0, &slot->extras, 0);
return true;
} AccessibleAudioEngine::AccessibleAudioEngine() {
void AccessibleAudioEngine::destroySound(SoundSlot* slot) { initialized = 0;
ma_node_detach_all_output_buses(&slot->extras); ma_resource_manager_config rmc = ma_resource_manager_config_init();
ma_sound_uninit(&slot->sound); rmc.decodedChannels = AAE_CHANNELS;
ma_gainer_uninit(&slot->extras.gainer, NULL); rmc.decodedFormat = ma_format_f32;
rmc.decodedSampleRate = AAE_SAMPLE_RATE;
slot->active = false; rmc.flags = MA_RESOURCE_MANAGER_FLAG_NON_BLOCKING;
rmc.jobThreadCount = 0;
} if (ma_resource_manager_init(&rmc, &resourceManager) != MA_SUCCESS)
destroyAndThrow("AccessibleAudioEngine: Unable to initialize the resource manager.");
AccessibleAudioEngine::AccessibleAudioEngine() { initialized = 1;
initialized = 0; if (ma_pcm_rb_init(ma_format_f32, AAE_CHANNELS, AAE_MAX_BUFFER_SIZE, NULL, NULL, &preparedOutput) != MA_SUCCESS)
ma_resource_manager_config rmc = ma_resource_manager_config_init(); destroyAndThrow("AccessibleAudioEngine: Unable to initialize the output buffer.");
rmc.decodedChannels = AAE_CHANNELS; initialized = 2;
rmc.decodedFormat = ma_format_f32; ma_engine_config ec = ma_engine_config_init();
rmc.decodedSampleRate = AAE_SAMPLE_RATE;
rmc.flags = MA_RESOURCE_MANAGER_FLAG_NON_BLOCKING;
rmc.jobThreadCount = 0;
if (ma_resource_manager_init(&rmc, &resourceManager) != MA_SUCCESS)
destroyAndThrow("AccessibleAudioEngine: Unable to initialize the resource manager.");
initialized = 1;
if (ma_pcm_rb_init(ma_format_f32, AAE_CHANNELS, AAE_MAX_BUFFER_SIZE, NULL, NULL, &preparedOutput) != MA_SUCCESS)
destroyAndThrow("AccessibleAudioEngine: Unable to initialize the output buffer.");
initialized = 2;
ma_engine_config ec = ma_engine_config_init();
ec.channels = AAE_CHANNELS; ec.channels = AAE_CHANNELS;
ec.noDevice = true; ec.noDevice = true;
ec.sampleRate = AAE_SAMPLE_RATE; ec.sampleRate = AAE_SAMPLE_RATE;
@ -477,152 +455,150 @@ void AccessibleAudioEngine::postHighPrioritySoundAction(SoundAction& action) {
nextOutgoingSoundAction = 0; nextOutgoingSoundAction = 0;
framesUntilGC = AAE_GC_INTERVAL; framesUntilGC = AAE_GC_INTERVAL;
thread = std::thread(&AccessibleAudioEngine::runThread, this); thread = std::thread(&AccessibleAudioEngine::runThread, this);
}
} AccessibleAudioEngine::~AccessibleAudioEngine() {
AccessibleAudioEngine::~AccessibleAudioEngine() { // Place a terminate command on the top of the pile, then wait for thread to die.
//Place a terminate command on the top of the pile, then wait for thread to die. SoundAction action;
SoundAction action; action.command = AAE_TERMINATE;
action.command = AAE_TERMINATE; postHighPrioritySoundAction(action);
postHighPrioritySoundAction(action); thread.join();
thread.join(); destroy();
destroy(); }
void AccessibleAudioEngine::mix(int16_t* ogBuffer, uint32_t nFrames) {
} uint32_t framesAvailable = ma_pcm_rb_available_read(&preparedOutput);
void AccessibleAudioEngine::mix(int16_t * ogBuffer, uint32_t nFrames) { float sourceChunk[AAE_MIX_CHUNK_SIZE * AAE_CHANNELS];
uint32_t framesAvailable = ma_pcm_rb_available_read(&preparedOutput); float mixedChunk[AAE_MIX_CHUNK_SIZE * AAE_CHANNELS];
float sourceChunk[AAE_MIX_CHUNK_SIZE * AAE_CHANNELS]; while (nFrames > 0) {
float mixedChunk[AAE_MIX_CHUNK_SIZE * AAE_CHANNELS]; uint32_t nextChunk = std::min<uint32_t>(AAE_MIX_CHUNK_SIZE, nFrames);
while (nFrames > 0) { ma_silence_pcm_frames(
uint32_t nextChunk = std::min <uint32_t> (AAE_MIX_CHUNK_SIZE, nFrames); sourceChunk, nextChunk, ma_format_f32,
ma_silence_pcm_frames(sourceChunk, nextChunk, ma_format_f32, AAE_CHANNELS);//This is so that it doesn't matter if we have less output available than expected. AAE_CHANNELS); // This is so that it doesn't matter if we have less output available than expected.
ma_silence_pcm_frames(mixedChunk, nextChunk, ma_format_f32, AAE_CHANNELS); ma_silence_pcm_frames(mixedChunk, nextChunk, ma_format_f32, AAE_CHANNELS);
retrieve(sourceChunk, nextChunk); retrieve(sourceChunk, nextChunk);
ma_pcm_s16_to_f32(mixedChunk, ogBuffer, nextChunk * AAE_CHANNELS, ma_dither_mode_none);//The game's output is changed to 32-bit floating point samples. ma_pcm_s16_to_f32(mixedChunk, ogBuffer, nextChunk * AAE_CHANNELS,
ma_mix_pcm_frames_f32(mixedChunk, sourceChunk, nextChunk, AAE_CHANNELS, 1.0); ma_dither_mode_none); // The game's output is changed to 32-bit floating point samples.
//If we've gone over 1.0, we'll need to scale back before we go back to 16-bit or we'll distort. ma_mix_pcm_frames_f32(mixedChunk, sourceChunk, nextChunk, AAE_CHANNELS, 1.0);
float scalar = 1.0; // If we've gone over 1.0, we'll need to scale back before we go back to 16-bit or we'll distort.
float scalar = 1.0;
for (int i = 0; i < nextChunk * AAE_CHANNELS; i++)
scalar = std::max(scalar, mixedChunk[i]);
if (scalar > 1.0) {
scalar = 1.0 / scalar;
for (int i = 0; i < nextChunk * AAE_CHANNELS; i++) for (int i = 0; i < nextChunk * AAE_CHANNELS; i++)
scalar = std::max(scalar, mixedChunk[i]); mixedChunk[i] *= scalar;
if (scalar > 1.0) { }
scalar = 1.0 / scalar; ma_pcm_f32_to_s16(ogBuffer, mixedChunk, nextChunk * AAE_CHANNELS,
for (int i = 0; i < nextChunk * AAE_CHANNELS; i++) ma_dither_mode_triangle); // Chunk is ready to go out via the game's usual channels.
mixedChunk[i] *= scalar; ogBuffer += nextChunk * AAE_CHANNELS;
} nFrames -= nextChunk;
ma_pcm_f32_to_s16(ogBuffer, mixedChunk, nextChunk * AAE_CHANNELS, ma_dither_mode_triangle);//Chunk is ready to go out via the game's usual channels.
ogBuffer += nextChunk * AAE_CHANNELS;
nFrames -= nextChunk;
}
} }
}
void AccessibleAudioEngine::playSound(uintptr_t handle, int slot, const char* path, bool looping) { void AccessibleAudioEngine::playSound(uintptr_t handle, int slot, const char* path, bool looping) {
if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE) if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE)
return; return;
SoundAction& action = getNextOutgoingSoundAction(); SoundAction& action = getNextOutgoingSoundAction();
action.handle = handle; action.handle = handle;
action.slot = slot; action.slot = slot;
action.command = AAE_START; action.command = AAE_START;
action.path = path; action.path = path;
action.looping = looping; action.looping = looping;
} }
void AccessibleAudioEngine::stopSound(uintptr_t handle, int slot) { void AccessibleAudioEngine::stopSound(uintptr_t handle, int slot) {
if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE) if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE)
return; return;
SoundAction& action = getNextOutgoingSoundAction(); SoundAction& action = getNextOutgoingSoundAction();
action.command = AAE_STOP; action.command = AAE_STOP;
action.handle = (uintptr_t) handle; action.handle = (uintptr_t)handle;
action.slot = slot; action.slot = slot;
} }
void AccessibleAudioEngine::stopAllSounds(uintptr_t handle) { void AccessibleAudioEngine::stopAllSounds(uintptr_t handle) {
SoundAction& action = getNextOutgoingSoundAction(); SoundAction& action = getNextOutgoingSoundAction();
action.command = AAE_STOP_ALL; action.command = AAE_STOP_ALL;
action.handle = handle; action.handle = handle;
} }
void AccessibleAudioEngine::setPitch(uintptr_t handle, int slot, float pitch) { void AccessibleAudioEngine::setPitch(uintptr_t handle, int slot, float pitch) {
if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE) if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE)
return; return;
SoundAction& action = getNextOutgoingSoundAction(); SoundAction& action = getNextOutgoingSoundAction();
action.command = AAE_PITCH; action.command = AAE_PITCH;
action.handle = handle; action.handle = handle;
action.slot = slot; action.slot = slot;
action.pitch = pitch; action.pitch = pitch;
}
void AccessibleAudioEngine::setPitchBehindModifier(uintptr_t handle, int slot, float mod) {
if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE)
return;
} SoundAction& action = getNextOutgoingSoundAction();
void AccessibleAudioEngine::setPitchBehindModifier(uintptr_t handle, int slot, float mod) { action.command = AAE_PITCH_BEHIND;
if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE) action.handle = handle;
return; action.slot = slot;
action.pitch = mod;
}
SoundAction& action = getNextOutgoingSoundAction(); void AccessibleAudioEngine::setVolume(uintptr_t handle, int slot, float volume) {
action.command = AAE_PITCH_BEHIND;
action.handle = handle;
action.slot = slot;
action.pitch = mod;
if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE)
} return;
SoundAction& action = getNextOutgoingSoundAction();
void AccessibleAudioEngine::setVolume(uintptr_t handle, int slot, float volume) { action.command = AAE_VOLUME;
action.handle = handle;
if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE) action.slot = slot;
return; action.volume = volume;
SoundAction& action = getNextOutgoingSoundAction(); }
action.command = AAE_VOLUME;
action.handle = handle;
action.slot = slot;
action.volume = volume;
}
void AccessibleAudioEngine::setPan(uintptr_t handle, int slot, float pan) { void AccessibleAudioEngine::setPan(uintptr_t handle, int slot, float pan) {
if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE) if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE)
return; return;
SoundAction& action = getNextOutgoingSoundAction(); SoundAction& action = getNextOutgoingSoundAction();
action.command = AAE_PAN; action.command = AAE_PAN;
action.handle = handle; action.handle = handle;
action.slot = slot; action.slot = slot;
action.pan = pan; action.pan = pan;
} }
void AccessibleAudioEngine::setFilter(uintptr_t handle, int slot, float cutoff) { void AccessibleAudioEngine::setFilter(uintptr_t handle, int slot, float cutoff) {
if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE) if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE)
return; return;
if (cutoff < 0.0 || cutoff > 1.0) if (cutoff < 0.0 || cutoff > 1.0)
return; return;
SoundAction& action = getNextOutgoingSoundAction(); SoundAction& action = getNextOutgoingSoundAction();
action.handle = handle; action.handle = handle;
action.slot = slot; action.slot = slot;
action.command = AAE_FILTER; action.command = AAE_FILTER;
action.cutoff = cutoff; action.cutoff = cutoff;
}
void AccessibleAudioEngine::seekSound(uintptr_t handle, int slot, size_t offset) {
if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE)
return;
SoundAction& action = getNextOutgoingSoundAction();
action.handle = handle;
action.slot = slot;
action.command = AAE_SEEK;
action.offset = offset;
} }
void AccessibleAudioEngine::setSoundPosition(uintptr_t handle, int slot, float posX, float posY, float posZ, float distToPlayer, float maxDistance) {
if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE)
return;
SoundAction& action = getNextOutgoingSoundAction();
action.command = AAE_POS;
action.handle = handle;
action.slot = slot;
action.posX = posX;
action.posY = posY;
action.posZ = posZ;
action.distToPlayer = distToPlayer;
action.maxDistance = maxDistance;
void AccessibleAudioEngine::seekSound(uintptr_t handle, int slot, size_t offset) {
if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE)
return;
SoundAction& action = getNextOutgoingSoundAction();
action.handle = handle;
action.slot = slot;
action.command = AAE_SEEK;
action.offset = offset;
}
void AccessibleAudioEngine::setSoundPosition(uintptr_t handle, int slot, float posX, float posY, float posZ,
float distToPlayer, float maxDistance) {
if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE)
return;
SoundAction& action = getNextOutgoingSoundAction();
action.command = AAE_POS;
action.handle = handle;
action.slot = slot;
action.posX = posX;
action.posY = posY;
action.posZ = posZ;
action.distToPlayer = distToPlayer;
action.maxDistance = maxDistance;
}
void AccessibleAudioEngine::prepare() {
SoundAction& action = getNextOutgoingSoundAction();
action.command = AAE_PREPARE;
// This is called once at the end of every frame, so now is the time to post all of the accumulated commands.
postSoundActions();
} }
void AccessibleAudioEngine::prepare() {
SoundAction& action = getNextOutgoingSoundAction();
action.command = AAE_PREPARE;
//This is called once at the end of every frame, so now is the time to post all of the accumulated commands.
postSoundActions();
}
void AccessibleAudioEngine::cacheDecodedSample(std::string& path, void* data, size_t size) { void AccessibleAudioEngine::cacheDecodedSample(std::string& path, void* data, size_t size) {
//The data is stored in wave format, so we register it with MiniAudio as an encoded asset as opposed to a decoded one. // The data is stored in wave format, so we register it with MiniAudio as an encoded asset as opposed to a decoded
ma_resource_manager_register_encoded_data(&resourceManager, path.c_str(), data, size); // one.
} ma_resource_manager_register_encoded_data(&resourceManager, path.c_str(), data, size);
}

View file

@ -13,90 +13,91 @@
#define AAE_SLOTS_PER_HANDLE 10 #define AAE_SLOTS_PER_HANDLE 10
class IResource; class IResource;
struct DecodedSample { struct DecodedSample {
void* data;//A wav file. void* data; // A wav file.
size_t dataSize; size_t dataSize;
}; };
struct SoundAction { struct SoundAction {
uintptr_t handle; // This handle is user-defined and uniquely identifies a sound source. It can be anything, but the uintptr_t handle; // This handle is user-defined and uniquely identifies a sound source. It can be anything, but the
// address of an object with which the sound is associated is recommended. // address of an object with which the sound is associated is recommended.
int slot;//Allows multiple sounds per handle. The exact number is controlled by AAE_SOUNDS_PER_HANDLE. int slot; // Allows multiple sounds per handle. The exact number is controlled by AAE_SOUNDS_PER_HANDLE.
int command; // One of the items belonging to AAE_COMMANDS. int command; // One of the items belonging to AAE_COMMANDS.
std::string path; // If command is AAE_START, this is the path to the desired resource. std::string path; // If command is AAE_START, this is the path to the desired resource.
bool looping; // If command is AAE_START, specifies whether or not the sound should loop. bool looping; // If command is AAE_START, specifies whether or not the sound should loop.
union { union {
float pitch; float pitch;
float volume; float volume;
float pan; float pan;
float cutoff; float cutoff;
size_t offset;//for seeking. size_t offset; // for seeking.
float distance; float distance;
}; };
//Position and rotation vectors for AAE_LISTENER and AAE_POS. // Position and rotation vectors for AAE_LISTENER and AAE_POS.
float posX; float posX;
float posY; float posY;
float posZ; float posZ;
float distToPlayer; float distToPlayer;
float maxDistance; float maxDistance;
uint32_t frames; // If command is AAE_PREPARE, this tells the engine how many PCM frames to get ready. uint32_t frames; // If command is AAE_PREPARE, this tells the engine how many PCM frames to get ready.
}; };
typedef struct typedef struct {
{ ma_node_base base;
ma_node_base base; ma_panner panner;
ma_panner panner; ma_gainer gainer;
ma_gainer gainer; ma_lpf filter;
ma_lpf filter; float cutoff;
float cutoff; float x;
float x; float y;
float y; float z;
float z; float distToPlayer;
float distToPlayer; float maxDistance;
float maxDistance; float pitch;
float pitch; float pitchBehindModifier;
float pitchBehindModifier; } SoundExtras; // Used for attenuation and other effects.
}SoundExtras;//Used for attenuation and other effects.
typedef struct typedef struct {
{ ma_sound sound;
ma_sound sound; SoundExtras extras;
SoundExtras extras;
bool active; bool active;
}SoundSlot; } SoundSlot;
typedef std::array<SoundSlot, AAE_SLOTS_PER_HANDLE> SoundSlots; typedef std::array<SoundSlot, AAE_SLOTS_PER_HANDLE> SoundSlots;
class AccessibleAudioEngine { class AccessibleAudioEngine {
int initialized; int initialized;
ma_resource_manager resourceManager; ma_resource_manager resourceManager;
ma_engine engine; ma_engine engine;
ma_pcm_rb preparedOutput;//Lock-free single producer single consumer. ma_pcm_rb preparedOutput; // Lock-free single producer single consumer.
std::deque <SoundAction> soundActions;//A command cue. std::deque<SoundAction> soundActions; // A command cue.
std::thread thread; std::thread thread;
std::condition_variable cv; std::condition_variable cv;
std::mutex mtx; std::mutex mtx;
std::unordered_map<uintptr_t, SoundSlots> sounds; std::unordered_map<uintptr_t, SoundSlots> sounds;
SoundAction outgoingSoundActions[AAE_SOUND_ACTION_BATCH_SIZE];//Allows batch delivery of SoundActions to the FIFO to minimize the amount of time spent locking and unlocking. SoundAction
outgoingSoundActions[AAE_SOUND_ACTION_BATCH_SIZE]; // Allows batch delivery of SoundActions to the FIFO to
// minimize the amount of time spent locking and unlocking.
int nextOutgoingSoundAction; int nextOutgoingSoundAction;
int framesUntilGC; int framesUntilGC;
void destroy();//Called by the destructor, or if a throw occurs during construction. void destroy(); // Called by the destructor, or if a throw occurs during construction.
//Dismantal a partial initialization and throw an exception. // Dismantal a partial initialization and throw an exception.
void destroyAndThrow(const char* exceptionText); void destroyAndThrow(const char* exceptionText);
//Retrieve some audio from the output buffer. This is to be performed by the audio thread. May return less data than requested. // Retrieve some audio from the output buffer. This is to be performed by the audio thread. May return less data
// than requested.
uint32_t retrieve(float* buffer, uint32_t nFrames); uint32_t retrieve(float* buffer, uint32_t nFrames);
//Functions dealing with the command queue. // Functions dealing with the command queue.
int getSoundActions(SoundAction* dest, int limit); int getSoundActions(SoundAction* dest, int limit);
void postSoundActions(); void postSoundActions();
void postHighPrioritySoundAction(SoundAction& action);//For now this is used only for termination events. void postHighPrioritySoundAction(SoundAction& action); // For now this is used only for termination events.
SoundAction& getNextOutgoingSoundAction(); SoundAction& getNextOutgoingSoundAction();
void runThread(); void runThread();
//Find a sound by handle and slot, if it exists. // Find a sound by handle and slot, if it exists.
SoundSlot* findSound(SoundAction& action); SoundSlot* findSound(SoundAction& action);
//Functions which correspond to SoundAction commands. // Functions which correspond to SoundAction commands.
//Ready a sound for playback. // Ready a sound for playback.
void doPlaySound(SoundAction& action); void doPlaySound(SoundAction& action);
void doStopSound(SoundAction& action); void doStopSound(SoundAction& action);
void doStopAllSounds(SoundAction& action); void doStopAllSounds(SoundAction& action);
@ -113,37 +114,39 @@ SoundSlot* findSound(SoundAction& action);
// Generate some output, and store it in the output buffer for later retrieval. May generate less output than // Generate some output, and store it in the output buffer for later retrieval. May generate less output than
// requested if buffer space is insufficient. // requested if buffer space is insufficient.
void doPrepare(SoundAction& action); void doPrepare(SoundAction& action);
//Run every so often to clean up expired sound handles. // Run every so often to clean up expired sound handles.
void garbageCollect(); void garbageCollect();
//Run MiniAudio's jobs. // Run MiniAudio's jobs.
void processAudioJobs(); void processAudioJobs();
//Set up the panner and other effect processing on a sound slot. // Set up the panner and other effect processing on a sound slot.
bool initSoundExtras(SoundSlot* slot); bool initSoundExtras(SoundSlot* slot);
void destroySound(SoundSlot* slot); void destroySound(SoundSlot* slot);
public: public:
AccessibleAudioEngine(); AccessibleAudioEngine();
~AccessibleAudioEngine(); ~AccessibleAudioEngine();
//Mix the game's audio with this engine's audio to produce the final mix. To be performed exclusively in the audio thread. Mixing is done in-place (meaning the buffer containing the game's audio is overwritten with the mixed content). // Mix the game's audio with this engine's audio to produce the final mix. To be performed exclusively in the audio
// thread. Mixing is done in-place (meaning the buffer containing the game's audio is overwritten with the mixed
// content).
void mix(int16_t* ogBuffer, uint32_t nFrames); void mix(int16_t* ogBuffer, uint32_t nFrames);
//Start playing a sound. // Start playing a sound.
void playSound(uintptr_t handle, int slot, const char* path, bool looping); void playSound(uintptr_t handle, int slot, const char* path, bool looping);
void stopSound(uintptr_t handle, int slot); void stopSound(uintptr_t handle, int slot);
//Stop all sounds belonging to a handle. // Stop all sounds belonging to a handle.
void stopAllSounds(uintptr_t handle); void stopAllSounds(uintptr_t handle);
void setPitch(uintptr_t handle, int slot, float pitch); void setPitch(uintptr_t handle, int slot, float pitch);
void setPitchBehindModifier(uintptr_t handle, int slot, float mod); void setPitchBehindModifier(uintptr_t handle, int slot, float mod);
void setVolume(uintptr_t handle, int slot, float volume); void setVolume(uintptr_t handle, int slot, float volume);
void setPan(uintptr_t handle, int slot, float pan); void setPan(uintptr_t handle, int slot, float pan);
//Set the lowpass filter cutoff. Set to 1.0 for no filtering. // Set the lowpass filter cutoff. Set to 1.0 for no filtering.
void setFilter(uintptr_t handle, int slot, float cutoff); void setFilter(uintptr_t handle, int slot, float cutoff);
//Seek the sound to a particular PCM frame. // Seek the sound to a particular PCM frame.
void seekSound(uintptr_t handle, int slot, size_t offset); void seekSound(uintptr_t handle, int slot, size_t offset);
void setSoundPosition(uintptr_t handle, int slot, float posX, float posY, float posZ, float distToPlayer, float maxDistance); void setSoundPosition(uintptr_t handle, int slot, float posX, float posY, float posZ, float distToPlayer,
//Schedule the preparation of output for delivery. float maxDistance);
// Schedule the preparation of output for delivery.
void prepare(); void prepare();
void cacheDecodedSample(std::string& path, void* data, size_t size); void cacheDecodedSample(std::string& path, void* data, size_t size);
}; };
#endif #endif

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,9 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define NUM_MANAGED_SOUND_SLOTS 10 //How many auto-managed sound slots can any given actor have? this can differ from AAE_SLOTS_PER_HANDLE, but cannot be greater. #define NUM_MANAGED_SOUND_SLOTS \
10 // How many auto-managed sound slots can any given actor have? this can differ from AAE_SLOTS_PER_HANDLE, but
// cannot be greater.
struct AccessibleActor; struct AccessibleActor;
typedef struct AccessibleActor AccessibleActor; typedef struct AccessibleActor AccessibleActor;
// A callback that is run regularely as the game progresses in order to provide accessibility services for an actor. // A callback that is run regularely as the game progresses in order to provide accessibility services for an actor.
@ -28,20 +30,20 @@ typedef struct {
int n; // How often to run the callback in frames. int n; // How often to run the callback in frames.
f32 distance; // Maximum xz distance from player before the actor should be considered out of range. f32 distance; // Maximum xz distance from player before the actor should be considered out of range.
f32 ydist; // Maximum y distance from player before the actor should be considered out of range. f32 ydist; // Maximum y distance from player before the actor should be considered out of range.
f32 pitch; f32 pitch;
f32 volume; f32 volume;
f32 pitchModifier; f32 pitchModifier;
bool runsAlways; // If set, then the distance policy is ignored. bool runsAlways; // If set, then the distance policy is ignored.
ActorAccessibilityUserDataInit initUserData; ActorAccessibilityUserDataInit initUserData;
ActorAccessibilityUserDataCleanup cleanupUserData; ActorAccessibilityUserDataCleanup cleanupUserData;
//Aim assist settings. // Aim assist settings.
struct { struct {
bool isProvider;//determines whether or not this actor supports aim assist. bool isProvider; // determines whether or not this actor supports aim assist.
s16 sfx; // The sound to play when this actor provides aim assist. Uses sound slot 9. s16 sfx; // The sound to play when this actor provides aim assist. Uses sound slot 9.
f32 tolerance; // How close to the center of the actor does Link have to aim for aim assist to consider f32 tolerance; // How close to the center of the actor does Link have to aim for aim assist to consider
// it lined up. // it lined up.
}aimAssist; } aimAssist;
} ActorAccessibilityPolicy; } ActorAccessibilityPolicy;
@ -71,8 +73,10 @@ struct AccessibleActor {
f32 basePitch; f32 basePitch;
f32 currentPitch; f32 currentPitch;
s16 sceneIndex;//If this actor represents a scene transition, then this will contain the destination scene index. Zero otherwise. s16 sceneIndex; // If this actor represents a scene transition, then this will contain the destination scene index.
bool managedSoundSlots[NUM_MANAGED_SOUND_SLOTS];//These have their attenuation and panning parameters updated every frame automatically. // Zero otherwise.
bool managedSoundSlots[NUM_MANAGED_SOUND_SLOTS]; // These have their attenuation and panning parameters updated
// every frame automatically.
struct { struct {
u16 framesSinceAimAssist; // Allows rate-based vertical aim assist. Incremented every frame for aim assist u16 framesSinceAimAssist; // Allows rate-based vertical aim assist. Incremented every frame for aim assist
// actors. Manually reset by aim assist provider. // actors. Manually reset by aim assist provider.
@ -99,22 +103,25 @@ void ActorAccessibility_AddSupportedActor(s16 type, ActorAccessibilityPolicy pol
void ActorAccessibility_RunAccessibilityForActor(PlayState* play, AccessibleActor* actor); void ActorAccessibility_RunAccessibilityForActor(PlayState* play, AccessibleActor* actor);
void ActorAccessibility_RunAccessibilityForAllActors(PlayState* play); void ActorAccessibility_RunAccessibilityForAllActors(PlayState* play);
/* /*
*Play sounds (usually from the game) using the external sound engine. This is probably not the function you want to call most of the time (see below). *Play sounds (usually from the game) using the external sound engine. This is probably not the function you want to
* handle: pointer to an arbitrary object. This object can be anything as it's only used as a classifier, but it's recommended that you use an AccessibleActor* as your handle whenever possible. Using AccessibleActor* as the handle gives you automatic cleanup when the actor is killed. *call most of the time (see below). handle: pointer to an arbitrary object. This object can be anything as it's only
* slot: Allows multiple sounds to be assigned to a single handle. The maximum number of slots per actor is 10 by default (but can be controlled by modifying AAE_SLOTS_PER_HANDLE). *used as a classifier, but it's recommended that you use an AccessibleActor* as your handle whenever possible. Using
* sfxId: one of the game's sfx IDs. Note that this plays prerendered sounds which you must have previously prepared. *AccessibleActor* as the handle gives you automatic cleanup when the actor is killed. slot: Allows multiple sounds to
*looping: whether to play the sound just once or on a continuous loop. *be assigned to a single handle. The maximum number of slots per actor is 10 by default (but can be controlled by
*/ *modifying AAE_SLOTS_PER_HANDLE). sfxId: one of the game's sfx IDs. Note that this plays prerendered sounds which you
*must have previously prepared. looping: whether to play the sound just once or on a continuous loop.
*/
void ActorAccessibility_PlaySound(void* actor, int slot, s16 sfxId, bool looping); void ActorAccessibility_PlaySound(void* actor, int slot, s16 sfxId, bool looping);
//Play one of the game's internal samples. // Play one of the game's internal samples.
void ActorAccessibility_PlayRawSample(void* handle, int slot, const char* name, bool looping); void ActorAccessibility_PlayRawSample(void* handle, int slot, const char* name, bool looping);
// //
//Stop a sound. Todo: consider making this a short fade instead of just cutting it off. // Stop a sound. Todo: consider making this a short fade instead of just cutting it off.
void ActorAccessibility_StopSound(void* handle, int slot); void ActorAccessibility_StopSound(void* handle, int slot);
void ActorAccessibility_StopAllSounds(void* handle); void ActorAccessibility_StopAllSounds(void* handle);
void ActorAccessibility_SetSoundPitch(void* handle, int slot, float pitch); void ActorAccessibility_SetSoundPitch(void* handle, int slot, float pitch);
//When we don't have access to something super fancy (such as HRTF), blind-accessible games generally use a change in pitch to tell the player that an object is behind the player. // When we don't have access to something super fancy (such as HRTF), blind-accessible games generally use a change in
// pitch to tell the player that an object is behind the player.
void ActorAccessibility_SetPitchBehindModifier(void* handle, int slot, float mod); void ActorAccessibility_SetPitchBehindModifier(void* handle, int slot, float mod);
void ActorAccessibility_SetListenerPos(Vec3f* pos, Vec3f* rot); void ActorAccessibility_SetListenerPos(Vec3f* pos, Vec3f* rot);
@ -125,18 +132,19 @@ void ActorAccessibility_SetSoundPan(void* handle, int slot, Vec3f* projectedPos)
void ActorAccessibility_SetSoundFilter(void* handle, int slot, float cutoff); void ActorAccessibility_SetSoundFilter(void* handle, int slot, float cutoff);
void ActorAccessibility_SeekSound(void* handle, int slot, size_t offset); void ActorAccessibility_SeekSound(void* handle, int slot, size_t offset);
/* /*
* Play a sound on behalf of an AccessibleActor. * Play a sound on behalf of an AccessibleActor.
* This version includes automatic sound management: pitch, panning and attenuation parameters will be updated automatically based on the actor's position. * This version includes automatic sound management: pitch, panning and attenuation parameters will be updated
* * automatically based on the actor's position.
*/ *
*/
void ActorAccessibility_PlaySoundForActor(AccessibleActor* actor, int slot, s16 sfxId, bool looping); void ActorAccessibility_PlaySoundForActor(AccessibleActor* actor, int slot, s16 sfxId, bool looping);
void ActorAccessibility_PlaySampleForActor(AccessibleActor* actor, int slot, const char* name, bool looping); void ActorAccessibility_PlaySampleForActor(AccessibleActor* actor, int slot, const char* name, bool looping);
void ActorAccessibility_StopSoundForActor(AccessibleActor* actor, int slot); void ActorAccessibility_StopSoundForActor(AccessibleActor* actor, int slot);
void ActorAccessibility_StopAllSoundsForActor(AccessibleActor* actor); void ActorAccessibility_StopAllSoundsForActor(AccessibleActor* actor);
f32 ActorAccessibility_ComputeCurrentVolume(f32 maxDistance, f32 xzDistToPlayer); f32 ActorAccessibility_ComputeCurrentVolume(f32 maxDistance, f32 xzDistToPlayer);
// Computes a relative angle based on Link's (or some other actor's) current angle. // Computes a relative angle based on Link's (or some other actor's) current angle.
Vec3s ActorAccessibility_ComputeRelativeAngle(Vec3s* origin, Vec3s* offset); Vec3s ActorAccessibility_ComputeRelativeAngle(Vec3s* origin, Vec3s* offset);
void ActorAccessibility_InitCues(); void ActorAccessibility_InitCues();
// Stuff related to lists of virtual actors. // Stuff related to lists of virtual actors.
@ -153,38 +161,37 @@ typedef enum {
VA_MARKER, VA_MARKER,
VA_SPIKE, VA_SPIKE,
VA_GENERAL_HELPER, // Room announcements, action icon and other misc help. VA_GENERAL_HELPER, // Room announcements, action icon and other misc help.
VA_AUDIO_COMPASS,//Points north. VA_AUDIO_COMPASS, // Points north.
VA_STICK_WARNING,//beep when stick is about to burn out. VA_STICK_WARNING, // beep when stick is about to burn out.
VA_FINAL, VA_FINAL,
} VIRTUAL_ACTOR_TABLE; } VIRTUAL_ACTOR_TABLE;
#define EVERYWHERE -32768 // Denotes a virtual actor that is global/ omnipresent. #define EVERYWHERE -32768 // Denotes a virtual actor that is global/ omnipresent.
// Get the list of virtual actors for a given scene and room index. // Get the list of virtual actors for a given scene and room index.
VirtualActorList* ActorAccessibility_GetVirtualActorList(s16 sceneNum, s8 roomNum); VirtualActorList* ActorAccessibility_GetVirtualActorList(s16 sceneNum, s8 roomNum);
AccessibleActor* ActorAccessibility_AddVirtualActor(VirtualActorList* list, VIRTUAL_ACTOR_TABLE type, PosRot where); AccessibleActor* ActorAccessibility_AddVirtualActor(VirtualActorList* list, VIRTUAL_ACTOR_TABLE type, PosRot where);
//Parses the loaded seen and converts select polygons (like ladders, spikes and scene exits) into virtual actors. // Parses the loaded seen and converts select polygons (like ladders, spikes and scene exits) into virtual actors.
void ActorAccessibility_InterpretCurrentScene(PlayState* play); void ActorAccessibility_InterpretCurrentScene(PlayState* play);
//Convert a collision polygon into a virtual actor. // Convert a collision polygon into a virtual actor.
void ActorAccessibility_PolyToVirtualActor(PlayState* play, CollisionPoly* poly, VIRTUAL_ACTOR_TABLE va, VirtualActorList* destination); void ActorAccessibility_PolyToVirtualActor(PlayState* play, CollisionPoly* poly, VIRTUAL_ACTOR_TABLE va,
//Report which room of a dungeon the player is in. VirtualActorList* destination);
void ActorAccessibility_AnnounceRoomNumber(PlayState* play); // Report which room of a dungeon the player is in.
//Aim cue support. void ActorAccessibility_AnnounceRoomNumber(PlayState* play);
void ActorAccessibility_ProvideAimAssistForActor(AccessibleActor* actor); // Aim cue support.
// External audio engine stuff. void ActorAccessibility_ProvideAimAssistForActor(AccessibleActor* actor);
// External audio engine stuff.
// Initialize the accessible audio engine. // Initialize the accessible audio engine.
bool ActorAccessibility_InitAudio(); bool ActorAccessibility_InitAudio();
void ActorAccessibility_ShutdownAudio(); void ActorAccessibility_ShutdownAudio();
// Combine the games' audio with the output from AccessibleAudioEngine. To be called exclusively from the audio thread. // Combine the games' audio with the output from AccessibleAudioEngine. To be called exclusively from the audio thread.
void ActorAccessibility_MixAccessibleAudioWithGameAudio(int16_t* ogBuffer, uint32_t nFrames); void ActorAccessibility_MixAccessibleAudioWithGameAudio(int16_t* ogBuffer, uint32_t nFrames);
void ActorAccessibility_HandleSoundExtractionMode(PlayState* play); void ActorAccessibility_HandleSoundExtractionMode(PlayState* play);
//This is called by the audio thread when it's ready to try to pull sfx from the game. // This is called by the audio thread when it's ready to try to pull sfx from the game.
void ActorAccessibility_DoSoundExtractionStep(); void ActorAccessibility_DoSoundExtractionStep();
void ActorAccessibility_AudioGlossary(PlayState* play); void ActorAccessibility_AudioGlossary(PlayState* play);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -92,13 +92,13 @@ void SfxExtractor::renderOutput() {
void SfxExtractor::setup() { void SfxExtractor::setup() {
try { try {
SpeechSynthesizer::Instance->Speak(
SpeechSynthesizer::Instance->Speak("Sfx extraction speedrun initiated. Please wait. This will take a few minutes.", GetLanguageCode()); "Sfx extraction speedrun initiated. Please wait. This will take a few minutes.", GetLanguageCode());
// Kill the audio thread so we can take control. // Kill the audio thread so we can take control.
captureThreadState = CT_WAITING; captureThreadState = CT_WAITING;
OTRAudio_InstallSfxCaptureThread(); OTRAudio_InstallSfxCaptureThread();
// Make sure we're starting from a clean slate. // Make sure we're starting from a clean slate.
std::string sohAccessibilityPath = Ship::Context::GetPathRelativeToAppDirectory("accessibility.otr"); std::string sohAccessibilityPath = Ship::Context::GetPathRelativeToAppDirectory("accessibility.o2r");
if (std::filesystem::exists(sohAccessibilityPath)) { if (std::filesystem::exists(sohAccessibilityPath)) {
currentStep = STEP_ERROR_OTR; currentStep = STEP_ERROR_OTR;
return; return;
@ -115,10 +115,11 @@ void SfxExtractor::setup() {
for (int i = 1; i < 10; i++) { for (int i = 1; i < 10; i++) {
progressMilestones[i - 1] = sfxToRip.size() - ((int)ceil(sfxToRip.size() * (i / 10.0f))); progressMilestones[i - 1] = sfxToRip.size() - ((int)ceil(sfxToRip.size() * (i / 10.0f)));
} }
archive = Ship::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->AddArchive("accessibility.otr"); archive = std::make_shared<Ship::O2rArchive>("accessibility.o2r");
archive->Open();
} catch (...) { currentStep = STEP_ERROR; } } catch (...) { currentStep = STEP_ERROR; }
} }
void SfxExtractor::ripNextSfx() { void SfxExtractor::ripNextSfx() {
{ {
auto lock = OTRAudio_Lock(); auto lock = OTRAudio_Lock();
@ -143,7 +144,8 @@ void SfxExtractor::ripNextSfx() {
sfxToRip.pop(); sfxToRip.pop();
startOfInput = 0; startOfInput = 0;
endOfInput = 0; endOfInput = 0;
Audio_PlaySoundGeneral(currentSfx, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); Audio_PlaySoundGeneral(currentSfx, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultReverb);
{ {
auto lock = OTRAudio_Lock(); auto lock = OTRAudio_Lock();
@ -161,17 +163,18 @@ void SfxExtractor::finished() {
Audio_QueueSeqCmd(NA_BGM_TITLE); Audio_QueueSeqCmd(NA_BGM_TITLE);
if (currentStep == STEP_ERROR || currentStep == STEP_ERROR_OTR) { if (currentStep == STEP_ERROR || currentStep == STEP_ERROR_OTR) {
Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale,
Audio_PlaySoundGeneral(NA_SE_EN_GANON_LAUGH, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);
Audio_PlaySoundGeneral(NA_SE_EN_GANON_LAUGH, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);
std::stringstream ss; std::stringstream ss;
ss << "Sorry, we tried to extract the sound effects, but Ganondorf overruled us with an iron fist." ss << "Sorry, we tried to extract the sound effects, but Ganondorf overruled us with an iron fist."
<< std::endl; << std::endl;
if (currentStep == STEP_ERROR_OTR) if (currentStep == STEP_ERROR_OTR)
ss << "In all seriousness, please delete accessibility.otr and try again."; ss << "In all seriousness, please delete accessibility.o2r and try again.";
SpeechSynthesizer::Instance->Speak(ss.str().c_str(), GetLanguageCode()); SpeechSynthesizer::Instance->Speak(ss.str().c_str(), GetLanguageCode());
} else } else
Audio_PlayFanfare(NA_BGM_ITEM_GET); Audio_PlayFanfare(NA_BGM_ITEM_GET);
} }
void SfxExtractor::maybeGiveProgressReport() { void SfxExtractor::maybeGiveProgressReport() {
size_t ripsRemaining = sfxToRip.size() + 1; size_t ripsRemaining = sfxToRip.size() + 1;
@ -188,7 +191,7 @@ SfxExtractor::SfxExtractor() {
currentStep = STEP_SETUP; currentStep = STEP_SETUP;
} }
void SfxExtractor::frameCallback() { void SfxExtractor::frameCallback() {
switch (currentStep) { switch (currentStep) {
case STEP_SETUP: case STEP_SETUP:
setup(); setup();
@ -223,9 +226,9 @@ void SfxExtractor::captureCallback() {
AudioMgr_CreateNextAudioBuffer(mark, SFX_EXTRACTION_ONE_FRAME); AudioMgr_CreateNextAudioBuffer(mark, SFX_EXTRACTION_ONE_FRAME);
if (!outputStarted && isAllZero(mark, SFX_EXTRACTION_ONE_FRAME * 2)) { if (!outputStarted && isAllZero(mark, SFX_EXTRACTION_ONE_FRAME * 2)) {
waitTime++; waitTime++;
if (waitTime < 300) if (waitTime < 300)
continue;//Output is silent, allow more time for audio to begin. continue; // Output is silent, allow more time for audio to begin.
captureThreadState = CT_FINISHED; // Sound is unavailable, so skip over it and move on. captureThreadState = CT_FINISHED; // Sound is unavailable, so skip over it and move on.
return; return;
} }

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
//A big nasty array containing every SFX ID in the game. // A big nasty array containing every SFX ID in the game.
//All of the "DUMMY's" and "YOBI's" have been removed as they produce duplicate sounds at best, and cause errors or even crashes at worst. // All of the "DUMMY's" and "YOBI's" have been removed as they produce duplicate sounds at best, and cause errors or
// even crashes at worst.
const s16 sfxTable[1207] = { const s16 sfxTable[1207] = {
NA_SE_PL_WALK_GROUND, NA_SE_PL_WALK_GROUND,

File diff suppressed because it is too large Load diff

View file

@ -274,7 +274,7 @@ OTRGlobals::OTRGlobals() {
if (std::filesystem::exists(ootPath)) { if (std::filesystem::exists(ootPath)) {
OTRFiles.push_back(ootPath); OTRFiles.push_back(ootPath);
} }
std::string sohOtrPath = Ship::Context::GetPathRelativeToAppBundle("soh.otr"); std::string sohOtrPath = Ship::Context::GetPathRelativeToAppBundle("soh.o2r");
if (std::filesystem::exists(sohOtrPath)) { if (std::filesystem::exists(sohOtrPath)) {
OTRFiles.push_back(sohOtrPath); OTRFiles.push_back(sohOtrPath);
} }