[Audio] Start to add config

This commit is contained in:
zilmar 2017-09-25 22:00:04 +10:00
parent 226cfd8bf6
commit a6661e460b
14 changed files with 341 additions and 22 deletions

View File

@ -26,10 +26,9 @@
#include "AudioSettings.h"
#include "trace.h"
#include "AudioMain.h"
#include "ConfigUI.h"
#include "SettingsID.h"
bool g_AudioEnabled = true;
/* Read header for type definition */
AUDIO_INFO g_AudioInfo;
@ -94,7 +93,7 @@ EXPORT void CALL AiDacrateChanged(int SystemType)
EXPORT void CALL AiLenChanged(void)
{
WriteTrace(TraceAudioInterface, TraceDebug, "Start (DRAM_ADDR = 0x%X Len = 0x%X)", *g_AudioInfo.AI_DRAM_ADDR_REG, *g_AudioInfo.AI_LEN_REG);
if (g_SoundDriver && g_AudioEnabled)
if (g_SoundDriver && g_settings->AudioEnabled())
{
uint32_t Len = *g_AudioInfo.AI_LEN_REG & 0x3FFF8;
uint8_t * Buffer = (g_AudioInfo.RDRAM + (*g_AudioInfo.AI_DRAM_ADDR_REG & 0x00FFFFF8));
@ -142,9 +141,15 @@ EXPORT void CALL DllAbout(void * /*hParent*/)
WriteTrace(TraceAudioInterface, TraceDebug, "Called");
}
EXPORT void CALL DllConfig(void * /*hParent*/)
EXPORT void CALL DllConfig(void * hParent)
{
WriteTrace(TraceAudioInterface, TraceDebug, "Called");
#ifdef _WIN32
ConfigAudio(hParent);
if (g_SoundDriver)
{
g_SoundDriver->SetVolume(g_settings->GetVolume());
}
#endif
}
EXPORT void CALL DllTest(void * /*hParent*/)

View File

@ -24,15 +24,41 @@ CSettings::CSettings() :
m_FlushLogs(false),
m_AudioEnabled(true),
m_advanced_options(false),
m_debugger_enabled(false)
m_debugger_enabled(false),
m_Volume(100)
{
memset(m_log_dir, 0, sizeof(m_log_dir));
RegisterSettings();
ReadSettings();
SettingsChanged();
if (m_Set_EnableAudio != 0) { SettingsRegisterChange(false, m_Set_EnableAudio, this, stSettingsChanged); }
if (m_Set_basic_mode != 0) { SettingsRegisterChange(false, m_Set_basic_mode, this, stSettingsChanged); }
if (m_Set_debugger != 0) { SettingsRegisterChange(false, m_Set_debugger, this, stSettingsChanged); }
if (m_Set_log_flush != 0) { SettingsRegisterChange(false, m_Set_log_flush, this, stSettingsChanged); }
SettingsRegisterChange(false, Set_Volume, this, stSettingsChanged);
SettingsRegisterChange(false, Set_Logging_MD5, this, stLogLevelChanged);
SettingsRegisterChange(false, Set_Logging_Thread, this, stLogLevelChanged);
SettingsRegisterChange(false, Set_Logging_Path, this, stLogLevelChanged);
SettingsRegisterChange(false, Set_Logging_InitShutdown, this, stLogLevelChanged);
SettingsRegisterChange(false, Set_Logging_Interface, this, stLogLevelChanged);
SettingsRegisterChange(false, Set_Logging_Driver, this, stLogLevelChanged);
}
CSettings::~CSettings()
{
if (m_Set_EnableAudio != 0) { SettingsUnregisterChange(false, m_Set_EnableAudio, this, stSettingsChanged); }
if (m_Set_basic_mode != 0) { SettingsUnregisterChange(false, m_Set_basic_mode, this, stSettingsChanged); }
if (m_Set_debugger != 0) { SettingsUnregisterChange(false, m_Set_debugger, this, stSettingsChanged); }
if (m_Set_log_flush != 0) { SettingsUnregisterChange(false, m_Set_log_flush, this, stSettingsChanged); }
SettingsUnregisterChange(false, Set_Volume, this, stSettingsChanged);
SettingsUnregisterChange(false, Set_Logging_MD5, this, stLogLevelChanged);
SettingsUnregisterChange(false, Set_Logging_Thread, this, stLogLevelChanged);
SettingsUnregisterChange(false, Set_Logging_Path, this, stLogLevelChanged);
SettingsUnregisterChange(false, Set_Logging_InitShutdown, this, stLogLevelChanged);
SettingsUnregisterChange(false, Set_Logging_Interface, this, stLogLevelChanged);
SettingsUnregisterChange(false, Set_Logging_Driver, this, stLogLevelChanged);
}
void CSettings::RegisterSettings(void)
@ -45,6 +71,7 @@ void CSettings::RegisterSettings(void)
m_Set_log_dir = FindSystemSettingId("Dir:Log");
SetModuleName("Project64-Audio");
RegisterSetting(Set_Volume, Data_DWORD_General, "Volume", "Settings", 100, NULL);
RegisterSetting(Set_Logging_MD5, Data_DWORD_General, "MD5", "Logging", g_ModuleLogLevel[TraceMD5], NULL);
RegisterSetting(Set_Logging_Thread, Data_DWORD_General, "Thread", "Logging", g_ModuleLogLevel[TraceThread], NULL);
RegisterSetting(Set_Logging_Path, Data_DWORD_General, "Path", "Logging", g_ModuleLogLevel[TracePath], NULL);
@ -54,17 +81,20 @@ void CSettings::RegisterSettings(void)
LogLevelChanged();
}
void CSettings::ReadSettings()
void CSettings::SetAudioEnabled(bool Enabled)
{
m_AudioEnabled = m_Set_EnableAudio ? GetSystemSetting(m_Set_EnableAudio) != 0 : true;
m_advanced_options = m_Set_basic_mode ? GetSystemSetting(m_Set_basic_mode) == 0 : false;
m_debugger_enabled = m_advanced_options && m_Set_debugger ? GetSystemSetting(m_Set_debugger) == 1 : false;
if (m_Set_log_dir != 0)
if (m_Set_EnableAudio != 0)
{
GetSystemSettingSz(m_Set_log_dir, m_log_dir, sizeof(m_log_dir));
SetSystemSetting(m_Set_EnableAudio, Enabled ? 1 : 0);
}
}
void CSettings::SetVolume(uint32_t Volume)
{
if (m_Set_EnableAudio != 0)
{
SetSetting(Set_Volume, Volume);
}
m_FlushLogs = m_Set_log_flush != 0 ? GetSystemSetting(m_Set_log_flush) != 0 : false;
}
void CSettings::LogLevelChanged(void)
@ -77,6 +107,20 @@ void CSettings::LogLevelChanged(void)
g_ModuleLogLevel[TraceAudioDriver] = GetSetting(Set_Logging_Driver);
}
void CSettings::SettingsChanged(void)
{
m_Volume = GetSetting(Set_Volume);
m_AudioEnabled = m_Set_EnableAudio ? GetSystemSetting(m_Set_EnableAudio) != 0 : true;
m_advanced_options = m_Set_basic_mode ? GetSystemSetting(m_Set_basic_mode) == 0 : false;
m_debugger_enabled = m_advanced_options && m_Set_debugger ? GetSystemSetting(m_Set_debugger) == 1 : false;
if (m_Set_log_dir != 0)
{
GetSystemSettingSz(m_Set_log_dir, m_log_dir, sizeof(m_log_dir));
}
m_FlushLogs = m_Set_log_flush != 0 ? GetSystemSetting(m_Set_log_flush) != 0 : false;
}
void SetupAudioSettings(void)
{
if (g_settings == NULL)

View File

@ -18,14 +18,27 @@ public:
inline bool AudioEnabled(void) const { return m_AudioEnabled; }
inline bool debugger_enabled(void) const { return m_debugger_enabled; }
inline uint32_t GetVolume(void) const { return m_Volume; }
inline bool FlushLogs(void) const { return m_FlushLogs; }
inline const char * log_dir(void) const { return m_log_dir; }
void SetAudioEnabled(bool Enabled);
void SetVolume(uint32_t Volume);
void ReadSettings();
private:
static void stLogLevelChanged(void * _this)
{
((CSettings *)_this)->LogLevelChanged();
}
static void stSettingsChanged(void * _this)
{
((CSettings *)_this)->SettingsChanged();
}
void RegisterSettings(void);
void LogLevelChanged(void);
void SettingsChanged(void);
short m_Set_EnableAudio;
short m_Set_basic_mode;
@ -37,6 +50,7 @@ private:
bool m_AudioEnabled;
bool m_advanced_options;
bool m_debugger_enabled;
uint32_t m_Volume;
};
extern CSettings * g_settings;

