diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index 14abcf053..9c4905acb 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -496,6 +496,7 @@ extern struct TCommonSettings { , spu_advanced(false) , rigorous_timing(false) , advanced_timing(true) + , spu_captureMuted(false) { strcpy(ARM9BIOS, "biosnds9.bin"); strcpy(ARM7BIOS, "biosnds7.bin"); @@ -557,6 +558,7 @@ extern struct TCommonSettings { int manualBackupType; bool spu_muteChannels[16]; + bool spu_captureMuted; bool spu_advanced; struct _ShowGpu { diff --git a/desmume/src/SPU.cpp b/desmume/src/SPU.cpp index de7d8b0ba..836f22c1f 100644 --- a/desmume/src/SPU.cpp +++ b/desmume/src/SPU.cpp @@ -1036,6 +1036,7 @@ static void SPU_MixAudio_Advanced(bool actuallyMix, SPU_struct *SPU, int length) SPU->sndbuf[1] = 0; SPU->buflength = 1; + s32 capmix[2] = {0,0}; s32 chanout[16]; s32 submix[32]; @@ -1047,12 +1048,27 @@ static void SPU_MixAudio_Advanced(bool actuallyMix, SPU_struct *SPU, int length) if (chan->status == CHANSTAT_PLAY) { SPU->bufpos = 0; - - bool domix = actuallyMix && !CommonSettings.spu_muteChannels[i]; + bool bypass = false; if(i==1 && SPU->regs.ctl_ch1bypass) bypass=true; if(i==3 && SPU->regs.ctl_ch3bypass) bypass=true; + bool domix = !CommonSettings.spu_muteChannels[i]; + bool docapmix = true; + if(!domix) { + bypass = true; + if(CommonSettings.spu_captureMuted) + { + domix = true; + docapmix = true; + } + } + if(!actuallyMix) { + domix = false; + bypass = true; + } + + //save our old mix accumulators so we can generate a clean panned sample s32 save[] = {SPU->sndbuf[0],SPU->sndbuf[1]}; SPU->sndbuf[0] = SPU->sndbuf[1] = 0; @@ -1069,13 +1085,26 @@ static void SPU_MixAudio_Advanced(bool actuallyMix, SPU_struct *SPU, int length) SPU->sndbuf[0] = save[0]; SPU->sndbuf[1] = save[1]; + //mix sample into our capture mix + if(docapmix) + { + capmix[0] += submix[i*2]; + capmix[1] += submix[i*2+1]; + } + //mix in this sample, unless we were bypassing it - if(!bypass) + if(bypass) + { + submix[i*2]=0; + submix[i*2+1]=0; + } + else { SPU->sndbuf[0] += submix[i*2]; SPU->sndbuf[1] += submix[i*2+1]; } + } else { @@ -1083,9 +1112,10 @@ static void SPU_MixAudio_Advanced(bool actuallyMix, SPU_struct *SPU, int length) submix[i*2] = 0; submix[i*2+1] = 0; } - } + } //foreach channel s32 mixout[2] = {SPU->sndbuf[0],SPU->sndbuf[1]}; + s32 capmixout[2] = {capmix[0],capmix[1]}; s32 sndout[2]; s32 capout[2]; @@ -1108,13 +1138,13 @@ static void SPU_MixAudio_Advanced(bool actuallyMix, SPU_struct *SPU, int length) //generate capture output ("capture bugs" from gbatek are not emulated) if(SPU->regs.cap[0].source==0) - capout[0] = mixout[0]; //cap0 = L-mix + capout[0] = capmixout[0]; //cap0 = L-mix else if(SPU->regs.cap[0].add) capout[0] = chanout[0] + chanout[1]; //cap0 = ch0+ch1 else capout[0] = chanout[0]; //cap0 = ch0 if(SPU->regs.cap[1].source==0) - capout[1] = mixout[1]; //cap1 = R-mix + capout[1] = capmixout[1]; //cap1 = R-mix else if(SPU->regs.cap[1].add) capout[1] = chanout[2] + chanout[3]; //cap1 = ch2+ch3 else capout[1] = chanout[2]; //cap1 = ch2 @@ -1144,6 +1174,9 @@ static void SPU_MixAudio_Advanced(bool actuallyMix, SPU_struct *SPU, int length) if(cap.bits8) { s8 sample8 = sample>>8; + static FILE* fCapOut = NULL; + if(!fCapOut) fCapOut = fopen("d:\\capout.raw","wb"); + fwrite(&sample8,1,1,fCapOut); if(skipcap) _MMU_write08<1,MMU_AT_DMA>(cap.runtime.curdad,0); else _MMU_write08<1,MMU_AT_DMA>(cap.runtime.curdad,sample8); cap.runtime.curdad++; diff --git a/desmume/src/windows/resource.h b/desmume/src/windows/resource.h index 19eb69be8..95647a470 100644 --- a/desmume/src/windows/resource.h +++ b/desmume/src/windows/resource.h @@ -361,7 +361,11 @@ #define IDC_SNDCTRL_CH1NOMIX 1029 #define IDC_TXT_VERSION 1030 #define IDC_SNDCTRL_CH3NOMIX 1030 +#define IDC_SOUND_CAPTURE_MUTED 1031 +#define IDC_SOUND_ANALYZE_CAP 1032 #define IDC_ADDONS_LIST 1033 +#define IDC_BUTTON3 1033 +#define IDC_SOUND_UNMUTE_ALL 1033 #define IDC_ADDONS_INFO 1034 #define IDC_BORDER 1034 #define IDC_BBROWSE 1035 @@ -911,7 +915,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 121 #define _APS_NEXT_COMMAND_VALUE 40079 -#define _APS_NEXT_CONTROL_VALUE 1029 +#define _APS_NEXT_CONTROL_VALUE 1033 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/desmume/src/windows/resources.rc b/desmume/src/windows/resources.rc index 0a9d58f40..16c5fec35 100644 Binary files a/desmume/src/windows/resources.rc and b/desmume/src/windows/resources.rc differ diff --git a/desmume/src/windows/soundView.cpp b/desmume/src/windows/soundView.cpp index 64cf766fd..443a21f1a 100644 --- a/desmume/src/windows/soundView.cpp +++ b/desmume/src/windows/soundView.cpp @@ -307,12 +307,16 @@ static void updateMute_toSettings(HWND hDlg, int chan) CommonSettings.spu_muteChannels[chanId+chanOfs()] = IsDlgButtonChecked(hDlg, IDC_SOUND0MUTE+chanId) == BST_CHECKED; } +static void updateMute_allFromSettings(HWND hDlg) +{ + for(int chanId = 0; chanId < 16; chanId++) + CheckDlgItem(hDlg,IDC_SOUND0MUTE+chanId,CommonSettings.spu_muteChannels[chanId]); +} + static void updateMute_fromSettings(HWND hDlg) { for(int chanId = 0; chanId < 8; chanId++) - SendDlgItemMessage(hDlg, IDC_SOUND0MUTE+chanId, BM_SETCHECK, - CommonSettings.spu_muteChannels[chanId+chanOfs()] ? TRUE : FALSE, - 0); + CheckDlgItem(hDlg,IDC_SOUND0MUTE+chanId,CommonSettings.spu_muteChannels[chanId+chanOfs()]); } static void SoundView_SwitchChanOfs(SoundView_DataStruct *data) { @@ -332,6 +336,7 @@ static void SoundView_SwitchChanOfs(SoundView_DataStruct *data) } updateMute_fromSettings(hDlg); + CheckDlgItem(hDlg,IDC_SOUND_CAPTURE_MUTED,CommonSettings.spu_captureMuted); SoundView_Refresh(); } @@ -397,6 +402,22 @@ static INT_PTR CALLBACK SoundView_DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, L case IDC_SOUND0MUTE+7: updateMute_toSettings(hDlg,LOWORD(wParam)-IDC_SOUND0MUTE); return 1; + case IDC_SOUND_CAPTURE_MUTED: + CommonSettings.spu_captureMuted = IsDlgButtonChecked(hDlg,IDC_SOUND_CAPTURE_MUTED) != 0; + return 1; + case IDC_SOUND_UNMUTE_ALL: + for(int i=0;i<16;i++) CommonSettings.spu_muteChannels[i] = false; + updateMute_allFromSettings(hDlg); + return 1; + case IDC_SOUND_ANALYZE_CAP: + printf("WTF\n"); + for(int i=0;i<16;i++) CommonSettings.spu_muteChannels[i] = true; + CommonSettings.spu_muteChannels[1] = false; + CommonSettings.spu_muteChannels[3] = false; + CommonSettings.spu_captureMuted = true; + updateMute_allFromSettings(hDlg); + CheckDlgItem(hDlg,IDC_SOUND_CAPTURE_MUTED,CommonSettings.spu_captureMuted); + return 1; case IDC_SOUNDVIEW_CHANSWITCH: