mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-24 06:14:54 +00:00
IOS/USB: Only sample Wii Speak data when necessary
This commit is contained in:
parent
e4fd94b24b
commit
15b614ceef
4 changed files with 36 additions and 14 deletions
|
@ -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 <Objbase.h>
|
||||
|
@ -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<Microphone*>(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
|
||||
|
|
|
@ -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<cubeb> m_cubeb_ctx = nullptr;
|
||||
cubeb_stream* m_cubeb_stream = nullptr;
|
||||
|
||||
const WiiSpeakState& m_sampler;
|
||||
|
||||
#ifdef _WIN32
|
||||
Common::WorkQueueThread<std::function<void()>> m_work_queue{
|
||||
"Wii Speak Worker", [](const std::function<void()>& func) { func(); }};
|
||||
|
|
|
@ -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<Microphone>();
|
||||
m_microphone = std::make_unique<Microphone>(m_sampler);
|
||||
m_device_attached = true;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -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<IsoMessage> 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
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue