diff --git a/Source/Core/Core/IOS/USB/Emulated/Microphone.cpp b/Source/Core/Core/IOS/USB/Emulated/Microphone.cpp index 93e4bcfbc6..7490749557 100644 --- a/Source/Core/Core/IOS/USB/Emulated/Microphone.cpp +++ b/Source/Core/Core/IOS/USB/Emulated/Microphone.cpp @@ -13,6 +13,9 @@ #include "Common/ScopeGuard.h" #include "Common/Swap.h" #include "Core/Config/MainSettings.h" +#include "Core/Core.h" +#include "Core/IOS/USB/Emulated/WiiSpeak.h" +#include "Core/System.h" #ifdef _WIN32 #include @@ -20,7 +23,7 @@ namespace IOS::HLE::USB { -Microphone::Microphone() +Microphone::Microphone(const WiiSpeakState& sampler) : m_sampler(sampler) { #ifdef _WIN32 Common::Event sync_event; @@ -174,7 +177,16 @@ void Microphone::StreamStop() long Microphone::DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer, void* /*output_buffer*/, long nframes) { + // Skip data when core isn't running + if (Core::GetState(Core::System::GetInstance()) != Core::State::Running) + return nframes; + auto* mic = static_cast(user_data); + const auto& sampler = mic->GetSampler(); + + // Skip data if sampling is off or mute is on + if (!sampler.sample_on || sampler.mute) + return nframes; std::lock_guard lk(mic->m_ring_lock); @@ -227,4 +239,9 @@ bool Microphone::HasData() const { return m_samples_avail > 0 && Config::Get(Config::MAIN_WII_SPEAK_CONNECTED); } + +const WiiSpeakState& Microphone::GetSampler() const +{ + return m_sampler; +} } // namespace IOS::HLE::USB diff --git a/Source/Core/Core/IOS/USB/Emulated/Microphone.h b/Source/Core/Core/IOS/USB/Emulated/Microphone.h index 1b02e81d42..1919abfa21 100644 --- a/Source/Core/Core/IOS/USB/Emulated/Microphone.h +++ b/Source/Core/Core/IOS/USB/Emulated/Microphone.h @@ -15,14 +15,17 @@ struct cubeb_stream; namespace IOS::HLE::USB { +struct WiiSpeakState; + class Microphone final { public: - Microphone(); + Microphone(const WiiSpeakState& sampler); ~Microphone(); bool HasData() const; void ReadIntoBuffer(u8* dst, u32 size); + const WiiSpeakState& GetSampler() const; private: static long DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer, @@ -47,6 +50,8 @@ private: std::shared_ptr m_cubeb_ctx = nullptr; cubeb_stream* m_cubeb_stream = nullptr; + const WiiSpeakState& m_sampler; + #ifdef _WIN32 Common::WorkQueueThread> m_work_queue{ "Wii Speak Worker", [](const std::function& func) { func(); }}; diff --git a/Source/Core/Core/IOS/USB/Emulated/WiiSpeak.cpp b/Source/Core/Core/IOS/USB/Emulated/WiiSpeak.cpp index 0bd30a4109..aa13b66b89 100644 --- a/Source/Core/Core/IOS/USB/Emulated/WiiSpeak.cpp +++ b/Source/Core/Core/IOS/USB/Emulated/WiiSpeak.cpp @@ -43,7 +43,7 @@ bool WiiSpeak::Attach() DEBUG_LOG_FMT(IOS_USB, "[{:04x}:{:04x}] Opening device", m_vid, m_pid); if (!m_microphone) - m_microphone = std::make_unique(); + m_microphone = std::make_unique(m_sampler); m_device_attached = true; return true; } diff --git a/Source/Core/Core/IOS/USB/Emulated/WiiSpeak.h b/Source/Core/Core/IOS/USB/Emulated/WiiSpeak.h index e827e4e3d9..7eafee155a 100644 --- a/Source/Core/Core/IOS/USB/Emulated/WiiSpeak.h +++ b/Source/Core/Core/IOS/USB/Emulated/WiiSpeak.h @@ -12,6 +12,16 @@ namespace IOS::HLE::USB { +struct WiiSpeakState +{ + bool sample_on; + bool mute; + int freq; + int gain; + bool ec_reset; + bool sp_on; +}; + class WiiSpeak final : public Device { public: @@ -34,17 +44,7 @@ public: int SubmitTransfer(std::unique_ptr message) override; private: - struct WSState - { - bool sample_on; - bool mute; - int freq; - int gain; - bool ec_reset; - bool sp_on; - }; - - WSState m_sampler{}; + WiiSpeakState m_sampler{}; enum Registers {