From c68e7c58e0d10d341bccea1d0e66dc574d1e8b03 Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 12 Jan 2009 18:59:00 +0000 Subject: [PATCH] checking in WIP of Individual sound channel control --- src/driver.h | 6 ++++ src/drivers/win/config.cpp | 5 +++ src/drivers/win/main.cpp | 11 ++++++- src/drivers/win/main.h | 8 ++++- src/drivers/win/res.rc | 25 +++++++++++---- src/drivers/win/resource.h | 6 ++++ src/drivers/win/sound.cpp | 66 +++++++++++++++++++++++++++++++++++--- src/fceu.cpp | 5 +++ src/fceu.h | 7 +++- src/filter.cpp | 1 + src/sound.cpp | 46 ++++++++++++++++++++------ 11 files changed, 163 insertions(+), 23 deletions(-) diff --git a/src/driver.h b/src/driver.h index 3540a510..264c472e 100644 --- a/src/driver.h +++ b/src/driver.h @@ -143,6 +143,12 @@ void FCEUI_SetPaletteArray(uint8 *pal); //If "Rate" equals 0, sound is disabled. void FCEUI_Sound(int Rate); void FCEUI_SetSoundVolume(uint32 volume); +void FCEUI_SetTriangleVolume(uint32 volume); +void FCEUI_SetSquare1Volume(uint32 volume); +void FCEUI_SetSquare2Volume(uint32 volume); +void FCEUI_SetNoiseVolume(uint32 volume); +void FCEUI_SetPCMVolume(uint32 volume); + void FCEUI_SetSoundQuality(int quality); void FCEUD_SoundToggle(void); diff --git a/src/drivers/win/config.cpp b/src/drivers/win/config.cpp index cb0ebdad..5f154b8e 100644 --- a/src/drivers/win/config.cpp +++ b/src/drivers/win/config.cpp @@ -134,6 +134,11 @@ static CFGSTRUCT fceuconfig[] = { AC(soundoptions), AC(soundquality), AC(soundvolume), + AC(soundTrianglevol), + AC(soundSquare1vol), + AC(soundSquare2vol), + AC(soundNoisevol), + AC(soundPCMvol), AC(muteTurbo), AC(goptions), diff --git a/src/drivers/win/main.cpp b/src/drivers/win/main.cpp index 8d126f98..0d8578ff 100644 --- a/src/drivers/win/main.cpp +++ b/src/drivers/win/main.cpp @@ -119,8 +119,17 @@ int eoptions = EO_BGRUN | EO_FORCEISCALE; int soundoptions = SO_SECONDARY | SO_GFOCUS; int soundrate = 44100; int soundbuftime = 50; -int soundvolume = 100; int soundquality = 0; + +//Sound volume controls (range 0-150 by 10's)j----- +int soundvolume = 100; //Master sound volume +int soundTrianglevol = 150; //Sound channel Triangle - volume control +int soundSquare1vol = 150; //Sound channel Square1 - volume control +int soundSquare2vol = 150; //Sound channel Square2 - volume control +int soundNoisevol = 150; //Sound channel Noise - volume control +int soundPCMvol = 150; //Sound channel PCM - volume control +//------------------------------------------------- + double saspectw = 1, saspecth = 1; double winsizemulx = 1, winsizemuly = 1; int genie = 0; diff --git a/src/drivers/win/main.h b/src/drivers/win/main.h index 3589c290..5d4801a1 100644 --- a/src/drivers/win/main.h +++ b/src/drivers/win/main.h @@ -77,7 +77,13 @@ extern int ismaximized; extern int soundoptions; extern int soundrate; extern int soundbuftime; -extern int soundvolume; +extern int soundvolume; //Master volume control +extern int soundTrianglevol;//Sound channel Triangle - volume control +extern int soundSquare1vol; //Sound channel Square1 - volume control +extern int soundSquare2vol; //Sound channel Square2 - volume control +extern int soundNoisevol; //Sound channel Noise - volume control +extern int soundPCMvol; //Sound channel PCM - volume control + extern int soundquality; extern bool muteTurbo; diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 8fa20cc6..0d1b9eb7 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -749,12 +749,12 @@ BEGIN PUSHBUTTON "6",305,126,23,16,12 END -SOUNDCONFIG DIALOGEX 8, 95, 356, 131 +SOUNDCONFIG DIALOGEX 8, 95, 334, 268 STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "Sound Configuration" FONT 8, "MS Sans Serif", 0, 0, 0x0 BEGIN - DEFPUSHBUTTON "Close",BTN_CLOSE,290,109,56,14 + DEFPUSHBUTTON "Close",BTN_CLOSE,280,246,44,14 GROUPBOX "Output/Output Format:",302,10,9,131,93,WS_GROUP CONTROL "Sound enabled.",CHECK_SOUND_ENABLED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,22,117,12 CONTROL "Force 8-bit sound.",CHECK_SOUND_8BIT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,38,117,11 @@ -764,8 +764,8 @@ BEGIN CONTROL "Use Global Focus",124,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,157,22,100,12 CTEXT "Sound Latency",65459,162,50,107,8 CONTROL "",CTL_LATENCY_TRACKBAR,"msctls_trackbar32",WS_TABSTOP,162,70,107,13 - GROUPBOX "Volume",125,290,9,56,93,WS_GROUP - CONTROL "",CTL_VOLUME_TRACKBAR,"msctls_trackbar32",TBS_AUTOTICKS | TBS_VERT | TBS_BOTH | WS_TABSTOP,305,17,28,83 + GROUPBOX "Master",125,19,142,44,93,WS_GROUP + CONTROL "",CTL_VOLUME_TRACKBAR,"msctls_trackbar32",TBS_AUTOTICKS | TBS_VERT | TBS_BOTH | WS_TABSTOP,27,150,28,83 LTEXT "15 ms",65458,160,87,20,8 LTEXT "200 ms",65457,250,87,25,8 LTEXT "ms",65456,211,60,19,8 @@ -773,7 +773,18 @@ BEGIN COMBOBOX COMBO_SOUND_QUALITY,57,54,77,46,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP LTEXT "Quality:",65455,17,54,35,10 CONTROL "Mute frame advance.",CHECK_SOUND_MUTEFA,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,110,87,11 - CONTROL "Mute Turbo.",CHECK_SOUND_MUTETURBO,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,100,111,55,10 + CONTROL "Mute Turbo.",CHECK_SOUND_MUTETURBO,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,150,111,55,10 + GROUPBOX "Triangle",131,70,142,44,93,WS_GROUP + CONTROL "",CTL_VOLUME_TRACKBAR_TRIANGLE,"msctls_trackbar32",TBS_AUTOTICKS | TBS_VERT | TBS_BOTH | WS_TABSTOP,78,150,28,83 + GROUPBOX "Square1",132,121,142,44,93,WS_GROUP + CONTROL "",CTL_VOLUME_TRACKBAR_SQUARE1,"msctls_trackbar32",TBS_AUTOTICKS | TBS_VERT | TBS_BOTH | WS_TABSTOP,129,150,28,83 + GROUPBOX "Square2",133,170,142,44,93,WS_GROUP + CONTROL "",CTL_VOLUME_TRACKBAR_SQUARE2,"msctls_trackbar32",TBS_AUTOTICKS | TBS_VERT | TBS_BOTH | WS_TABSTOP,178,150,28,83 + GROUPBOX "Noise",134,221,142,44,93,WS_GROUP + CONTROL "",CTL_VOLUME_TRACKBAR_NOISE,"msctls_trackbar32",TBS_AUTOTICKS | TBS_VERT | TBS_BOTH | WS_TABSTOP,229,150,28,83 + GROUPBOX "PCM",135,271,142,44,93,WS_GROUP + CONTROL "",CTL_VOLUME_TRACKBAR_PCM,"msctls_trackbar32",TBS_AUTOTICKS | TBS_VERT | TBS_BOTH | WS_TABSTOP,279,150,28,83 + GROUPBOX "Volume Control",IDC_STATIC,10,127,314,118 END TIMINGCONFIG DIALOGEX 23, 157, 203, 60 @@ -1517,9 +1528,9 @@ BEGIN "SOUNDCONFIG", DIALOG BEGIN LEFTMARGIN, 10 - RIGHTMARGIN, 346 + RIGHTMARGIN, 324 TOPMARGIN, 8 - BOTTOMMARGIN, 123 + BOTTOMMARGIN, 260 END "TIMINGCONFIG", DIALOG diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index 76b3f6a2..ae5366f0 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -271,9 +271,15 @@ #define IDC_SCANLINE_LAST_NTSC 501 #define CTL_HUE_TRACKBAR 501 #define IDC_DEBUGGER_VAL_SLINE 501 +#define CTL_VOLUME_TRACKBAR_TRIANGLE 501 #define IDC_SCANLINE_FIRST_PAL 502 #define IDC_DEBUGGER_ADDR_LINE 502 +#define CTL_VOLUME_TRACKBAR_SQUARE1 502 #define IDC_SCANLINE_LAST_PAL 503 +#define CTL_VOLUME_TRACKBAR_SQUARE2 503 +#define CTL_VOLUME_TRACKBAR_NOISE 504 +#define CTL_VOLUME_TRACKBAR_NOISE2 505 +#define CTL_VOLUME_TRACKBAR_PCM 505 #define IDC_VIDEOCONFIG_NO8LIM 600 #define IDC_DEBUGGER_ROM_PATCHER 602 #define LIST_DEBUGGER_BOOKMARKS 701 diff --git a/src/drivers/win/sound.cpp b/src/drivers/win/sound.cpp index 7217cb9e..539a381b 100644 --- a/src/drivers/win/sound.cpp +++ b/src/drivers/win/sound.cpp @@ -441,10 +441,34 @@ case WM_NCMBUTTONDOWN: case WM_NCLBUTTONDOWN:break; case WM_INITDIALOG: - /* Volume Trackbar */ + //Volume Trackbars-------------------------------------------------------------- + //Master SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR,TBM_SETRANGE,1,MAKELONG(0,150)); SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR,TBM_SETTICFREQ,25,0); SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR,TBM_SETPOS,1,150-soundvolume); + //Triangle + SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_TRIANGLE,TBM_SETRANGE,1,MAKELONG(0,150)); + SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_TRIANGLE,TBM_SETTICFREQ,25,0); + SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_TRIANGLE,TBM_SETPOS,1,150-soundTrianglevol); + //Square1 + SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_SQUARE1,TBM_SETRANGE,1,MAKELONG(0,150)); + SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_SQUARE1,TBM_SETTICFREQ,25,0); + SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_SQUARE1,TBM_SETPOS,1,150-soundSquare1vol); + + //Square2 + SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_SQUARE2,TBM_SETRANGE,1,MAKELONG(0,150)); + SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_SQUARE2,TBM_SETTICFREQ,25,0); + SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_SQUARE2,TBM_SETPOS,1,150-soundSquare2vol); + + //Noise + SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_NOISE,TBM_SETRANGE,1,MAKELONG(0,150)); + SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_NOISE,TBM_SETTICFREQ,25,0); + SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_NOISE,TBM_SETPOS,1,150-soundNoisevol); + + //PCM + SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_PCM,TBM_SETRANGE,1,MAKELONG(0,150)); + SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_PCM,TBM_SETTICFREQ,25,0); + SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_PCM,TBM_SETPOS,1,150-soundPCMvol); /* buffer size time trackbar */ SendDlgItemMessage(hwndDlg,CTL_LATENCY_TRACKBAR,TBM_SETRANGE,1,MAKELONG(15,200)); @@ -470,9 +494,43 @@ case WM_INITDIALOG: UpdateSD(hwndDlg); break; case WM_VSCROLL: - soundvolume=150-SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR,TBM_GETPOS,0,0); - FCEUI_SetSoundVolume(soundvolume); - break; + { + if (LOWORD(wParam) == SB_ENDSCROLL) + return true; + int i = CTL_VOLUME_TRACKBAR; + while (GetDlgItem(hwndDlg,i) != (HWND) lParam) + i++; + switch (i) + { + case CTL_VOLUME_TRACKBAR: + soundvolume=150-SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR,TBM_GETPOS,0,0); + FCEUI_SetSoundVolume(soundvolume); + break; + case CTL_VOLUME_TRACKBAR_TRIANGLE: + soundTrianglevol=150-SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_TRIANGLE,TBM_GETPOS,0,0); + FCEUI_SetTriangleVolume(soundTrianglevol); + break; + case CTL_VOLUME_TRACKBAR_SQUARE1: + soundSquare1vol=150-SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_SQUARE1,TBM_GETPOS,0,0); + FCEUI_SetSquare1Volume(soundSquare1vol); + break; + case CTL_VOLUME_TRACKBAR_SQUARE2: + soundSquare2vol=150-SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_SQUARE2,TBM_GETPOS,0,0); + FCEUI_SetSquare2Volume(soundSquare2vol); + break; + case CTL_VOLUME_TRACKBAR_NOISE: + soundNoisevol=150-SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_NOISE,TBM_GETPOS,0,0); + FCEUI_SetNoiseVolume(soundNoisevol); + break; + case CTL_VOLUME_TRACKBAR_PCM: + soundPCMvol=150-SendDlgItemMessage(hwndDlg,CTL_VOLUME_TRACKBAR_PCM,TBM_GETPOS,0,0); + FCEUI_SetPCMVolume(soundPCMvol); + break; + default: + break; + } + return true; + } case WM_HSCROLL: { char tbuf[8]; diff --git a/src/fceu.cpp b/src/fceu.cpp index db9228ea..4bb22125 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -479,6 +479,11 @@ bool FCEUI_Initialize() FSettings.UsrLastSLine[0]=239; FSettings.UsrLastSLine[1]=239; FSettings.SoundVolume=100; + FSettings.TriangleVolume=150; + FSettings.Square1Volume=150; + FSettings.Square2Volume=150; + FSettings.NoiseVolume=150; + FSettings.PCMVolume=150; FCEUPPU_Init(); diff --git a/src/fceu.h b/src/fceu.h index d435fe59..6198aa7c 100644 --- a/src/fceu.h +++ b/src/fceu.h @@ -72,7 +72,12 @@ extern uint8 PAL; typedef struct { int PAL; int NetworkPlay; - int SoundVolume; + int SoundVolume; //Master volume + int TriangleVolume; + int Square1Volume; + int Square2Volume; + int NoiseVolume; + int PCMVolume; bool GameGenie; //the currently selected first and last rendered scanlines. diff --git a/src/filter.cpp b/src/filter.cpp index d99582e3..247e1c5a 100644 --- a/src/filter.cpp +++ b/src/filter.cpp @@ -56,6 +56,7 @@ void SexyFilter(int32 *in, int32 *out, int32 count) mul2=(24<<16)/FSettings.SndRate; vmul=(FSettings.SoundVolume<<16)*3/4/100; +FCEU_DispMessage("SoundVolume %d, vmul %d",FSettings.SoundVolume,vmul); if(FSettings.soundq) vmul/=4; else vmul*=2; /* TODO: Increase volume in low quality sound rendering code itself */ diff --git a/src/sound.cpp b/src/sound.cpp index 4e9e11f3..e44ecc3f 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -552,7 +552,7 @@ void RDoPCM(void) } /* This has the correct phase. Don't mess with it. */ -static INLINE void RDoSQ(int x) +static INLINE void RDoSQ(int x) //Int x decides if this is Square Wave 1 or 2 { int32 V; int32 amp; @@ -572,8 +572,12 @@ static INLINE void RDoSQ(int x) if(EnvUnits[x].Mode&0x1) amp=EnvUnits[x].Speed; else - amp=EnvUnits[x].decvolume; -// printf("%d\n",amp); + amp=EnvUnits[x].decvolume; //Set the volume of the Square Wave + int32 zzz = amp; + //if (x==0) amp<<=128; //Alter sqaurewave volumes here + //else amp>>=8; + // FCEU_DispMessage("Before = %d After = %d",zzz,amp); //Debug + // printf("%d\n",amp); amp<<=24; rthresh=RectDuties[(PSG[(x<<2)]&0xC0)>>6]; @@ -1195,26 +1199,50 @@ void SetSoundVariables(void) void FCEUI_Sound(int Rate) { - FSettings.SndRate=Rate; - SetSoundVariables(); + FSettings.SndRate=Rate; + SetSoundVariables(); } void FCEUI_SetLowPass(int q) { - FSettings.lowpass=q; + FSettings.lowpass=q; } void FCEUI_SetSoundQuality(int quality) { - FSettings.soundq=quality; - SetSoundVariables(); + FSettings.soundq=quality; + SetSoundVariables(); } void FCEUI_SetSoundVolume(uint32 volume) { - FSettings.SoundVolume=volume; + FSettings.SoundVolume=volume; } +void FCEUI_SetTriangleVolume(uint32 volume) +{ + FSettings.TriangleVolume=volume; +} + +void FCEUI_SetSquare1Volume(uint32 volume) +{ + FSettings.Square1Volume=volume; +} + +void FCEUI_SetSquare2Volume(uint32 volume) +{ + FSettings.Square2Volume=volume; +} + +void FCEUI_SetNoiseVolume(uint32 volume) +{ + FSettings.NoiseVolume=volume; +} + +void FCEUI_SetPCMVolume(uint32 volume) +{ + FSettings.PCMVolume=volume; +} SFORMAT FCEUSND_STATEINFO[]={