Merge pull request #978 from skidau/emu-wiimote-speaker

Hooked up the emulated Wiimote speaker.
This commit is contained in:
skidau 2014-09-07 15:54:21 +10:00
commit d12d4a558b
8 changed files with 72 additions and 14 deletions

View File

@ -121,6 +121,7 @@ unsigned int CMixer::Mix(short* samples, unsigned int num_samples, bool consider
m_dma_mixer.Mix(samples, num_samples, consider_framelimit);
m_streaming_mixer.Mix(samples, num_samples, consider_framelimit);
m_wiimote_speaker_mixer.Mix(samples, num_samples, consider_framelimit);
if (m_logAudio)
g_wave_writer.AddStereoSamples(samples, num_samples);
return num_samples;
@ -167,6 +168,24 @@ void CMixer::PushStreamingSamples(const short *samples, unsigned int num_samples
m_streaming_mixer.PushSamples(samples, num_samples);
}
void CMixer::PushWiimoteSpeakerSamples(const short *samples, unsigned int num_samples, unsigned int sample_rate)
{
short samples_stereo[MAX_SAMPLES * 2];
if (num_samples < MAX_SAMPLES)
{
m_wiimote_speaker_mixer.SetInputSampleRate(sample_rate);
for (unsigned int i = 0; i < num_samples; ++i)
{
samples_stereo[i * 2] = Common::swap16(samples[i]);
samples_stereo[i * 2 + 1] = Common::swap16(samples[i]);
}
m_wiimote_speaker_mixer.PushSamples(samples_stereo, num_samples);
}
}
void CMixer::SetDMAInputSampleRate(unsigned int rate)
{
m_dma_mixer.SetInputSampleRate(rate);
@ -182,6 +201,11 @@ void CMixer::SetStreamingVolume(unsigned int lvolume, unsigned int rvolume)
m_streaming_mixer.SetVolume(lvolume, rvolume);
}
void CMixer::SetWiimoteSpeakerVolume(unsigned int lvolume, unsigned int rvolume)
{
m_wiimote_speaker_mixer.SetVolume(lvolume, rvolume);
}
void CMixer::MixerFifo::SetInputSampleRate(unsigned int rate)
{
m_input_sample_rate = rate;

View File

@ -24,6 +24,7 @@ public:
CMixer(unsigned int BackendSampleRate)
: m_dma_mixer(this, 32000)
, m_streaming_mixer(this, 48000)
, m_wiimote_speaker_mixer(this, 3000)
, m_sampleRate(BackendSampleRate)
, m_logAudio(0)
, m_speed(0)
@ -39,11 +40,13 @@ public:
// Called from main thread
virtual void PushSamples(const short* samples, unsigned int num_samples);
virtual void PushStreamingSamples(const short* samples, unsigned int num_samples);
virtual void PushWiimoteSpeakerSamples(const short* samples, unsigned int num_samples, unsigned int sample_rate);
unsigned int GetSampleRate() const { return m_sampleRate; }
void SetDMAInputSampleRate(unsigned int rate);
void SetStreamInputSampleRate(unsigned int rate);
void SetStreamingVolume(unsigned int lvolume, unsigned int rvolume);
void SetWiimoteSpeakerVolume(unsigned int lvolume, unsigned int rvolume);
virtual void StartLogAudio(const std::string& filename)
{
@ -112,6 +115,7 @@ protected:
};
MixerFifo m_dma_mixer;
MixerFifo m_streaming_mixer;
MixerFifo m_wiimote_speaker_mixer;
unsigned int m_sampleRate;
WaveFileWriter g_wave_writer;

View File

@ -521,7 +521,7 @@ void SConfig::LoadCoreSettings(IniFile& ini)
core->Get("WiiSDCard", &m_WiiSDCard, false);
core->Get("WiiKeyboard", &m_WiiKeyboard, false);
core->Get("WiimoteContinuousScanning", &m_WiimoteContinuousScanning, false);
core->Get("WiimoteEnableSpeaker", &m_WiimoteEnableSpeaker, true);
core->Get("WiimoteEnableSpeaker", &m_WiimoteEnableSpeaker, false);
core->Get("RunCompareServer", &m_LocalCoreStartupParameter.bRunCompareServer, false);
core->Get("RunCompareClient", &m_LocalCoreStartupParameter.bRunCompareClient, false);
core->Get("MMU", &m_LocalCoreStartupParameter.bMMU, false);

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2
// Refer to the license.txt file included.
#include "AudioCommon/AudioCommon.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
//#define WIIMOTE_SPEAKER_DUMP
@ -64,6 +65,9 @@ void stopdamnwav(){wav.Stop();ofile.close();}
void Wiimote::SpeakerData(wm_speaker_data* sd)
{
if (!SConfig::GetInstance().m_WiimoteEnableSpeaker)
return;
// TODO consider using static max size instead of new
s16 *samples = new s16[sd->length * 2];
@ -74,6 +78,12 @@ void Wiimote::SpeakerData(wm_speaker_data* sd)
{
samples[i] = (s16)(s8)sd->data[i];
}
// Speaker Pan
unsigned int vol = (unsigned int)(m_options->settings[4]->GetValue() * 100);
soundStream->GetMixer()->SetWiimoteSpeakerVolume(128 + vol, 128 - vol);
soundStream->GetMixer()->PushWiimoteSpeakerSamples(samples, sd->length, 1500);
}
else if (m_reg_speaker.format == 0x00)
{
@ -83,6 +93,12 @@ void Wiimote::SpeakerData(wm_speaker_data* sd)
samples[i * 2] = adpcm_yamaha_expand_nibble(m_adpcm_state, (sd->data[i] >> 4) & 0xf);
samples[i * 2 + 1] = adpcm_yamaha_expand_nibble(m_adpcm_state, sd->data[i] & 0xf);
}
// Speaker Pan
unsigned int vol = (unsigned int)(m_options->settings[4]->GetValue() * 100);
soundStream->GetMixer()->SetWiimoteSpeakerVolume(128 + vol, 128 - vol);
soundStream->GetMixer()->PushWiimoteSpeakerSamples(samples, sd->length, 3000);
}
#ifdef WIIMOTE_SPEAKER_DUMP

View File

@ -309,6 +309,7 @@ Wiimote::Wiimote( const unsigned int index )
m_options->settings.emplace_back(new ControlGroup::Setting(_trans("Sideways Wiimote"), false));
m_options->settings.emplace_back(new ControlGroup::Setting(_trans("Upright Wiimote"), false));
m_options->settings.emplace_back(new ControlGroup::IterateUI(_trans("Iterative Input")));
m_options->settings.emplace_back(new ControlGroup::Setting(_trans("Speaker Pan"), 0, -127, 127));
// TODO: This value should probably be re-read if SYSCONF gets changed
m_sensor_bar_on_top = SConfig::GetInstance().m_SYSCONF->GetData<u8>("BT.BAR") != 0;

View File

@ -911,19 +911,31 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
//options
for (auto& groupSetting : group->settings)
{
PadSettingCheckBox* setting_cbox = new PadSettingCheckBox(parent, groupSetting.get());
if (groupSetting.get()->is_iterate == true)
if (groupSetting.get()->high == DEFAULT_HIGH_VALUE)
{
setting_cbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustSettingUI, eventsink);
groupSetting.get()->value = 0;
PadSettingCheckBox* setting_cbox = new PadSettingCheckBox(parent, groupSetting.get());
if (groupSetting.get()->is_iterate == true)
{
setting_cbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustSettingUI, eventsink);
groupSetting.get()->value = 0;
}
else
{
setting_cbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustSetting, eventsink);
}
options.push_back(setting_cbox);
Add(setting_cbox->wxcontrol, 0, wxALL | wxLEFT, 5);
}
else
{
setting_cbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustSetting, eventsink);
PadSettingSpin* setting = new PadSettingSpin(parent, groupSetting.get());
setting->wxcontrol->Bind(wxEVT_SPINCTRL, &GamepadPage::AdjustSetting, eventsink);
options.push_back(setting);
wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL);
szr->Add(new wxStaticText(parent, -1, wxGetTranslation(StrToWxStr(groupSetting->name))), 0, wxCENTER | wxRIGHT, 3);
szr->Add(setting->wxcontrol, 0, wxRIGHT, 3);
Add(szr, 0, wxALL | wxCENTER, 3);
}
options.push_back(setting_cbox);
Add(setting_cbox->wxcontrol, 0, wxALL|wxLEFT, 5);
}
}
break;