View File

@ -0,0 +1,212 @@
/****************************************************************************
* *
* Project64-audio - A Nintendo 64 audio plugin. *
* http://www.pj64-emu.com/ *
* Copyright (C) 2017 Project64. All rights reserved. *
* *
* License: *
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
* *
****************************************************************************/
#include "ConfigUI.h"
#pragma warning(push)
#pragma warning(disable : 4091) // warning C4091: 'typedef ': ignored on left of 'tagGPFIDL_FLAGS' when no variable is declared
#pragma warning(disable : 4302) // warning C4302: 'type cast': truncation from 'LPCTSTR' to 'WORD'
#pragma warning(disable : 4458) // warning C4458: declaration of 'dwCommonButtons' hides class member
#pragma warning(disable : 4838) // warning C4838: conversion from 'int' to 'UINT' requires a narrowing conversion
#pragma warning(disable : 4996) // warning C4996: 'GetVersionExA': was declared deprecated
#pragma warning(disable : 4302) // warning C4302: 'type cast': truncation from 'LPCTSTR' to 'WORD'
#define _ATL_DISABLE_NOTHROW_NEW
#include <atlbase.h>
#include <wtl/atlapp.h>
#include <wtl/atldlgs.h>
#include <wtl/atlctrls.h>
#include <wtl/atlcrack.h>
#pragma warning(pop)
#include <Settings/Settings.h>
#include "trace.h"
#include "AudioSettings.h"
#include "SettingsID.h"
#include "resource.h"
void SetComboBoxIndex(CComboBox & cmb, uint32_t data)
{
cmb.SetCurSel(0);
for (DWORD i = 0, n = cmb.GetCount(); i < n; i++)
{
if (cmb.GetItemData(i) == data)
{
cmb.SetCurSel(i);
break;
}
}
}
class CGeneralSettings :
public CPropertyPageImpl<CGeneralSettings>
{
public:
enum { IDD = IDD_CONFIG };
BEGIN_MSG_MAP(CDebugSettings)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER_EX(IDC_MUTE, ItemChanged)
NOTIFY_HANDLER_EX(IDC_VOLUME, NM_RELEASEDCAPTURE, ItemChangedNotify);
CHAIN_MSG_MAP(CPropertyPageImpl<CGeneralSettings>)
END_MSG_MAP()
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
m_btnMute.Attach(GetDlgItem(IDC_MUTE));
m_btnMute.SetCheck(!g_settings->AudioEnabled() ? BST_CHECKED : BST_UNCHECKED);
m_Volume.Attach(GetDlgItem(IDC_VOLUME));
m_Volume.SetPos(100 - g_settings->GetVolume());
m_Volume.SetTicFreq(20);
m_Volume.SetRangeMin(0);
m_Volume.SetRangeMax(100);
return TRUE;
}
bool OnApply()
{
g_settings->SetAudioEnabled(m_btnMute.GetCheck() != BST_CHECKED);
g_settings->SetVolume(100 - m_Volume.GetPos());
FlushSettings();
return true;
}
private:
LRESULT ItemChangedNotify(NMHDR* /*pNMHDR*/)
{
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
return 0;
}
void ItemChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
}
CTrackBarCtrl m_Volume;
CButton m_btnMute;
};
class CLogSettings :
public CPropertyPageImpl<CLogSettings>
{
public:
enum { IDD = IDD_LOG_SETTINGS };
BEGIN_MSG_MAP(CDebugSettings)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_HANDLER_EX(IDC_CMB_TRACE_THREAD, CBN_SELCHANGE, ItemChanged)
COMMAND_HANDLER_EX(IDC_CMB_TRACE_PATH, CBN_SELCHANGE, ItemChanged)
COMMAND_HANDLER_EX(IDC_CMB_TRACE_INIT_SHUTDOWN, CBN_SELCHANGE, ItemChanged)
COMMAND_HANDLER_EX(IDC_CMB_TRACE_INTERFACE, CBN_SELCHANGE, ItemChanged)
CHAIN_MSG_MAP(CPropertyPageImpl<CLogSettings>)
END_MSG_MAP()
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
m_cmbTraceThread.Attach(GetDlgItem(IDC_CMB_TRACE_THREAD));
m_cmbTracePath.Attach(GetDlgItem(IDC_CMB_TRACE_PATH));
m_cmbTraceInitShutdown.Attach(GetDlgItem(IDC_CMB_TRACE_INIT_SHUTDOWN));
m_cmbTraceInterface.Attach(GetDlgItem(IDC_CMB_TRACE_INTERFACE));
m_cmbTraceDriver.Attach(GetDlgItem(IDC_CMB_TRACE_AUDIO_DRIVER));
struct {
CComboBox & cmb;
uint16_t SettingId;
} TraceCMB[] =
{
{ m_cmbTraceThread, Set_Logging_Thread },
{ m_cmbTracePath, Set_Logging_Path },
{ m_cmbTraceInitShutdown, Set_Logging_InitShutdown },
{ m_cmbTraceInterface, Set_Logging_Interface },
{ m_cmbTraceDriver, Set_Logging_Driver },
};
for (size_t i = 0, n = sizeof(TraceCMB) / sizeof(TraceCMB[0]); i < n; i++)
{
TraceCMB[i].cmb.SetItemData(TraceCMB[i].cmb.AddString("Error"), TraceError);
TraceCMB[i].cmb.SetItemData(TraceCMB[i].cmb.AddString("Warning"), TraceWarning);
TraceCMB[i].cmb.SetItemData(TraceCMB[i].cmb.AddString("Notice"), TraceNotice);
TraceCMB[i].cmb.SetItemData(TraceCMB[i].cmb.AddString("Info"), TraceInfo);
TraceCMB[i].cmb.SetItemData(TraceCMB[i].cmb.AddString("Debug"), TraceDebug);
TraceCMB[i].cmb.SetItemData(TraceCMB[i].cmb.AddString("Verbose"), TraceVerbose);
SetComboBoxIndex(TraceCMB[i].cmb, (uint32_t)GetSetting(TraceCMB[i].SettingId));
}
return TRUE;
}
bool OnApply()
{
struct {
CComboBox & cmb;
uint16_t SettingId;
} TraceCMB[] =
{
{ m_cmbTraceThread, Set_Logging_Thread },
{ m_cmbTracePath, Set_Logging_Path },
{ m_cmbTraceInitShutdown, Set_Logging_InitShutdown },
{ m_cmbTraceInterface, Set_Logging_Interface },
{ m_cmbTraceDriver, Set_Logging_Driver },
};
for (size_t i = 0, n = sizeof(TraceCMB) / sizeof(TraceCMB[0]); i < n; i++)
{
SetSetting(TraceCMB[i].SettingId, TraceCMB[i].cmb.GetItemData(TraceCMB[i].cmb.GetCurSel()));
}
FlushSettings();
return true;
}
private:
void ItemChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
}
CComboBox m_cmbTraceThread;
CComboBox m_cmbTracePath;
CComboBox m_cmbTraceInitShutdown;
CComboBox m_cmbTraceInterface;
CComboBox m_cmbTraceDriver;
};
class CAudioUI : public CPropertySheetImpl < CAudioUI >
{
public:
CAudioUI();
~CAudioUI();
BEGIN_MSG_MAP(CAudioUI)
CHAIN_MSG_MAP(CPropertySheetImpl<CAudioUI>)
END_MSG_MAP()
private:
CGeneralSettings * m_pgGeneralSettings;
CLogSettings * m_pgLogSettings;
};
CAudioUI::CAudioUI() :
m_pgGeneralSettings(new CGeneralSettings),
m_pgLogSettings(new CLogSettings)
{
AddPage(&m_pgGeneralSettings->m_psp);
if (g_settings->debugger_enabled())
{
AddPage(&m_pgLogSettings->m_psp);
}
}
CAudioUI::~CAudioUI()
{
delete m_pgLogSettings;
delete m_pgGeneralSettings;
}
void ConfigAudio(void * hParent)
{
CAudioUI().DoModal((HWND)hParent);
}

