From fc7a55b5c111dfe74aaa782b7127737c9302c1f2 Mon Sep 17 00:00:00 2001 From: Barry Harris <44396066+barry65536@users.noreply.github.com> Date: Tue, 22 May 2012 15:16:02 +0000 Subject: [PATCH] Added support to es8712.cpp for left/right selection for each route. Changed volume to fraction rather than percentage. Updated necessary drivers to support. --- src/burn/drv/pst90s/d_vmetal.cpp | 3 +- src/burn/snd/es8712.cpp | 51 ++++++++++++++++++++++++-------- src/burn/snd/es8712.h | 3 +- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/burn/drv/pst90s/d_vmetal.cpp b/src/burn/drv/pst90s/d_vmetal.cpp index 7f1196cb2..804f40898 100644 --- a/src/burn/drv/pst90s/d_vmetal.cpp +++ b/src/burn/drv/pst90s/d_vmetal.cpp @@ -347,7 +347,8 @@ static INT32 DrvInit() SekSetWriteWordHandler(1, vmetal_palette_write_word); SekClose(); - es8712Init(0, DrvSndROM1, 12000 / 60 /* Rate / FPS */, 50.0, 0); + es8712Init(0, DrvSndROM1, 12000 / 60 /* Rate / FPS */, 0); + es8712SetRoute(0, 0.50, BURN_SND_ROUTE_BOTH); MSM6295Init(0, 1320000 / 132, 1); MSM6295SetRoute(0, 0.75, BURN_SND_ROUTE_BOTH); diff --git a/src/burn/snd/es8712.cpp b/src/burn/snd/es8712.cpp index 3a1bf94cb..92d9a47ab 100644 --- a/src/burn/snd/es8712.cpp +++ b/src/burn/snd/es8712.cpp @@ -47,7 +47,8 @@ struct _es8712_state UINT8 *region_base; /* pointer to the base of the region */ INT32 sample_rate; /* samples per frame */ - INT32 volume; /* set gain */ + double volume; /* set gain */ + INT32 output_dir; INT32 addSignal; /* add signal to stream? */ }; @@ -113,7 +114,7 @@ static void generate_adpcm(INT16 *buffer, INT32 samples) INT32 signal = chip->signal; INT32 count = chip->count; INT32 step = chip->step; - INT32 volume = chip->volume; + double volume = chip->volume; INT32 val; /* loop while we still have samples to generate */ @@ -137,7 +138,7 @@ static void generate_adpcm(INT16 *buffer, INT32 samples) step = 0; /* output to the buffer */ - *buffer++ = (signal * 16 * volume) / 100; + *buffer++ = (INT32)(signal * 16 * volume); samples--; /* next! */ @@ -194,16 +195,28 @@ void es8712Update(INT32 device, INT16 *buffer, INT32 samples) generate_adpcm(buf, sample_num); float r = 0; - if (chip->addSignal) { - for (INT32 i = 0; i < samples; i++, r += step, buffer+=2) { - buffer[0] += buf[(INT32)r]; - buffer[1] += buf[(INT32)r]; + for (INT32 i = 0; i < samples; i++, r += step, buffer+=2) { + INT32 nLeftSample = 0, nRightSample = 0; + + if ((chip->output_dir & BURN_SND_ROUTE_LEFT) == BURN_SND_ROUTE_LEFT) { + nLeftSample += (INT32)(buf[(INT32)r] * chip->volume); } - } else { - for (INT32 i = 0; i < samples; i++, r += step, buffer+=2) { - buffer[0] = buffer[1] = buf[(INT32)r]; + if ((chip->output_dir & BURN_SND_ROUTE_RIGHT) == BURN_SND_ROUTE_RIGHT) { + nRightSample += (INT32)(buf[(INT32)r] * chip->volume); + } + + nLeftSample = BURN_SND_CLIP(nLeftSample); + nRightSample = BURN_SND_CLIP(nRightSample); + + if (chip->addSignal) { + buffer[0] += nLeftSample; + buffer[1] += nRightSample; + } else { + buffer[0] = nLeftSample; + buffer[1] = nRightSample; } } + } @@ -213,7 +226,7 @@ void es8712Update(INT32 device, INT16 *buffer, INT32 samples) ***********************************************************************************************/ -void es8712Init(INT32 device, UINT8 *rom, INT32 sample_rate, float volume, INT32 addSignal) +void es8712Init(INT32 device, UINT8 *rom, INT32 sample_rate, INT32 addSignal) { DebugSnd_ES8712Initted = 1; @@ -235,7 +248,8 @@ void es8712Init(INT32 device, UINT8 *rom, INT32 sample_rate, float volume, INT32 chip->sample_rate = sample_rate; - chip->volume = (INT32)(volume+0.5); + chip->volume = 1.00; + chip->output_dir = BURN_SND_ROUTE_BOTH; chip->addSignal = addSignal; if (tbuf[device] == NULL) { @@ -243,6 +257,19 @@ void es8712Init(INT32 device, UINT8 *rom, INT32 sample_rate, float volume, INT32 } } +void es8712SetRoute(INT32 device, double nVolume, INT32 nRouteDir) +{ +#if defined FBA_DEBUG + if (!DebugSnd_ES8712Initted) bprintf(PRINT_ERROR, _T("es8712SetRoute called without init\n")); +#endif + + if (device >= MAX_ES8712_CHIPS) return; + + chip = &chips[device]; + chip->volume = nVolume; + chip->output_dir = nRouteDir; +} + /********************************************************************************************** es8712Exit -- stop emulation of an ES8712 chip diff --git a/src/burn/snd/es8712.h b/src/burn/snd/es8712.h index 8c49f8aea..b75d2166e 100644 --- a/src/burn/snd/es8712.h +++ b/src/burn/snd/es8712.h @@ -3,7 +3,8 @@ void es8712Play(INT32 device); void es8712SetBankBase(INT32 device, INT32 base); -void es8712Init(INT32 device, UINT8 *rom, INT32 sample_rate, float volume, INT32 addSignal); +void es8712Init(INT32 device, UINT8 *rom, INT32 sample_rate, INT32 addSignal); +void es8712SetRoute(INT32 device, double nVolume, INT32 nRouteDir); void es8712Reset(INT32 device); void es8712Update(INT32 device, INT16 *buffer, INT32 samples); void es8712Exit(INT32 device);