Skip to content

Commit

Permalink
SPU2: Prepare for Qt (add Host wrapper)
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek authored and refractionpcsx2 committed Dec 28, 2021
1 parent c5c4cdd commit 4305e17
Show file tree
Hide file tree
Showing 12 changed files with 619 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pcsx2/SPU2/Config.h
Expand Up @@ -83,7 +83,7 @@ extern u32 OutputModule;
extern int SndOutLatencyMS;
extern int SynchMode;

#ifndef __POSIX__
#if defined(_WIN32) && !defined(PCSX2_CORE)
extern wchar_t dspPlugin[];
extern int dspPluginModule;

Expand Down
75 changes: 75 additions & 0 deletions pcsx2/SPU2/Host/CfgHelpers.cpp
@@ -0,0 +1,75 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2020 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/

#include "PrecompiledHeader.h"
#include "common/StringUtil.h"
#include "SPU2/Host/Config.h"
#include "SPU2/Host/Dialogs.h"
#include "HostSettings.h"

bool CfgReadBool(const wchar_t* Section, const wchar_t* Name, bool Default)
{
return Host::GetBoolSettingValue(StringUtil::WideStringToUTF8String(Section).c_str(),
StringUtil::WideStringToUTF8String(Name).c_str(), Default);
}

int CfgReadInt(const wchar_t* Section, const wchar_t* Name, int Default)
{
return Host::GetIntSettingValue(StringUtil::WideStringToUTF8String(Section).c_str(),
StringUtil::WideStringToUTF8String(Name).c_str(), Default);
}

float CfgReadFloat(const wchar_t* Section, const wchar_t* Name, float Default)
{
return Host::GetFloatSettingValue(StringUtil::WideStringToUTF8String(Section).c_str(),
StringUtil::WideStringToUTF8String(Name).c_str(), Default);
}

void CfgReadStr(const wchar_t* Section, const wchar_t* Name, wchar_t* Data, int DataSize, const wchar_t* Default)
{
const std::wstring res(StringUtil::UTF8StringToWideString(
Host::GetStringSettingValue(
StringUtil::WideStringToUTF8String(Section).c_str(),
StringUtil::WideStringToUTF8String(Name).c_str(),
StringUtil::WideStringToUTF8String(Default).c_str())));

std::wcsncpy(Data, res.c_str(), DataSize);
Data[DataSize - 1] = 0;
}

void CfgReadStr(const wchar_t* Section, const wchar_t* Name, wxString& Data, const wchar_t* Default)
{
Data = StringUtil::UTF8StringToWxString(
Host::GetStringSettingValue(
StringUtil::WideStringToUTF8String(Section).c_str(),
StringUtil::WideStringToUTF8String(Name).c_str(),
StringUtil::WideStringToUTF8String(Default).c_str()));
}

void CfgWriteBool(const wchar_t* Section, const wchar_t* Name, bool Value)
{
}

void CfgWriteInt(const wchar_t* Section, const wchar_t* Name, int Value)
{
}

void CfgWriteFloat(const wchar_t* Section, const wchar_t* Name, float Value)
{
}

void CfgWriteStr(const wchar_t* Section, const wchar_t* Name, const wxString& Data)
{
}
118 changes: 118 additions & 0 deletions pcsx2/SPU2/Host/Config.cpp
@@ -0,0 +1,118 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2021 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/

#include "PrecompiledHeader.h"

#include "common/StringUtil.h"

#include "SPU2/Global.h"
#include "SPU2/Host/Config.h"
#include "SPU2/Host/Dialogs.h"
#include "HostSettings.h"

int AutoDMAPlayRate[2] = {0, 0};

// Default settings.

// MIXING
int Interpolation = 5;
/* values:
0: No interpolation (uses nearest)
1. Linear interpolation
2. Cubic interpolation
3. Hermite interpolation
4. Catmull-Rom interpolation
5. Gaussian interpolation
*/

float FinalVolume; // global
bool AdvancedVolumeControl;
float VolumeAdjustFLdb; // Decibels settings, because audiophiles love that.
float VolumeAdjustCdb;
float VolumeAdjustFRdb;
float VolumeAdjustBLdb;
float VolumeAdjustBRdb;
float VolumeAdjustSLdb;
float VolumeAdjustSRdb;
float VolumeAdjustLFEdb;
float VolumeAdjustFL; // Linear coefficients calculated from decibels,
float VolumeAdjustC;
float VolumeAdjustFR;
float VolumeAdjustBL;
float VolumeAdjustBR;
float VolumeAdjustSL;
float VolumeAdjustSR;
float VolumeAdjustLFE;

bool _visual_debug_enabled = false; // Windows-only feature

// OUTPUT
u32 OutputModule = 0;
int SndOutLatencyMS = 100;
int SynchMode = 0; // Time Stretch, Async or Disabled.

int numSpeakers = 0;
int dplLevel = 0;
bool temp_debug_state;

/*****************************************************************************/

