diff --git a/desmume/src/SPU.cpp b/desmume/src/SPU.cpp index f1935c182..883b53333 100644 --- a/desmume/src/SPU.cpp +++ b/desmume/src/SPU.cpp @@ -52,9 +52,9 @@ extern SoundInterface_struct *SNDCoreList[]; static FORCEINLINE u32 sputrunc(float f) { return u32floor(f); } static FORCEINLINE u32 sputrunc(double d) { return u32floor(d); } -static FORCEINLINE s32 spudivide(s32 val) { - //return val / 127; //more accurate - return val >> 7; //faster +static FORCEINLINE s32 spumuldiv7(s32 val, u8 multiplier) { + assert(multiplier <= 127); + return (multiplier == 127) ? val : ((val * multiplier) >> 7); } //const int shift = (FORMAT == 0 ? 2 : 1); @@ -452,11 +452,17 @@ void SPU_struct::ShutUp() channels[i].status = CHANSTAT_STOPPED; } +static FORCEINLINE void adjust_channel_timer(channel_struct *chan) +{ + //chan->sampinc = (((double)33512000) / (44100 * 2)) / (double)(0x10000 - chan->timer); + chan->sampinc = (16777216 / (0x10000 - (double)chan->timer)) / 44100; +} + void SPU_struct::KeyOn(int channel) { channel_struct &thischan = channels[channel]; - thischan.sampinc = (16777216 / (0x10000 - (double)thischan.timer)) / 44100; + adjust_channel_timer(&thischan); // LOG("Channel %d key on: vol = %d, datashift = %d, hold = %d, pan = %d, waveduty = %d, repeat = %d, format = %d, source address = %07X, timer = %04X, loop start = %04X, length = %06X, MMU.ARM7_REG[0x501] = %02X\n", channel, chan->vol, chan->datashift, chan->hold, chan->pan, chan->waveduty, chan->repeat, chan->format, chan->addr, chan->timer, chan->loopstart, chan->length, T1ReadByte(MMU.ARM7_REG, 0x501)); switch(thischan.format) @@ -580,7 +586,7 @@ void SPU_struct::WriteWord(u32 addr, u16 val) break; case 0x8: thischan.timer = val & 0xFFFF; - thischan.sampinc = (16777216 / (0x10000 - (double)thischan.timer)) / 44100; + adjust_channel_timer(&thischan); break; case 0xA: thischan.loopstart = val; @@ -631,7 +637,7 @@ void SPU_struct::WriteLong(u32 addr, u32 val) case 0x8: thischan.timer = val & 0xFFFF; thischan.loopstart = val >> 16; - thischan.sampinc = (16777216 / (0x10000 - (double)thischan.timer)) / 44100; + adjust_channel_timer(&thischan); break; case 0xC: thischan.length = val & 0x3FFFFF; @@ -787,21 +793,21 @@ static FORCEINLINE void FetchPSGData(channel_struct *chan, s32 *data) static FORCEINLINE void MixL(SPU_struct* SPU, channel_struct *chan, s32 data) { - data = (spudivide(data * chan->vol)) >> chan->datashift; + data = spumuldiv7(data, chan->vol) >> chan->datashift; SPU->sndbuf[SPU->bufpos<<1] += data; } static FORCEINLINE void MixR(SPU_struct* SPU, channel_struct *chan, s32 data) { - data = (spudivide(data * chan->vol)) >> chan->datashift; + data = spumuldiv7(data, chan->vol) >> chan->datashift; SPU->sndbuf[(SPU->bufpos<<1)+1] += data; } static FORCEINLINE void MixLR(SPU_struct* SPU, channel_struct *chan, s32 data) { - data = (spudivide(data * chan->vol)) >> chan->datashift; - SPU->sndbuf[SPU->bufpos<<1] += spudivide(data * (127 - chan->pan)); - SPU->sndbuf[(SPU->bufpos<<1)+1] += spudivide(data * chan->pan); + data = spumuldiv7(data, chan->vol) >> chan->datashift; + SPU->sndbuf[SPU->bufpos<<1] += spumuldiv7(data, 127 - chan->pan); + SPU->sndbuf[(SPU->bufpos<<1)+1] += spumuldiv7(data, chan->pan); } ////////////////////////////////////////////////////////////////////////////// @@ -976,7 +982,7 @@ static void SPU_MixAudio(SPU_struct *SPU, int length) for (i = 0; i < length*2; i++) { // Apply Master Volume - SPU->sndbuf[i] = spudivide(SPU->sndbuf[i] * vol); + SPU->sndbuf[i] = spumuldiv7(SPU->sndbuf[i], vol); if (SPU->sndbuf[i] > 0x7FFF) SPU->outbuf[i] = 0x7FFF; diff --git a/desmume/src/windows/DeSmuME_2005.vcproj b/desmume/src/windows/DeSmuME_2005.vcproj index bf3f8dd73..9396bbd3d 100644 --- a/desmume/src/windows/DeSmuME_2005.vcproj +++ b/desmume/src/windows/DeSmuME_2005.vcproj @@ -525,6 +525,14 @@ RelativePath=".\snddx.h" > + + + + diff --git a/desmume/src/windows/DeSmuME_2008.vcproj b/desmume/src/windows/DeSmuME_2008.vcproj index e985fae87..f6a4b6126 100644 --- a/desmume/src/windows/DeSmuME_2008.vcproj +++ b/desmume/src/windows/DeSmuME_2008.vcproj @@ -760,6 +760,10 @@ RelativePath=".\snddx.cpp" > + + @@ -894,6 +898,10 @@ RelativePath=".\snddx.h" > + + diff --git a/desmume/src/windows/DeSmuME_Intel.vcproj b/desmume/src/windows/DeSmuME_Intel.vcproj index 00487de35..2d6b069ac 100644 --- a/desmume/src/windows/DeSmuME_Intel.vcproj +++ b/desmume/src/windows/DeSmuME_Intel.vcproj @@ -656,6 +656,10 @@ RelativePath=".\snddx.cpp" > + + @@ -790,6 +794,10 @@ RelativePath=".\snddx.h" > + + diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 6c7e63349..952ab0894 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -81,6 +81,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "ram_search.h" #include "aviout.h" #include "wavout.h" +#include "soundView.h" #include "directx/ddraw.h" @@ -1052,7 +1053,9 @@ void CheckMessages() SendMessage(RamWatchHWnd, msg.message, msg.wParam, msg.lParam); continue; } - + if (SoundView_GetHWnd() && IsDialogMessage(SoundView_GetHWnd(), &msg)) + continue; + if(!TranslateAccelerator(hwnd,hAccel,&msg)) { TranslateMessage(&msg); @@ -1213,7 +1216,7 @@ DWORD WINAPI run() tools_frames = 0; } - + if(SoundView_IsOpened()) SoundView_Refresh(); Update_RAM_Watch(); Update_RAM_Search(); @@ -1801,6 +1804,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance, GInfo_Init(); MemView_Init(); + SoundView_Init(); ViewDisasm_ARM7 = new TOOLSCLASS(hThisInstance, IDD_DESASSEMBLEUR_VIEWER7, (DLGPROC) ViewDisasm_ARM7Proc); ViewDisasm_ARM9 = new TOOLSCLASS(hThisInstance, IDD_DESASSEMBLEUR_VIEWER9, (DLGPROC) ViewDisasm_ARM9Proc); @@ -1982,9 +1986,11 @@ int WINAPI WinMain (HINSTANCE hThisInstance, MemView_DlgClose(ARMCPU_ARM9); MemView_DlgClose(ARMCPU_ARM7); + SoundView_DlgClose(); //IORegView_DlgClose(); MemView_DeInit(); + SoundView_DeInit(); //if (input!=NULL) delete input; if (ViewLights!=NULL) delete ViewLights; @@ -3164,6 +3170,9 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM if(!MemView_IsOpened(ARMCPU_ARM9)) MemView_DlgOpen(HWND_DESKTOP, "ARM9 memory", ARMCPU_ARM9); if(!MemView_IsOpened(ARMCPU_ARM7)) MemView_DlgOpen(HWND_DESKTOP, "ARM7 memory", ARMCPU_ARM7); return 0; + case IDM_SOUND_VIEW: + if(!SoundView_IsOpened()) SoundView_DlgOpen(HWND_DESKTOP); + return 0; case IDM_DISASSEMBLER: ViewDisasm_ARM7->regClass("DesViewBox7",ViewDisasm_ARM7BoxProc); if (!ViewDisasm_ARM7->open()) diff --git a/desmume/src/windows/resource.h b/desmume/src/windows/resource.h index 7f1b72e7f..a3ee58ae7 100644 --- a/desmume/src/windows/resource.h +++ b/desmume/src/windows/resource.h @@ -199,6 +199,7 @@ #define IDD_IOREG_VIEW_MEM_IRQ 970 #define IDD_IOREG_VIEW_SPI 973 #define IDD_IOREG_VIEW_CP15 975 +#define IDD_SOUND_VIEW 977 #define IDC_C_WATCH_UP 980 #define IDD_EDITWATCH 980 #define IDC_C_WATCH_DOWN 981 @@ -231,6 +232,7 @@ #define IDC_EDIT01 1001 #define IDC_IOREG_TAB 1001 #define IDC_SOUNDBUFFERET 1001 +#define IDC_SOUNDVIEW_CHANSWITCH 1001 #define PM_FILENAME 1001 #define IDC_ARM9BIOS 1002 #define IDC_EDIT05 1002 @@ -454,6 +456,110 @@ #define IDC_LIGHT_VIEWER_LIGHT3COLOR_COLORCTRL 1332 #define IDC_LIGHT_VIEWER_LIGHT3COLOR_EDIT 1333 #define IDC_LIGHT_VIEWER_LIGHT3VECTOR_EDIT 1334 +#define IDC_SOUND0ID 1350 +#define IDC_SOUND1ID 1351 +#define IDC_SOUND2ID 1352 +#define IDC_SOUND3ID 1353 +#define IDC_SOUND4ID 1354 +#define IDC_SOUND5ID 1355 +#define IDC_SOUND6ID 1356 +#define IDC_SOUND7ID 1357 +#define IDC_SOUND0VOL 1358 +#define IDC_SOUND1VOL 1359 +#define IDC_SOUND2VOL 1360 +#define IDC_SOUND3VOL 1361 +#define IDC_SOUND4VOL 1362 +#define IDC_SOUND5VOL 1363 +#define IDC_SOUND6VOL 1364 +#define IDC_SOUND7VOL 1365 +#define IDC_SOUND0VOLBAR 1366 +#define IDC_SOUND1VOLBAR 1367 +#define IDC_SOUND2VOLBAR 1368 +#define IDC_SOUND3VOLBAR 1369 +#define IDC_SOUND4VOLBAR 1370 +#define IDC_SOUND5VOLBAR 1371 +#define IDC_SOUND6VOLBAR 1372 +#define IDC_SOUND7VOLBAR 1373 +#define IDC_SOUND0PAN 1374 +#define IDC_SOUND1PAN 1375 +#define IDC_SOUND2PAN 1376 +#define IDC_SOUND3PAN 1377 +#define IDC_SOUND4PAN 1378 +#define IDC_SOUND5PAN 1379 +#define IDC_SOUND6PAN 1380 +#define IDC_SOUND7PAN 1381 +#define IDC_SOUND0PANBAR 1382 +#define IDC_SOUND1PANBAR 1383 +#define IDC_SOUND2PANBAR 1384 +#define IDC_SOUND3PANBAR 1385 +#define IDC_SOUND4PANBAR 1386 +#define IDC_SOUND5PANBAR 1387 +#define IDC_SOUND6PANBAR 1388 +#define IDC_SOUND7PANBAR 1389 +#define IDC_SOUND0HOLD 1390 +#define IDC_SOUND1HOLD 1391 +#define IDC_SOUND2HOLD 1392 +#define IDC_SOUND3HOLD 1393 +#define IDC_SOUND4HOLD 1394 +#define IDC_SOUND5HOLD 1395 +#define IDC_SOUND6HOLD 1396 +#define IDC_SOUND7HOLD 1397 +#define IDC_SOUND0BUSY 1398 +#define IDC_SOUND1BUSY 1399 +#define IDC_SOUND2BUSY 1400 +#define IDC_SOUND3BUSY 1401 +#define IDC_SOUND4BUSY 1402 +#define IDC_SOUND5BUSY 1403 +#define IDC_SOUND6BUSY 1404 +#define IDC_SOUND7BUSY 1405 +#define IDC_SOUND0REPEATMODE 1406 +#define IDC_SOUND1REPEATMODE 1407 +#define IDC_SOUND2REPEATMODE 1408 +#define IDC_SOUND3REPEATMODE 1409 +#define IDC_SOUND4REPEATMODE 1410 +#define IDC_SOUND5REPEATMODE 1411 +#define IDC_SOUND6REPEATMODE 1412 +#define IDC_SOUND7REPEATMODE 1413 +#define IDC_SOUND0FORMAT 1414 +#define IDC_SOUND1FORMAT 1415 +#define IDC_SOUND2FORMAT 1416 +#define IDC_SOUND3FORMAT 1417 +#define IDC_SOUND4FORMAT 1418 +#define IDC_SOUND5FORMAT 1419 +#define IDC_SOUND6FORMAT 1420 +#define IDC_SOUND7FORMAT 1421 +#define IDC_SOUND0SAD 1422 +#define IDC_SOUND1SAD 1423 +#define IDC_SOUND2SAD 1424 +#define IDC_SOUND3SAD 1425 +#define IDC_SOUND4SAD 1426 +#define IDC_SOUND5SAD 1427 +#define IDC_SOUND6SAD 1428 +#define IDC_SOUND7SAD 1429 +#define IDC_SOUND0PNT 1430 +#define IDC_SOUND1PNT 1431 +#define IDC_SOUND2PNT 1432 +#define IDC_SOUND3PNT 1433 +#define IDC_SOUND4PNT 1434 +#define IDC_SOUND5PNT 1435 +#define IDC_SOUND6PNT 1436 +#define IDC_SOUND7PNT 1437 +#define IDC_SOUND0TMR 1438 +#define IDC_SOUND1TMR 1439 +#define IDC_SOUND2TMR 1440 +#define IDC_SOUND3TMR 1441 +#define IDC_SOUND4TMR 1442 +#define IDC_SOUND5TMR 1443 +#define IDC_SOUND6TMR 1444 +#define IDC_SOUND7TMR 1445 +#define IDC_SOUND0POSLEN 1446 +#define IDC_SOUND1POSLEN 1447 +#define IDC_SOUND2POSLEN 1448 +#define IDC_SOUND3POSLEN 1449 +#define IDC_SOUND4POSLEN 1450 +#define IDC_SOUND5POSLEN 1451 +#define IDC_SOUND6POSLEN 1452 +#define IDC_SOUND7POSLEN 1453 #define IDC_GI_FATOFS 4464 #define IDC_INTERPOLATECOLOR 4464 #define IDC_GI_FATSIZE 4465 @@ -494,7 +600,9 @@ #define IDD_IOREG_VIEW_DMA 10006 #define IDD_IOREG_VIEW_TIMERS 10007 #define IDD_IOREG_VIEW_IPC_ROM 10008 +#define IDM_FILE_STOPAVI 40000 #define IDM_SCREENSEP_NONE 40000 +#define IDM_FILE_STOPWAV 40001 #define IDM_SCREENSEP_BORDER 40001 #define IDM_SCREENSEP_NDSGAP 40002 #define IDM_ABOUT 40003 @@ -510,9 +618,8 @@ #define ID_VIEW_HUDEDITOR 40013 #define ID_VIEW_DISPLAYMICROPHONE 40014 #define IDM_FILE_RECORDAVI 40015 -#define IDM_FILE_STOPAVI 40016 +#define IDM_SOUND_VIEW 40016 #define IDM_FILE_RECORDWAV 40017 -#define IDM_FILE_STOPWAV 40018 #define IDM_STOPMOVIE 40019 #define ID_FILE_RECENTROM 40034 #define IDC_SAVETYPE7 40037 diff --git a/desmume/src/windows/resources.rc b/desmume/src/windows/resources.rc index bb207a83e..e226ae98f 100644 --- a/desmume/src/windows/resources.rc +++ b/desmume/src/windows/resources.rc @@ -350,6 +350,7 @@ MENU_PRINCIPAL MENU MENUITEM "View &OAM", IDM_OAM MENUITEM "View Matrices", IDM_MATRIX_VIEWER MENUITEM "View Lights", IDM_LIGHT_VIEWER + MENUITEM "View &Sound State", IDM_SOUND_VIEW MENUITEM "RAM Watch...", ID_RAM_WATCH MENUITEM "RAM Search...", ID_RAM_SEARCH MENUITEM SEPARATOR @@ -638,7 +639,6 @@ FONT 8, "MS Sans Serif" - LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US IDD_3DSETTINGS DIALOGEX 0, 0, 174, 136 STYLE DS_MODALFRAME | DS_SETFONT | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_POPUP | WS_SYSMENU @@ -3589,6 +3589,131 @@ FONT 8, "MS Sans Serif", 0, 0, 1 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +IDD_SOUND_VIEW DIALOG 0, 0, 387, 246 +STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_VISIBLE | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_POPUP | WS_SYSMENU +CAPTION "Sound View" +FONT 8, "Ms Shell Dlg 2" +{ + CTEXT "Volume", IDC_STATIC, 30, 7, 100, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "Pan", IDC_STATIC, 30, 19, 100, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "Hold", IDC_STATIC, 131, 7, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "Busy", IDC_STATIC, 131, 19, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "Repeat Mode", IDC_STATIC, 154, 7, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "Format", IDC_STATIC, 154, 19, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "Source Addr", IDC_STATIC, 227, 7, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "Loop Start", IDC_STATIC, 227, 19, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "Timer Value", IDC_STATIC, 288, 6, 88, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "Sound Pos / Len", IDC_STATIC, 288, 19, 88, 11, SS_CENTER, WS_EX_STATICEDGE + RTEXT "#00", IDC_SOUND0ID, 4, 35, 23, 10, SS_RIGHT + CONTROL "", IDC_SOUND0VOLBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 35, 68, 9 + CTEXT "", IDC_SOUND0VOL, 100, 34, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CONTROL "", IDC_SOUND0PANBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 47, 68, 9 + CTEXT "", IDC_SOUND0PAN, 100, 46, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND0HOLD, 131, 34, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND0BUSY, 131, 46, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND0REPEATMODE, 154, 34, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND0FORMAT, 154, 46, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND0SAD, 227, 34, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND0PNT, 227, 46, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND0TMR, 288, 34, 88, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND0POSLEN, 288, 46, 88, 11, SS_CENTER, WS_EX_STATICEDGE + RTEXT "#01", IDC_SOUND1ID, 4, 60, 23, 10, SS_RIGHT + CONTROL "", IDC_SOUND1VOLBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 61, 68, 9 + CTEXT "", IDC_SOUND1VOL, 100, 59, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CONTROL "", IDC_SOUND1PANBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 72, 68, 9 + CTEXT "", IDC_SOUND1PAN, 100, 72, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND1HOLD, 131, 59, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND1BUSY, 131, 72, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND1REPEATMODE, 154, 59, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND1FORMAT, 154, 72, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND1SAD, 227, 59, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND1PNT, 227, 72, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND1TMR, 288, 59, 88, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND1POSLEN, 288, 72, 88, 11, SS_CENTER, WS_EX_STATICEDGE + RTEXT "#02", IDC_SOUND2ID, 4, 86, 23, 10, SS_RIGHT + CONTROL "", IDC_SOUND2VOLBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 86, 68, 9 + CTEXT "", IDC_SOUND2VOL, 100, 85, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CONTROL "", IDC_SOUND2PANBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 98, 68, 9 + CTEXT "", IDC_SOUND2PAN, 100, 98, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND2HOLD, 131, 85, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND2BUSY, 131, 98, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND2REPEATMODE, 154, 85, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND2FORMAT, 154, 98, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND2SAD, 227, 85, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND2PNT, 227, 98, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND2TMR, 288, 85, 88, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND2POSLEN, 288, 98, 88, 11, SS_CENTER, WS_EX_STATICEDGE + RTEXT "#03", IDC_SOUND3ID, 4, 112, 23, 10, SS_RIGHT + CONTROL "", IDC_SOUND3VOLBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 112, 68, 9 + CTEXT "", IDC_SOUND3VOL, 100, 111, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CONTROL "", IDC_SOUND3PANBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 124, 68, 9 + CTEXT "", IDC_SOUND3PAN, 100, 124, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND3HOLD, 131, 111, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND3BUSY, 131, 124, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND3REPEATMODE, 154, 111, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND3FORMAT, 154, 124, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND3SAD, 227, 111, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND3PNT, 227, 124, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND3TMR, 288, 111, 88, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND3POSLEN, 288, 124, 88, 11, SS_CENTER, WS_EX_STATICEDGE + RTEXT "#04", IDC_SOUND4ID, 4, 138, 23, 10, SS_RIGHT + CONTROL "", IDC_SOUND4VOLBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 138, 68, 9 + CTEXT "", IDC_SOUND4VOL, 100, 137, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CONTROL "", IDC_SOUND4PANBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 150, 68, 9 + CTEXT "", IDC_SOUND4PAN, 100, 150, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND4HOLD, 131, 137, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND4BUSY, 131, 150, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND4REPEATMODE, 154, 137, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND4FORMAT, 154, 150, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND4SAD, 227, 137, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND4PNT, 227, 150, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND4TMR, 288, 137, 88, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND4POSLEN, 288, 150, 88, 11, SS_CENTER, WS_EX_STATICEDGE + RTEXT "#05", IDC_SOUND5ID, 4, 164, 23, 10, SS_RIGHT + CONTROL "", IDC_SOUND5VOLBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 164, 68, 9 + CTEXT "", IDC_SOUND5VOL, 100, 163, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CONTROL "", IDC_SOUND5PANBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 176, 68, 9 + CTEXT "", IDC_SOUND5PAN, 100, 176, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND5HOLD, 131, 163, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND5BUSY, 131, 176, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND5REPEATMODE, 154, 163, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND5FORMAT, 154, 176, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND5SAD, 227, 163, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND5PNT, 227, 176, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND5TMR, 288, 163, 88, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND5POSLEN, 288, 176, 88, 11, SS_CENTER, WS_EX_STATICEDGE + RTEXT "#06", IDC_SOUND6ID, 4, 190, 23, 10, SS_RIGHT + CONTROL "", IDC_SOUND6VOLBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 190, 68, 9 + CTEXT "", IDC_SOUND6VOL, 100, 189, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CONTROL "", IDC_SOUND6PANBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 202, 68, 9 + CTEXT "", IDC_SOUND6PAN, 100, 202, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND6HOLD, 131, 189, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND6BUSY, 131, 202, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND6REPEATMODE, 154, 189, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND6FORMAT, 154, 202, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND6SAD, 227, 189, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND6PNT, 227, 202, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND6TMR, 288, 189, 88, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND6POSLEN, 288, 202, 88, 11, SS_CENTER, WS_EX_STATICEDGE + RTEXT "#07", IDC_SOUND7ID, 4, 216, 23, 10, SS_RIGHT + CONTROL "", IDC_SOUND7VOLBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 216, 68, 9 + CTEXT "", IDC_SOUND7VOL, 100, 215, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CONTROL "", IDC_SOUND7PANBAR, PROGRESS_CLASS, PBS_SMOOTH, 30, 228, 68, 9 + CTEXT "", IDC_SOUND7PAN, 100, 228, 30, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND7HOLD, 131, 215, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND7BUSY, 131, 228, 22, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND7REPEATMODE, 154, 215, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND7FORMAT, 154, 228, 72, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND7SAD, 227, 215, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND7PNT, 227, 228, 60, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND7TMR, 288, 215, 88, 11, SS_CENTER, WS_EX_STATICEDGE + CTEXT "", IDC_SOUND7POSLEN, 288, 228, 88, 11, SS_CENTER, WS_EX_STATICEDGE + PUSHBUTTON "V", IDC_SOUNDVIEW_CHANSWITCH, 16, 18, 12, 12, BS_PUSHBUTTON +} + + + LANGUAGE LANG_DANISH, SUBLANG_DANISH_DENMARK IDD_TILE DIALOGEX 0, 0, 446, 180 STYLE DS_SETFONT | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_SYSMENU diff --git a/desmume/src/windows/soundView.cpp b/desmume/src/windows/soundView.cpp new file mode 100644 index 000000000..15dff852b --- /dev/null +++ b/desmume/src/windows/soundView.cpp @@ -0,0 +1,283 @@ +/* Copyright (C) 2006 yopyop + yopyop156@ifrance.com + yopyop156.ifrance.com + + This file is part of DeSmuME + + DeSmuME is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DeSmuME 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 DeSmuME; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#include "../SPU.h" +#include "../debug.h" +#include "../common.h" +#include "../matrix.h" +#include "resource.h" +#include +#include +#include +#include +#include "soundView.h" + +#include + +using namespace std; + +////////////////////////////////////////////////////////////////////////////// + +typedef struct SoundView_DataStruct +{ + SoundView_DataStruct() : viewFirst8Channels(TRUE) + { + } + + HWND hDlg; + + BOOL viewFirst8Channels; +} SoundView_DataStruct; + +SoundView_DataStruct * SoundView_Data = NULL; + +////////////////////////////////////////////////////////////////////////////// + +BOOL SoundView_Init() +{ + return 1; +} + +void SoundView_DeInit() +{ +} + +////////////////////////////////////////////////////////////////////////////// + +BOOL SoundView_DlgOpen(HWND hParentWnd) +{ + HWND hDlg; + + SoundView_Data = new SoundView_DataStruct(); + if(SoundView_Data == NULL) + return 0; + + hDlg = CreateDialogParam(hAppInst, MAKEINTRESOURCE(IDD_SOUND_VIEW), hParentWnd, SoundView_DlgProc, (LPARAM)SoundView_Data); + if(hDlg == NULL) + { + delete SoundView_Data; + SoundView_Data = NULL; + return 0; + } + + //SoundView_Data->hDlg = hDlg; + + ShowWindow(hDlg, SW_SHOW); + UpdateWindow(hDlg); + + return 1; +} + +void SoundView_DlgClose() +{ + if(SoundView_Data != NULL) + { + DestroyWindow(SoundView_Data->hDlg); + delete SoundView_Data; + SoundView_Data = NULL; + } +} + +BOOL SoundView_IsOpened() +{ + return (SoundView_Data != NULL); +} + +HWND SoundView_GetHWnd() +{ + return SoundView_Data ? SoundView_Data->hDlg : NULL; +} + +#define CHANSTAT_STOPPED 0 +#define CHANSTAT_PLAY 1 +static u32 sputrunc(float f) { return u32floor(f); } +static u32 sputrunc(double d) { return u32floor(d); } +static FORCEINLINE s32 spumuldiv7(s32 val, u8 multiplier) { + assert(multiplier <= 127); + return (multiplier == 127) ? val : ((val * multiplier) >> 7); +} +void SoundView_Refresh() +{ + if(SoundView_Data == NULL || SPU_core == NULL) + return; + + char buf[256]; + HWND hDlg = SoundView_Data->hDlg; + int chanOfs = SoundView_Data->viewFirst8Channels ? 0 : 8; + static const int format_shift[] = { 2, 1, 3, 0 }; + static const double ARM7_CLOCK = 33513982; + for(int chanId = 0; chanId < 8; chanId++) { + int chan = chanId + chanOfs; + channel_struct &thischan = SPU_core->channels[chan]; + + SendDlgItemMessage(hDlg, IDC_SOUND0PANBAR+chanId, PBM_SETPOS, (WPARAM)spumuldiv7(128, thischan.pan), (LPARAM)0); + if(thischan.status != CHANSTAT_STOPPED) + { + SendDlgItemMessage(hDlg, IDC_SOUND0VOLBAR+chanId, PBM_SETPOS, + (WPARAM)(spumuldiv7(128, thischan.vol) >> thischan.datashift), (LPARAM)0); + + sprintf(buf, "%d/%d", thischan.vol, 1 << thischan.datashift); + SetDlgItemText(hDlg, IDC_SOUND0VOL+chanId, buf); + + if (thischan.pan == 0) + strcpy(buf, "L"); + else if (thischan.pan == 64) + strcpy(buf, "C"); + else if (thischan.pan == 127) + strcpy(buf, "R"); + else if (thischan.pan < 64) + sprintf(buf, "L%d", 64 - thischan.pan); + else //if (thischan.pan > 64) + sprintf(buf, "R%d", thischan.pan - 64); + SetDlgItemText(hDlg, IDC_SOUND0PAN+chanId, buf); + + sprintf(buf, "%d", thischan.hold); + SetDlgItemText(hDlg, IDC_SOUND0HOLD+chanId, buf); + + sprintf(buf, "%d", thischan.status); + SetDlgItemText(hDlg, IDC_SOUND0BUSY+chanId, buf); + + const char* modes[] = { "Manual", "Loop Infinite", "One-Shot", "Prohibited" }; + sprintf(buf, "%d (%s)", thischan.repeat, modes[thischan.repeat]); + SetDlgItemText(hDlg, IDC_SOUND0REPEATMODE+chanId, buf); + + if(thischan.format != 3) { + const char* formats[] = { "PCM8", "PCM16", "IMA-ADPCM" }; + sprintf(buf, "%d (%s)", thischan.format, formats[thischan.format]); + SetDlgItemText(hDlg, IDC_SOUND0FORMAT+chanId, buf); + } + else { + if (chan < 8) + sprintf(buf, "%d (PSG/Noise?)", thischan.format); + else if (chan < 14) + sprintf(buf, "%d (%.1f% Square)", thischan.format, (float)thischan.waveduty/8); + else + sprintf(buf, "%d (Noise)", thischan.format); + } + + sprintf(buf, "$%07X", thischan.addr); + SetDlgItemText(hDlg, IDC_SOUND0SAD+chanId, buf); + + sprintf(buf, "samp #%d", thischan.loopstart << format_shift[thischan.format]); + SetDlgItemText(hDlg, IDC_SOUND0PNT+chanId, buf); + + sprintf(buf, "$%04X (%.1f Hz)", thischan.timer, (ARM7_CLOCK/2) / (double)(0x10000 - thischan.timer)); + SetDlgItemText(hDlg, IDC_SOUND0TMR+chanId, buf); + + sprintf(buf, "samp #%d / #%d", sputrunc(thischan.sampcnt), thischan.totlength << format_shift[thischan.format]); + SetDlgItemText(hDlg, IDC_SOUND0POSLEN+chanId, buf); + } + else { + SendDlgItemMessage(hDlg, IDC_SOUND0VOLBAR+chanId, PBM_SETPOS, (WPARAM)0, (LPARAM)0); + strcpy(buf, "---"); + SetDlgItemText(hDlg, IDC_SOUND0VOL+chanId, buf); + SetDlgItemText(hDlg, IDC_SOUND0PAN+chanId, buf); + SetDlgItemText(hDlg, IDC_SOUND0HOLD+chanId, buf); + SetDlgItemText(hDlg, IDC_SOUND0BUSY+chanId, buf); + SetDlgItemText(hDlg, IDC_SOUND0REPEATMODE+chanId, buf); + SetDlgItemText(hDlg, IDC_SOUND0FORMAT+chanId, buf); + SetDlgItemText(hDlg, IDC_SOUND0SAD+chanId, buf); + SetDlgItemText(hDlg, IDC_SOUND0PNT+chanId, buf); + SetDlgItemText(hDlg, IDC_SOUND0TMR+chanId, buf); + SetDlgItemText(hDlg, IDC_SOUND0POSLEN+chanId, buf); + } + } +} + +////////////////////////////////////////////////////////////////////////////// + +static void SoundView_SwitchChanOfs(SoundView_DataStruct *data) +{ + if (data == NULL) + return; + + HWND hDlg = data->hDlg; + data->viewFirst8Channels = !data->viewFirst8Channels; + SetWindowText(GetDlgItem(hDlg, IDC_SOUNDVIEW_CHANSWITCH), + data->viewFirst8Channels ? "V" : "^"); + + char buf[256]; + int chanOfs = SoundView_Data->viewFirst8Channels ? 0 : 8; + for(int chanId = 0; chanId < 8; chanId++) { + int chan = chanId + chanOfs; + sprintf(buf, "#%02d", chan); + SetDlgItemText(hDlg, IDC_SOUND0ID+chanId, buf); + } + + SoundView_Refresh(); +} + +BOOL CALLBACK SoundView_DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + SoundView_DataStruct *data = (SoundView_DataStruct*)GetWindowLong(hDlg, DWL_USER); + if((data == NULL) && (uMsg != WM_INITDIALOG)) + return 0; + + switch(uMsg) + { + case WM_INITDIALOG: + { + for(int chanId = 0; chanId < 8; chanId++) { + SendDlgItemMessage(hDlg, IDC_SOUND0VOLBAR+chanId, PBM_SETRANGE, (WPARAM)0, MAKELPARAM(0, 128)); + SendDlgItemMessage(hDlg, IDC_SOUND0PANBAR+chanId, PBM_SETRANGE, (WPARAM)0, MAKELPARAM(0, 128)); + } + + if(data == NULL) + { + data = (SoundView_DataStruct*)lParam; + SetWindowLong(hDlg, DWL_USER, (LONG)data); + } + data->hDlg = hDlg; + + data->viewFirst8Channels = !data->viewFirst8Channels; + SoundView_SwitchChanOfs(data); + //SoundView_Refresh(); + //InvalidateRect(hDlg, NULL, FALSE); UpdateWindow(hDlg); + } + return 1; + + case WM_CLOSE: + case WM_DESTROY: + SoundView_DlgClose(); + return 1; + + case WM_COMMAND: + switch(LOWORD(wParam)) + { + case IDOK: + case IDCANCEL: + SoundView_DlgClose(); + return 1; + + case IDC_SOUNDVIEW_CHANSWITCH: + { + SoundView_SwitchChanOfs(data); + } + return 1; + } + return 0; + } + + return 0; +} + +////////////////////////////////////////////////////////////////////////////// diff --git a/desmume/src/windows/soundView.h b/desmume/src/windows/soundView.h new file mode 100644 index 000000000..23e1e73c3 --- /dev/null +++ b/desmume/src/windows/soundView.h @@ -0,0 +1,36 @@ +/* Copyright (C) 2006 yopyop + yopyop156@ifrance.com + yopyop156.ifrance.com + + This file is part of DeSmuME + + DeSmuME is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DeSmuME 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 DeSmuME; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef SOUND_VIEW_H +#define SOUND_VIEW_H + +BOOL SoundView_Init(); +void SoundView_DeInit(); + +BOOL SoundView_DlgOpen(HWND hParentWnd); +void SoundView_DlgClose(); +BOOL SoundView_IsOpened(); +HWND SoundView_GetHWnd(); +void SoundView_Refresh(); + +BOOL CALLBACK SoundView_DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); + +#endif