Skip to content

Commit

Permalink
Revert "prepare for volume handling refactor"
Browse files Browse the repository at this point in the history
sorry......... this refactor is canceled as it seems harder than I thought...
  • Loading branch information
tildearrow committed Nov 4, 2023
1 parent 54187d0 commit 6df06a7
Show file tree
Hide file tree
Showing 4 changed files with 879 additions and 25 deletions.
3 changes: 1 addition & 2 deletions src/engine/chipUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
template<typename T> struct SharedChannel {
int freq, baseFreq, baseNoteOverride, pitch, pitch2, arpOff;
int ins, note;
bool active, insChanged, freqChanged, fixedArp, keyOn, keyOff, portaPause, inPorta, volChanged;
bool active, insChanged, freqChanged, fixedArp, keyOn, keyOff, portaPause, inPorta;
T vol, outVol;
DivMacroInt std;
void handleArp(int offset=0) {
Expand Down Expand Up @@ -79,7 +79,6 @@ template<typename T> struct SharedChannel {
keyOff(false),
portaPause(false),
inPorta(false),
volChanged(false),
vol(initVol),
outVol(initVol),
std() {}
Expand Down
38 changes: 19 additions & 19 deletions src/engine/platform/es5506.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,22 @@ void DivPlatformES5506::tick(bool sysTick) {
const int nextVol=VOL_SCALE_LOG((0xfff*chan[i].vol)/0xff,(0xfff*chan[i].std.vol.val)/chan[i].volMacroMax,0xfff);
if (chan[i].outVol!=nextVol) {
chan[i].outVol=nextVol;
chan[i].volChangedES.lVol=1;
chan[i].volChangedES.rVol=1;
chan[i].volChanged.lVol=1;
chan[i].volChanged.rVol=1;
}
}
if (chan[i].std.panL.had) {
const int nextLVol=VOL_SCALE_LOG((0xfff*chan[i].lVol)/0xff,(0xfff*chan[i].std.panL.val)/chan[i].panMacroMax,0xfff);
if (chan[i].outLVol!=nextLVol) {
chan[i].outLVol=nextLVol;
chan[i].volChangedES.lVol=1;
chan[i].volChanged.lVol=1;
}
}
if (chan[i].std.panR.had) {
const int nextRVol=VOL_SCALE_LOG((0xfff*chan[i].rVol)/0xff,(0xfff*chan[i].std.panR.val)/chan[i].panMacroMax,0xfff);
if (chan[i].outRVol!=nextRVol) {
chan[i].outRVol=nextRVol;
chan[i].volChangedES.rVol=1;
chan[i].volChanged.rVol=1;
}
}
// arpeggio/pitch macros, frequency related
Expand Down Expand Up @@ -340,7 +340,7 @@ void DivPlatformES5506::tick(bool sysTick) {
if (chan[i].ca!=ca) {
chan[i].ca=ca;
if (!chan[i].keyOn) {
chan[i].volChangedES.ca=1;
chan[i].volChanged.ca=1;
}
}
}
Expand All @@ -360,9 +360,9 @@ void DivPlatformES5506::tick(bool sysTick) {
}
}
// update registers
if (chan[i].volChangedES.changed) {
if (chan[i].volChanged.changed) {
// calculate volume (16 bit)
if (chan[i].volChangedES.lVol) {
if (chan[i].volChanged.lVol) {
chan[i].resLVol=VOL_SCALE_LOG(chan[i].outVol,chan[i].outLVol,0xfff);
chan[i].resLVol-=volScale;
if (chan[i].resLVol<0) chan[i].resLVol=0;
Expand All @@ -371,7 +371,7 @@ void DivPlatformES5506::tick(bool sysTick) {
pageWrite(0x00|i,0x02,chan[i].resLVol);
}
}
if (chan[i].volChangedES.rVol) {
if (chan[i].volChanged.rVol) {
chan[i].resRVol=VOL_SCALE_LOG(chan[i].outVol,chan[i].outRVol,0xfff);
chan[i].resRVol-=volScale;
if (chan[i].resRVol<0) chan[i].resRVol=0;
Expand All @@ -380,10 +380,10 @@ void DivPlatformES5506::tick(bool sysTick) {
pageWrite(0x00|i,0x04,chan[i].resRVol);
}
}
if (chan[i].volChangedES.ca) {
if (chan[i].volChanged.ca) {
pageWriteMask(0x00|i,0x5f,0x00,(chan[i].ca<<10),0x1c00);
}
chan[i].volChangedES.changed=0;
chan[i].volChanged.changed=0;
}
if (chan[i].pcmChanged.changed) {
if (chan[i].pcmChanged.index) {
Expand Down Expand Up @@ -750,7 +750,7 @@ int DivPlatformES5506::dispatch(DivCommand c) {
chan[c.chan].freqChanged=true;
chan[c.chan].pcmChanged.changed=0xff;
chan[c.chan].noteChanged.changed=0xff;
chan[c.chan].volChangedES.changed=0xff;
chan[c.chan].volChanged.changed=0xff;
}
if (!chan[c.chan].std.vol.will) {
chan[c.chan].outVol=(0xfff*chan[c.chan].vol)/0xff;
Expand Down Expand Up @@ -787,7 +787,7 @@ int DivPlatformES5506::dispatch(DivCommand c) {
chan[c.chan].vol=c.value;
if (!chan[c.chan].std.vol.has) {
chan[c.chan].outVol=(0xfff*c.value)/0xff;
chan[c.chan].volChangedES.changed=0xff;
chan[c.chan].volChanged.changed=0xff;
}
}
break;
Expand All @@ -797,22 +797,22 @@ int DivPlatformES5506::dispatch(DivCommand c) {
case DIV_CMD_PANNING: {
if (chan[c.chan].ca!=0) {
chan[c.chan].ca=0;
chan[c.chan].volChangedES.ca=1;
chan[c.chan].volChanged.ca=1;
}
// Left volume
if (chan[c.chan].lVol!=c.value) {
chan[c.chan].lVol=c.value;
if (!chan[c.chan].std.panL.has) {
chan[c.chan].outLVol=(0xfff*c.value)/0xff;
chan[c.chan].volChangedES.lVol=1;
chan[c.chan].volChanged.lVol=1;
}
}
// Right volume
if (chan[c.chan].rVol!=c.value2) {
chan[c.chan].rVol=c.value2;
if (!chan[c.chan].std.panR.has) {
chan[c.chan].outRVol=(0xfff*c.value2)/0xff;
chan[c.chan].volChangedES.rVol=1;
chan[c.chan].volChanged.rVol=1;
}
}
break;
Expand All @@ -821,15 +821,15 @@ int DivPlatformES5506::dispatch(DivCommand c) {
unsigned char ca=CLAMP(c.value>>1,0,5);
if (chan[c.chan].ca!=ca) {
chan[c.chan].ca=ca;
chan[c.chan].volChangedES.ca=1;
chan[c.chan].volChanged.ca=1;
}
if ((c.value&1)==0) {
// Left volume
if (chan[c.chan].lVol!=c.value2) {
chan[c.chan].lVol=c.value2;
if (!chan[c.chan].std.panL.has) {
chan[c.chan].outLVol=(0xfff*c.value2)/0xff;
chan[c.chan].volChangedES.lVol=1;
chan[c.chan].volChanged.lVol=1;
}
}
}
Expand All @@ -839,7 +839,7 @@ int DivPlatformES5506::dispatch(DivCommand c) {
chan[c.chan].rVol=c.value2;
if (!chan[c.chan].std.panR.has) {
chan[c.chan].outRVol=(0xfff*c.value2)/0xff;
chan[c.chan].volChangedES.rVol=1;
chan[c.chan].volChanged.rVol=1;
}
}
}
Expand Down Expand Up @@ -1041,7 +1041,7 @@ void DivPlatformES5506::forceIns() {
chan[i].insChanged=true;
chan[i].freqChanged=true;
chan[i].noteChanged.changed=0xff;
chan[i].volChangedES.changed=0xff;
chan[i].volChanged.changed=0xff;
chan[i].filterChanged.changed=0xff;
chan[i].envChanged.changed=0xff;
chan[i].pcmChanged.changed=0xff;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/platform/es5506.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class DivPlatformES5506: public DivDispatch, public es550x_intf {

VolChanged() :
changed(0) {}
} volChangedES;
} volChanged;

struct FilterChanged { // Filter changed flags
union { // pack flag bits in single byte
Expand Down Expand Up @@ -198,7 +198,7 @@ class DivPlatformES5506: public DivDispatch, public es550x_intf {
isReverseLoop(false),
cr(0),
noteChanged(NoteChanged()),
volChangedES(VolChanged()),
volChanged(VolChanged()),
filterChanged(FilterChanged()),
envChanged(EnvChanged()),
pcmChanged(PCMChanged()),
Expand Down
Loading

0 comments on commit 6df06a7

Please sign in to comment.