From ace0e9a96ee0966fd8623a142448203c3a72c3f6 Mon Sep 17 00:00:00 2001 From: Barry Harris <44396066+barry65536@users.noreply.github.com> Date: Wed, 23 May 2012 13:11:48 +0000 Subject: [PATCH] Added support to cps3snd.cpp for volume and left/right selection for each route. Updated necessary drivers to support. --- src/burn/drv/cps3/cps3.h | 8 ++++++ src/burn/drv/cps3/cps3run.cpp | 2 ++ src/burn/drv/cps3/cps3snd.cpp | 49 ++++++++++++++++++++++++----------- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/burn/drv/cps3/cps3.h b/src/burn/drv/cps3/cps3.h index bd4c60ff9..7d7b26b7e 100644 --- a/src/burn/drv/cps3/cps3.h +++ b/src/burn/drv/cps3/cps3.h @@ -39,8 +39,16 @@ void __fastcall cps3SndWriteWord(UINT32 addr, UINT16 data); void __fastcall cps3SndWriteLong(UINT32 addr, UINT32 data); INT32 cps3SndInit(UINT8 *); +void cps3SndSetRoute(INT32 nIndex, double nVolume, INT32 nRouteDir); void cps3SndReset(); void cps3SndExit(); void cps3SndUpdate(); INT32 cps3SndScan(INT32); + +#define BURN_SND_CPS3SND_ROUTE_1 0 +#define BURN_SND_CPS3SND_ROUTE_2 1 + +#define cps3SndSetAllRoutes(v, d) \ + cps3SndSetRoute(BURN_SND_CPS3SND_ROUTE_1, v, d); \ + cps3SndSetRoute(BURN_SND_CPS3SND_ROUTE_2, v, d); diff --git a/src/burn/drv/cps3/cps3run.cpp b/src/burn/drv/cps3/cps3run.cpp index c945a1491..37ed75b95 100644 --- a/src/burn/drv/cps3/cps3run.cpp +++ b/src/burn/drv/cps3/cps3run.cpp @@ -1232,6 +1232,8 @@ INT32 cps3Init() BurnDrvGetVisibleSize(&cps3_gfx_width, &cps3_gfx_height); RamScreen += (512 * 2) * 16 + 16; // safe draw cps3SndInit(RomUser); + cps3SndSetRoute(BURN_SND_CPS3SND_ROUTE_1, 1.00, BURN_SND_ROUTE_LEFT); + cps3SndSetRoute(BURN_SND_CPS3SND_ROUTE_2, 1.00, BURN_SND_ROUTE_RIGHT); pBurnDrvPalette = (UINT32*)Cps3CurPal; diff --git a/src/burn/drv/cps3/cps3snd.cpp b/src/burn/drv/cps3/cps3snd.cpp index ff8fb6728..b229eb109 100644 --- a/src/burn/drv/cps3/cps3snd.cpp +++ b/src/burn/drv/cps3/cps3snd.cpp @@ -19,6 +19,9 @@ typedef struct { UINT8 * rombase; UINT32 delta; + + double gain[2]; + INT32 output_dir[2]; } cps3snd_chip; @@ -107,11 +110,22 @@ INT32 cps3SndInit(UINT8 * sndrom) //bprintf(0, _T("BurnSnd %08x, %d, %d\n"), chip->delta, chip->burnlen, nBurnSoundLen); } + chip->gain[BURN_SND_CPS3SND_ROUTE_1] = 1.00; + chip->gain[BURN_SND_CPS3SND_ROUTE_2] = 1.00; + chip->output_dir[BURN_SND_CPS3SND_ROUTE_1] = BURN_SND_ROUTE_LEFT; + chip->output_dir[BURN_SND_CPS3SND_ROUTE_2] = BURN_SND_ROUTE_RIGHT; + return 0; } return 1; } +void cps3SndSetRoute(INT32 nIndex, double nVolume, INT32 nRouteDir) +{ + chip->gain[nIndex] = nVolume; + chip->output_dir[nIndex] = nRouteDir; +} + void cps3SndReset() { } @@ -171,22 +185,27 @@ void cps3SndUpdate() sample = base[(start + pos) ^ 1]; frac += step; -#if 1 - INT32 sample_l; - - sample_l = ((sample * vol_r) >> 8) + buffer[0]; - if (sample_l > 32767) buffer[0] = 32767; - else if (sample_l < -32768) buffer[0] = -32768; - else buffer[0] = sample_l; + INT32 nLeftSample = 0, nRightSample = 0; - sample_l = ((sample * vol_l) >> 8) + buffer[1]; - if (sample_l > 32767) buffer[1] = 32767; - else if (sample_l < -32768) buffer[1] = -32768; - else buffer[1] = sample_l; -#else - buffer[0] += (sample * (vol_l >> 8)); - buffer[1] += (sample * (vol_r >> 8)); -#endif + if ((chip->output_dir[BURN_SND_CPS3SND_ROUTE_1] & BURN_SND_ROUTE_LEFT) == BURN_SND_ROUTE_LEFT) { + nLeftSample += (INT32)(((sample * vol_l) >> 8) * chip->gain[BURN_SND_CPS3SND_ROUTE_1]); + } + if ((chip->output_dir[BURN_SND_CPS3SND_ROUTE_1] & BURN_SND_ROUTE_RIGHT) == BURN_SND_ROUTE_RIGHT) { + nRightSample += (INT32)(((sample * vol_l) >> 8) * chip->gain[BURN_SND_CPS3SND_ROUTE_1]); + } + + if ((chip->output_dir[BURN_SND_CPS3SND_ROUTE_2] & BURN_SND_ROUTE_LEFT) == BURN_SND_ROUTE_LEFT) { + nLeftSample += (INT32)(((sample * vol_r) >> 8) * chip->gain[BURN_SND_CPS3SND_ROUTE_2]); + } + if ((chip->output_dir[BURN_SND_CPS3SND_ROUTE_2] & BURN_SND_ROUTE_RIGHT) == BURN_SND_ROUTE_RIGHT) { + nRightSample += (INT32)(((sample * vol_r) >> 8) * chip->gain[BURN_SND_CPS3SND_ROUTE_2]); + } + + nLeftSample = BURN_SND_CLIP(nLeftSample + buffer[0]); + nRightSample = BURN_SND_CLIP(nRightSample + buffer[1]); + + buffer[0] = nLeftSample; + buffer[1] = nRightSample; buffer += 2; }