diff --git a/libs/JSystem/src/JAudio2/JASChannel.cpp b/libs/JSystem/src/JAudio2/JASChannel.cpp index ffd5056e1d..61fe80a098 100644 --- a/libs/JSystem/src/JAudio2/JASChannel.cpp +++ b/libs/JSystem/src/JAudio2/JASChannel.cpp @@ -470,7 +470,7 @@ void JASChannel::updateMixer(f32 i_volume, f32 i_pan, f32 i_fxmix, f32 i_dolby, case 6: volume *= scale; break; - default: + default: // 0, 1, 4, 5, 8-15 if (JASDriver::getOutputMode() == JAS_OUTPUT_MONO) { volume *= scale; } else { diff --git a/src/dusk/imgui/ImGuiAudio.cpp b/src/dusk/imgui/ImGuiAudio.cpp index 2c1f6d96ad..07caf9f0c0 100644 --- a/src/dusk/imgui/ImGuiAudio.cpp +++ b/src/dusk/imgui/ImGuiAudio.cpp @@ -1,12 +1,81 @@ #include "ImGuiConsole.hpp" #include "ImGuiMenuTools.hpp" #include "JSystem/JAudio2/JAISeMgr.h" +#include "JSystem/JAudio2/JAISeqMgr.h" #include "JSystem/JAudio2/JAIStreamMgr.h" #include "JSystem/JAudio2/JASCriticalSection.h" #include "JSystem/JAudio2/JASDSPChannel.h" #include "JSystem/JAudio2/JASDSPInterface.h" +#include "JSystem/JAudio2/JASDriverIF.h" #include "JSystem/JAudio2/JASTrack.h" +static std::array channelSortIndices = {}; + +static bool sortUpdateCount = true; + +static void DisplayDspChannel(int i) { + auto& channel = JASDsp::CH_BUF[i]; + auto& jasChannel = JASDSPChannel::sDspChannels[i]; + if (!channel.mIsActive) { + return; + } + + char buf[64]; + snprintf(buf, sizeof(buf), "%d", i); + + if (ImGui::BeginChild(buf, ImVec2(), ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY)) { + ImGui::Text("[%02X]", i); + ImGui::SameLine(); + ImGui::Text("Update count: %d", jasChannel.mUpdateCounter); + ImGui::TextUnformatted(channel.mLoopFlag ? "Loop: true" : "Loop: false"); + ImGui::SameLine(); + ImGui::Text("Priority: %hd", jasChannel.mPriority); + ImGui::Text("Format: %02X/%02X", channel.mSamplesPerBlock, channel.mBytesPerBlock); + ImGui::Text("Position: %08X/%08X", channel.mSamplePosition, channel.mEndSample); + ImGui::SameLine(); + ImGui::Text("Memory: %08X/%08X", channel.mWaveAramAddress, channel.mAramStreamPosition); + + if (channel.mAutoMixerBeenSet) { + auto pan = (channel.mAutoMixerPanDolby >> 8) / 127.5f; + auto dolby = (channel.mAutoMixerPanDolby & 0xFF) / 127.5f; + auto fxMix = (channel.mAutoMixerFxMix >> 8) / 127.5f; + auto volume = (channel.mAutoMixerVolume) / (f32) JASDriver::getChannelLevel_dsp(); + ImGui::Text( + "Auto mixer active (pan: %f, dolby: %f, fx: %f, volume: %f)", + pan, dolby, fxMix, volume); + } else { + ImGui::Text( + "Bus connect: %04X,%04X,%04X,%04X,%04X,%04X", + channel.mOutputChannels[0].mBusConnect, + channel.mOutputChannels[1].mBusConnect, + channel.mOutputChannels[2].mBusConnect, + channel.mOutputChannels[3].mBusConnect, + channel.mOutputChannels[4].mBusConnect, + channel.mOutputChannels[5].mBusConnect); + } + } + + ImGui::EndChild(); +} + +static void InitChannelSortIndices() { + for (int i = 0; i < channelSortIndices.size(); i++) { + channelSortIndices[i] = i; + } +} + +static void SortChannelsByUpdateCount() { + InitChannelSortIndices(); + std::ranges::sort( + channelSortIndices, + [](u8 a, u8 b) { + auto& jasChannelA = JASDSPChannel::sDspChannels[a]; + auto& jasChannelB = JASDSPChannel::sDspChannels[b]; + + return jasChannelA.mUpdateCounter > jasChannelB.mUpdateCounter; + }); +} + static void ShowAllDspChannels() { int activeChannels = 0; for (int i = 0; i < DSP_CHANNELS; i++) { @@ -16,29 +85,17 @@ static void ShowAllDspChannels() { } ImGui::Text("Active channels: %d", activeChannels); + ImGui::Checkbox("Sort by update count", &sortUpdateCount); - for (int i = 0; i < DSP_CHANNELS; i++) { - auto& channel = JASDsp::CH_BUF[i]; - auto& jasChannel = JASDSPChannel::sDspChannels[i]; - if (!channel.mIsActive) { - continue; + if (sortUpdateCount) { + SortChannelsByUpdateCount(); + for (u8 index : channelSortIndices) { + DisplayDspChannel(index); } - - char buf[64]; - snprintf(buf, sizeof(buf), "%d", i); - - if (ImGui::BeginChild(buf, ImVec2(), ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY)) { - ImGui::Text("[%02X]", i); - ImGui::TextUnformatted(channel.mLoopFlag ? "Loop: true" : "Loop: false"); - ImGui::SameLine(); - ImGui::Text("Priority: %hd", jasChannel.mPriority); - ImGui::Text("Format: %02X/%02X", channel.mSamplesPerBlock, channel.mBytesPerBlock); - ImGui::Text("Position: %08X/%08X", channel.mSamplePosition, channel.mEndSample); - ImGui::SameLine(); - ImGui::Text("Memory: %08X/%08X", channel.mWaveAramAddress, channel.mAramStreamPosition); + } else { + for (int i = 0; i < DSP_CHANNELS; i++) { + DisplayDspChannel(i); } - - ImGui::EndChild(); } } @@ -58,6 +115,9 @@ static void ShowAllTracks() { bool paused = track.mFlags.pause; ImGui::Checkbox("Paused", &paused); track.mFlags.pause = paused; + bool muted = track.mFlags.mute; + ImGui::Checkbox("Muted", &muted); + track.mFlags.mute = muted; for (int i = 0; i < JASTrack::MAX_CHILDREN; i++) { const auto child = track.getChild(i); @@ -116,6 +176,19 @@ static void ShowAllJAISes() { } } + +static void ShowAllJAISeqs() { + auto& mgr = *JAISeqMgr::getInstance(); + + if (ImGui::Button("Pause")) { + mgr.pause(true); + } + ImGui::SameLine(); + if (ImGui::Button("Unpause")) { + mgr.pause(false); + } +} + void dusk::ImGuiMenuTools::ShowAudioDebug() { if (!ImGuiConsole::CheckMenuViewToggle(ImGuiKey_F7, m_showAudioDebug)) { return; @@ -150,6 +223,11 @@ void dusk::ImGuiMenuTools::ShowAudioDebug() { ImGui::EndTabItem(); } + if (ImGui::BeginTabItem("JAISeq")) { + ShowAllJAISeqs(); + ImGui::EndTabItem(); + } + ImGui::EndTabBar(); } }