Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
wip gets wippier with eventual leadup to something nice
Browse files Browse the repository at this point in the history
  • Loading branch information
dinkc64 committed Apr 9, 2019
1 parent 09346d6 commit a519033
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
70 changes: 64 additions & 6 deletions src/burn/snd/dac.cpp
Expand Up @@ -30,6 +30,38 @@ static INT32 bAddSignal;
static INT32 (*pCPUTotalCycles)() = NULL;
static UINT32 nDACCPUMHZ = 0;

// single-order dc blocking filter
static INT32 dac_dcblock = 0; // enable
static INT16 dac_lastin_r = 0;
static INT16 dac_lastout_r = 0;
static INT16 dac_lastin_l = 0;
static INT16 dac_lastout_l = 0;

void DACDCBlock(INT32 enable)
{
dac_dcblock = enable;
}

static INT16 dc_blockR(INT16 sam)
{
if (!dac_dcblock) return sam;
INT16 outr = sam - dac_lastin_r + 0.998 * dac_lastout_r;
dac_lastin_r = sam;
dac_lastout_r = outr;

return outr;
}

static INT16 dc_blockL(INT16 sam)
{
if (!dac_dcblock) return sam;
INT16 outl = sam - dac_lastin_l + 0.998 * dac_lastout_l;
dac_lastin_l = sam;
dac_lastout_l = outl;

return outl;
}

static INT32 DACSyncInternal()
{
return (INT32)(float)(nBurnSoundLen * (pCPUTotalCycles() / (nDACCPUMHZ / (nBurnFPS / 100.0000))));
Expand Down Expand Up @@ -99,8 +131,8 @@ void DACUpdate(INT16* Buffer, INT32 Length)

if (bAddSignal) {
while (Length--) {
Buffer[0] = BURN_SND_CLIP((INT32)(lbuf[0] + Buffer[0]));
Buffer[1] = BURN_SND_CLIP((INT32)(rbuf[0] + Buffer[1]));
Buffer[0] = BURN_SND_CLIP((INT32)(dc_blockL(lbuf[0]) + Buffer[0]));
Buffer[1] = BURN_SND_CLIP((INT32)(dc_blockR(rbuf[0]) + Buffer[1]));
Buffer += 2;
lbuf[0] = 0; // clear buffer
rbuf[0] = 0; // clear buffer
Expand All @@ -109,8 +141,8 @@ void DACUpdate(INT16* Buffer, INT32 Length)
}
} else {
while (Length--) {
Buffer[0] = lbuf[0];
Buffer[1] = rbuf[0];
Buffer[0] = dc_blockL(lbuf[0]);
Buffer[1] = dc_blockR(rbuf[0]);
Buffer += 2;
lbuf[0] = 0; // clear buffer
rbuf[0] = 0; // clear buffer
Expand Down Expand Up @@ -181,6 +213,27 @@ void DACWrite16Stereo(INT32 Chip, INT16 Data, INT16 Data2)
}
}

void DACWrite16Signed(INT32 Chip, UINT16 Data)
{
#if defined FBA_DEBUG
if (!DebugSnd_DACInitted) bprintf(PRINT_ERROR, _T("DACWrite16 called without init\n"));
if (Chip > NumChips) bprintf(PRINT_ERROR, _T("DACWrite16 called with invalid chip number %x\n"), Chip);
#endif

struct dac_info *ptr;

ptr = &dac_table[Chip];

INT16 Signed = Data - 0x8000;

Data = (INT32)(Signed * ptr->nVolume);

if (Data != ptr->Output) {
UpdateStream(Chip, ptr->pSyncCallback());
ptr->Output = Data;
}
}

void DACSignedWrite(INT32 Chip, UINT8 Data)
{
#if defined FBA_DEBUG
Expand Down Expand Up @@ -289,7 +342,10 @@ void DACReset()
ptr->nCurrentPosition = 0;
ptr->Output = 0;
ptr->Output2 = 0;
}
}

dac_lastin_r = dac_lastout_r = 0;
dac_lastin_l = dac_lastout_l = 0;
}

void DACExit()
Expand All @@ -313,7 +369,9 @@ void DACExit()
nDACCPUMHZ = 0;

NumChips = 0;


dac_dcblock = 0;

DebugSnd_DACInitted = 0;

BurnFree (lBuffer);
Expand Down
2 changes: 2 additions & 0 deletions src/burn/snd/dac.h
@@ -1,12 +1,14 @@
void DACUpdate(INT16* Buffer, INT32 Length);
void DACWrite(INT32 Chip, UINT8 Data);
void DACWrite16(INT32 Chip, INT16 Data);
void DACWrite16Signed(INT32 Chip, UINT16 Data);
void DACWrite16Stereo(INT32 Chip, INT16 Data, INT16 Data2);
void DACSignedWrite(INT32 Chip, UINT8 Data);
void DACInit(INT32 Num, UINT32 Clock, INT32 bAdd, INT32 (*pSyncCB)());
void DACInit(INT32 Num, UINT32 Clock, INT32 bAdd, INT32 (*pCPUCyclesCB)(), INT32 nCpuMHZ);
void DACSetRoute(INT32 Chip, double nVolume, INT32 nRouteDir);
void DACStereoMode(INT32 Chip);
void DACDCBlock(INT32 enable);
void DACReset();
void DACExit();
void DACScan(INT32 nAction, INT32 *pnMin);

0 comments on commit a519033

Please sign in to comment.