| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | // Copyright 2015 Dolphin Emulator Project
 | 
					
						
							| 
									
										
										
										
											2015-05-18 01:08:10 +02:00
										 |  |  | // Licensed under GPLv2+
 | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | // Refer to the license.txt file included.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-05 08:29:29 -04:00
										 |  |  | #include "DolphinWX/Config/AudioConfigPane.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | #include <string>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <wx/checkbox.h>
 | 
					
						
							|  |  |  | #include <wx/choice.h>
 | 
					
						
							|  |  |  | #include <wx/gbsizer.h>
 | 
					
						
							|  |  |  | #include <wx/radiobox.h>
 | 
					
						
							|  |  |  | #include <wx/sizer.h>
 | 
					
						
							|  |  |  | #include <wx/spinctrl.h>
 | 
					
						
							|  |  |  | #include <wx/stattext.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "AudioCommon/AudioCommon.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-26 17:13:07 -04:00
										 |  |  | #include "Common/Common.h"
 | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | #include "Core/ConfigManager.h"
 | 
					
						
							|  |  |  | #include "Core/Core.h"
 | 
					
						
							| 
									
										
										
										
											2016-08-02 06:22:37 +00:00
										 |  |  | #include "DolphinWX/DolphinSlider.h"
 | 
					
						
							| 
									
										
										
										
											2016-11-05 08:29:29 -04:00
										 |  |  | #include "DolphinWX/WxEventUtils.h"
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | #include "DolphinWX/WxUtils.h"
 | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | AudioConfigPane::AudioConfigPane(wxWindow* parent, wxWindowID id) : wxPanel(parent, id) | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   InitializeGUI(); | 
					
						
							|  |  |  |   LoadGUIValues(); | 
					
						
							| 
									
										
										
										
											2016-11-05 08:29:29 -04:00
										 |  |  |   BindEvents(); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioConfigPane::InitializeGUI() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   m_dsp_engine_strings.Add(_("DSP HLE emulation (fast)")); | 
					
						
							|  |  |  |   m_dsp_engine_strings.Add(_("DSP LLE recompiler")); | 
					
						
							|  |  |  |   m_dsp_engine_strings.Add(_("DSP LLE interpreter (slow)")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   m_dsp_engine_radiobox = | 
					
						
							|  |  |  |       new wxRadioBox(this, wxID_ANY, _("DSP Emulator Engine"), wxDefaultPosition, wxDefaultSize, | 
					
						
							|  |  |  |                      m_dsp_engine_strings, 0, wxRA_SPECIFY_ROWS); | 
					
						
							|  |  |  |   m_dpl2_decoder_checkbox = new wxCheckBox(this, wxID_ANY, _("Dolby Pro Logic II decoder")); | 
					
						
							| 
									
										
										
										
											2016-08-02 06:22:37 +00:00
										 |  |  |   m_volume_slider = new DolphinSlider(this, wxID_ANY, 0, 0, 100, wxDefaultPosition, wxDefaultSize, | 
					
						
							|  |  |  |                                       wxSL_VERTICAL | wxSL_INVERSE); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   m_volume_text = new wxStaticText(this, wxID_ANY, ""); | 
					
						
							|  |  |  |   m_audio_backend_choice = | 
					
						
							|  |  |  |       new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_audio_backend_strings); | 
					
						
							|  |  |  |   m_audio_latency_spinctrl = | 
					
						
							|  |  |  |       new wxSpinCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 30); | 
					
						
							| 
									
										
										
										
											2016-10-09 19:28:50 -07:00
										 |  |  |   m_audio_latency_label = new wxStaticText(this, wxID_ANY, _("Latency:")); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   m_audio_backend_choice->SetToolTip( | 
					
						
							|  |  |  |       _("Changing this will have no effect while the emulator is running.")); | 
					
						
							| 
									
										
										
										
											2016-10-09 19:34:11 -07:00
										 |  |  |   m_audio_latency_spinctrl->SetToolTip(_("Sets the latency (in ms). Higher values may reduce audio " | 
					
						
							|  |  |  |                                          "crackling. Certain backends only.")); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   m_dpl2_decoder_checkbox->SetToolTip( | 
					
						
							| 
									
										
										
										
											2016-10-09 19:18:16 -07:00
										 |  |  |       _("Enables Dolby Pro Logic II emulation using 5.1 surround. Certain backends only.")); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-02 06:22:37 +00:00
										 |  |  |   const int space5 = FromDIP(5); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   wxStaticBoxSizer* const dsp_engine_sizer = | 
					
						
							|  |  |  |       new wxStaticBoxSizer(wxVERTICAL, this, _("Sound Settings")); | 
					
						
							| 
									
										
										
										
											2016-08-02 06:22:37 +00:00
										 |  |  |   dsp_engine_sizer->Add(m_dsp_engine_radiobox, 0, wxEXPAND | wxLEFT | wxRIGHT, space5); | 
					
						
							|  |  |  |   dsp_engine_sizer->AddSpacer(space5); | 
					
						
							|  |  |  |   dsp_engine_sizer->AddStretchSpacer(); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   wxStaticBoxSizer* const volume_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Volume")); | 
					
						
							| 
									
										
										
										
											2016-08-02 06:22:37 +00:00
										 |  |  |   volume_sizer->Add(m_volume_slider, 1, wxALIGN_CENTER_HORIZONTAL); | 
					
						
							|  |  |  |   volume_sizer->Add(m_volume_text, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, space5); | 
					
						
							|  |  |  |   volume_sizer->AddSpacer(space5); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-02 06:22:37 +00:00
										 |  |  |   wxGridBagSizer* const backend_grid_sizer = new wxGridBagSizer(space5, space5); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   backend_grid_sizer->Add(new wxStaticText(this, wxID_ANY, _("Audio Backend:")), wxGBPosition(0, 0), | 
					
						
							| 
									
										
										
										
											2016-08-02 06:22:37 +00:00
										 |  |  |                           wxDefaultSpan, wxALIGN_CENTER_VERTICAL); | 
					
						
							|  |  |  |   backend_grid_sizer->Add(m_audio_backend_choice, wxGBPosition(0, 1), wxDefaultSpan, | 
					
						
							|  |  |  |                           wxALIGN_CENTER_VERTICAL); | 
					
						
							| 
									
										
										
										
											2016-10-09 19:34:11 -07:00
										 |  |  |   backend_grid_sizer->Add(m_dpl2_decoder_checkbox, wxGBPosition(1, 0), wxGBSpan(1, 2), | 
					
						
							|  |  |  |                           wxALIGN_CENTER_VERTICAL); | 
					
						
							|  |  |  |   backend_grid_sizer->Add(m_audio_latency_label, wxGBPosition(2, 0), wxDefaultSpan, | 
					
						
							|  |  |  |                           wxALIGN_CENTER_VERTICAL); | 
					
						
							| 
									
										
										
										
											2016-10-09 19:22:18 -07:00
										 |  |  |   backend_grid_sizer->Add(m_audio_latency_spinctrl, wxGBPosition(2, 1), wxDefaultSpan, | 
					
						
							| 
									
										
										
										
											2016-08-02 06:22:37 +00:00
										 |  |  |                           wxALIGN_CENTER_VERTICAL); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   wxStaticBoxSizer* const backend_static_box_sizer = | 
					
						
							| 
									
										
										
										
											2016-08-02 06:22:37 +00:00
										 |  |  |       new wxStaticBoxSizer(wxVERTICAL, this, _("Backend Settings")); | 
					
						
							|  |  |  |   backend_static_box_sizer->AddSpacer(space5); | 
					
						
							|  |  |  |   backend_static_box_sizer->Add(backend_grid_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, space5); | 
					
						
							|  |  |  |   backend_static_box_sizer->AddSpacer(space5); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   wxBoxSizer* const dsp_audio_sizer = new wxBoxSizer(wxHORIZONTAL); | 
					
						
							| 
									
										
										
										
											2016-08-02 06:22:37 +00:00
										 |  |  |   dsp_audio_sizer->AddSpacer(space5); | 
					
						
							|  |  |  |   dsp_audio_sizer->Add(dsp_engine_sizer, 1, wxEXPAND | wxTOP | wxBOTTOM, space5); | 
					
						
							|  |  |  |   dsp_audio_sizer->AddSpacer(space5); | 
					
						
							|  |  |  |   dsp_audio_sizer->Add(volume_sizer, 0, wxEXPAND | wxTOP | wxBOTTOM, space5); | 
					
						
							|  |  |  |   dsp_audio_sizer->AddSpacer(space5); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   wxBoxSizer* const main_sizer = new wxBoxSizer(wxVERTICAL); | 
					
						
							| 
									
										
										
										
											2016-08-02 06:22:37 +00:00
										 |  |  |   main_sizer->AddSpacer(space5); | 
					
						
							|  |  |  |   main_sizer->Add(dsp_audio_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, space5); | 
					
						
							|  |  |  |   main_sizer->AddSpacer(space5); | 
					
						
							|  |  |  |   main_sizer->Add(backend_static_box_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, space5); | 
					
						
							|  |  |  |   main_sizer->AddSpacer(space5); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   SetSizerAndFit(main_sizer); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioConfigPane::LoadGUIValues() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   const SConfig& startup_params = SConfig::GetInstance(); | 
					
						
							| 
									
										
										
										
											2016-10-09 19:10:16 -07:00
										 |  |  |   PopulateBackendChoiceBox(); | 
					
						
							|  |  |  |   ToggleBackendSpecificControls(SConfig::GetInstance().sBackend); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // Audio DSP Engine
 | 
					
						
							|  |  |  |   if (startup_params.bDSPHLE) | 
					
						
							|  |  |  |     m_dsp_engine_radiobox->SetSelection(0); | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     m_dsp_engine_radiobox->SetSelection(SConfig::GetInstance().m_DSPEnableJIT ? 1 : 2); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   m_volume_slider->SetValue(SConfig::GetInstance().m_Volume); | 
					
						
							|  |  |  |   m_volume_text->SetLabel(wxString::Format("%d %%", SConfig::GetInstance().m_Volume)); | 
					
						
							|  |  |  |   m_dpl2_decoder_checkbox->SetValue(startup_params.bDPL2Decoder); | 
					
						
							|  |  |  |   m_audio_latency_spinctrl->SetValue(startup_params.iLatency); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-09 19:10:16 -07:00
										 |  |  | void AudioConfigPane::ToggleBackendSpecificControls(const std::string& backend) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-10-09 19:18:16 -07:00
										 |  |  |   m_dpl2_decoder_checkbox->Enable(AudioCommon::SupportsDPL2Decoder(backend)); | 
					
						
							| 
									
										
										
										
											2016-10-09 19:34:11 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   bool supports_latency_control = AudioCommon::SupportsLatencyControl(backend); | 
					
						
							|  |  |  |   m_audio_latency_spinctrl->Enable(supports_latency_control); | 
					
						
							|  |  |  |   m_audio_latency_label->Enable(supports_latency_control); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   bool supports_volume_changes = AudioCommon::SupportsVolumeChanges(backend); | 
					
						
							|  |  |  |   m_volume_slider->Enable(supports_volume_changes); | 
					
						
							|  |  |  |   m_volume_text->Enable(supports_volume_changes); | 
					
						
							| 
									
										
										
										
											2016-10-09 19:10:16 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-05 08:29:29 -04:00
										 |  |  | void AudioConfigPane::BindEvents() | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-11-05 08:29:29 -04:00
										 |  |  |   m_dsp_engine_radiobox->Bind(wxEVT_RADIOBOX, &AudioConfigPane::OnDSPEngineRadioBoxChanged, this); | 
					
						
							|  |  |  |   m_dsp_engine_radiobox->Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   m_dpl2_decoder_checkbox->Bind(wxEVT_CHECKBOX, &AudioConfigPane::OnDPL2DecoderCheckBoxChanged, | 
					
						
							|  |  |  |                                 this); | 
					
						
							|  |  |  |   m_dpl2_decoder_checkbox->Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   m_volume_slider->Bind(wxEVT_SLIDER, &AudioConfigPane::OnVolumeSliderChanged, this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   m_audio_backend_choice->Bind(wxEVT_CHOICE, &AudioConfigPane::OnAudioBackendChanged, this); | 
					
						
							|  |  |  |   m_audio_backend_choice->Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   m_audio_latency_spinctrl->Bind(wxEVT_SPINCTRL, &AudioConfigPane::OnLatencySpinCtrlChanged, this); | 
					
						
							|  |  |  |   m_audio_latency_spinctrl->Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioConfigPane::OnDSPEngineRadioBoxChanged(wxCommandEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   SConfig::GetInstance().bDSPHLE = m_dsp_engine_radiobox->GetSelection() == 0; | 
					
						
							|  |  |  |   SConfig::GetInstance().m_DSPEnableJIT = m_dsp_engine_radiobox->GetSelection() == 1; | 
					
						
							|  |  |  |   AudioCommon::UpdateSoundStream(); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioConfigPane::OnDPL2DecoderCheckBoxChanged(wxCommandEvent&) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   SConfig::GetInstance().bDPL2Decoder = m_dpl2_decoder_checkbox->IsChecked(); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioConfigPane::OnVolumeSliderChanged(wxCommandEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   SConfig::GetInstance().m_Volume = m_volume_slider->GetValue(); | 
					
						
							|  |  |  |   AudioCommon::UpdateSoundStream(); | 
					
						
							|  |  |  |   m_volume_text->SetLabel(wxString::Format("%d %%", m_volume_slider->GetValue())); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioConfigPane::OnAudioBackendChanged(wxCommandEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // Don't save the translated BACKEND_NULLSOUND string
 | 
					
						
							|  |  |  |   SConfig::GetInstance().sBackend = m_audio_backend_choice->GetSelection() ? | 
					
						
							|  |  |  |                                         WxStrToStr(m_audio_backend_choice->GetStringSelection()) : | 
					
						
							|  |  |  |                                         BACKEND_NULLSOUND; | 
					
						
							| 
									
										
										
										
											2016-10-09 19:10:16 -07:00
										 |  |  |   ToggleBackendSpecificControls(WxStrToStr(m_audio_backend_choice->GetStringSelection())); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   AudioCommon::UpdateSoundStream(); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioConfigPane::OnLatencySpinCtrlChanged(wxCommandEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   SConfig::GetInstance().iLatency = m_audio_latency_spinctrl->GetValue(); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioConfigPane::PopulateBackendChoiceBox() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   for (const std::string& backend : AudioCommon::GetSoundBackends()) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     m_audio_backend_choice->Append(wxGetTranslation(StrToWxStr(backend))); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-08-02 06:22:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   int num = m_audio_backend_choice->FindString(StrToWxStr(SConfig::GetInstance().sBackend)); | 
					
						
							|  |  |  |   m_audio_backend_choice->SetSelection(num); | 
					
						
							| 
									
										
										
										
											2015-03-18 18:00:27 -04:00
										 |  |  | } |