From 6d5328beb3d493b90e5064cf70093ded4b640e0d Mon Sep 17 00:00:00 2001 From: cam900 Date: Mon, 6 Mar 2023 08:02:31 +0900 Subject: [PATCH] Add volume (2 levels) --- src/engine/platform/pv1000.cpp | 30 +++++++++++++++++++++++++++--- src/engine/platform/pv1000.h | 4 +++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/engine/platform/pv1000.cpp b/src/engine/platform/pv1000.cpp index 37217ccb..fdb101d2 100644 --- a/src/engine/platform/pv1000.cpp +++ b/src/engine/platform/pv1000.cpp @@ -50,6 +50,11 @@ void DivPlatformPV1000::acquire(short** buf, size_t len) { void DivPlatformPV1000::tick(bool sysTick) { for (int i=0; i<3; i++) { chan[i].std.next(); + if (chan[i].std.vol.had) { + chan[i].outVol=VOL_SCALE_LINEAR(chan[i].std.vol.val,chan[i].vol,1); + if (chan[i].outVol<0) chan[i].outVol=0; + chan[i].writeVol=true; + } if (NEW_ARP_STRAT) { chan[i].handleArp(); } else if (chan[i].std.arp.had) { @@ -73,10 +78,10 @@ void DivPlatformPV1000::tick(bool sysTick) { if (chan[i].freq>62) chan[i].freq=62; if (isMuted[i]) chan[i].keyOn=false; if (chan[i].keyOn) { - rWrite(i,chan[i].freq); + rWrite(i,(isMuted[i] || (chan[i].outVol<=0)) ? 0 : chan[i].freq); chan[i].keyOn=false; } else if (chan[i].freqChanged && chan[i].active && !isMuted[i]) { - rWrite(i,chan[i].freq); + rWrite(i,(isMuted[i] || (chan[i].outVol<=0)) ? 0 : chan[i].freq); } if (chan[i].keyOff) { rWrite(i,0); @@ -85,6 +90,12 @@ void DivPlatformPV1000::tick(bool sysTick) { chan[i].freqChanged=false; } } + for (int i=0; i<3; i++) { + if (chan[i].writeVol) { + rWrite(i,(isMuted[i] || (chan[i].outVol<=0)) ? 0 : chan[i].freq); + chan[i].writeVol=false; + } + } } int DivPlatformPV1000::dispatch(DivCommand c) { @@ -97,6 +108,7 @@ int DivPlatformPV1000::dispatch(DivCommand c) { chan[c.chan].note=c.value; } chan[c.chan].active=true; + chan[c.chan].writeVol=true; chan[c.chan].keyOn=true; chan[c.chan].macroInit(ins); break; @@ -115,6 +127,17 @@ int DivPlatformPV1000::dispatch(DivCommand c) { chan[c.chan].ins=c.value; } break; + case DIV_CMD_VOLUME: + if (chan[c.chan].vol!=c.value) { + chan[c.chan].vol=c.value; + if (!chan[c.chan].std.vol.has) { + chan[c.chan].outVol=c.value; + } + if (chan[c.chan].active) { + chan[c.chan].writeVol=true; + } + } + break; case DIV_CMD_GET_VOLUME: return chan[c.chan].vol; break; @@ -158,7 +181,7 @@ int DivPlatformPV1000::dispatch(DivCommand c) { chan[c.chan].inPorta=c.value; break; case DIV_CMD_GET_VOLMAX: - return 15; + return 1; break; case DIV_CMD_MACRO_OFF: chan[c.chan].std.mask(c.value,true); @@ -181,6 +204,7 @@ void DivPlatformPV1000::muteChannel(int ch, bool mute) { chan[ch].keyOff=true; } else if (chan[ch].active) { chan[ch].keyOn=true; + chan[ch].writeVol=true; } } diff --git a/src/engine/platform/pv1000.h b/src/engine/platform/pv1000.h index 59484bcd..8ad463f1 100644 --- a/src/engine/platform/pv1000.h +++ b/src/engine/platform/pv1000.h @@ -26,8 +26,10 @@ class DivPlatformPV1000: public DivDispatch { struct Channel: public SharedChannel { + bool writeVol; Channel(): - SharedChannel(15) {} + SharedChannel(1), + writeVol(false) {} }; Channel chan[3]; DivDispatchOscBuffer* oscBuf[3];