From c213e157519ce4e6c4db5bd7d83fb64c48ecc5e6 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Sun, 12 Nov 2023 05:19:09 -0500 Subject: [PATCH 1/6] get it to build for linux and add tts logging --- .../accessible-actors/AccessibleActorList.cpp | 4 ++-- .../accessible-actors/AccessibleAudioEngine.cpp | 10 +++++----- .../accessible-actors/AccessibleAudioEngine.h | 1 + .../accessible-actors/accessibility_cues.cpp | 1 + .../speechsynthesizer/SpeechLogger.cpp | 16 ++++++++++++++++ .../speechsynthesizer/SpeechLogger.h | 17 +++++++++++++++++ .../speechsynthesizer/SpeechSynthesizer.h | 2 ++ soh/soh/OTRGlobals.cpp | 3 +++ 8 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 soh/soh/Enhancements/speechsynthesizer/SpeechLogger.cpp create mode 100644 soh/soh/Enhancements/speechsynthesizer/SpeechLogger.h diff --git a/soh/soh/Enhancements/accessible-actors/AccessibleActorList.cpp b/soh/soh/Enhancements/accessible-actors/AccessibleActorList.cpp index 72c61f3fa..be79eb9b4 100644 --- a/soh/soh/Enhancements/accessible-actors/AccessibleActorList.cpp +++ b/soh/soh/Enhancements/accessible-actors/AccessibleActorList.cpp @@ -8,7 +8,7 @@ #include #include #include -#include "overlays\actors\ovl_Boss_Goma\z_boss_goma.h" +#include "overlays/actors/ovl_Boss_Goma/z_boss_goma.h" //Declarations specific to chests. #include "overlays/actors/ovl_En_Box/z_en_box.h" extern "C" { @@ -22,7 +22,7 @@ extern "C" { void EnKarebaba_DeadItemDrop(EnKarebaba*, PlayState*); } //Declarations specific to Torches -#include "overlays\actors\ovl_Obj_Syokudai\z_obj_syokudai.h" +#include "overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.h" //User data for the general helper VA. typedef struct { diff --git a/soh/soh/Enhancements/accessible-actors/AccessibleAudioEngine.cpp b/soh/soh/Enhancements/accessible-actors/AccessibleAudioEngine.cpp index 919992b66..9b55fe6f7 100644 --- a/soh/soh/Enhancements/accessible-actors/AccessibleAudioEngine.cpp +++ b/soh/soh/Enhancements/accessible-actors/AccessibleAudioEngine.cpp @@ -39,7 +39,7 @@ typedef float f32; typedef int8_t s8; typedef uint8_t u8; //Processing for our custom audio positioning. -static float lerp(float x, float y, float z) { +static float lerp_aae(float x, float y, float z) { return (1.0 - z) * x + z * y; } @@ -48,9 +48,9 @@ static float lerp(float x, float y, float z) { return 0; float leftover = ma_volume_db_to_linear(AAE_MAX_DB_REDUCTION); float normDist = fabs(extras->distToPlayer) / extras->maxDistance; - float db = lerp(0, AAE_MAX_DB_REDUCTION, normDist); + float db = lerp_aae(0, AAE_MAX_DB_REDUCTION, normDist); float gain = ma_volume_db_to_linear(db); - gain -= lerp(0, leftover, normDist); + gain -= lerp_aae(0, leftover, normDist); return gain; } //Borrow the pan calculation from the game itself. Todo: this is technical debt, so copy/ revise it or something at some point. @@ -148,7 +148,7 @@ void AccessibleAudioEngine::doPrepare(SoundAction& action) //This should not loop more than twice. 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. - uint64_t framesRead = 0; + ma_uint64 framesRead = 0; 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. if (framesRead < nextChunk) @@ -357,7 +357,7 @@ void AccessibleAudioEngine::postHighPrioritySoundAction(SoundAction& action) { return; slot->extras.cutoff = action.cutoff; ma_lpf_config config = - ma_lpf_config_init(ma_format_f32, AAE_CHANNELS, AAE_SAMPLE_RATE, lerp(0.0, AAE_SAMPLE_RATE / 2, action.cutoff), AAE_LPF_ORDER); + 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); ma_lpf_reinit(&config, &slot->extras.filter); } diff --git a/soh/soh/Enhancements/accessible-actors/AccessibleAudioEngine.h b/soh/soh/Enhancements/accessible-actors/AccessibleAudioEngine.h index c2bccabf3..d069a1cef 100644 --- a/soh/soh/Enhancements/accessible-actors/AccessibleAudioEngine.h +++ b/soh/soh/Enhancements/accessible-actors/AccessibleAudioEngine.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/soh/soh/Enhancements/accessible-actors/accessibility_cues.cpp b/soh/soh/Enhancements/accessible-actors/accessibility_cues.cpp index bfd95fcb8..7054f8397 100644 --- a/soh/soh/Enhancements/accessible-actors/accessibility_cues.cpp +++ b/soh/soh/Enhancements/accessible-actors/accessibility_cues.cpp @@ -2,6 +2,7 @@ #include "z64.h" #include "macros.h" #include "functions.h" +#include extern "C" { s32 func_80839768(PlayState* play, Player* p, Vec3f* arg2, CollisionPoly** arg3, s32* arg4, Vec3f* arg5); void func_8083E298(CollisionPoly* arg0, Vec3f* arg1, s16* arg2); diff --git a/soh/soh/Enhancements/speechsynthesizer/SpeechLogger.cpp b/soh/soh/Enhancements/speechsynthesizer/SpeechLogger.cpp new file mode 100644 index 000000000..a47a61d62 --- /dev/null +++ b/soh/soh/Enhancements/speechsynthesizer/SpeechLogger.cpp @@ -0,0 +1,16 @@ +#include "SpeechLogger.h" +#include + +SpeechLogger::SpeechLogger() { +} + +void SpeechLogger::Speak(const char* text, const char* language) { + lusprintf(__FILE__, __LINE__, 2, "Spoken Text (%s): %s", language, text); +} + +bool SpeechLogger::DoInit() { + return true; +} + +void SpeechLogger::DoUninitialize() { +} diff --git a/soh/soh/Enhancements/speechsynthesizer/SpeechLogger.h b/soh/soh/Enhancements/speechsynthesizer/SpeechLogger.h new file mode 100644 index 000000000..3be27945f --- /dev/null +++ b/soh/soh/Enhancements/speechsynthesizer/SpeechLogger.h @@ -0,0 +1,17 @@ +#ifndef SOHSpeechLogger_h +#define SOHSpeechLogger_h + +#include "SpeechSynthesizer.h" + +class SpeechLogger : public SpeechSynthesizer { + public: + SpeechLogger(); + + void Speak(const char* text, const char* language); + + protected: + bool DoInit(void); + void DoUninitialize(void); +}; + +#endif diff --git a/soh/soh/Enhancements/speechsynthesizer/SpeechSynthesizer.h b/soh/soh/Enhancements/speechsynthesizer/SpeechSynthesizer.h index b08aab05c..29d209b5f 100644 --- a/soh/soh/Enhancements/speechsynthesizer/SpeechSynthesizer.h +++ b/soh/soh/Enhancements/speechsynthesizer/SpeechSynthesizer.h @@ -36,3 +36,5 @@ class SpeechSynthesizer { #elif defined(__APPLE__) #include "DarwinSpeechSynthesizer.h" #endif + +#include "SpeechLogger.h" diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index bf99e74cd..1b9ec11c3 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1042,6 +1042,9 @@ extern "C" void InitOTR() { #elif defined(_WIN32) SpeechSynthesizer::Instance = new SAPISpeechSynthesizer(); SpeechSynthesizer::Instance->Init(); +#else + SpeechSynthesizer::Instance = new SpeechLogger(); + SpeechSynthesizer::Instance->Init(); #endif clearMtx = (uintptr_t)&gMtxClear; From 1a4d6f5be78eeb3eb2fc263a941f5dbba80a8bf0 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Sun, 12 Nov 2023 05:33:46 -0500 Subject: [PATCH 2/6] fix mac too? --- soh/soh/Enhancements/accessible-actors/SfxExtractor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/soh/soh/Enhancements/accessible-actors/SfxExtractor.cpp b/soh/soh/Enhancements/accessible-actors/SfxExtractor.cpp index 0202ac5a9..d681b76aa 100644 --- a/soh/soh/Enhancements/accessible-actors/SfxExtractor.cpp +++ b/soh/soh/Enhancements/accessible-actors/SfxExtractor.cpp @@ -7,6 +7,7 @@ #include "functions.h" #include "soh/OTRGlobals.h" #include "SfxTable.h" +#include const char* GetLanguageCode(); extern "C" { extern Vec3f D_801333D4; From b7600f77bd1f3486db6c8adb564da8c1f2cd2bbb Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Sun, 12 Nov 2023 05:58:25 -0500 Subject: [PATCH 3/6] maybe fix switch/wii u builds --- soh/soh/OTRGlobals.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 1b9ec11c3..a5b8b85ca 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -114,8 +114,9 @@ CrowdControl* CrowdControl::Instance; #include "soh/resource/importer/BackgroundFactory.h" #include "soh/config/ConfigUpdaters.h" -#include "soh/Enhancements/accessible-actors/ActorAccessibility.h" -#include "Enhancements//accessible-actors/ActorAccessibility.h" +#if !defined(__SWITCH__) && !defined(__WIIU__) +#include "Enhancements/accessible-actors/ActorAccessibility.h" +#endif OTRGlobals* OTRGlobals::Instance; SaveManager* SaveManager::Instance; CustomMessageManager* CustomMessageManager::Instance; @@ -467,10 +468,11 @@ void OTRAudio_Thread() { for (int i = 0; i < AUDIO_FRAMES_PER_UPDATE; i++) { AudioMgr_CreateNextAudioBuffer(audio_buffer + i * (num_audio_samples * NUM_AUDIO_CHANNELS), num_audio_samples); +#if !defined(__SWITCH__) && !defined(__WIIU__) // Give accessibility a chance to merge its own audio in. ActorAccessibility_MixAccessibleAudioWithGameAudio( audio_buffer + i * (num_audio_samples * NUM_AUDIO_CHANNELS), num_audio_samples); - +#endif } AudioPlayer_Play((u8*)audio_buffer, num_audio_samples * (sizeof(int16_t) * NUM_AUDIO_CHANNELS * AUDIO_FRAMES_PER_UPDATE)); @@ -1049,7 +1051,9 @@ extern "C" void InitOTR() { clearMtx = (uintptr_t)&gMtxClear; OTRMessage_Init(); + #if !defined(__SWITCH__) && !defined(__WIIU__) ActorAccessibility_Init(); + #endif OTRAudio_Init(); OTRExtScanner(); VanillaItemTable_Init(); @@ -1094,7 +1098,9 @@ extern "C" void DeinitOTR() { CrowdControl::Instance->Disable(); CrowdControl::Instance->Shutdown(); #endif +#if !defined(__SWITCH__) && !defined(__WIIU__) ActorAccessibility_Shutdown(); +#endif // Destroying gui here because we have shared ptrs to LUS objects which output to SPDLOG which is destroyed before these shared ptrs. SohGui::Destroy(); From 2ffc3d4b98949af4c5cac6999ebfbab5ae12c1c5 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Sun, 12 Nov 2023 06:03:47 -0500 Subject: [PATCH 4/6] missed a line --- soh/soh/OTRGlobals.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index a5b8b85ca..3dcfd8c78 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -2541,7 +2541,9 @@ void OTRAudio_SfxCaptureThread() { } } std::unique_lock Lock(audio.mutex); +#if !defined(__SWITCH__) && !defined(__WIIU__) ActorAccessibility_DoSoundExtractionStep(); +#endif audio.processing = false; audio.cv_from_thread.notify_one(); } From d6a00762b4202f6567ef694aed31f8d5cd2fae2b Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Sun, 12 Nov 2023 06:11:29 -0500 Subject: [PATCH 5/6] cmake remove --- soh/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/soh/CMakeLists.txt b/soh/CMakeLists.txt index fd0c6ac25..4e98ec89d 100644 --- a/soh/CMakeLists.txt +++ b/soh/CMakeLists.txt @@ -167,6 +167,11 @@ else() list(FILTER soh__Enhancements EXCLUDE REGEX "soh/Enhancements/speechsynthesizer/(Darwin|SAPI).*") endif() +# handle accessible audio engine removals +if (CMAKE_SYSTEM_NAME MATCHES "NintendoSwitch|CafeOS") + list(FILTER soh__Enhancements EXCLUDE REGEX "soh/Enhancements/accessible-actors/*") +endif() + source_group("soh\\Enhancements" REGULAR_EXPRESSION "soh/Enhancements/*") source_group("soh\\Enhancements\\audio" REGULAR_EXPRESSION "soh/Enhancements/audio/*") source_group("soh\\Enhancements\\controls" REGULAR_EXPRESSION "soh/Enhancements/controls/*") From 95e9bb48974cae7df3f98c947747c2240d4cc454 Mon Sep 17 00:00:00 2001 From: Caturria Date: Thu, 18 Jan 2024 21:01:14 -0500 Subject: [PATCH 6/6] Aim assist shouldn't make you wait when you first draw your weapon. --- .../accessible-actors/ActorAccessibility.cpp | 18 ++++++++++++------ .../accessible-actors/ActorAccessibility.h | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/soh/soh/Enhancements/accessible-actors/ActorAccessibility.cpp b/soh/soh/Enhancements/accessible-actors/ActorAccessibility.cpp index 397f59ecb..d22cc5577 100644 --- a/soh/soh/Enhancements/accessible-actors/ActorAccessibility.cpp +++ b/soh/soh/Enhancements/accessible-actors/ActorAccessibility.cpp @@ -187,7 +187,7 @@ int ActorAccessibility_GetRandomStartingFrameCount(int min, int max) { accessibleActor.sceneIndex = 0; for (int i = 0; i < NUM_MANAGED_SOUND_SLOTS; i++) accessibleActor.managedSoundSlots[i] = false; - accessibleActor.aimAssist.framesSinceAimAssist = 0; + accessibleActor.aimAssist.framesSinceAimAssist = 32768; accessibleActor.aimAssist.frequency = 10; accessibleActor.aimAssist.pitch = 1.0; @@ -399,17 +399,23 @@ int ActorAccessibility_GetRandomStartingFrameCount(int min, int max) { } if (actor->isDrawn == 0 && actor->actor->id != 406 && actor->actor->id != 302) return; - if (actor->policy.aimAssist.isProvider && player->stateFlags1 & PLAYER_STATE1_FIRST_PERSON && (player->stateFlags1 & PLAYER_STATE1_BOOMERANG_IN_HAND || player->stateFlags1 & PLAYER_STATE1_ITEM_IN_HAND)) - { + if (actor->policy.aimAssist.isProvider) { + if (player->stateFlags1 & PLAYER_STATE1_FIRST_PERSON && + (player->stateFlags1 & PLAYER_STATE1_BOOMERANG_IN_HAND || + player->stateFlags1 & PLAYER_STATE1_ITEM_IN_HAND)) { ActorAccessibility_SetSoundPitch(actor, 9, actor->aimAssist.pitch); actor->aimAssist.framesSinceAimAssist++; ActorAccessibility_ProvideAimAssistForActor(actor); -//The above will have taken care of setting the appropriate frequency and pitch, so we'll take care of the audio here based on those results. + // The above will have taken care of setting the appropriate frequency and pitch, so we'll take care of the + // audio here based on those results. if (actor->aimAssist.framesSinceAimAssist >= actor->aimAssist.frequency) { - actor->aimAssist.framesSinceAimAssist = 0; - ActorAccessibility_PlaySoundForActor(actor, 9, actor->policy.aimAssist.sfx, false); + actor->aimAssist.framesSinceAimAssist = 0; + ActorAccessibility_PlaySoundForActor(actor, 9, actor->policy.aimAssist.sfx, false); } + } else + actor->aimAssist.framesSinceAimAssist = 32768;//Make sure there's no delay the next time you draw your bow or whatever. + } if (actor->policy.callback != NULL) diff --git a/soh/soh/Enhancements/accessible-actors/ActorAccessibility.h b/soh/soh/Enhancements/accessible-actors/ActorAccessibility.h index b108531f2..ffc8a09e8 100644 --- a/soh/soh/Enhancements/accessible-actors/ActorAccessibility.h +++ b/soh/soh/Enhancements/accessible-actors/ActorAccessibility.h @@ -74,7 +74,7 @@ struct AccessibleActor { s16 sceneIndex;//If this actor represents a scene transition, then this will contain the destination scene index. Zero otherwise. bool managedSoundSlots[NUM_MANAGED_SOUND_SLOTS];//These have their attenuation and panning parameters updated every frame automatically. struct { - s16 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. f32 pitch; // Used to report whether Link is aiming higher or lower than the actor. u8 frequency; // How often the sound will be played. Lower frequencies indicate that Link's vertical aim is