From 34308a326c0d0192f9dd071e41852b11a34754ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 19 Feb 2025 10:50:32 -0600 Subject: [PATCH] Add basic sceSas state viewer to debugger --- Core/HLE/sceSas.cpp | 8 ++- Core/HLE/sceSas.h | 4 ++ Core/HW/SasAudio.cpp | 6 +- Core/HW/SasAudio.h | 1 + UI/ImDebugger/ImDebugger.cpp | 109 +++++++++++++++++++++++++++++++++++ UI/ImDebugger/ImDebugger.h | 3 + 6 files changed, 126 insertions(+), 5 deletions(-) diff --git a/Core/HLE/sceSas.cpp b/Core/HLE/sceSas.cpp index 5252ec2580..05091303fd 100644 --- a/Core/HLE/sceSas.cpp +++ b/Core/HLE/sceSas.cpp @@ -77,7 +77,11 @@ enum { // TODO - allow more than one, associating each with one Core pointer (passed in to all the functions) // No known games use more than one instance of Sas though. -static SasInstance *sas = NULL; +static SasInstance *sas; + +SasInstance *GetSasInstance() { + return sas; +} enum SasThreadState { DISABLED, @@ -247,7 +251,7 @@ static u32 sceSasInit(u32 core, u32 grainSize, u32 maxVoices, u32 outputMode, u3 INFO_LOG(Log::sceSas, "sceSasInit(%08x, %i, %i, %i, %i)", core, grainSize, maxVoices, outputMode, sampleRate); sas->SetGrainSize(grainSize); - // Seems like maxVoices is actually ignored for all intents and purposes. + // Seems like the maxVoices param is actually ignored for all intents and purposes. sas->maxVoices = PSP_SAS_VOICES_MAX; sas->outputMode = outputMode; for (int i = 0; i < sas->maxVoices; i++) { diff --git a/Core/HLE/sceSas.h b/Core/HLE/sceSas.h index a957f3d475..66dc65db6d 100644 --- a/Core/HLE/sceSas.h +++ b/Core/HLE/sceSas.h @@ -24,3 +24,7 @@ void __SasShutdown(); void __SasGetDebugStats(char *stats, size_t bufsize); void Register_sceSasCore(); + +class SasInstance; + +SasInstance *GetSasInstance(); diff --git a/Core/HW/SasAudio.cpp b/Core/HW/SasAudio.cpp index 081469c1ef..7532297397 100644 --- a/Core/HW/SasAudio.cpp +++ b/Core/HW/SasAudio.cpp @@ -188,9 +188,9 @@ void VagDecoder::DoState(PointerWrap &p) { Do(p, end_); } -int SasAtrac3::setContext(u32 context) { - contextAddr_ = context; - atracID_ = AtracSasGetIDByContext(context); +int SasAtrac3::setContext(u32 contextAddr) { + contextAddr_ = contextAddr; + atracID_ = AtracSasGetIDByContext(contextAddr); if (!sampleQueue_) sampleQueue_ = new BufferQueue(); sampleQueue_->clear(); diff --git a/Core/HW/SasAudio.h b/Core/HW/SasAudio.h index 7cd5e094f1..1cd2bc255c 100644 --- a/Core/HW/SasAudio.h +++ b/Core/HW/SasAudio.h @@ -140,6 +140,7 @@ public: SasAtrac3() : contextAddr_(0), atracID_(-1), sampleQueue_(0), end_(false) {} ~SasAtrac3() { delete sampleQueue_; } int setContext(u32 context); + int id() const { return atracID_; } void getNextSamples(s16 *outbuf, int wantedSamples); int addStreamData(u32 bufPtr, u32 addbytes); void DoState(PointerWrap &p); diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index 69dd68488a..77a3bdf9a5 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -36,6 +36,9 @@ #include "Core/HLE/sceAudiocodec.h" #include "Core/HLE/sceMp3.h" #include "Core/HLE/AtracCtx.h" +#include "Core/HLE/sceSas.h" +#include "Core/HW/SasAudio.h" + #include "Core/CoreTiming.h" // Threads window #include "Core/HLE/sceKernelThread.h" @@ -1053,6 +1056,106 @@ void DrawAudioChannels(ImConfig &cfg) { ImGui::End(); } +static const char *VoiceTypeToString(VoiceType type) { + switch (type) { + case VOICETYPE_OFF: return "OFF"; + case VOICETYPE_VAG: return "VAG"; // default + case VOICETYPE_NOISE: return "NOISE"; + case VOICETYPE_TRIWAVE: return "TRIWAVE"; // are these used? there are functions for them (sceSetTriangularWave) + case VOICETYPE_PULSEWAVE: return "PULSEWAVE"; + case VOICETYPE_PCM: return "PCM"; + case VOICETYPE_ATRAC3: return "ATRAC3"; + default: return "(unknown!)"; + } +} + +void DrawSasAudio(ImConfig &cfg) { + if (!ImGui::Begin("sasAudio", &cfg.sasAudioOpen)) { + ImGui::End(); + return; + } + + const SasInstance *sas = GetSasInstance(); + if (!sas) { + ImGui::Text("Sas instance not available"); + ImGui::End(); + return; + } + + ImGui::Checkbox("Show all voices", &cfg.sasShowAllVoices); + + if (ImGui::BeginTable("saschannels", 9, ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersH)) { + ImGui::TableSetupColumn("Index", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("On", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("Loop", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("Pause", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("Cur", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("Addr", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("Size", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("Volume", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableHeadersRow(); + + for (int i = 0; i < PSP_SAS_VOICES_MAX; i++) { + const SasVoice &voice = sas->voices[i]; + if (!voice.on && !cfg.sasShowAllVoices) { + continue; + } + if (!voice.on) { + ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 255, 255, 128)); + } + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("%d", i); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(VoiceTypeToString(voice.type)); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(BoolStr(voice.on)); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(BoolStr(voice.loop)); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(BoolStr(voice.paused)); + ImGui::TableNextColumn(); + switch (voice.type) { + case VOICETYPE_OFF: ImGui::TextUnformatted("(off)"); break; + case VOICETYPE_VAG: ImGui::Text("%08x", voice.vag.GetReadPtr()); break; + case VOICETYPE_PCM: ImGui::Text("%08x", voice.pcmAddr + voice.pcmIndex * 2); break; + default: + ImGui::TextUnformatted("N/A"); + break; + } + ImGui::TableNextColumn(); + switch (voice.type) { + case VOICETYPE_OFF: ImGui::TextUnformatted("(off)"); break; + case VOICETYPE_VAG: ImGui::Text("%08x", voice.vagAddr); break; + case VOICETYPE_PCM: ImGui::Text("%08x", voice.pcmAddr); break; + case VOICETYPE_ATRAC3: ImGui::Text("atrac: %d", voice.atrac3.id()); break; + default: + ImGui::TextUnformatted("N/A"); + break; + } + ImGui::TableNextColumn(); + switch (voice.type) { + case VOICETYPE_OFF: ImGui::TextUnformatted("(off)"); break; + case VOICETYPE_VAG: ImGui::Text("%08x", voice.vagSize); break; + case VOICETYPE_PCM: ImGui::Text("%08x", voice.pcmSize); break; + case VOICETYPE_ATRAC3: ImGui::Text("atrac: n/a"); break; + default: + ImGui::TextUnformatted("N/A"); + break; + } + ImGui::TableNextColumn(); + ImGui::Text("%d | %d", voice.volumeLeft, voice.volumeRight); + if (!voice.on) { + ImGui::PopStyleColor(); + } + } + + ImGui::EndTable(); + } + ImGui::End(); +} + static void DrawCallStacks(const MIPSDebugInterface *debug, bool *open) { if (!ImGui::Begin("Callstacks", open)) { ImGui::End(); @@ -1327,6 +1430,7 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu ImGui::EndMenu(); } if (ImGui::BeginMenu("Audio")) { + ImGui::MenuItem("SasAudio mixer", nullptr, &cfg_.sasAudioOpen); ImGui::MenuItem("Raw audio channels", nullptr, &cfg_.audioChannelsOpen); ImGui::MenuItem("Decoder contexts", nullptr, &cfg_.audioDecodersOpen); ImGui::EndMenu(); @@ -1391,6 +1495,10 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu DrawAudioChannels(cfg_); } + if (cfg_.sasAudioOpen) { + DrawSasAudio(cfg_); + } + if (cfg_.kernelObjectsOpen) { DrawKernelObjects(cfg_); } @@ -1851,6 +1959,7 @@ void ImConfig::SyncConfig(IniFile *ini, bool save) { sync.Sync("apctlOpen", &apctlOpen, false); sync.Sync("pixelViewerOpen", &pixelViewerOpen, false); sync.Sync("internalsOpen", &internalsOpen, false); + sync.Sync("sasAudioOpen", &sasAudioOpen, false); for (int i = 0; i < 4; i++) { char name[64]; snprintf(name, sizeof(name), "memory%dOpen", i + 1); diff --git a/UI/ImDebugger/ImDebugger.h b/UI/ImDebugger/ImDebugger.h index 80f7d204fb..685c99373e 100644 --- a/UI/ImDebugger/ImDebugger.h +++ b/UI/ImDebugger/ImDebugger.h @@ -147,6 +147,7 @@ struct ImConfig { bool adhocOpen; bool memDumpOpen; bool internalsOpen; + bool sasAudioOpen; bool memViewOpen[4]; // HLE explorer settings @@ -166,6 +167,8 @@ struct ImConfig { bool displayLatched = false; int requesterToken; + bool sasShowAllVoices = false; + // We use a separate ini file from the main PPSSPP config. void LoadConfig(const Path &iniFile); void SaveConfig(const Path &iniFile);