-Cleaned up some of my old code

-Removed a few duplicate extern's
-Added Sound Settings dialog - You can now select which sound core to use, the sound buffer size, and the volume level
-All sound settings are loaded from and saved to desmume.ini
This commit is contained in:
cyberwarriorx 2006-11-30 06:09:17 +00:00
parent 450364c4d6
commit 4e988e18f6
9 changed files with 193 additions and 31 deletions

View File

@ -43,10 +43,6 @@
//#define LOG_DMA2
//#define LOG_DIV
extern BOOL execute;
extern BOOL click;
extern NDSSystem nds;
char szRomPath[512];
MMU_struct MMU;

View File

@ -34,7 +34,7 @@
extern "C" {
#endif
extern BOOL execute;
extern volatile BOOL execute;
extern BOOL click;
//#define LOG_ARM9

View File

@ -157,6 +157,14 @@ void SPU_Pause(int pause)
//////////////////////////////////////////////////////////////////////////////
void SPU_SetVolume(int volume)
{
if (SNDCore)
SNDCore->SetVolume(volume);
}
//////////////////////////////////////////////////////////////////////////////
void SPU_Reset(void)
{
int i;
@ -1213,7 +1221,7 @@ void SNDDummySetVolume(int volume)
}
//////////////////////////////////////////////////////////////////////////////
// File Write Interface
// WAV Write Interface
//////////////////////////////////////////////////////////////////////////////
int SNDFileInit(int buffersize);
@ -1226,7 +1234,7 @@ void SNDFileSetVolume(int volume);
SoundInterface_struct SNDFile = {
SNDCORE_FILEWRITE,
"File Write Sound Interface",
"WAV Write Sound Interface",
SNDFileInit,
SNDFileDeInit,
SNDFileUpdateAudio,

View File

@ -68,9 +68,6 @@ typedef struct
typedef struct
{
// u8 mvol;
// u8 lout;
// u8 rout;
BOOL enable;
u32 bufpos;
u32 buflength;
@ -84,6 +81,7 @@ extern SPU_struct *SPU;
int SPU_ChangeSoundCore(int coreid, int buffersize);
int SPU_Init(int coreid, int buffersize);
void SPU_SetVolume(int volume);
void SPU_Reset(void);
void SPU_DeInit(void);
void SPU_KeyOn(int channel);

View File

@ -63,15 +63,21 @@ extern DWORD ds_start;
#define KEY_SELECT ds_select
#define KEY_DEBUG ds_debug
const char *get_path()
{
if (*vPath) return vPath;
ZeroMemory(vPath, sizeof(vPath));
GetModuleFileName(NULL, vPath, sizeof(vPath));
char *p = vPath + lstrlen(vPath);
while (p >= vPath && *p != '\\') p--;
if (++p >= vPath) *p = 0;
return vPath;
void GetINIPath(char *inipath)
{
if (*vPath)
szPath = vPath;
else
{
ZeroMemory(vPath, sizeof(vPath));
GetModuleFileName(NULL, vPath, sizeof(vPath));
char *p = vPath + lstrlen(vPath);
while (p >= vPath && *p != '\\') p--;
if (++p >= vPath) *p = 0;
szPath = vPath;
}
sprintf(inipath, "%s\\desmume.ini",szPath);
}
void ReadConfig(void)
@ -79,8 +85,7 @@ void ReadConfig(void)
FILE *fp;
int i;
szPath = (char*)get_path();
sprintf(IniName,"%s\\desmume.ini",szPath);
GetINIPath(IniName);
i=GetPrivateProfileInt("KEYS","KEY_A",31, IniName);
KEY_A = i;
@ -137,8 +142,7 @@ void WriteConfig(void)
FILE *fp;
int i;
szPath = (char*)get_path();
sprintf(IniName,"%s\\desmume.ini",szPath);
GetINIPath(IniName);
WritePrivateProfileInt("KEYS","KEY_A",KEY_A,IniName);
WritePrivateProfileInt("KEYS","KEY_B",KEY_B,IniName);

View File

@ -18,7 +18,7 @@ extern DWORD ds_select;
extern DWORD ds_start;
extern DWORD ds_debug;
char *get_path();
void GetINIPath(char *initpath);
void ReadConfig(void);
BOOL CALLBACK ConfigView_Proc(HWND dialog,UINT komunikat,WPARAM wparam,LPARAM lparam);

View File

@ -24,6 +24,7 @@
//#define RENDER3D
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "CWindow.h"
#include "../MMU.h"
@ -64,7 +65,8 @@ HWND hwnd;
HDC hdc;
HINSTANCE hAppInst;
BOOL execute = FALSE;
volatile BOOL execute = FALSE;
volatile BOOL paused = TRUE;
u32 glock = 0;
BOOL click = FALSE;
@ -76,6 +78,10 @@ HANDLE runthread=INVALID_HANDLE_VALUE;
const DWORD tabkey[48]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,VK_SPACE,VK_UP,VK_DOWN,VK_LEFT,VK_RIGHT,VK_TAB,VK_SHIFT,VK_DELETE,VK_INSERT,VK_HOME,VK_END,0x0d};
DWORD ds_up,ds_down,ds_left,ds_right,ds_a,ds_b,ds_x,ds_y,ds_l,ds_r,ds_select,ds_start,ds_debug;
static char IniName[MAX_PATH];
int sndcoretype=SNDCORE_DIRECTX;
int sndbuffersize=735*4;
int sndvolume=100;
SoundInterface_struct *SNDCoreList[] = {
&SNDDummy,
@ -84,6 +90,9 @@ SoundInterface_struct *SNDCoreList[] = {
NULL
};
LRESULT CALLBACK SoundSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam);
DWORD WINAPI run( LPVOID lpParameter)
{
char txt[80];
@ -209,6 +218,7 @@ DWORD WINAPI run( LPVOID lpParameter)
CWindow_RefreshALL();
Sleep(0);
}
paused = TRUE;
Sleep(500);
}
return 1;
@ -218,10 +228,12 @@ void NDS_Pause()
{
execute = FALSE;
SPU_Pause(1);
while (!paused) {}
}
void NDS_UnPause()
{
paused = FALSE;
execute = TRUE;
SPU_Pause(0);
}
@ -276,13 +288,21 @@ int WINAPI WinMain (HINSTANCE hThisInstance,
LogStart();
#endif
GetINIPath(IniName);
NDS_Init();
if (SPU_ChangeSoundCore(SNDCORE_DIRECTX, 735 * 4) != 0)
sndcoretype = GetPrivateProfileInt("Sound","SoundCore", SNDCORE_DIRECTX, IniName);
sndbuffersize = GetPrivateProfileInt("Sound","SoundBufferSize", 735 * 4, IniName);
if (SPU_ChangeSoundCore(sndcoretype, sndbuffersize) != 0)
{
MessageBox(hwnd,"Unable to initialize DirectSound","Error",MB_OK);
return messages.wParam;
}
sndvolume = GetPrivateProfileInt("Sound","Volume",100, IniName);
SPU_SetVolume(sndvolume);
runthread = CreateThread(NULL, 0, run, NULL, 0, &threadID);
@ -329,10 +349,10 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
return 0;
case WM_DESTROY:
NDS_Pause();
finished = TRUE;
if (runthread != INVALID_HANDLE_VALUE)
{
finished = TRUE;
if (WaitForSingleObject(runthread,INFINITE) == WAIT_TIMEOUT)
{
// Couldn't close thread cleanly
@ -347,10 +367,10 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
return 0;
case WM_CLOSE:
NDS_Pause();
finished = TRUE;
if (runthread != INVALID_HANDLE_VALUE)
{
finished = TRUE;
if (WaitForSingleObject(runthread,INFINITE) == WAIT_TIMEOUT)
{
// Couldn't close thread cleanly
@ -657,6 +677,11 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
NDS_UnPause();
}
return 0;
case IDM_SOUNDSETTINGS:
{
DialogBox(GetModuleHandle(NULL), "SoundSettingsDlg", hwnd, (DLGPROC)SoundSettingsDlgProc);
}
return 0;
case IDM_GAME_INFO:
{
CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_GAME_INFO), hwnd, GinfoView_Proc);
@ -893,3 +918,108 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
return 0;
}
LRESULT CALLBACK SoundSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
static timerid=0;
switch (uMsg)
{
case WM_INITDIALOG:
{
int i;
char tempstr[MAX_PATH];
// Setup Sound Core Combo box
SendDlgItemMessage(hDlg, IDC_SOUNDCORECB, CB_RESETCONTENT, 0, 0);
SendDlgItemMessage(hDlg, IDC_SOUNDCORECB, CB_ADDSTRING, 0, (long)"None");
for (i = 1; SNDCoreList[i] != NULL; i++)
SendDlgItemMessage(hDlg, IDC_SOUNDCORECB, CB_ADDSTRING, 0, (long)SNDCoreList[i]->Name);
// Set Selected Sound Core
for (i = 0; SNDCoreList[i] != NULL; i++)
{
if (sndcoretype == SNDCoreList[i]->id)
SendDlgItemMessage(hDlg, IDC_SOUNDCORECB, CB_SETCURSEL, i, 0);
}
// Setup Sound Buffer Size Edit Text
sprintf(tempstr, "%d", sndbuffersize);
SetDlgItemText(hDlg, IDC_SOUNDBUFFERET, tempstr);
// Setup Volume Slider
SendDlgItemMessage(hDlg, IDC_SLVOLUME, TBM_SETRANGE, 0, MAKELONG(0, 100));
// Set Selected Volume
SendDlgItemMessage(hDlg, IDC_SLVOLUME, TBM_SETPOS, TRUE, sndvolume);
timerid = SetTimer(hDlg, 1, 500, NULL);
return TRUE;
}
case WM_TIMER:
{
if (timerid == wParam)
{
int setting;
setting = SendDlgItemMessage(hDlg, IDC_SLVOLUME, TBM_GETPOS, 0, 0);
SPU_SetVolume(setting);
break;
}
break;
}
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDOK:
{
char tempstr[MAX_PATH];
EndDialog(hDlg, TRUE);
NDS_Pause();
// Write Sound core type
sndcoretype = SNDCoreList[SendDlgItemMessage(hDlg, IDC_SOUNDCORECB, CB_GETCURSEL, 0, 0)]->id;
sprintf(tempstr, "%d", sndcoretype);
WritePrivateProfileString("Sound", "SoundCore", tempstr, IniName);
// Write Sound Buffer size
GetDlgItemText(hDlg, IDC_SOUNDBUFFERET, tempstr, 6);
sscanf(tempstr, "%d", &sndbuffersize);
WritePrivateProfileString("Sound", "SoundBufferSize", tempstr, IniName);
SPU_ChangeSoundCore(sndcoretype, sndbuffersize);
// Write Volume
sndvolume = SendDlgItemMessage(hDlg, IDC_SLVOLUME, TBM_GETPOS, 0, 0);
sprintf(tempstr, "%d", sndvolume);
WritePrivateProfileString("Sound", "Volume", tempstr, IniName);
SPU_SetVolume(sndvolume);
NDS_UnPause();
return TRUE;
}
case IDCANCEL:
{
EndDialog(hDlg, FALSE);
return TRUE;
}
default: break;
}
break;
}
case WM_DESTROY:
{
if (timerid != 0)
KillTimer(hDlg, timerid);
break;
}
}
return FALSE;
}

View File

@ -63,8 +63,9 @@ void refreshAll();
#define IDM_SBG2 127
#define IDM_SBG3 128
#define IDM_OAM 129
#define IDM_PRINTSCREEN 140
#define IDM_QUICK_PRINTSCREEN 141
#define IDM_PRINTSCREEN 140
#define IDM_QUICK_PRINTSCREEN 141
#define IDM_SOUNDSETTINGS 142
#define IDM_STATE_LOAD 150
#define IDM_STATE_SAVE 151
@ -178,4 +179,9 @@ void refreshAll();
#define IDC_PROP0 908
#define IDC_PROP1 909
#define IDC_OAM_BOX 910
#define IDC_SOUNDCORECB 1000
#define IDC_SOUNDBUFFERET 1001
#define IDC_SLVOLUME 1002
#endif

View File

@ -300,6 +300,8 @@ MENU_PRINCIPAL MENU
MENUITEM "Save Screenshot &As", IDM_PRINTSCREEN
MENUITEM "&Quick Screenshot", IDM_QUICK_PRINTSCREEN
MENUITEM SEPARATOR
MENUITEM "Sound Settings", IDM_SOUNDSETTINGS
MENUITEM SEPARATOR
MENUITEM "&Quit", IDM_QUIT
}
POPUP "&Emulation"
@ -601,3 +603,21 @@ BEGIN
// CONTROL "Edit", IDC_OAM_BOX,"OAMViewBox",WS_TABSTOP,100,50,45,42,WS_EX_CLIENTEDGE
PUSHBUTTON "&Close",IDC_FERMER,50,134,50,14
END
SOUNDSETTINGSDLG DIALOG DISCARDABLE 0, 0, 174, 96
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Sound Settings"
FONT 8, "MS Sans Serif"
BEGIN
GROUPBOX "Sound Core Settings", -1, 3, 2, 168, 28, WS_CHILD | WS_VISIBLE
LTEXT "Sound Core", -1, 10, 14, 40, 10
COMBOBOX IDC_SOUNDCORECB, 54, 13, 110, 33, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
GROUPBOX "Other Settings", -1, 3, 31, 168, 43, WS_CHILD | WS_VISIBLE
LTEXT "Buffer Size", -1, 10, 42, 60, 10
EDITTEXT IDC_SOUNDBUFFERET, 136, 41, 28, 13
LTEXT "Volume", -1, 10, 57, 30, 10
CONTROL "", IDC_SLVOLUME, "msctls_trackbar32", WS_VISIBLE | WS_CHILD, 40, 57, 128, 10
DEFPUSHBUTTON "&OK",IDOK,82,78,40,14
PUSHBUTTON "&Cancel",IDCANCEL,127,78,40,14
END