From a1d83e869d8e8c9ba78fae6905b03b3a8627a117 Mon Sep 17 00:00:00 2001 From: cam900 Date: Sun, 12 Feb 2023 14:36:24 +0900 Subject: [PATCH] Reduce duplicates --- src/engine/platform/es5506.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/engine/platform/es5506.cpp b/src/engine/platform/es5506.cpp index 50e30c8b5..27056409f 100644 --- a/src/engine/platform/es5506.cpp +++ b/src/engine/platform/es5506.cpp @@ -23,6 +23,7 @@ #include #include +#define VOL_CALC(vol) ((0xffff*(vol))/0xff) #define PITCH_OFFSET ((double)(16*2048*(chanMax+1))) #define NOTE_ES5506(c,note) (parent->calcBaseFreq(chipClock,chan[c].pcm.freqOffs,note,false)) @@ -190,7 +191,7 @@ void DivPlatformES5506::tick(bool sysTick) { signed int k1=chan[i].k1Prev,k2=chan[i].k2Prev; // volume/panning macros if (chan[i].std.vol.had) { - const unsigned int nextVol=VOL_SCALE_LOG((0xffff*chan[i].vol)/0xff,(0xffff*(unsigned int)chan[i].std.vol.val)/chan[i].volMacroMax,0xffff); + const unsigned int nextVol=VOL_SCALE_LOG(VOL_CALC(chan[i].vol),(0xffff*(unsigned int)chan[i].std.vol.val)/chan[i].volMacroMax,0xffff); if (chan[i].outVol!=nextVol) { chan[i].outVol=nextVol; chan[i].volChanged.lVol=1; @@ -198,14 +199,14 @@ void DivPlatformES5506::tick(bool sysTick) { } } if (chan[i].std.panL.had) { - const unsigned int nextLVol=VOL_SCALE_LOG((0xffff*chan[i].lVol)/0xff,(0xffff*(unsigned int)chan[i].std.panL.val)/chan[i].panMacroMax,0xffff); + const unsigned int nextLVol=VOL_SCALE_LOG(VOL_CALC(chan[i].lVol),(0xffff*(unsigned int)chan[i].std.panL.val)/chan[i].panMacroMax,0xffff); if (chan[i].outLVol!=nextLVol) { chan[i].outLVol=nextLVol; chan[i].volChanged.lVol=1; } } if (chan[i].std.panR.had) { - const unsigned int nextRVol=VOL_SCALE_LOG((0xffff*chan[i].rVol)/0xff,(0xffff*(unsigned int)chan[i].std.panR.val)/chan[i].panMacroMax,0xffff); + const unsigned int nextRVol=VOL_SCALE_LOG(VOL_CALC(chan[i].rVol),(0xffff*(unsigned int)chan[i].std.panR.val)/chan[i].panMacroMax,0xffff); if (chan[i].outRVol!=nextRVol) { chan[i].outRVol=nextRVol; chan[i].volChanged.rVol=1; @@ -701,7 +702,7 @@ void DivPlatformES5506::tick(bool sysTick) { pageWrite(0x00|i,0x06,chan[i].envelope.ecount); // Clear ECOUNT pageWriteMask(0x00|i,0x5f,0x00,loopFlag,0x3cff); if (!chan[i].std.vol.had) { - chan[i].outVol=(0xffff*chan[i].vol)/0xff; + chan[i].outVol=VOL_CALC(chan[i].vol); chan[i].volChanged.changed=0xff; } } @@ -767,16 +768,16 @@ int DivPlatformES5506::dispatch(DivCommand c) { chan[c.chan].keyOn=true; chan[c.chan].macroInit(ins); if (!chan[c.chan].std.vol.will) { - chan[c.chan].outVol=(0xffff*chan[c.chan].vol)/0xff; + chan[c.chan].outVol=VOL_CALC(chan[c.chan].vol); chan[c.chan].volChanged.lVol=1; chan[c.chan].volChanged.rVol=1; } if (!chan[c.chan].std.panL.will) { - chan[c.chan].outLVol=(0xffff*chan[c.chan].lVol)/0xff; + chan[c.chan].outLVol=VOL_CALC(chan[c.chan].lVol); chan[c.chan].volChanged.lVol=1; } if (!chan[c.chan].std.panR.will) { - chan[c.chan].outRVol=(0xffff*chan[c.chan].rVol)/0xff; + chan[c.chan].outRVol=VOL_CALC(chan[c.chan].rVol); chan[c.chan].volChanged.rVol=1; } break; @@ -801,7 +802,7 @@ int DivPlatformES5506::dispatch(DivCommand c) { if (chan[c.chan].vol!=(unsigned int)(c.value)) { chan[c.chan].vol=c.value; if (!chan[c.chan].std.vol.has) { - chan[c.chan].outVol=(0xffff*chan[c.chan].vol)/0xff; + chan[c.chan].outVol=VOL_CALC(chan[c.chan].vol); chan[c.chan].volChanged.changed=0xff; } } @@ -821,7 +822,7 @@ int DivPlatformES5506::dispatch(DivCommand c) { if (chan[c.chan].lVol!=(unsigned int)(c.value)) { chan[c.chan].lVol=c.value; if (!chan[c.chan].std.panL.has) { - chan[c.chan].outLVol=(0xffff*c.value)/0xff; + chan[c.chan].outLVol=VOL_CALC(c.value); chan[c.chan].volChanged.lVol=1; } } @@ -829,7 +830,7 @@ int DivPlatformES5506::dispatch(DivCommand c) { if (chan[c.chan].rVol!=(unsigned int)(c.value2)) { chan[c.chan].rVol=c.value2; if (!chan[c.chan].std.panR.has) { - chan[c.chan].outRVol=(0xffff*c.value2)/0xff; + chan[c.chan].outRVol=VOL_CALC(c.value2); chan[c.chan].volChanged.rVol=1; } } @@ -846,7 +847,7 @@ int DivPlatformES5506::dispatch(DivCommand c) { if (chan[c.chan].lVol!=(unsigned int)(c.value2)) { chan[c.chan].lVol=c.value2; if (!chan[c.chan].std.panL.has) { - chan[c.chan].outLVol=(0xffff*c.value2)/0xff; + chan[c.chan].outLVol=VOL_CALC(c.value2); chan[c.chan].volChanged.lVol=1; } } @@ -856,7 +857,7 @@ int DivPlatformES5506::dispatch(DivCommand c) { if (chan[c.chan].rVol!=(unsigned int)(c.value2)) { chan[c.chan].rVol=c.value2; if (!chan[c.chan].std.panR.has) { - chan[c.chan].outRVol=(0xffff*c.value2)/0xff; + chan[c.chan].outRVol=VOL_CALC(c.value2); chan[c.chan].volChanged.rVol=1; } }