View File

@ -7,6 +7,7 @@
#define SLIDER_TICK_COUNT 100
#define DETECT_WAIT_TIME 2500
#define PREVIEW_UPDATE_TIME 25
#define DEFAULT_HIGH_VALUE 100
// might have to change this setup for wiimote
#define PROFILES_PATH "Profiles/"

View File

@ -113,15 +113,10 @@ WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputConfig& config
continuous_scanning->Bind(wxEVT_CHECKBOX, &WiimoteConfigDiag::OnContinuousScanning, this);
continuous_scanning->SetValue(SConfig::GetInstance().m_WiimoteContinuousScanning);
auto wiimote_speaker = new wxCheckBox(this, wxID_ANY, _("Enable Speaker Data"));
wiimote_speaker->Bind(wxEVT_CHECKBOX, &WiimoteConfigDiag::OnEnableSpeaker, this);
wiimote_speaker->SetValue(SConfig::GetInstance().m_WiimoteEnableSpeaker);
real_wiimotes_sizer->Add(continuous_scanning, 0, wxALIGN_CENTER_VERTICAL);
real_wiimotes_sizer->AddStretchSpacer(1);
real_wiimotes_sizer->Add(refresh_btn, 0, wxALL | wxALIGN_CENTER, 5);
real_wiimotes_group->Add(wiimote_speaker, 0);
real_wiimotes_group->Add(real_wiimotes_sizer, 0, wxEXPAND);
// "General Settings" controls
@ -131,6 +126,10 @@ WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputConfig& config
wxSlider* const WiimoteSpkVolume = new wxSlider(this, wxID_ANY, 0, 0, 127);
wxCheckBox* const WiimoteMotor = new wxCheckBox(this, wxID_ANY, _("Wiimote Motor"));
auto wiimote_speaker = new wxCheckBox(this, wxID_ANY, _("Enable Speaker Data"));
wiimote_speaker->Bind(wxEVT_CHECKBOX, &WiimoteConfigDiag::OnEnableSpeaker, this);
wiimote_speaker->SetValue(SConfig::GetInstance().m_WiimoteEnableSpeaker);
wxStaticText* const WiiSensBarPosText = new wxStaticText(this, wxID_ANY, _("Sensor Bar Position:"));
wxStaticText* const WiiSensBarSensText = new wxStaticText(this, wxID_ANY, _("IR Sensitivity:"));
wxStaticText* const WiiSensBarSensMinText = new wxStaticText(this, wxID_ANY, _("Min"));
@ -204,6 +203,7 @@ WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputConfig& config
wxGridSizer* const general_wiimote_sizer = new wxGridSizer(1, 5, 5);
general_wiimote_sizer->Add(WiimoteMotor);
general_wiimote_sizer->Add(wiimote_speaker, 0);
general_sizer->Add(choice_sizer);
general_sizer->Add(general_wiimote_sizer);