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) {
writeAudDat(s->data8[chan[i].audPos++]);
}
if (s->isLoopable() && chan[i].audPos>=MIN(131071,(unsigned int)s->getLoopEndPosition())) {
chan[i].audPos=s->getLoopStartPosition();
} else if (chan[i].audPos>=MIN(131071,(unsigned int)s->getEndPosition())) {
if (s->isLoopable() && chan[i].audPos>=MIN(131071,(unsigned int)s->loopEnd)) {
chan[i].audPos=s->loopStart;
} else if (chan[i].audPos>=MIN(131071,s->samples)) {
chan[i].sample=-1;
}
} else {

View File

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

View File

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

View File

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

View File

@ -88,9 +88,9 @@ void DivPlatformNES::doWrite(unsigned short addr, unsigned char data) {
} \
} \
dacPos++; \
if (s->isLoopable() && dacPos>=(unsigned int)s->getLoopEndPosition()) { \
dacPos=s->getLoopStartPosition(); \
} else if (dacPos>=(unsigned int)s->getEndPosition()) { \
if (s->isLoopable() && dacPos>=(unsigned int)s->loopEnd) { \
dacPos=s->loopStart; \
} else if (dacPos>=s->samples) { \
dacSample=-1; \
} \
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);
}
chan[i].dacPos++;
if (s->isLoopable() && chan[i].dacPos>=(unsigned int)s->getLoopEndPosition()) {
chan[i].dacPos=s->getLoopStartPosition();
} else if (chan[i].dacPos>=(unsigned int)s->getEndPosition()) {
if (s->isLoopable() && chan[i].dacPos>=(unsigned int)s->loopEnd) {
chan[i].dacPos=s->loopStart;
} else if (chan[i].dacPos>=s->samples) {
chan[i].dacSample=-1;
}
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) {
case DIV_SAMPLE_LOOP_FORWARD:
case DIV_SAMPLE_LOOP_PINGPONG:
if (chan.audPos<s->getLoopStartPosition()) {
chan.audPos=s->getLoopStartPosition()+(s->getLoopStartPosition()-chan.audPos);
if (chan.audPos<s->loopStart) {
chan.audPos=s->loopStart+(s->loopStart-chan.audPos);
chan.audDir=false;
}
break;
case DIV_SAMPLE_LOOP_BACKWARD:
if (chan.audPos<s->getLoopStartPosition()) {
chan.audPos=s->getLoopEndPosition()-1-(s->getLoopStartPosition()-chan.audPos);
if (chan.audPos<s->loopStart) {
chan.audPos=s->loopEnd-1-(s->loopStart-chan.audPos);
chan.audDir=true;
}
break;
@ -73,36 +73,36 @@ void DivPlatformPCMDAC::acquire(short* bufL, short* bufR, size_t start, size_t l
}
break;
}
} else if (chan.audPos>=s->getEndPosition()) {
} else if (chan.audPos>=(int)s->samples) {
chan.sample=-1;
}
} else {
if (s->isLoopable()) {
switch (s->loopMode) {
case DIV_SAMPLE_LOOP_FORWARD:
if (chan.audPos>=s->getLoopEndPosition()) {
chan.audPos=(chan.audPos+s->getLoopStartPosition())-s->getLoopEndPosition();
if (chan.audPos>=s->loopEnd) {
chan.audPos=(chan.audPos+s->loopStart)-s->loopEnd;
chan.audDir=false;
}
break;
case DIV_SAMPLE_LOOP_BACKWARD:
case DIV_SAMPLE_LOOP_PINGPONG:
if (chan.audPos>=s->getLoopEndPosition()) {
chan.audPos=s->getLoopEndPosition()-1-(s->getLoopEndPosition()-1-chan.audPos);
if (chan.audPos>=s->loopEnd) {
chan.audPos=s->loopEnd-1-(s->loopEnd-1-chan.audPos);
chan.audDir=true;
}
break;
default:
if (chan.audPos>=s->getEndPosition()) {
if (chan.audPos>=(int)s->samples) {
chan.sample=-1;
}
break;
}
} else if (chan.audPos>=s->getEndPosition()) {
} else if (chan.audPos>=(int)s->samples) {
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];
}
} else {

View File

@ -289,8 +289,8 @@ void DivPlatformQSound::tick(bool sysTick) {
qsound_bank = 0x8000 | (s->offQSound >> 16);
qsound_addr = s->offQSound & 0xffff;
int loopStart=s->getLoopStartPosition();
int length = s->getLoopEndPosition();
int loopStart=s->loopStart;
int length = s->loopEnd;
if (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);
}
if (s->isLoopable()) {
loop=start+s->getLoopStartPosition();
loop=start+s->loopStart;
}
start=MIN(start,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);
}
chan[i].pcm.pos+=chan[i].pcm.freq;
if (s->isLoopable() && chan[i].pcm.pos>=((unsigned int)s->getLoopEndPosition()<<8)) {
chan[i].pcm.pos=s->getLoopStartPosition()<<8;
} else if (chan[i].pcm.pos>=((unsigned int)s->getEndPosition()<<8)) {
if (s->isLoopable() && chan[i].pcm.pos>=((unsigned int)s->loopEnd<<8)) {
chan[i].pcm.pos=s->loopStart<<8;
} else if (chan[i].pcm.pos>=(s->samples<<8)) {
chan[i].pcm.sample=-1;
}
} else {

View File

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

View File

@ -62,9 +62,9 @@ void DivPlatformSwan::acquire(short* bufL, short* bufR, size_t start, size_t len
continue;
}
rWrite(0x09,(unsigned char)s->data8[dacPos++]+0x80);
if (s->isLoopable() && dacPos>=(unsigned int)s->getLoopEndPosition()) {
dacPos=s->getLoopStartPosition();
} else if (dacPos>=(unsigned int)s->getEndPosition()) {
if (s->isLoopable() && dacPos>=(unsigned int)s->loopEnd) {
dacPos=s->loopStart;
} else if (dacPos>=s->samples) {
dacSample=-1;
}
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);
}
chan[16].pcm.pos++;
if (s->isLoopable() && chan[16].pcm.pos>=(unsigned int)s->getLoopEndPosition()) {
chan[16].pcm.pos=s->getLoopStartPosition();
} else if (chan[16].pcm.pos>=(unsigned int)s->getEndPosition()) {
if (s->isLoopable() && chan[16].pcm.pos>=(unsigned int)s->loopEnd) {
chan[16].pcm.pos=s->loopStart;
} else if (chan[16].pcm.pos>=s->samples) {
chan[16].pcm.sample=-1;
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);
}
chan[i].dacPos++;
if (s->isLoopable() && chan[i].dacPos>=(unsigned int)s->getLoopEndPosition()) {
chan[i].dacPos=s->getLoopStartPosition();
} else if (chan[i].dacPos>=(unsigned int)s->getEndPosition()) {
if (s->isLoopable() && chan[i].dacPos>=(unsigned int)s->loopEnd) {
chan[i].dacPos=s->loopStart;
} else if (chan[i].dacPos>=s->samples) {
chan[i].dacSample=-1;
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;
if (sPreview.dir) { // backward
if (sPreview.pos<s->getLoopStartPosition() || (sPreview.pBegin>=0 && sPreview.pos<sPreview.pBegin)) {
if (s->isLoopable() && sPreview.pos<s->getLoopEndPosition()) {
if (sPreview.pos<s->loopStart || (sPreview.pBegin>=0 && sPreview.pos<sPreview.pBegin)) {
if (s->isLoopable() && sPreview.pos<s->loopEnd) {
switch (s->loopMode) {
case DivSampleLoopMode::DIV_SAMPLE_LOOP_FORWARD:
sPreview.pos=s->getLoopStartPosition();
sPreview.pos=s->loopStart;
sPreview.dir=false;
break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_BACKWARD:
sPreview.pos=s->getLoopEndPosition()-1;
sPreview.pos=s->loopEnd-1;
sPreview.dir=true;
break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_PINGPONG:
sPreview.pos=s->getLoopStartPosition();
sPreview.pos=s->loopStart;
sPreview.dir=false;
break;
default:
@ -1355,19 +1355,19 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
}
}
} else { // forward
if (sPreview.pos>=s->getLoopEndPosition() || (sPreview.pEnd>=0 && sPreview.pos>=sPreview.pEnd)) {
if (s->isLoopable() && sPreview.pos>=s->getLoopStartPosition()) {
if (sPreview.pos>=s->loopEnd || (sPreview.pEnd>=0 && sPreview.pos>=sPreview.pEnd)) {
if (s->isLoopable() && sPreview.pos>=s->loopStart) {
switch (s->loopMode) {
case DivSampleLoopMode::DIV_SAMPLE_LOOP_FORWARD:
sPreview.pos=s->getLoopStartPosition();
sPreview.pos=s->loopStart;
sPreview.dir=false;
break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_BACKWARD:
sPreview.pos=s->getLoopEndPosition()-1;
sPreview.pos=s->loopEnd-1;
sPreview.dir=true;
break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_PINGPONG:
sPreview.pos=s->getLoopEndPosition()-1;
sPreview.pos=s->loopEnd-1;
sPreview.dir=true;
break;
default:
@ -1378,19 +1378,19 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
}
}
if (sPreview.dir) { // backward
if (sPreview.pos<=s->getLoopStartPosition() || (sPreview.pBegin>=0 && sPreview.pos<=sPreview.pBegin)) {
if (s->isLoopable() && sPreview.pos>=s->getLoopStartPosition()) {
if (sPreview.pos<=s->loopStart || (sPreview.pBegin>=0 && sPreview.pos<=sPreview.pBegin)) {
if (s->isLoopable() && sPreview.pos>=s->loopStart) {
switch (s->loopMode) {
case DivSampleLoopMode::DIV_SAMPLE_LOOP_FORWARD:
sPreview.pos=s->getLoopStartPosition();
sPreview.pos=s->loopStart;
sPreview.dir=false;
break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_BACKWARD:
sPreview.pos=s->getLoopEndPosition()-1;
sPreview.pos=s->loopEnd-1;
sPreview.dir=true;
break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_PINGPONG:
sPreview.pos=s->getLoopStartPosition();
sPreview.pos=s->loopStart;
sPreview.dir=false;
break;
default:
@ -1401,25 +1401,25 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
}
}
} else { // forward
if (sPreview.pos>=s->getLoopEndPosition() || (sPreview.pEnd>=0 && sPreview.pos>=sPreview.pEnd)) {
if (s->isLoopable() && sPreview.pos>=s->getLoopStartPosition()) {
if (sPreview.pos>=s->loopEnd || (sPreview.pEnd>=0 && sPreview.pos>=sPreview.pEnd)) {
if (s->isLoopable() && sPreview.pos>=s->loopStart) {
switch (s->loopMode) {
case DivSampleLoopMode::DIV_SAMPLE_LOOP_FORWARD:
sPreview.pos=s->getLoopStartPosition();
sPreview.pos=s->loopStart;
sPreview.dir=false;
break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_BACKWARD:
sPreview.pos=s->getLoopEndPosition()-1;
sPreview.pos=s->loopEnd-1;
sPreview.dir=true;
break;
case DivSampleLoopMode::DIV_SAMPLE_LOOP_PINGPONG:
sPreview.pos=s->getLoopEndPosition()-1;
sPreview.pos=s->loopEnd-1;
sPreview.dir=true;
break;
default:
break;
}
} else if (sPreview.pos>=s->getEndPosition()) {
} else if (sPreview.pos>=(int)s->samples) {
sPreview.sample=-1;
}
}