more cleanup

This commit is contained in:
Demur Rumed 2025-04-23 01:02:29 +00:00
parent 9cbcf55a70
commit 4edea05106
6 changed files with 40 additions and 61 deletions

View file

@ -461,13 +461,6 @@ void accessible_goma(AccessibleActor* actor) {
} }
} }
void accessible_door_of_time(AccessibleActor* actor) {
ActorAccessibility_PlaySampleForActor(actor, 0, "Chanting", false);
ActorAccessibility_SetSoundPitch(actor, 0, 1.0);
// ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EV_DIAMOND_SWITCH, false);
}
void accessible_sticks(AccessibleActor* actor) { void accessible_sticks(AccessibleActor* actor) {
EnKarebaba* baba = (EnKarebaba*)actor->actor; EnKarebaba* baba = (EnKarebaba*)actor->actor;
@ -891,8 +884,6 @@ void ActorAccessibility_InitActors() {
ActorAccessibility_InitPolicy(&policy, "Amos Statue", NA_SE_EN_AMOS_WAVE); ActorAccessibility_InitPolicy(&policy, "Amos Statue", NA_SE_EN_AMOS_WAVE);
policy.n = 30; policy.n = 30;
ActorAccessibility_AddSupportedActor(ACTOR_EN_AM, policy); ActorAccessibility_AddSupportedActor(ACTOR_EN_AM, policy);
ActorAccessibility_InitPolicy(&policy, "door of time", accessible_door_of_time);
ActorAccessibility_AddSupportedActor(ACTOR_BG_MJIN, policy);
ActorAccessibility_InitPolicy(&policy, "shooting gallery rupees", nullptr); ActorAccessibility_InitPolicy(&policy, "shooting gallery rupees", nullptr);
policy.aimAssist.isProvider = true; policy.aimAssist.isProvider = true;
policy.distance = 1000; policy.distance = 1000;

View file

@ -30,8 +30,7 @@ enum AAE_COMMANDS {
AAE_PAN, AAE_PAN,
AAE_FILTER, AAE_FILTER,
AAE_SEEK, AAE_SEEK,
AAE_LISTENER, // Set the listener's position and direction. AAE_POS,
AAE_POS, // Set the sound source's position and direction.
AAE_PREPARE, AAE_PREPARE,
AAE_TERMINATE, AAE_TERMINATE,
}; };
@ -108,11 +107,12 @@ void AccessibleAudioEngine::destroy() {
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)
@ -136,6 +136,7 @@ uint32_t AccessibleAudioEngine::retrieve(float* buffer, uint32_t nFrames) {
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);
@ -214,7 +215,6 @@ void AccessibleAudioEngine::runThread() {
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;
@ -233,13 +233,9 @@ void AccessibleAudioEngine::runThread() {
case AAE_SEEK: case AAE_SEEK:
doSeekSound(action); doSeekSound(action);
break; break;
case AAE_LISTENER:
doSetListenerPos(action);
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;
@ -351,8 +347,6 @@ void AccessibleAudioEngine::doSeekSound(SoundAction& action) {
return; return;
ma_sound_seek_to_pcm_frame(&slot->sound, action.offset); ma_sound_seek_to_pcm_frame(&slot->sound, action.offset);
} }
void AccessibleAudioEngine::doSetListenerPos(SoundAction& action) {
}
void AccessibleAudioEngine::doSetSoundPos(SoundAction& action) { void AccessibleAudioEngine::doSetSoundPos(SoundAction& action) {
SoundSlot* slot = findSound(action); SoundSlot* slot = findSound(action);
if (slot == NULL) if (slot == NULL)
@ -469,13 +463,12 @@ void AccessibleAudioEngine::mix(int16_t* ogBuffer, uint32_t nFrames) {
float mixedChunk[AAE_MIX_CHUNK_SIZE * AAE_CHANNELS]; float mixedChunk[AAE_MIX_CHUNK_SIZE * AAE_CHANNELS];
while (nFrames > 0) { while (nFrames > 0) {
uint32_t nextChunk = std::min<uint32_t>(AAE_MIX_CHUNK_SIZE, nFrames); uint32_t nextChunk = std::min<uint32_t>(AAE_MIX_CHUNK_SIZE, nFrames);
ma_silence_pcm_frames( // This is so that it doesn't matter if we have less output available than expected.
sourceChunk, nextChunk, ma_format_f32, ma_silence_pcm_frames(sourceChunk, nextChunk, ma_format_f32, AAE_CHANNELS);
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, // The game's output is changed to 32-bit floating point samples.
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_dither_mode_none);
ma_mix_pcm_frames_f32(mixedChunk, sourceChunk, nextChunk, AAE_CHANNELS, 1.0); ma_mix_pcm_frames_f32(mixedChunk, sourceChunk, nextChunk, AAE_CHANNELS, 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. // 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; float scalar = 1.0;
@ -486,12 +479,13 @@ void AccessibleAudioEngine::mix(int16_t* ogBuffer, uint32_t nFrames) {
for (int i = 0; i < nextChunk * AAE_CHANNELS; i++) for (int i = 0; i < nextChunk * AAE_CHANNELS; i++)
mixedChunk[i] *= scalar; mixedChunk[i] *= scalar;
} }
ma_pcm_f32_to_s16(ogBuffer, mixedChunk, nextChunk * AAE_CHANNELS, // Chunk is ready to go out via the game's usual channels
ma_dither_mode_triangle); // Chunk is ready to go out via the game's usual channels. ma_pcm_f32_to_s16(ogBuffer, mixedChunk, nextChunk * AAE_CHANNELS, ma_dither_mode_triangle);
ogBuffer += nextChunk * AAE_CHANNELS; ogBuffer += nextChunk * AAE_CHANNELS;
nFrames -= nextChunk; 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;
@ -502,6 +496,7 @@ void AccessibleAudioEngine::playSound(uintptr_t handle, int slot, const char* pa
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;
@ -510,25 +505,26 @@ void AccessibleAudioEngine::stopSound(uintptr_t handle, int slot) {
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) { void AccessibleAudioEngine::setPitchBehindModifier(uintptr_t handle, int slot, float mod) {
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_BEHIND; action.command = AAE_PITCH_BEHIND;
action.handle = handle; action.handle = handle;
@ -537,7 +533,6 @@ void AccessibleAudioEngine::setPitchBehindModifier(uintptr_t handle, int slot, f
} }
void AccessibleAudioEngine::setVolume(uintptr_t handle, int slot, float volume) { void AccessibleAudioEngine::setVolume(uintptr_t handle, int slot, float volume) {
if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE) if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE)
return; return;
SoundAction& action = getNextOutgoingSoundAction(); SoundAction& action = getNextOutgoingSoundAction();
@ -546,6 +541,7 @@ void AccessibleAudioEngine::setVolume(uintptr_t handle, int slot, float volume)
action.slot = slot; action.slot = slot;
action.volume = volume; 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;
@ -576,6 +572,7 @@ void AccessibleAudioEngine::seekSound(uintptr_t handle, int slot, size_t offset)
action.command = AAE_SEEK; action.command = AAE_SEEK;
action.offset = offset; action.offset = offset;
} }
void AccessibleAudioEngine::setSoundPosition(uintptr_t handle, int slot, float posX, float posY, float posZ, void AccessibleAudioEngine::setSoundPosition(uintptr_t handle, int slot, float posX, float posY, float posZ,
float distToPlayer, float maxDistance) { float distToPlayer, float maxDistance) {
if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE) if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE)
@ -590,14 +587,15 @@ void AccessibleAudioEngine::setSoundPosition(uintptr_t handle, int slot, float p
action.distToPlayer = distToPlayer; action.distToPlayer = distToPlayer;
action.maxDistance = maxDistance; action.maxDistance = maxDistance;
} }
void AccessibleAudioEngine::prepare() { void AccessibleAudioEngine::prepare() {
SoundAction& action = getNextOutgoingSoundAction(); SoundAction& action = getNextOutgoingSoundAction();
action.command = AAE_PREPARE; 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. // This is called once at the end of every frame, so now is the time to post all of the accumulated commands.
postSoundActions(); postSoundActions();
} }
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 void AccessibleAudioEngine::cacheDecodedSample(const char* path, void* data, size_t size) {
// one. // data stored as wave, so we register it with MiniAudio as an encoded asset as opposed to a decoded one
ma_resource_manager_register_encoded_data(&resourceManager, path.c_str(), data, size); ma_resource_manager_register_encoded_data(&resourceManager, path, data, size);
} }

View file

@ -32,7 +32,7 @@ struct SoundAction {
float distance; float distance;
}; };
// Position and rotation vectors for AAE_LISTENER and AAE_POS. // Position and rotation vectors for AAE_POS
float posX; float posX;
float posY; float posY;
float posZ; float posZ;
@ -147,5 +147,5 @@ class AccessibleAudioEngine {
float maxDistance); float maxDistance);
// Schedule the preparation of output for delivery. // Schedule the preparation of output for delivery.
void prepare(); void prepare();
void cacheDecodedSample(std::string& path, void* data, size_t size); void cacheDecodedSample(const char* path, void* data, size_t size);
}; };

View file

@ -62,7 +62,6 @@ typedef std::unordered_set<s16> SceneList_t;
typedef struct { typedef struct {
std::string path; std::string path;
std::shared_ptr<Ship::File> resource; std::shared_ptr<Ship::File> resource;
std::shared_ptr<s16*> decodedSample; // Set if the record is for a raw sample as opposed to a SFX.
} SfxRecord; } SfxRecord;
class AudioGlossaryData { class AudioGlossaryData {
@ -88,9 +87,10 @@ class ActorAccessibility {
SceneList_t sceneList; SceneList_t sceneList;
AccessibleAudioEngine* audioEngine; AccessibleAudioEngine* audioEngine;
SfxExtractor sfxExtractor; SfxExtractor sfxExtractor;
std::unordered_map<s16, SfxRecord> sfxMap; // Maps internal sfx to external (prerendered) resources. // Maps internal sfx to external (prerendered) resources.
std::unordered_map<std::string, SfxRecord> std::unordered_map<s16, SfxRecord> sfxMap;
sampleMap; // Similar to above, but this one maps raw audio samples as opposed to SFX. // Similar to above, but this one maps raw audio samples as opposed to SFX.
std::unordered_set<const char*> sampleMap;
int extractSfx = 0; int extractSfx = 0;
s16 currentScene = -1; s16 currentScene = -1;
s8 currentRoom = -1; s8 currentRoom = -1;
@ -708,7 +708,7 @@ const char* ActorAccessibility_MapSfxToExternalAudio(s16 sfxId) {
tempRecord.path = ss.str(); tempRecord.path = ss.str();
aa->sfxMap[sfxId] = tempRecord; aa->sfxMap[sfxId] = tempRecord;
record = &aa->sfxMap[sfxId]; record = &aa->sfxMap[sfxId];
aa->audioEngine->cacheDecodedSample(record->path, record->resource->Buffer->data(), aa->audioEngine->cacheDecodedSample(record->path.c_str(), record->resource->Buffer->data(),
record->resource->Buffer->size()); record->resource->Buffer->size());
} else { } else {
record = &it->second; record = &it->second;
@ -718,32 +718,24 @@ const char* ActorAccessibility_MapSfxToExternalAudio(s16 sfxId) {
} }
// Map the path to a raw sample to the external audio engine. // Map the path to a raw sample to the external audio engine.
const char* ActorAccessibility_MapRawSampleToExternalAudio(const char* name) { const char* ActorAccessibility_MapRawSampleToExternalAudio(const char* name) {
SfxRecord* record; auto it = aa->sampleMap.find(name);
std::string key(name);
auto it = aa->sampleMap.find(key);
if (it == aa->sampleMap.end()) { if (it == aa->sampleMap.end()) {
SfxRecord tempRecord;
std::stringstream ss; std::stringstream ss;
ss << "audio/samples/" << key; ss << "audio/samples/" << name;
std::string fullPath = ss.str(); std::string fullPath = ss.str();
auto res = Ship::Context::GetInstance()->GetResourceManager()->LoadResource(fullPath); auto res = Ship::Context::GetInstance()->GetResourceManager()->LoadResource(fullPath);
if (res == nullptr) if (res == nullptr)
return NULL; // Resource doesn't exist, user's gotta run the extractor. return NULL; // Resource doesn't exist, user's gotta run the extractor.
AudioDecoder decoder; AudioDecoder decoder;
decoder.setSample((SOH::AudioSample*)res.get()); decoder.setSample((SOH::AudioSample*)res.get());
// TODO track wav somehow & free it with drwav_free
s16* wav; s16* wav;
size_t wavSize = decoder.decodeToWav(&wav); size_t wavSize = decoder.decodeToWav(&wav);
aa->sampleMap.insert(name);
tempRecord.path = key; aa->audioEngine->cacheDecodedSample(name, wav, wavSize);
tempRecord.decodedSample = std::make_shared<s16*>(wav);
aa->sampleMap[key] = tempRecord;
record = &aa->sampleMap[key];
aa->audioEngine->cacheDecodedSample(record->path, wav, wavSize);
} else {
record = &it->second;
} }
return record->path.c_str(); return name;
} }
// Call once per frame to tell the audio engine to start working on the latest batch of queued instructions. // Call once per frame to tell the audio engine to start working on the latest batch of queued instructions.

View file

@ -6,7 +6,6 @@
#include "soh/OTRGlobals.h" #include "soh/OTRGlobals.h"
#include "SfxTable.h" #include "SfxTable.h"
#include <sstream> #include <sstream>
const char* GetLanguageCode();
extern "C" { extern "C" {
#include "z64.h" #include "z64.h"
#include "functions.h" #include "functions.h"
@ -93,14 +92,14 @@ bool SfxExtractor::renderOutput(size_t endOfInput) {
} }
drwav_uninit(&wav); drwav_uninit(&wav);
std::vector<uint8_t> fileData((uint8_t*)mem, (uint8_t*)mem + size); std::vector<uint8_t> fileData((uint8_t*)mem, (uint8_t*)mem + size);
drwav_free(mem, NULL); drwav_free(mem, nullptr);
return archive->WriteFile(fileName.c_str(), fileData); return archive->WriteFile(fileName.c_str(), fileData);
} }
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.", "en-US");
// 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();
@ -171,7 +170,7 @@ void SfxExtractor::finished() {
<< std::endl; << std::endl;
if (currentStep == STEP_ERROR_OTR) if (currentStep == STEP_ERROR_OTR)
ss << "In all seriousness, please delete accessibility.o2r 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(), "en-US");
} else } else
Audio_PlayFanfare(NA_BGM_ITEM_GET); Audio_PlayFanfare(NA_BGM_ITEM_GET);
} }
@ -180,7 +179,7 @@ void SfxExtractor::maybeGiveProgressReport() {
if (sfxToRip == sfxCount * (i + 1) / 10) { if (sfxToRip == sfxCount * (i + 1) / 10) {
std::stringstream ss; std::stringstream ss;
ss << (i + 1) * 10 << " percent complete."; ss << (i + 1) * 10 << " percent complete.";
SpeechSynthesizer::Instance->Speak(ss.str().c_str(), GetLanguageCode()); SpeechSynthesizer::Instance->Speak(ss.str().c_str(), "en-US");
} }
} }
} }

View file

@ -2567,8 +2567,7 @@ extern "C" void OTRAudio_UninstallSfxCaptureThread() {
std::unique_lock<std::mutex> OTRAudio_Lock() { std::unique_lock<std::mutex> OTRAudio_Lock() {
return std::unique_lock<std::mutex>(audio.mutex); return std::unique_lock<std::mutex>(audio.mutex);
} }
// extern "C" void CheckTracker_OnMessageClose() {
// CheckTracker::CheckTrackerDialogClosed();
extern "C" void Gfx_UnregisterBlendedTexture(const char* name) { extern "C" void Gfx_UnregisterBlendedTexture(const char* name) {
gfx_unregister_blended_texture(name); gfx_unregister_blended_texture(name);
} }