Reduce performance issue

This commit is contained in:
cam900 2022-08-28 10:50:57 +09:00
parent e3aee980c5
commit 3fcccb52ee
17 changed files with 76 additions and 76 deletions

View file

@ -99,9 +99,9 @@ void DivPlatformAmiga::acquire(short* bufL, short* bufR, size_t start, size_t le
if (chan[i].audPos<s->samples) { if (chan[i].audPos<s->samples) {
writeAudDat(s->data8[chan[i].audPos++]); writeAudDat(s->data8[chan[i].audPos++]);
} }
if (s->isLoopable() && chan[i].audPos>=MIN(131071,(unsigned int)s->getLoopEndPosition())) { if (s->isLoopable() && chan[i].audPos>=MIN(131071,(unsigned int)s->loopEnd)) {
chan[i].audPos=s->getLoopStartPosition(); chan[i].audPos=s->loopStart;
} else if (chan[i].audPos>=MIN(131071,(unsigned int)s->getEndPosition())) { } else if (chan[i].audPos>=MIN(131071,s->samples)) {
chan[i].sample=-1; chan[i].sample=-1;
} }
} else { } else {

View file

@ -104,9 +104,9 @@ void DivPlatformAY8910::acquire(short* bufL, short* bufR, size_t start, size_t l
changed=true; changed=true;
} }
chan[i].dac.pos++; chan[i].dac.pos++;
if (s->isLoopable() && chan[i].dac.pos>=s->getLoopEndPosition()) { if (s->isLoopable() && chan[i].dac.pos>=s->loopEnd) {
chan[i].dac.pos=s->getLoopStartPosition(); chan[i].dac.pos=s->loopStart;
} else if (chan[i].dac.pos>=s->getEndPosition()) { } else if (chan[i].dac.pos>=(int)s->samples) {
chan[i].dac.sample=-1; chan[i].dac.sample=-1;
rWrite(0x08+i,0); rWrite(0x08+i,0);
end=true; end=true;

View file

@ -108,9 +108,9 @@ void DivPlatformAY8930::acquire(short* bufL, short* bufR, size_t start, size_t l
changed=true; changed=true;
} }
chan[i].dac.pos++; chan[i].dac.pos++;
if (s->isLoopable() && chan[i].dac.pos>=s->getLoopEndPosition()) { if (s->isLoopable() && chan[i].dac.pos>=s->loopEnd) {
chan[i].dac.pos=s->getLoopStartPosition(); chan[i].dac.pos=s->loopStart;
} else if (chan[i].dac.pos>=s->getEndPosition()) { } else if (chan[i].dac.pos>=(int)s->samples) {
chan[i].dac.sample=-1; chan[i].dac.sample=-1;
rWrite(0x08+i,0); rWrite(0x08+i,0);
end=true; end=true;

View file

@ -52,9 +52,9 @@ void DivPlatformGenesis::processDAC() {
if (s->samples>0) { if (s->samples>0) {
while (chan[i].dacPeriod>=(chipClock/576)) { while (chan[i].dacPeriod>=(chipClock/576)) {
++chan[i].dacPos; ++chan[i].dacPos;
if (!chan[i].dacDirection && (s->isLoopable() && chan[i].dacPos>=(unsigned int)s->getLoopEndPosition())) { if (!chan[i].dacDirection && (s->isLoopable() && chan[i].dacPos>=(unsigned int)s->loopEnd)) {
chan[i].dacPos=s->getLoopStartPosition(); chan[i].dacPos=s->loopStart;
} else if (chan[i].dacPos>=(unsigned int)s->getEndPosition()) { } else if (chan[i].dacPos>=s->samples) {
chan[i].dacSample=-1; chan[i].dacSample=-1;
chan[i].dacPeriod=0; chan[i].dacPeriod=0;
break; break;
@ -98,9 +98,9 @@ void DivPlatformGenesis::processDAC() {
} }
} }
chan[5].dacPos++; chan[5].dacPos++;
if (!chan[5].dacDirection && (s->isLoopable() && chan[5].dacPos>=(unsigned int)s->getLoopEndPosition())) { if (!chan[5].dacDirection && (s->isLoopable() && chan[5].dacPos>=(unsigned int)s->loopEnd)) {
chan[5].dacPos=s->getLoopStartPosition(); chan[5].dacPos=s->loopStart;
} else if (chan[5].dacPos>=(unsigned int)s->getEndPosition()) { } else if (chan[5].dacPos>=s->samples) {
chan[5].dacSample=-1; chan[5].dacSample=-1;
if (parent->song.brokenDACMode) { if (parent->song.brokenDACMode) {
rWrite(0x2b,0); rWrite(0x2b,0);

View file

@ -146,9 +146,9 @@ void DivPlatformLynx::acquire(short* bufL, short* bufR, size_t start, size_t len
WRITE_OUTPUT(i,CLAMP((s->data8[chan[i].samplePos++]*chan[i].outVol)>>7,-128,127)); WRITE_OUTPUT(i,CLAMP((s->data8[chan[i].samplePos++]*chan[i].outVol)>>7,-128,127));
} }
if (s->isLoopable() && chan[i].samplePos>=s->getLoopEndPosition()) { if (s->isLoopable() && chan[i].samplePos>=s->loopEnd) {
chan[i].samplePos=s->getLoopStartPosition(); chan[i].samplePos=s->loopStart;
} else if (chan[i].samplePos>=s->getEndPosition()) { } else if (chan[i].samplePos>=(int)s->samples) {
chan[i].sample=-1; chan[i].sample=-1;
} }
} }

View file

@ -54,9 +54,9 @@ void DivPlatformMMC5::acquire(short* bufL, short* bufR, size_t start, size_t len
rWrite(0x5011,((unsigned char)s->data8[dacPos]+0x80)); rWrite(0x5011,((unsigned char)s->data8[dacPos]+0x80));
} }
dacPos++; dacPos++;
if (s->isLoopable() && dacPos>=(unsigned int)s->getLoopEndPosition()) { if (s->isLoopable() && dacPos>=(unsigned int)s->loopEnd) {
dacPos=s->getLoopStartPosition(); dacPos=s->loopStart;
} else if (dacPos>=(unsigned int)s->getEndPosition()) { } else if (dacPos>=s->samples) {
dacSample=-1; dacSample=-1;
} }
dacPeriod-=rate; dacPeriod-=rate;

View file

@ -88,9 +88,9 @@ void DivPlatformNES::doWrite(unsigned short addr, unsigned char data) {
} \ } \
} \ } \
dacPos++; \ dacPos++; \
if (s->isLoopable() && dacPos>=(unsigned int)s->getLoopEndPosition()) { \ if (s->isLoopable() && dacPos>=(unsigned int)s->loopEnd) { \
dacPos=s->getLoopStartPosition(); \ dacPos=s->loopStart; \
} else if (dacPos>=(unsigned int)s->getEndPosition()) { \ } else if (dacPos>=s->samples) { \
dacSample=-1; \ dacSample=-1; \
} \ } \
dacPeriod-=rate; \ dacPeriod-=rate; \

View file

@ -76,9 +76,9 @@ void DivPlatformPCE::acquire(short* bufL, short* bufR, size_t start, size_t len)
chWrite(i,0x06,0x10); chWrite(i,0x06,0x10);
} }
chan[i].dacPos++; chan[i].dacPos++;
if (s->isLoopable() && chan[i].dacPos>=(unsigned int)s->getLoopEndPosition()) { if (s->isLoopable() && chan[i].dacPos>=(unsigned int)s->loopEnd) {
chan[i].dacPos=s->getLoopStartPosition(); chan[i].dacPos=s->loopStart;
} else if (chan[i].dacPos>=(unsigned int)s->getEndPosition()) { } else if (chan[i].dacPos>=s->samples) {
chan[i].dacSample=-1; chan[i].dacSample=-1;
} }
chan[i].dacPeriod-=rate; chan[i].dacPeriod-=rate;

View file

@ -56,14 +56,14 @@ void DivPlatformPCMDAC::acquire(short* bufL, short* bufR, size_t start, size_t l
switch (s->loopMode) { switch (s->loopMode) {
case DIV_SAMPLE_LOOP_FORWARD: case DIV_SAMPLE_LOOP_FORWARD:
case DIV_SAMPLE_LOOP_PINGPONG: case DIV_SAMPLE_LOOP_PINGPONG:
if (chan.audPos<s->getLoopStartPosition()) { if (chan.audPos<s->loopStart) {
chan.audPos=s->getLoopStartPosition()+(s->getLoopStartPosition()-chan.audPos); chan.audPos=s->loopStart+(s->loopStart-chan.audPos);
chan.audDir=false; chan.audDir=false;
} }
break; break;
case DIV_SAMPLE_LOOP_BACKWARD: case DIV_SAMPLE_LOOP_BACKWARD:
if (chan.audPos<s->getLoopStartPosition()) { if (chan.audPos<s->loopStart) {
chan.audPos=s->getLoopEndPosition()-1-(s->getLoopStartPosition()-chan.audPos); chan.audPos=s->loopEnd-1-(s->loopStart-chan.audPos);
chan.audDir=true; chan.audDir=true;
} }
break; break;
@ -73,36 +73,36 @@ void DivPlatformPCMDAC::acquire(short* bufL, short* bufR, size_t start, size_t l
} }
break; break;
} }
} else if (chan.audPos>=s->getEndPosition()) { } else if (chan.audPos>=(int)s->samples) {
chan.sample=-1; chan.sample=-1;
} }
} else { } else {
if (s->isLoopable()) { if (s->isLoopable()) {
switch (s->loopMode) { switch (s->loopMode) {
case DIV_SAMPLE_LOOP_FORWARD: case DIV_SAMPLE_LOOP_FORWARD:
if (chan.audPos>=s->getLoopEndPosition()) { if (chan.audPos>=s->loopEnd) {
chan.audPos=(chan.audPos+s->getLoopStartPosition())-s->getLoopEndPosition(); chan.audPos=(chan.audPos+s->loopStart)-s->loopEnd;
chan.audDir=false; chan.audDir=false;
} }
break; break;
case DIV_SAMPLE_LOOP_BACKWARD: case DIV_SAMPLE_LOOP_BACKWARD:
case DIV_SAMPLE_LOOP_PINGPONG: case DIV_SAMPLE_LOOP_PINGPONG:
if (chan.audPos>=s->getLoopEndPosition()) { if (chan.audPos>=s->loopEnd) {
chan.audPos=s->getLoopEndPosition()-1-(s->getLoopEndPosition()-1-chan.audPos); chan.audPos=s->loopEnd-1-(s->loopEnd-1-chan.audPos);
chan.audDir=true; chan.audDir=true;
} }
break; break;
default: default:
if (chan.audPos>=s->getEndPosition()) { if (chan.audPos>=(int)s->samples) {
chan.sample=-1; chan.sample=-1;
} }
break; break;
} }
} else if (chan.audPos>=s->getEndPosition()) { } else if (chan.audPos>=(int)s->samples) {
chan.sample=-1; chan.sample=-1;
} }
} }
if (chan.audPos>=0 && chan.audPos<s->getEndPosition()) { if (chan.audPos>=0 && chan.audPos<(int)s->samples) {
output=s->data16[chan.audPos]; output=s->data16[chan.audPos];
} }
} else { } else {

View file

@ -289,8 +289,8 @@ void DivPlatformQSound::tick(bool sysTick) {
qsound_bank = 0x8000 | (s->offQSound >> 16); qsound_bank = 0x8000 | (s->offQSound >> 16);
qsound_addr = s->offQSound & 0xffff; qsound_addr = s->offQSound & 0xffff;
int loopStart=s->getLoopStartPosition(); int loopStart=s->loopStart;
int length = s->getLoopEndPosition(); int length = s->loopEnd;
if (length > 65536 - 16) { if (length > 65536 - 16) {
length = 65536 - 16; length = 65536 - 16;
} }

View file

@ -136,7 +136,7 @@ void DivPlatformRF5C68::tick(bool sysTick) {
start=start+MIN(chan[i].audPos,s->length8); start=start+MIN(chan[i].audPos,s->length8);
} }
if (s->isLoopable()) { if (s->isLoopable()) {
loop=start+s->getLoopStartPosition(); loop=start+s->loopStart;
} }
start=MIN(start,getSampleMemCapacity()-31); start=MIN(start,getSampleMemCapacity()-31);
loop=MIN(loop,getSampleMemCapacity()-31); loop=MIN(loop,getSampleMemCapacity()-31);

View file

@ -47,9 +47,9 @@ void DivPlatformSegaPCM::acquire(short* bufL, short* bufR, size_t start, size_t
pcmR+=(s->data8[chan[i].pcm.pos>>8]*chan[i].chVolR); pcmR+=(s->data8[chan[i].pcm.pos>>8]*chan[i].chVolR);
} }
chan[i].pcm.pos+=chan[i].pcm.freq; chan[i].pcm.pos+=chan[i].pcm.freq;
if (s->isLoopable() && chan[i].pcm.pos>=((unsigned int)s->getLoopEndPosition()<<8)) { if (s->isLoopable() && chan[i].pcm.pos>=((unsigned int)s->loopEnd<<8)) {
chan[i].pcm.pos=s->getLoopStartPosition()<<8; chan[i].pcm.pos=s->loopStart<<8;
} else if (chan[i].pcm.pos>=((unsigned int)s->getEndPosition()<<8)) { } else if (chan[i].pcm.pos>=(s->samples<<8)) {
chan[i].pcm.sample=-1; chan[i].pcm.sample=-1;
} }
} else { } else {

View file

@ -552,7 +552,7 @@ void DivPlatformSoundUnit::renderSamples() {
for (int i=0; i<parent->song.sampleLen; i++) { for (int i=0; i<parent->song.sampleLen; i++) {
DivSample* s=parent->song.sample[i]; DivSample* s=parent->song.sample[i];
if (s->data8==NULL) continue; if (s->data8==NULL) continue;
int paddedLen=s->getEndPosition(); int paddedLen=s->length8;
if (memPos>=getSampleMemCapacity(0)) { if (memPos>=getSampleMemCapacity(0)) {
logW("out of PCM memory for sample %d!",i); logW("out of PCM memory for sample %d!",i);
break; break;

View file

@ -62,9 +62,9 @@ void DivPlatformSwan::acquire(short* bufL, short* bufR, size_t start, size_t len
continue; continue;
} }
rWrite(0x09,(unsigned char)s->data8[dacPos++]+0x80); rWrite(0x09,(unsigned char)s->data8[dacPos++]+0x80);
if (s->isLoopable() && dacPos>=(unsigned int)s->getLoopEndPosition()) { if (s->isLoopable() && dacPos>=(unsigned int)s->loopEnd) {
dacPos=s->getLoopStartPosition(); dacPos=s->loopStart;
} else if (dacPos>=(unsigned int)s->getEndPosition()) { } else if (dacPos>=s->samples) {
dacSample=-1; dacSample=-1;
} }
dacPeriod-=rate; dacPeriod-=rate;

View file

@ -84,9 +84,9 @@ void DivPlatformVERA::acquire(short* bufL, short* bufR, size_t start, size_t len
rWritePCMData(tmp_r&0xff); rWritePCMData(tmp_r&0xff);
} }
chan[16].pcm.pos++; chan[16].pcm.pos++;
if (s->isLoopable() && chan[16].pcm.pos>=(unsigned int)s->getLoopEndPosition()) { if (s->isLoopable() && chan[16].pcm.pos>=(unsigned int)s->loopEnd) {
chan[16].pcm.pos=s->getLoopStartPosition(); chan[16].pcm.pos=s->loopStart;
} else if (chan[16].pcm.pos>=(unsigned int)s->getEndPosition()) { } else if (chan[16].pcm.pos>=s->samples) {
chan[16].pcm.sample=-1; chan[16].pcm.sample=-1;
break; break;
} }

View file

@ -65,9 +65,9 @@ void DivPlatformVRC6::acquire(short* bufL, short* bufR, size_t start, size_t len
chWrite(i,0,0x80|chan[i].dacOut); chWrite(i,0,0x80|chan[i].dacOut);
} }
chan[i].dacPos++; chan[i].dacPos++;
if (s->isLoopable() && chan[i].dacPos>=(unsigned int)s->getLoopEndPosition()) { if (s->isLoopable() && chan[i].dacPos>=(unsigned int)s->loopEnd) {
chan[i].dacPos=s->getLoopStartPosition(); chan[i].dacPos=s->loopStart;
} else if (chan[i].dacPos>=(unsigned int)s->getEndPosition()) { } else if (chan[i].dacPos>=s->samples) {
chan[i].dacSample=-1; chan[i].dacSample=-1;
chWrite(i,0,0); chWrite(i,0,0);
} }

View file

@ -1334,19 +1334,19 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
samp_prevSample=samp_temp; samp_prevSample=samp_temp;
if (sPreview.dir) { // backward if (sPreview.dir) { // backward
if (sPreview.pos<s->getLoopStartPosition() || (sPreview.pBegin>=0 && sPreview.pos<sPreview.pBegin)) { if (sPreview.pos<s->loopStart || (sPreview.pBegin>=0 && sPreview.pos<sPreview.pBegin)) {
if (s->isLoopable() && sPreview.pos<s->getLoopEndPosition()) { if (s->isLoopable() && sPreview.pos<s->loopEnd) {
switch (s->loopMode) { switch (s->loopMode) {
case DivSampleLoopMode::DIV_SAMPLE_LOOP_FORWARD: case DivSampleLoopMode::DIV_SAMPLE_LOOP_FORWARD:
sPreview.pos=s->getLoopStartPosition(); sPreview.pos=s->loopStart;
sPreview.dir=false; sPreview.dir=false;
break; break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_BACKWARD: case DivSampleLoopMode::DIV_SAMPLE_LOOP_BACKWARD:
sPreview.pos=s->getLoopEndPosition()-1; sPreview.pos=s->loopEnd-1;
sPreview.dir=true; sPreview.dir=true;
break; break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_PINGPONG: case DivSampleLoopMode::DIV_SAMPLE_LOOP_PINGPONG:
sPreview.pos=s->getLoopStartPosition(); sPreview.pos=s->loopStart;
sPreview.dir=false; sPreview.dir=false;
break; break;
default: default:
@ -1355,19 +1355,19 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
} }
} }
} else { // forward } else { // forward
if (sPreview.pos>=s->getLoopEndPosition() || (sPreview.pEnd>=0 && sPreview.pos>=sPreview.pEnd)) { if (sPreview.pos>=s->loopEnd || (sPreview.pEnd>=0 && sPreview.pos>=sPreview.pEnd)) {
if (s->isLoopable() && sPreview.pos>=s->getLoopStartPosition()) { if (s->isLoopable() && sPreview.pos>=s->loopStart) {
switch (s->loopMode) { switch (s->loopMode) {
case DivSampleLoopMode::DIV_SAMPLE_LOOP_FORWARD: case DivSampleLoopMode::DIV_SAMPLE_LOOP_FORWARD:
sPreview.pos=s->getLoopStartPosition(); sPreview.pos=s->loopStart;
sPreview.dir=false; sPreview.dir=false;
break; break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_BACKWARD: case DivSampleLoopMode::DIV_SAMPLE_LOOP_BACKWARD:
sPreview.pos=s->getLoopEndPosition()-1; sPreview.pos=s->loopEnd-1;
sPreview.dir=true; sPreview.dir=true;
break; break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_PINGPONG: case DivSampleLoopMode::DIV_SAMPLE_LOOP_PINGPONG:
sPreview.pos=s->getLoopEndPosition()-1; sPreview.pos=s->loopEnd-1;
sPreview.dir=true; sPreview.dir=true;
break; break;
default: default:
@ -1378,19 +1378,19 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
} }
} }
if (sPreview.dir) { // backward if (sPreview.dir) { // backward
if (sPreview.pos<=s->getLoopStartPosition() || (sPreview.pBegin>=0 && sPreview.pos<=sPreview.pBegin)) { if (sPreview.pos<=s->loopStart || (sPreview.pBegin>=0 && sPreview.pos<=sPreview.pBegin)) {
if (s->isLoopable() && sPreview.pos>=s->getLoopStartPosition()) { if (s->isLoopable() && sPreview.pos>=s->loopStart) {
switch (s->loopMode) { switch (s->loopMode) {
case DivSampleLoopMode::DIV_SAMPLE_LOOP_FORWARD: case DivSampleLoopMode::DIV_SAMPLE_LOOP_FORWARD:
sPreview.pos=s->getLoopStartPosition(); sPreview.pos=s->loopStart;
sPreview.dir=false; sPreview.dir=false;
break; break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_BACKWARD: case DivSampleLoopMode::DIV_SAMPLE_LOOP_BACKWARD:
sPreview.pos=s->getLoopEndPosition()-1; sPreview.pos=s->loopEnd-1;
sPreview.dir=true; sPreview.dir=true;
break; break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_PINGPONG: case DivSampleLoopMode::DIV_SAMPLE_LOOP_PINGPONG:
sPreview.pos=s->getLoopStartPosition(); sPreview.pos=s->loopStart;
sPreview.dir=false; sPreview.dir=false;
break; break;
default: default:
@ -1401,25 +1401,25 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
} }
} }
} else { // forward } else { // forward
if (sPreview.pos>=s->getLoopEndPosition() || (sPreview.pEnd>=0 && sPreview.pos>=sPreview.pEnd)) { if (sPreview.pos>=s->loopEnd || (sPreview.pEnd>=0 && sPreview.pos>=sPreview.pEnd)) {
if (s->isLoopable() && sPreview.pos>=s->getLoopStartPosition()) { if (s->isLoopable() && sPreview.pos>=s->loopStart) {
switch (s->loopMode) { switch (s->loopMode) {
case DivSampleLoopMode::DIV_SAMPLE_LOOP_FORWARD: case DivSampleLoopMode::DIV_SAMPLE_LOOP_FORWARD:
sPreview.pos=s->getLoopStartPosition(); sPreview.pos=s->loopStart;
sPreview.dir=false; sPreview.dir=false;
break; break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_BACKWARD: case DivSampleLoopMode::DIV_SAMPLE_LOOP_BACKWARD:
sPreview.pos=s->getLoopEndPosition()-1; sPreview.pos=s->loopEnd-1;
sPreview.dir=true; sPreview.dir=true;
break; break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_PINGPONG: case DivSampleLoopMode::DIV_SAMPLE_LOOP_PINGPONG:
sPreview.pos=s->getLoopEndPosition()-1; sPreview.pos=s->loopEnd-1;
sPreview.dir=true; sPreview.dir=true;
break; break;
default: default:
break; break;
} }
} else if (sPreview.pos>=s->getEndPosition()) { } else if (sPreview.pos>=(int)s->samples) {
sPreview.sample=-1; sPreview.sample=-1;
} }
} }