prevent division by zero, part 1

This commit is contained in:
tildearrow 2022-02-15 15:19:36 -05:00
parent 6960112f69
commit b24c572632
4 changed files with 6 additions and 4 deletions

View File

@ -4017,7 +4017,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop) {
}
}
if (nextToTouch>=0) {
double waitTime=totalWait+(loopTimer[nextToTouch]*(44100.0/loopFreq[nextToTouch]));
double waitTime=totalWait+(loopTimer[nextToTouch]*(44100.0/MIN(1,loopFreq[nextToTouch])));
if (waitTime>0) {
w->writeC(0x61);
w->writeS(waitTime);

View File

@ -385,7 +385,8 @@ void DivPlatformGenesis::tick() {
off=8363.0/(double)s->centerRate;
}
}
dacRate=(1280000*1.25*off)/chan[i].baseFreq;
dacRate=(1280000*1.25*off)/MIN(1,chan[i].baseFreq);
if (dacRate<1) dacRate=1;
if (dumpWrites) addWrite(0xffff0001,1280000/dacRate);
}
chan[i].freqChanged=false;
@ -514,7 +515,7 @@ int DivPlatformGenesis::dispatch(DivCommand c) {
}
dacPos=0;
dacPeriod=0;
dacRate=1280000/parent->song.sample[dacSample]->rate;
dacRate=1280000/MIN(1,parent->song.sample[dacSample]->rate);
if (dumpWrites) addWrite(0xffff0001,parent->song.sample[dacSample]->rate);
chan[c.chan].furnaceDac=false;
}

View File

@ -209,7 +209,7 @@ void DivPlatformPCE::tick() {
off=8363.0/(double)s->centerRate;
}
}
chan[i].dacRate=((double)chipClock/2)/(off*chan[i].freq);
chan[i].dacRate=((double)chipClock/2)/MIN(1,off*chan[i].freq);
if (dumpWrites) addWrite(0xffff0001+(i<<8),chan[i].dacRate);
}
if (chan[i].freq>4095) chan[i].freq=4095;

View File

@ -57,6 +57,7 @@ unsigned char DivPlatformTIA::dealWithFreq(unsigned char shape, int base, int pi
}
int bp=base+pitch;
double mult=0.25*(parent->song.tuning*0.0625)*pow(2.0,double(768+bp)/(256.0*12.0));
if (mult<0.5) mult=0.5;
switch (shape) {
case 1: // buzzy
return ceil(31400/(30.6*mult))-1;