diff --git a/src/engine/platform/c140.cpp b/src/engine/platform/c140.cpp index 5330443ac..95b9dc021 100644 --- a/src/engine/platform/c140.cpp +++ b/src/engine/platform/c140.cpp @@ -80,9 +80,8 @@ void DivPlatformC140::tick(bool sysTick) { chan[i].std.next(); if (chan[i].std.vol.had) { chan[i].outVol=(chan[i].vol*MIN(chan[i].macroVolMul,chan[i].std.vol.val))/chan[i].macroVolMul; - if (!isMuted[i]) { - chan[i].volumeChanged.changed=0xff; - } + chan[i].volChangedL=true; + chan[i].volChangedR=true; } if (NEW_ARP_STRAT) { chan[i].handleArp(); @@ -103,16 +102,12 @@ void DivPlatformC140::tick(bool sysTick) { } if (chan[i].std.panL.had) { chan[i].chPanL=chan[i].std.panL.val&255; - if (!isMuted[i]) { - chan[i].volumeChanged.left=1; - } + chan[i].volChangedL=true; } if (chan[i].std.panR.had) { chan[i].chPanR=chan[i].std.panR.val&255; - if (!isMuted[i]) { - chan[i].volumeChanged.right=1; - } + chan[i].volChangedR=true; } if (chan[i].std.phaseReset.had) { @@ -121,24 +116,15 @@ void DivPlatformC140::tick(bool sysTick) { chan[i].setPos=true; } } - if (chan[i].volumeChanged.changed) { - if (chan[i].volumeChanged.left) { - if (isMuted[i]) { - chan[i].chVolL=0; - } else { - chan[i].chVolL=(chan[i].outVol*chan[i].chPanL)/255; - } - rWrite(1+(i<<4),chan[i].chVolL); - } - if (chan[i].volumeChanged.right) { - if (isMuted[i]) { - chan[i].chVolR=0; - } else { - chan[i].chVolR=(chan[i].outVol*chan[i].chPanR)/255; - } - rWrite(0+(i<<4),chan[i].chVolR); - } - chan[i].volumeChanged.changed=0; + if (chan[i].volChangedL) { + chan[i].chVolL=(chan[i].outVol*chan[i].chPanL)/255; + rWrite(1+(i<<4),chan[i].chVolL); + chan[i].volChangedL=false; + } + if (chan[i].volChangedR) { + chan[i].chVolR=(chan[i].outVol*chan[i].chPanR)/255; + rWrite(0+(i<<4),chan[i].chVolR); + chan[i].volChangedR=false; } if (chan[i].setPos) { // force keyon @@ -178,9 +164,8 @@ void DivPlatformC140::tick(bool sysTick) { rWrite(0x0b+(i<<4),loop&0xff); if (!chan[i].std.vol.had) { chan[i].outVol=chan[i].vol; - if (!isMuted[i]) { - chan[i].volumeChanged.changed=0xff; - } + chan[i].volChangedL=true; + chan[i].volChangedR=true; } chan[i].keyOn=false; } @@ -221,9 +206,8 @@ int DivPlatformC140::dispatch(DivCommand c) { chan[c.chan].macroInit(ins); if (!parent->song.brokenOutVol && !chan[c.chan].std.vol.will) { chan[c.chan].outVol=chan[c.chan].vol; - if (!isMuted[c.chan]) { - chan[c.chan].volumeChanged.changed=0xff; - } + chan[c.chan].volChangedL=true; + chan[c.chan].volChangedR=true; } break; } @@ -247,9 +231,8 @@ int DivPlatformC140::dispatch(DivCommand c) { if (!chan[c.chan].std.vol.has) { chan[c.chan].outVol=c.value; } - if (!isMuted[c.chan]) { - chan[c.chan].volumeChanged.changed=0xff; - } + chan[c.chan].volChangedL=true; + chan[c.chan].volChangedR=true; break; case DIV_CMD_GET_VOLUME: if (chan[c.chan].std.vol.has) { @@ -260,9 +243,8 @@ int DivPlatformC140::dispatch(DivCommand c) { case DIV_CMD_PANNING: chan[c.chan].chPanL=c.value; chan[c.chan].chPanR=c.value2; - if (!isMuted[c.chan]) { - chan[c.chan].volumeChanged.changed=0xff; - } + chan[c.chan].volChangedL=true; + chan[c.chan].volChangedR=true; break; case DIV_CMD_PITCH: chan[c.chan].pitch=c.value; @@ -328,14 +310,15 @@ int DivPlatformC140::dispatch(DivCommand c) { void DivPlatformC140::muteChannel(int ch, bool mute) { isMuted[ch]=mute; - chan[ch].volumeChanged.changed=0xff; + c140.voice[ch].muted=mute; } void DivPlatformC140::forceIns() { for (int i=0; i<24; i++) { chan[i].insChanged=true; chan[i].freqChanged=true; - chan[i].volumeChanged.changed=0xff; + chan[i].volChangedL=true; + chan[i].volChangedR=true; chan[i].sample=-1; } } @@ -480,7 +463,7 @@ int DivPlatformC140::init(DivEngine* p, int channels, int sugRate, const DivConf isMuted[i]=false; oscBuf[i]=new DivDispatchOscBuffer; } - sampleMem=new signed short[getSampleMemCapacity()/sizeof(short)]; + sampleMem=new short[getSampleMemCapacity()>>1]; sampleMemLen=0; c140_init(&c140); c140.sample_mem=sampleMem; diff --git a/src/engine/platform/c140.h b/src/engine/platform/c140.h index 5604a794e..fa221eec2 100644 --- a/src/engine/platform/c140.h +++ b/src/engine/platform/c140.h @@ -26,33 +26,20 @@ class DivPlatformC140: public DivDispatch { struct Channel: public SharedChannel { - struct VolumeUpdate { - union { // pack flag bits in single byte - struct { // flag bits - unsigned char left : 1; // left volume - unsigned char right : 1; // right volume - unsigned char reserved : 6; - }; - unsigned char changed = 0; // Packed flags are stored here - }; - - VolumeUpdate(): - changed(0) {} - } volumeChanged; - unsigned int audPos; int sample, wave; - bool setPos; + bool setPos, volChangedL, volChangedR; int chPanL, chPanR; int chVolL, chVolR; int macroVolMul; Channel(): SharedChannel(255), - volumeChanged(VolumeUpdate()), audPos(0), sample(-1), wave(-1), setPos(false), + volChangedL(false), + volChangedR(false), chPanL(255), chPanR(255), chVolL(255), diff --git a/src/engine/platform/sound/c140.c b/src/engine/platform/sound/c140.c index 948b2f074..d22677b24 100644 --- a/src/engine/platform/sound/c140.c +++ b/src/engine/platform/sound/c140.c @@ -52,8 +52,10 @@ void c140_tick(struct c140_t *c140, const int cycle) for (int i = 0; i < 24; i++) { c140_voice_tick(c140, i, cycle); - c140->lout += c140->voice[i].lout; - c140->rout += c140->voice[i].rout; + if (!c140->voice[i].muted) { + c140->lout += c140->voice[i].lout; + c140->rout += c140->voice[i].rout; + } } // scale as 16bit c140->lout >>= 10; @@ -131,6 +133,10 @@ void c140_init(struct c140_t *c140) << (exponent ? exponent - 1 : 0)); } } + for (int i = 0; i < 24; i++) + { + c140->voice[i].muted = false; + } } void c140_reset(struct c140_t *c140) @@ -186,4 +192,4 @@ void c140_write(struct c140_t *c140, const unsigned short addr, const unsigned c } } // Timer -} \ No newline at end of file +} diff --git a/src/engine/platform/sound/c140.h b/src/engine/platform/sound/c140.h index defe3f87d..6fe2c4930 100644 --- a/src/engine/platform/sound/c140.h +++ b/src/engine/platform/sound/c140.h @@ -2,9 +2,13 @@ ============================================================================ -Namco C140 sound emulator +MODIFIED Namco C140 sound emulator - MODIFIED VERSION by cam900 +MODIFICATION by tildearrow - adds muting function +THIS IS NOT THE ORIGINAL VERSION - you can find the original one in +commit 72d04777c013988ed8cf6da27c62a9d784a59dff + This file is licensed under zlib license. ============================================================================ @@ -49,6 +53,7 @@ extern "C" struct c140_voice_t { + bool muted; // muted - can be set by user bool busy; // busy flag bool keyon; // key on flag unsigned short freq; // sample frequency diff --git a/src/gui/debug.cpp b/src/gui/debug.cpp index a2089f47f..6e4a091da 100644 --- a/src/gui/debug.cpp +++ b/src/gui/debug.cpp @@ -1106,8 +1106,6 @@ void putDispatchChan(void* data, int chanNum, int type) { ImGui::Text("- chVolR: %.2x",ch->chVolR); ImGui::Text("- macroVolMul: %.2x",ch->macroVolMul); COMMON_CHAN_DEBUG_BOOL; - ImGui::TextColored(ch->volumeChanged.left?colorOn:colorOff,">> VolumeChangedLeft"); - ImGui::TextColored(ch->volumeChanged.right?colorOn:colorOff,">> VolumeChangedRight"); ImGui::TextColored(ch->setPos?colorOn:colorOff,">> SetPos"); break; }