void ReadSettings()
{
Interpolation = Host::GetIntSettingValue("SPU2/Mixing", "Interpolation", 5);
FinalVolume = ((float)Host::GetIntSettingValue("SPU2/Mixing", "FinalVolume", 100)) / 100;
if (FinalVolume > 1.0f)
FinalVolume = 1.0f;

AdvancedVolumeControl = Host::GetBoolSettingValue("SPU2/Mixing", "AdvancedVolumeControl", false);
VolumeAdjustCdb = Host::GetFloatSettingValue("SPU2/Mixing", "VolumeAdjustC", 0);
VolumeAdjustFLdb = Host::GetFloatSettingValue("SPU2/Mixing", "VolumeAdjustFL", 0);
VolumeAdjustFRdb = Host::GetFloatSettingValue("SPU2/Mixing", "VolumeAdjustFR", 0);
VolumeAdjustBLdb = Host::GetFloatSettingValue("SPU2/Mixing", "VolumeAdjustBL", 0);
VolumeAdjustBRdb = Host::GetFloatSettingValue("SPU2/Mixing", "VolumeAdjustBR", 0);
VolumeAdjustSLdb = Host::GetFloatSettingValue("SPU2/Mixing", "VolumeAdjustSL", 0);
VolumeAdjustSRdb = Host::GetFloatSettingValue("SPU2/Mixing", "VolumeAdjustSR", 0);
VolumeAdjustLFEdb = Host::GetFloatSettingValue("SPU2/Mixing", "VolumeAdjustLFE", 0);
VolumeAdjustC = powf(10, VolumeAdjustCdb / 10);
VolumeAdjustFL = powf(10, VolumeAdjustFLdb / 10);
VolumeAdjustFR = powf(10, VolumeAdjustFRdb / 10);
VolumeAdjustBL = powf(10, VolumeAdjustBLdb / 10);
VolumeAdjustBR = powf(10, VolumeAdjustBRdb / 10);
VolumeAdjustSL = powf(10, VolumeAdjustSLdb / 10);
VolumeAdjustSR = powf(10, VolumeAdjustSRdb / 10);
VolumeAdjustLFE = powf(10, VolumeAdjustLFEdb / 10);

const std::string modname(Host::GetStringSettingValue("SPU2/Output", "OutputModule", "cubeb"));
OutputModule = FindOutputModuleById(StringUtil::UTF8StringToWideString(modname).c_str()); // Find the driver index of this module...

SndOutLatencyMS = Host::GetIntSettingValue("SPU2/Output", "Latency", 100);
SynchMode = Host::GetIntSettingValue("SPU2/Output", "SynchMode", 0);
numSpeakers = Host::GetIntSettingValue("SPU2/Output", "SpeakerConfiguration", 0);

SoundtouchCfg::ReadSettings();
DebugConfig::ReadSettings();

// Sanity Checks
// -------------

Clampify(SndOutLatencyMS, LATENCY_MIN, LATENCY_MAX);

if (mods[OutputModule] == nullptr)
{
Console.Warning("* SPU2: Unknown output module '%s' specified in configuration file.", modname.c_str());
Console.Warning("* SPU2: Defaulting to Cubeb (%s).", CubebOut->GetIdent());
OutputModule = FindOutputModuleById(CubebOut->GetIdent());
}
}
106 changes: 106 additions & 0 deletions pcsx2/SPU2/Host/Config.h
@@ -0,0 +1,106 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2020 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef CONFIG_H_INCLUDED
#define CONFIG_H_INCLUDED

#include <string>
#include <wx/fileconf.h>

extern bool DebugEnabled;

extern bool _MsgToConsole;
extern bool _MsgKeyOnOff;
extern bool _MsgVoiceOff;
extern bool _MsgDMA;
extern bool _MsgAutoDMA;
extern bool _MsgOverruns;
extern bool _MsgCache;

extern bool _AccessLog;
extern bool _DMALog;
extern bool _WaveLog;

extern bool _CoresDump;
extern bool _MemDump;
extern bool _RegDump;
extern bool _visual_debug_enabled;

/*static __forceinline bool MsgToConsole() { return _MsgToConsole & DebugEnabled; }
static __forceinline bool MsgKeyOnOff() { return _MsgKeyOnOff & MsgToConsole(); }
static __forceinline bool MsgVoiceOff() { return _MsgVoiceOff & MsgToConsole(); }
static __forceinline bool MsgDMA() { return _MsgDMA & MsgToConsole(); }
static __forceinline bool MsgAutoDMA() { return _MsgAutoDMA & MsgDMA(); }
static __forceinline bool MsgOverruns() { return _MsgOverruns & MsgToConsole(); }
static __forceinline bool MsgCache() { return _MsgCache & MsgToConsole(); }
static __forceinline bool AccessLog() { return _AccessLog & DebugEnabled; }
static __forceinline bool DMALog() { return _DMALog & DebugEnabled; }
static __forceinline bool WaveLog() { return _WaveLog & DebugEnabled; }
static __forceinline bool CoresDump() { return _CoresDump & DebugEnabled; }
static __forceinline bool MemDump() { return _MemDump & DebugEnabled; }
static __forceinline bool RegDump() { return _RegDump & DebugEnabled; }*/


//extern wchar_t AccessLogFileName[255];
//extern wchar_t WaveLogFileName[255];
//extern wchar_t DMA4LogFileName[255];
//extern wchar_t DMA7LogFileName[255];
//extern wchar_t CoresDumpFileName[255];
//extern wchar_t MemDumpFileName[255];
//extern wchar_t RegDumpFileName[255];

extern int Interpolation;
extern float FinalVolume;

extern int AutoDMAPlayRate[2];

extern u32 OutputModule;
extern int SndOutLatencyMS;

extern int SynchMode;

#ifdef PCSX2_DEVBUILD
const int LATENCY_MAX = 3000;
#else
const int LATENCY_MAX = 750;
#endif

const int LATENCY_MIN = 3;
const int LATENCY_MIN_TIMESTRETCH = 15;

namespace SoundtouchCfg
{
extern const int SequenceLen_Min;
extern const int SequenceLen_Max;

extern const int SeekWindow_Min;
extern const int SeekWindow_Max;

extern const int Overlap_Min;
extern const int Overlap_Max;

extern int SequenceLenMS;
extern int SeekWindowMS;
extern int OverlapMS;

void ReadSettings();
}; // namespace SoundtouchCfg

void ReadSettings();

#endif // CONFIG_H_INCLUDED

0 comments on commit 4305e17

Please sign in to comment.