View File

@ -0,0 +1,13 @@
/****************************************************************************
* *
* Project64-audio - A Nintendo 64 audio plugin. *
* http://www.pj64-emu.com/ *
* Copyright (C) 2017 Project64. All rights reserved. *
* *
* License: *
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
* *
****************************************************************************/
#pragma once
void ConfigAudio(void * hParent);

View File

@ -130,6 +130,14 @@ void DirectSoundDriver::SetFrequency(uint32_t Frequency)
WriteTrace(TraceAudioDriver, TraceDebug, "Done");
}
void DirectSoundDriver::SetVolume(uint32_t Volume)
{
/*DWORD dsVolume = ((DWORD)Volume * -25);
if (Volume == 100) dsVolume = (DWORD)DSBVOLUME_MIN;
if (Volume == 0) dsVolume = DSBVOLUME_MAX;
if (lpdsb != NULL) lpdsb->SetVolume(dsVolume);*/
}
void DirectSoundDriver::SetSegmentSize(uint32_t length, uint32_t SampleRate)
{
if (SampleRate == 0) { return; }

View File

@ -21,7 +21,8 @@ public:
bool Initialize();
void StopAudio(); // Stops the Audio PlayBack (as if paused)
void StartAudio(); // Starts the Audio PlayBack (as if unpaused)
void SetFrequency(uint32_t);
void SetFrequency(uint32_t Frequency);
void SetVolume(uint32_t Volume);
private:
static uint32_t __stdcall stAudioThreadProc(DirectSoundDriver * _this) { _this->AudioThreadProc(); return 0; }

View File

@ -42,6 +42,7 @@
<ItemGroup>
<ClCompile Include="AudioMain.cpp" />
<ClCompile Include="AudioSettings.cpp" />
<ClCompile Include="ConfigUI.cpp" />
<ClCompile Include="Driver\DirectSound.cpp" />
<ClCompile Include="Driver\OpenSLES.cpp" />
<ClCompile Include="Driver\SoundBase.cpp" />
@ -51,6 +52,7 @@
<ClInclude Include="AudioMain.h" />
<ClInclude Include="Audio_1.1.h" />
<ClInclude Include="AudioSettings.h" />
<ClInclude Include="ConfigUI.h" />
<ClInclude Include="Driver\DirectSound.h" />
<ClInclude Include="Driver\OpenSLES.h" />
<ClInclude Include="Driver\SoundBase.h" />

View File

@ -39,6 +39,9 @@
<ClCompile Include="Driver\DirectSound.cpp">
<Filter>Source Files\Driver</Filter>
</ClCompile>
<ClCompile Include="ConfigUI.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Audio_1.1.h">
@ -71,6 +74,9 @@
<ClInclude Include="Driver\DirectSound.h">
<Filter>Header Files\Driver</Filter>
</ClInclude>
<ClInclude Include="ConfigUI.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Project64-audio.rc">

View File

@ -13,6 +13,7 @@
enum
{
Set_Volume,
Set_Logging_MD5,
Set_Logging_Thread,
Set_Logging_Path,

Binary file not shown.

View File

@ -77,11 +77,11 @@ typedef struct
typedef struct
{
void (*DisplayError)(const char * Message);
void (*FatalError)(const char * Message);
void (*DisplayMessage)(int DisplayTime, const char * Message);
void (*DisplayMessage2)(const char * Message);
void (*BreakPoint)(const char * FileName, int32_t LineNumber);
void(*DisplayError)(const char * Message);
void(*FatalError)(const char * Message);
void(*DisplayMessage)(int DisplayTime, const char * Message);
void(*DisplayMessage2)(const char * Message);
void(*BreakPoint)(const char * FileName, int32_t LineNumber);
} PLUGIN_NOTIFICATION;
static PLUGIN_SETTINGS g_PluginSettings;
@ -320,6 +320,16 @@ void SetSettingSz(short SettingID, const char * Value)
g_PluginSettings.SetSettingSz(g_PluginSettings.handle, SettingID + g_PluginSettings.SettingStartRange, Value);
}
void SetSystemSetting(short SettingID, unsigned int Value)
{
g_PluginSettings.SetSetting(g_PluginSettings.handle, SettingID, Value);
}
void SetSystemSettingSz(short SettingID, const char * Value)
{
g_PluginSettings.SetSettingSz(g_PluginSettings.handle, SettingID, Value);
}
void SettingsRegisterChange(bool SystemSetting, int SettingID, void * Data, SettingChangedFunc Func)
{
if (g_PluginSettingsNotification.RegisterChangeCB && g_PluginSettings.handle)
@ -374,4 +384,4 @@ void CNotification::BreakPoint(const char * FileName, int LineNumber)
{
g_PluginNotification.BreakPoint(FileName, LineNumber);
}
}
}

View File

@ -16,6 +16,9 @@ extern "C" {
void SetSetting(short SettingID, unsigned int Value);
void SetSettingSz(short SettingID, const char * Value);
void SetSystemSetting(short SettingID, unsigned int Value);
void SetSystemSettingSz(short SettingID, const char * Value);
// enum's
enum SETTING_DATA_TYPE
{