From 021cdac24c4753e303ee6a4357356ec116ff0a7b Mon Sep 17 00:00:00 2001 From: skidau Date: Thu, 6 Nov 2014 22:51:59 +1100 Subject: [PATCH 1/2] Ignore the emulated wiimotes speaker data if the sample rate is set at 0hz. Fixes issue 7806. --- Source/Core/Core/HW/WiimoteEmu/Speaker.cpp | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp b/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp index 725fa25adb..cdabd41bd2 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp @@ -109,19 +109,21 @@ void Wiimote::SpeakerData(wm_speaker_data* sd) unsigned int vol = (unsigned int)(m_options->settings[4]->GetValue() * 100); float amp = 10.0f; // Boost the speaker volume relative to the rest of the game audio - unsigned int sample_rate = sample_rate_dividend / Common::swap16(m_reg_speaker.sample_rate); - float speaker_volume_ratio = (float)m_reg_speaker.volume / volume_divisor; - unsigned int left_volume = (unsigned int)((128 + vol) * speaker_volume_ratio * amp); - unsigned int right_volume = (unsigned int)((128 - vol) * speaker_volume_ratio * amp); + if (m_reg_speaker.sample_rate) + { + unsigned int sample_rate = sample_rate_dividend / Common::swap16(m_reg_speaker.sample_rate); + float speaker_volume_ratio = (float)m_reg_speaker.volume / volume_divisor; + unsigned int left_volume = (unsigned int)((128 + vol) * speaker_volume_ratio * amp); + unsigned int right_volume = (unsigned int)((128 - vol) * speaker_volume_ratio * amp); - if (left_volume > 255) - left_volume = 255; - if (right_volume > 255) - right_volume = 255; - - g_sound_stream->GetMixer()->SetWiimoteSpeakerVolume(left_volume, right_volume); - g_sound_stream->GetMixer()->PushWiimoteSpeakerSamples(samples.get(), sd->length, sample_rate); + if (left_volume > 255) + left_volume = 255; + if (right_volume > 255) + right_volume = 255; + g_sound_stream->GetMixer()->SetWiimoteSpeakerVolume(left_volume, right_volume); + g_sound_stream->GetMixer()->PushWiimoteSpeakerSamples(samples.get(), sd->length, sample_rate); + } #ifdef WIIMOTE_SPEAKER_DUMP static int num = 0; From 0f615c754af4ea4e1f952c2460c4e91b936926f5 Mon Sep 17 00:00:00 2001 From: skidau Date: Sat, 8 Nov 2014 11:33:20 +1100 Subject: [PATCH 2/2] Packed the emu wiimote structs, removed swap16 and removed the speaker amp as the amp was distorting the audio. --- Source/Core/Core/HW/WiimoteEmu/Speaker.cpp | 7 +++---- Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h | 5 ++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp b/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp index cdabd41bd2..d7b0ff496d 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp @@ -107,14 +107,13 @@ void Wiimote::SpeakerData(wm_speaker_data* sd) // Speaker Pan unsigned int vol = (unsigned int)(m_options->settings[4]->GetValue() * 100); - float amp = 10.0f; // Boost the speaker volume relative to the rest of the game audio if (m_reg_speaker.sample_rate) { - unsigned int sample_rate = sample_rate_dividend / Common::swap16(m_reg_speaker.sample_rate); + unsigned int sample_rate = sample_rate_dividend / m_reg_speaker.sample_rate; float speaker_volume_ratio = (float)m_reg_speaker.volume / volume_divisor; - unsigned int left_volume = (unsigned int)((128 + vol) * speaker_volume_ratio * amp); - unsigned int right_volume = (unsigned int)((128 - vol) * speaker_volume_ratio * amp); + unsigned int left_volume = (unsigned int)((128 + vol) * speaker_volume_ratio); + unsigned int right_volume = (unsigned int)((128 - vol) * speaker_volume_ratio); if (left_volume > 255) left_volume = 255; diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h index c97383f8f0..113ea7baad 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h @@ -24,10 +24,9 @@ namespace WiimoteReal { class Wiimote; } - namespace WiimoteEmu { - +#pragma pack(push,1) struct ReportFeatures { u8 core, accel, ir, ext, size; @@ -197,7 +196,6 @@ private: wiimote_key m_ext_key; u8 m_eeprom[WIIMOTE_EEPROM_SIZE]; - struct MotionPlusReg { u8 unknown[0xF0]; @@ -233,6 +231,7 @@ private: u8 play; u8 unk_9; } m_reg_speaker; +#pragma pack(pop) }; void Spy(Wiimote* wm_, const void* data_, size_t size_);