From 9ff852d1dbb7bb28bc2ff625690b2eebc058e444 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 12 Jan 2022 22:14:20 -0500 Subject: [PATCH] PCE: reduce CPU usage --- src/engine/platform/pce.cpp | 36 +++++++++++++++------------ src/engine/platform/pce.h | 4 ++- src/engine/platform/sound/pce_psg.cpp | 4 +-- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/engine/platform/pce.cpp b/src/engine/platform/pce.cpp index 0afb1958..1128622b 100644 --- a/src/engine/platform/pce.cpp +++ b/src/engine/platform/pce.cpp @@ -20,7 +20,8 @@ void DivPlatformPCE::acquire(short* bufL, short* bufR, size_t start, size_t len) // PCM part for (int i=0; i<6; i++) { if (chan[i].pcm && chan[i].dacSample!=-1) { - if (--chan[i].dacPeriod<1) { + chan[i].dacPeriod-=6; + if (chan[i].dacPeriod<1) { DivSample* s=parent->song.sample[chan[i].dacSample]; chWrite(i,0x07,0); if (s->depth==8) { @@ -33,29 +34,32 @@ void DivPlatformPCE::acquire(short* bufL, short* bufR, size_t start, size_t len) if (chan[i].dacPos>=s->rendLength) { chan[i].dacSample=-1; } - chan[i].dacPeriod=chan[i].dacRate; + chan[i].dacPeriod+=chan[i].dacRate; } } } // PCE part - while (!writes.empty()) { + cycles=0; + while (!writes.empty() && cycles<24) { QueuedWrite w=writes.front(); pce->Write(cycles,w.addr,w.val); + //cycles+=2; writes.pop(); } - tempL=0; tempR=0; - pce->Update(4); + memset(tempL,0,24*sizeof(int)); + memset(tempR,0,24*sizeof(int)); + pce->Update(24); pce->ResetTS(0); - if (tempL<-32768) tempL=-32768; - if (tempL>32767) tempL=32767; - if (tempR<-32768) tempR=-32768; - if (tempR>32767) tempR=32767; + if (tempL[0]<-32768) tempL[0]=-32768; + if (tempL[0]>32767) tempL[0]=32767; + if (tempR[0]<-32768) tempR[0]=-32768; + if (tempR[0]>32767) tempR[0]=32767; //printf("tempL: %d tempR: %d\n",tempL,tempR); - bufL[h]=tempL; - bufR[h]=tempR; + bufL[h]=tempL[0]; + bufR[h]=tempR[0]; } } @@ -286,8 +290,8 @@ void DivPlatformPCE::reset() { } pce->Power(0); lastPan=0xff; - tempL=0; - tempR=0; + memset(tempL,0,32*sizeof(int)); + memset(tempR,0,32*sizeof(int)); cycles=0; curChan=-1; sampleBank=0; @@ -311,9 +315,9 @@ bool DivPlatformPCE::keyOffAffectsArp(int ch) { void DivPlatformPCE::setPAL(bool pal) { if (pal) { // technically there is no PAL PC Engine but oh well... - rate=1773448; + rate=1773448/6; } else { - rate=1789773; + rate=1789773/6; } } @@ -324,7 +328,7 @@ int DivPlatformPCE::init(DivEngine* p, int channels, int sugRate, bool pal) { isMuted[i]=false; } setPAL(pal); - pce=new PCE_PSG(&tempL,&tempR,PCE_PSG::REVISION_HUC6280); + pce=new PCE_PSG(tempL,tempR,PCE_PSG::REVISION_HUC6280); reset(); return 6; } diff --git a/src/engine/platform/pce.h b/src/engine/platform/pce.h index 5c0bb352..930c9b59 100644 --- a/src/engine/platform/pce.h +++ b/src/engine/platform/pce.h @@ -49,7 +49,9 @@ class DivPlatformPCE: public DivDispatch { std::queue writes; unsigned char lastPan; - int tempL, tempR, cycles, curChan, delay; + int cycles, curChan, delay; + int tempL[32]; + int tempR[32]; unsigned char sampleBank; PCE_PSG* pce; void updateWave(int ch); diff --git a/src/engine/platform/sound/pce_psg.cpp b/src/engine/platform/sound/pce_psg.cpp index a38638bb..0e2a3930 100644 --- a/src/engine/platform/sound/pce_psg.cpp +++ b/src/engine/platform/sound/pce_psg.cpp @@ -70,8 +70,8 @@ static const int scale_tab[] = inline void PCE_PSG::UpdateOutputSub(const int32_t timestamp, psg_channel *ch, const int32_t samp0, const int32_t samp1) { - HRBufs[0][0]+=samp0; - HRBufs[1][0]+=samp1; + HRBufs[0][timestamp]+=samp0; + HRBufs[1][timestamp]+=samp1; /* int32_t delta[2];