Added dtk sound mixing to audiocommon (should work with LLE now)

And also moved all common setting to audiocommonconfig


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2796 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
nakeee
2009-03-30 09:55:50 +00:00
parent 5987dbf7ba
commit 37d513c53b
19 changed files with 133 additions and 69 deletions

View File

@ -453,6 +453,14 @@
RelativePath=".\Src\AudioCommon.h" RelativePath=".\Src\AudioCommon.h"
> >
</File> </File>
<File
RelativePath=".\Src\AudioCommonConfig.cpp"
>
</File>
<File
RelativePath=".\Src\AudioCommonConfig.h"
>
</File>
<File <File
RelativePath=".\Src\Mixer.cpp" RelativePath=".\Src\Mixer.cpp"
> >

View File

@ -24,19 +24,28 @@
namespace AudioCommon namespace AudioCommon
{ {
SoundStream *InitSoundStream(std::string backend, CMixer *mixer) SoundStream *InitSoundStream(CMixer *mixer)
{ {
if (!mixer) if (!mixer)
mixer = new CMixer(); mixer = new CMixer();
std::string backend = ac_Config.sBackend;
if (backend == BACKEND_DIRECTSOUND && DSound::isValid()) soundStream = new DSound(mixer, g_dspInitialize.hWnd); if (backend == BACKEND_DIRECTSOUND && DSound::isValid()) soundStream = new DSound(mixer, g_dspInitialize.hWnd);
if (backend == BACKEND_AOSOUND && AOSound::isValid()) soundStream = new AOSound(mixer); if (backend == BACKEND_AOSOUND && AOSound::isValid()) soundStream = new AOSound(mixer);
if (backend == BACKEND_OPENAL && OpenALStream::isValid()) soundStream = new OpenALStream(mixer); if (backend == BACKEND_OPENAL && OpenALStream::isValid()) soundStream = new OpenALStream(mixer);
if (backend == BACKEND_NULL && NullSound::isValid()) soundStream = new NullSound(mixer); if (backend == BACKEND_NULL && NullSound::isValid()) soundStream = new NullSound(mixer);
if (soundStream != NULL) { if (soundStream != NULL) {
if (soundStream->Start()) ac_Config.Update();
if (soundStream->Start()) {
// Start the sound recording
/*
if (ac_Config.record) {
soundStream->StartLogAudio(FULL_DUMP_DIR g_Config.recordFile);
}
*/
return soundStream; return soundStream;
}
PanicAlert("Could not initialize backend %s, falling back to NULL", backend.c_str()); PanicAlert("Could not initialize backend %s, falling back to NULL", backend.c_str());
} }

View File

@ -19,25 +19,22 @@
#define _AUDIO_COMMON_H_ #define _AUDIO_COMMON_H_
#include "Common.h" #include "Common.h"
#include "AudioCommonConfig.h"
#include "../../../PluginSpecs/pluginspecs_dsp.h" #include "../../../PluginSpecs/pluginspecs_dsp.h"
#include "SoundStream.h" #include "SoundStream.h"
class CMixer; class CMixer;
extern DSPInitialize g_dspInitialize; extern DSPInitialize g_dspInitialize;
extern SoundStream *soundStream; extern SoundStream *soundStream;
extern AudioCommonConfig ac_Config;
namespace AudioCommon namespace AudioCommon
{ {
SoundStream *InitSoundStream(std::string backend, CMixer *mixer = NULL); SoundStream *InitSoundStream(CMixer *mixer = NULL);
void ShutdownSoundStream(); void ShutdownSoundStream();
std::vector<std::string> GetSoundBackends(); std::vector<std::string> GetSoundBackends();
// Backend Types
#define BACKEND_DIRECTSOUND "DSound"
#define BACKEND_AOSOUND "AOSound"
#define BACKEND_OPENAL "OpenAL"
#define BACKEND_NULL "NullSound"
} }
#endif // _AUDIO_COMMON_H_ #endif // _AUDIO_COMMON_H_

View File

@ -0,0 +1,29 @@
#include "AudioCommon.h"
AudioCommonConfig ac_Config;
// Load from given file
void AudioCommonConfig::Load(IniFile &file) {
file.Get("Config", "EnableDTKMusic", &m_EnableDTKMusic, true);
file.Get("Config", "EnableThrottle", &m_EnableThrottle, true);
#ifdef _WIN32
file.Get("Config", "Backend", &sBackend, "DSound");
#else
file.Get("Config", "Backend", &sBackend, "AOSound");
#endif
}
// Set the values for the file
void AudioCommonConfig::Set(IniFile &file) {
file.Set("Config", "EnableDTKMusic", m_EnableDTKMusic);
file.Set("Config", "EnableThrottle", m_EnableThrottle);
file.Set("Config", "Backend", sBackend.c_str());
}
// Update according to the values (stream/mixer)
void AudioCommonConfig::Update() {
if (soundStream) {
soundStream->GetMixer()->SetThrottle(m_EnableThrottle);
soundStream->GetMixer()->SetDTKMusic(m_EnableDTKMusic);
}
}

View File

@ -0,0 +1,29 @@
#ifndef _AUDIO_COMMON_CONFIG_H_
#define _AUDIO_COMMON_CONFIG_H_
#include <string>
#include "IniFile.h"
// Backend Types
#define BACKEND_DIRECTSOUND "DSound"
#define BACKEND_AOSOUND "AOSound"
#define BACKEND_OPENAL "OpenAL"
#define BACKEND_NULL "NullSound"
struct AudioCommonConfig
{
bool m_EnableDTKMusic;
bool m_EnableThrottle;
std::string sBackend;
// Load from given file
void Load(IniFile &file);
// Set the values for the file
void Set(IniFile &file);
// Update according to the values (stream/mixer)
void Update();
};
#endif //AUDIO_COMMON_CONFIG

View File

@ -39,6 +39,11 @@ void CMixer::Mix(short *samples, int numSamples)
return; return;
} }
// first get the DTK Music
if (m_EnableDTKMusic) {
g_dspInitialize.pGetAudioStreaming(samples, numSamples);
}
Premix(samples, numSamples); Premix(samples, numSamples);
push_sync.Enter(); push_sync.Enter();

View File

@ -41,6 +41,7 @@ public:
int GetSampleRate() {return m_sampleRate;} int GetSampleRate() {return m_sampleRate;}
void SetThrottle(bool use) { m_throttle = use;} void SetThrottle(bool use) { m_throttle = use;}
void SetDTKMusic(bool use) { m_EnableDTKMusic = use;}
// TODO: do we need this // TODO: do we need this
bool IsHLEReady() { return m_HLEready;} bool IsHLEReady() { return m_HLEready;}
@ -56,6 +57,7 @@ protected:
bool m_HLEready; bool m_HLEready;
int m_queueSize; int m_queueSize;
bool m_EnableDTKMusic;
bool m_throttle; bool m_throttle;
private: private:
Common::CriticalSection push_sync; Common::CriticalSection push_sync;

View File

@ -3,9 +3,10 @@
Import('env') Import('env')
files = [ files = [
'AOSoundStream.cpp', 'AOSoundStream.cpp',
'OpenALStream.cpp', 'AudioCommonConfig.cpp',
'WaveFile.cpp', 'OpenALStream.cpp',
'WaveFile.cpp',
'Mixer.cpp', 'Mixer.cpp',
'AudioCommon.cpp', 'AudioCommon.cpp',
] ]

View File

@ -18,6 +18,7 @@
#include "Common.h" #include "Common.h"
#include "IniFile.h" #include "IniFile.h"
#include "Config.h" #include "Config.h"
#include "AudioCommon.h"
CConfig g_Config; CConfig g_Config;
@ -34,13 +35,7 @@ void CConfig::Load()
IniFile file; IniFile file;
file.Load(FULL_CONFIG_DIR "DSP.ini"); file.Load(FULL_CONFIG_DIR "DSP.ini");
file.Get("Config", "EnableHLEAudio", &m_EnableHLEAudio, true); // Sound Settings file.Get("Config", "EnableHLEAudio", &m_EnableHLEAudio, true); // Sound Settings
file.Get("Config", "EnableDTKMusic", &m_EnableDTKMusic, true); ac_Config.Load(file);
file.Get("Config", "EnableThrottle", &m_EnableThrottle, true);
#ifdef _WIN32
file.Get("Config", "Backend", &sBackend, "DSound");
#else
file.Get("Config", "Backend", &sBackend, "AOSound");
#endif
} }
void CConfig::Save() void CConfig::Save()
@ -48,9 +43,7 @@ void CConfig::Save()
IniFile file; IniFile file;
file.Load(FULL_CONFIG_DIR "DSP.ini"); file.Load(FULL_CONFIG_DIR "DSP.ini");
file.Set("Config", "EnableHLEAudio", m_EnableHLEAudio); // Sound Settings file.Set("Config", "EnableHLEAudio", m_EnableHLEAudio); // Sound Settings
file.Set("Config", "EnableDTKMusic", m_EnableDTKMusic); ac_Config.Set(file);
file.Set("Config", "EnableThrottle", m_EnableThrottle);
file.Set("Config", "Backend", sBackend.c_str());
file.Save(FULL_CONFIG_DIR "DSP.ini"); file.Save(FULL_CONFIG_DIR "DSP.ini");
} }

