PCE: reduce CPU usage

This commit is contained in:
tildearrow 2022-01-12 22:14:20 -05:00
parent cd739f5fde
commit 9ff852d1db
3 changed files with 25 additions and 19 deletions

View File

@ -20,7 +20,8 @@ void DivPlatformPCE::acquire(short* bufL, short* bufR, size_t start, size_t len)
// PCM part // PCM part
for (int i=0; i<6; i++) { for (int i=0; i<6; i++) {
if (chan[i].pcm && chan[i].dacSample!=-1) { 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]; DivSample* s=parent->song.sample[chan[i].dacSample];
chWrite(i,0x07,0); chWrite(i,0x07,0);
if (s->depth==8) { 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) { if (chan[i].dacPos>=s->rendLength) {
chan[i].dacSample=-1; chan[i].dacSample=-1;
} }
chan[i].dacPeriod=chan[i].dacRate; chan[i].dacPeriod+=chan[i].dacRate;
} }
} }
} }
// PCE part // PCE part
while (!writes.empty()) { cycles=0;
while (!writes.empty() && cycles<24) {
QueuedWrite w=writes.front(); QueuedWrite w=writes.front();
pce->Write(cycles,w.addr,w.val); pce->Write(cycles,w.addr,w.val);
//cycles+=2;
writes.pop(); writes.pop();
} }
tempL=0; tempR=0; memset(tempL,0,24*sizeof(int));
pce->Update(4); memset(tempR,0,24*sizeof(int));
pce->Update(24);
pce->ResetTS(0); pce->ResetTS(0);
if (tempL<-32768) tempL=-32768; if (tempL[0]<-32768) tempL[0]=-32768;
if (tempL>32767) tempL=32767; if (tempL[0]>32767) tempL[0]=32767;
if (tempR<-32768) tempR=-32768; if (tempR[0]<-32768) tempR[0]=-32768;
if (tempR>32767) tempR=32767; if (tempR[0]>32767) tempR[0]=32767;
//printf("tempL: %d tempR: %d\n",tempL,tempR); //printf("tempL: %d tempR: %d\n",tempL,tempR);
bufL[h]=tempL; bufL[h]=tempL[0];
bufR[h]=tempR; bufR[h]=tempR[0];
} }
} }
@ -286,8 +290,8 @@ void DivPlatformPCE::reset() {
} }
pce->Power(0); pce->Power(0);
lastPan=0xff; lastPan=0xff;
tempL=0; memset(tempL,0,32*sizeof(int));
tempR=0; memset(tempR,0,32*sizeof(int));
cycles=0; cycles=0;
curChan=-1; curChan=-1;
sampleBank=0; sampleBank=0;
@ -311,9 +315,9 @@ bool DivPlatformPCE::keyOffAffectsArp(int ch) {
void DivPlatformPCE::setPAL(bool pal) { void DivPlatformPCE::setPAL(bool pal) {
if (pal) { // technically there is no PAL PC Engine but oh well... if (pal) { // technically there is no PAL PC Engine but oh well...
rate=1773448; rate=1773448/6;
} else { } else {
rate=1789773; rate=1789773/6;
} }
} }
@ -324,7 +328,7 @@ int DivPlatformPCE::init(DivEngine* p, int channels, int sugRate, bool pal) {
isMuted[i]=false; isMuted[i]=false;
} }
setPAL(pal); setPAL(pal);
pce=new PCE_PSG(&tempL,&tempR,PCE_PSG::REVISION_HUC6280); pce=new PCE_PSG(tempL,tempR,PCE_PSG::REVISION_HUC6280);
reset(); reset();
return 6; return 6;
} }

View File

@ -49,7 +49,9 @@ class DivPlatformPCE: public DivDispatch {
std::queue<QueuedWrite> writes; std::queue<QueuedWrite> writes;
unsigned char lastPan; unsigned char lastPan;
int tempL, tempR, cycles, curChan, delay; int cycles, curChan, delay;
int tempL[32];
int tempR[32];
unsigned char sampleBank; unsigned char sampleBank;
PCE_PSG* pce; PCE_PSG* pce;
void updateWave(int ch); void updateWave(int ch);

View File

@ -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) 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[0][timestamp]+=samp0;
HRBufs[1][0]+=samp1; HRBufs[1][timestamp]+=samp1;
/* /*
int32_t delta[2]; int32_t delta[2];