View File

@ -23,9 +23,6 @@
struct CConfig struct CConfig
{ {
bool m_EnableHLEAudio; bool m_EnableHLEAudio;
bool m_EnableDTKMusic;
bool m_EnableThrottle;
std::string sBackend;
CConfig(); CConfig();

View File

@ -46,8 +46,8 @@ ConfigDialog::ConfigDialog(wxWindow *parent, wxWindowID id, const wxString &titl
// Update values // Update values
m_buttonEnableHLEAudio->SetValue(g_Config.m_EnableHLEAudio ? true : false); m_buttonEnableHLEAudio->SetValue(g_Config.m_EnableHLEAudio ? true : false);
m_buttonEnableDTKMusic->SetValue(g_Config.m_EnableDTKMusic ? true : false); m_buttonEnableDTKMusic->SetValue(ac_Config.m_EnableDTKMusic ? true : false);
m_buttonEnableThrottle->SetValue(g_Config.m_EnableThrottle ? true : false); m_buttonEnableThrottle->SetValue(ac_Config.m_EnableThrottle ? true : false);
// Add tooltips // Add tooltips
m_buttonEnableHLEAudio->SetToolTip(wxT("This is the most common sound type")); m_buttonEnableHLEAudio->SetToolTip(wxT("This is the most common sound type"));
@ -81,7 +81,7 @@ void ConfigDialog::AddBackend(const char* backend)
{ {
m_BackendSelection->Append(wxString::FromAscii(backend)); m_BackendSelection->Append(wxString::FromAscii(backend));
// Update value // Update value
m_BackendSelection->SetValue(wxString::FromAscii(g_Config.sBackend.c_str())); m_BackendSelection->SetValue(wxString::FromAscii(ac_Config.sBackend.c_str()));
} }
ConfigDialog::~ConfigDialog() ConfigDialog::~ConfigDialog()
@ -91,9 +91,9 @@ ConfigDialog::~ConfigDialog()
void ConfigDialog::SettingsChanged(wxCommandEvent& event) void ConfigDialog::SettingsChanged(wxCommandEvent& event)
{ {
g_Config.m_EnableHLEAudio = m_buttonEnableHLEAudio->GetValue(); g_Config.m_EnableHLEAudio = m_buttonEnableHLEAudio->GetValue();
g_Config.m_EnableDTKMusic = m_buttonEnableDTKMusic->GetValue(); ac_Config.m_EnableDTKMusic = m_buttonEnableDTKMusic->GetValue();
g_Config.m_EnableThrottle = m_buttonEnableThrottle->GetValue(); ac_Config.m_EnableThrottle = m_buttonEnableThrottle->GetValue();
g_Config.sBackend = m_BackendSelection->GetValue().mb_str(); ac_Config.sBackend = m_BackendSelection->GetValue().mb_str();
g_Config.Save(); g_Config.Save();
if (event.GetId() == wxID_OK) if (event.GetId() == wxID_OK)

View File

@ -22,6 +22,7 @@
#include <wx/dialog.h> #include <wx/dialog.h>
#include <wx/button.h> #include <wx/button.h>
#include <wx/statbox.h> #include <wx/statbox.h>
#include "AudioCommon.h"
class ConfigDialog : public wxDialog class ConfigDialog : public wxDialog
{ {

View File

@ -15,9 +15,9 @@ void HLEMixer::MixUCode(short *samples, int numSamples) {
void HLEMixer::Premix(short *samples, int numSamples) { void HLEMixer::Premix(short *samples, int numSamples) {
// first get the DTK Music // first get the DTK Music
if (g_Config.m_EnableDTKMusic) { // if (g_Config.m_EnableDTKMusic) {
g_dspInitialize.pGetAudioStreaming(samples, numSamples); // g_dspInitialize.pGetAudioStreaming(samples, numSamples);
} // }
MixUCode(samples, numSamples); MixUCode(samples, numSamples);
} }

View File

@ -194,16 +194,8 @@ void Initialize(void *init)
CDSPHandler::CreateInstance(); CDSPHandler::CreateInstance();
soundStream = AudioCommon::InitSoundStream(g_Config.sBackend, soundStream = AudioCommon::InitSoundStream(new HLEMixer());
new HLEMixer());
soundStream->GetMixer()->SetThrottle(g_Config.m_EnableThrottle);
// Start the sound recording
/*
if (g_Config.record) {
soundStream->StartLogAudio(FULL_DUMP_DIR g_Config.recordFile);
}
*/
} }
void DSP_StopSoundStream() void DSP_StopSoundStream()

View File

@ -18,6 +18,8 @@
#include "Common.h" #include "Common.h"
#include "IniFile.h" #include "IniFile.h"
#include "Config.h" #include "Config.h"
#include "AudioCommon.h"
#define LLE_CONFIG_FILE "DSPLLE.ini" #define LLE_CONFIG_FILE "DSPLLE.ini"
CConfig g_Config; CConfig g_Config;
@ -34,20 +36,14 @@ void CConfig::Load()
IniFile file; IniFile file;
file.Load(FULL_CONFIG_DIR LLE_CONFIG_FILE); file.Load(FULL_CONFIG_DIR LLE_CONFIG_FILE);
file.Get("Config", "EnableThrottle", &m_EnableThrottle, true); ac_Config.Load(file);
#ifdef _WIN32
file.Get("Config", "Backend", &sBackend, "DSound");
#else
file.Get("Config", "Backend", &sBackend, "AOSound");
#endif
} }
void CConfig::Save() void CConfig::Save()
{ {
IniFile file; IniFile file;
file.Load(FULL_CONFIG_DIR LLE_CONFIG_FILE); file.Load(FULL_CONFIG_DIR LLE_CONFIG_FILE);
file.Set("Config", "EnableThrottle", m_EnableThrottle); ac_Config.Set(file);
file.Set("Config", "Backend", sBackend.c_str());
file.Save(FULL_CONFIG_DIR LLE_CONFIG_FILE); file.Save(FULL_CONFIG_DIR LLE_CONFIG_FILE);
} }

View File

@ -22,11 +22,6 @@
struct CConfig struct CConfig
{ {
bool m_EnableHLEAudio;
bool m_EnableDTKMusic;
bool m_EnableThrottle;
std::string sBackend;
CConfig(); CConfig();
void Load(); void Load();

View File

@ -21,6 +21,7 @@
BEGIN_EVENT_TABLE(DSPConfigDialogLLE, wxDialog) BEGIN_EVENT_TABLE(DSPConfigDialogLLE, wxDialog)
EVT_BUTTON(wxID_OK, DSPConfigDialogLLE::SettingsChanged) EVT_BUTTON(wxID_OK, DSPConfigDialogLLE::SettingsChanged)
EVT_CHECKBOX(ID_ENABLE_DTK_MUSIC, DSPConfigDialogLLE::SettingsChanged)
EVT_CHECKBOX(ID_ENABLE_THROTTLE, DSPConfigDialogLLE::SettingsChanged) EVT_CHECKBOX(ID_ENABLE_THROTTLE, DSPConfigDialogLLE::SettingsChanged)
END_EVENT_TABLE() END_EVENT_TABLE()
@ -36,14 +37,17 @@ DSPConfigDialogLLE::DSPConfigDialogLLE(wxWindow *parent, wxWindowID id, const wx
m_OK = new wxButton(this, wxID_OK, wxT("OK"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); m_OK = new wxButton(this, wxID_OK, wxT("OK"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
// Create items // Create items
m_buttonEnableDTKMusic = new wxCheckBox(this, ID_ENABLE_DTK_MUSIC, wxT("Enable DTK Music"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_buttonEnableThrottle = new wxCheckBox(this, ID_ENABLE_THROTTLE, wxT("Enable Other Audio (Throttle)"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); m_buttonEnableThrottle = new wxCheckBox(this, ID_ENABLE_THROTTLE, wxT("Enable Other Audio (Throttle)"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
wxStaticText *BackendText = new wxStaticText(this, wxID_ANY, wxT("Audio Backend"), wxDefaultPosition, wxDefaultSize, 0); wxStaticText *BackendText = new wxStaticText(this, wxID_ANY, wxT("Audio Backend"), wxDefaultPosition, wxDefaultSize, 0);
m_BackendSelection = new wxComboBox(this, ID_BACKEND, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxArrayBackends, wxCB_READONLY, wxDefaultValidator); m_BackendSelection = new wxComboBox(this, ID_BACKEND, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxArrayBackends, wxCB_READONLY, wxDefaultValidator);
// Update values // Update values
m_buttonEnableThrottle->SetValue(g_Config.m_EnableThrottle ? true : false); m_buttonEnableDTKMusic->SetValue(ac_Config.m_EnableDTKMusic ? true : false);
m_buttonEnableThrottle->SetValue(ac_Config.m_EnableThrottle ? true : false);
// Add tooltips // Add tooltips
m_buttonEnableDTKMusic->SetToolTip(wxT("This is sometimes used to play music tracks from the disc"));
m_buttonEnableThrottle->SetToolTip(wxT("This is sometimes used together with pre-rendered movies.\n" m_buttonEnableThrottle->SetToolTip(wxT("This is sometimes used together with pre-rendered movies.\n"
"Disabling this also disables the speed throttle which this causes,\n" "Disabling this also disables the speed throttle which this causes,\n"
"meaning that there will be no upper limit on your FPS.")); "meaning that there will be no upper limit on your FPS."));
@ -52,6 +56,7 @@ DSPConfigDialogLLE::DSPConfigDialogLLE(wxWindow *parent, wxWindowID id, const wx
// Create sizer and add items to dialog // Create sizer and add items to dialog
wxBoxSizer *sMain = new wxBoxSizer(wxVERTICAL); wxBoxSizer *sMain = new wxBoxSizer(wxVERTICAL);
wxStaticBoxSizer *sbSettings = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Sound Settings")); wxStaticBoxSizer *sbSettings = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Sound Settings"));
sbSettings->Add(m_buttonEnableDTKMusic, 0, wxALL, 5);
sbSettings->Add(m_buttonEnableThrottle, 0, wxALL, 5); sbSettings->Add(m_buttonEnableThrottle, 0, wxALL, 5);
wxBoxSizer *sBackend = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer *sBackend = new wxBoxSizer(wxHORIZONTAL);
sBackend->Add(BackendText, 0, wxALIGN_CENTRE_VERTICAL|wxALL, 5); sBackend->Add(BackendText, 0, wxALIGN_CENTRE_VERTICAL|wxALL, 5);
@ -71,7 +76,7 @@ void DSPConfigDialogLLE::AddBackend(const char* backend)
{ {
m_BackendSelection->Append(wxString::FromAscii(backend)); m_BackendSelection->Append(wxString::FromAscii(backend));
// Update value // Update value
m_BackendSelection->SetValue(wxString::FromAscii(g_Config.sBackend.c_str())); m_BackendSelection->SetValue(wxString::FromAscii(ac_Config.sBackend.c_str()));
} }
DSPConfigDialogLLE::~DSPConfigDialogLLE() DSPConfigDialogLLE::~DSPConfigDialogLLE()
@ -80,10 +85,13 @@ DSPConfigDialogLLE::~DSPConfigDialogLLE()
void DSPConfigDialogLLE::SettingsChanged(wxCommandEvent& event) void DSPConfigDialogLLE::SettingsChanged(wxCommandEvent& event)
{ {
g_Config.m_EnableThrottle = m_buttonEnableThrottle->GetValue(); ac_Config.m_EnableDTKMusic = m_buttonEnableDTKMusic->GetValue();
g_Config.sBackend = m_BackendSelection->GetValue().mb_str(); ac_Config.m_EnableThrottle = m_buttonEnableThrottle->GetValue();
ac_Config.sBackend = m_BackendSelection->GetValue().mb_str();
ac_Config.Update();
g_Config.Save(); g_Config.Save();
if (event.GetId() == wxID_OK) if (event.GetId() == wxID_OK)
EndModal(wxID_OK); EndModal(wxID_OK);
} }

View File

@ -22,6 +22,7 @@
#include <wx/dialog.h> #include <wx/dialog.h>
#include <wx/button.h> #include <wx/button.h>
#include <wx/statbox.h> #include <wx/statbox.h>
#include "AudioCommon.h"
class DSPConfigDialogLLE : public wxDialog class DSPConfigDialogLLE : public wxDialog
{ {
@ -39,6 +40,7 @@ private:
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
wxButton *m_OK; wxButton *m_OK;
wxCheckBox *m_buttonEnableDTKMusic;
wxCheckBox *m_buttonEnableThrottle; wxCheckBox *m_buttonEnableThrottle;
wxArrayString wxArrayBackends; wxArrayString wxArrayBackends;
wxComboBox *m_BackendSelection; wxComboBox *m_BackendSelection;
@ -46,6 +48,7 @@ private:
enum enum
{ {
wxID_OK, wxID_OK,
ID_ENABLE_DTK_MUSIC,
ID_ENABLE_THROTTLE, ID_ENABLE_THROTTLE,
ID_BACKEND ID_BACKEND
}; };

View File

@ -201,6 +201,7 @@ void Initialize(void *init)
bCanWork = true; bCanWork = true;
g_dspInitialize = *(DSPInitialize*)init; g_dspInitialize = *(DSPInitialize*)init;
g_Config.Load();
gdsp_init(); gdsp_init();
g_dsp.step_counter = 0; g_dsp.step_counter = 0;
g_dsp.cpu_ram = g_dspInitialize.pGetMemoryPointer(0); g_dsp.cpu_ram = g_dspInitialize.pGetMemoryPointer(0);
@ -224,9 +225,7 @@ void Initialize(void *init)
g_hDSPThread = new Common::Thread(dsp_thread, NULL); g_hDSPThread = new Common::Thread(dsp_thread, NULL);
soundStream = AudioCommon::InitSoundStream(g_Config.sBackend); soundStream = AudioCommon::InitSoundStream();
soundStream->GetMixer()->SetThrottle(g_Config.m_EnableThrottle);
} }
void DSP_StopSoundStream() void DSP_StopSoundStream()