prevent crash when playing empty sample

fixes #62
This commit is contained in:
tildearrow 2022-01-24 15:47:39 -05:00
parent c8eeac4f63
commit bd8c06bbb7
5 changed files with 58 additions and 34 deletions

View file

@ -10,21 +10,25 @@ void DivPlatformAmiga::acquire(short* bufL, short* bufR, size_t start, size_t le
bufL[h]=0;
bufR[h]=0;
for (int i=0; i<4; i++) {
if (chan[i].sample!=-1) {
if (chan[i].sample>=0 && chan[i].sample<parent->song.sampleLen) {
chan[i].audSub-=AMIGA_DIVIDER;
if (chan[i].audSub<0) {
DivSample* s=parent->song.sample[chan[i].sample];
if (s->depth==8) {
chan[i].audDat=s->rendData[chan[i].audPos++];
} else {
chan[i].audDat=s->rendData[chan[i].audPos++]>>8;
}
if (chan[i].audPos>=s->rendLength || chan[i].audPos>=131071) {
if (s->loopStart>=0 && s->loopStart<=(int)s->rendLength) {
chan[i].audPos=s->loopStart;
if (s->rendLength>0) {
if (s->depth==8) {
chan[i].audDat=s->rendData[chan[i].audPos++];
} else {
chan[i].sample=-1;
chan[i].audDat=s->rendData[chan[i].audPos++]>>8;
}
if (chan[i].audPos>=s->rendLength || chan[i].audPos>=131071) {
if (s->loopStart>=0 && s->loopStart<=(int)s->rendLength) {
chan[i].audPos=s->loopStart;
} else {
chan[i].sample=-1;
}
}
} else {
chan[i].sample=-1;
}
/*if (chan[i].freq<124) {
// ???

View file

@ -61,6 +61,10 @@ void DivPlatformArcade::acquire_nuked(short* bufL, short* bufR, size_t start, si
for (int i=8; i<13; i++) {
if (chan[i].pcm.sample>=0) {
DivSample* s=parent->song.sample[chan[i].pcm.sample];
if (s->rendLength<=0) {
chan[i].pcm.sample=-1;
continue;
}
if (!isMuted[i]) {
if (s->depth==8) {
pcmL+=(s->rendData[chan[i].pcm.pos>>8]*chan[i].chVolL);
@ -123,6 +127,10 @@ void DivPlatformArcade::acquire_ymfm(short* bufL, short* bufR, size_t start, siz
for (int i=8; i<13; i++) {
if (chan[i].pcm.sample>=0 && chan[i].pcm.sample<parent->song.sampleLen) {
DivSample* s=parent->song.sample[chan[i].pcm.sample];
if (s->rendLength<=0) {
chan[i].pcm.sample=-1;
continue;
}
if (!isMuted[i]) {
if (s->depth==8) {
pcmL+=(s->rendData[chan[i].pcm.pos>>8]*chan[i].chVolL);

View file

@ -18,21 +18,25 @@ void DivPlatformGenesis::acquire(short* bufL, short* bufR, size_t start, size_t
dacPeriod-=6;
if (dacPeriod<1) {
DivSample* s=parent->song.sample[dacSample];
if (!isMuted[5]) {
if (s->depth==8) {
immWrite(0x2a,(unsigned char)s->rendData[dacPos++]+0x80);
} else {
immWrite(0x2a,((unsigned short)s->rendData[dacPos++]+0x8000)>>8);
if (s->rendLength>0) {
if (!isMuted[5]) {
if (s->depth==8) {
immWrite(0x2a,(unsigned char)s->rendData[dacPos++]+0x80);
} else {
immWrite(0x2a,((unsigned short)s->rendData[dacPos++]+0x8000)>>8);
}
}
}
if (dacPos>=s->rendLength) {
if (s->loopStart>=0 && s->loopStart<=(int)s->rendLength) {
dacPos=s->loopStart;
} else {
dacSample=-1;
if (dacPos>=s->rendLength) {
if (s->loopStart>=0 && s->loopStart<=(int)s->rendLength) {
dacPos=s->loopStart;
} else {
dacSample=-1;
}
}
dacPeriod+=MAX(40,dacRate);
} else {
dacSample=-1;
}
dacPeriod+=MAX(40,dacRate);
}
}

View file

@ -15,21 +15,25 @@ void DivPlatformNES::acquire(short* bufL, short* bufR, size_t start, size_t len)
dacPeriod+=dacRate;
if (dacPeriod>=rate) {
DivSample* s=parent->song.sample[dacSample];
if (!isMuted[4]) {
if (s->depth==8) {
rWrite(0x4011,((unsigned char)s->rendData[dacPos++]+0x80)>>1);
} else {
rWrite(0x4011,((unsigned short)s->rendData[dacPos++]+0x8000)>>9);
if (s->rendLength>0) {
if (!isMuted[4]) {
if (s->depth==8) {
rWrite(0x4011,((unsigned char)s->rendData[dacPos++]+0x80)>>1);
} else {
rWrite(0x4011,((unsigned short)s->rendData[dacPos++]+0x8000)>>9);
}
}
}
if (dacPos>=s->rendLength) {
if (s->loopStart>=0 && s->loopStart<=(int)s->rendLength) {
dacPos=s->loopStart;
} else {
dacSample=-1;
if (dacPos>=s->rendLength) {
if (s->loopStart>=0 && s->loopStart<=(int)s->rendLength) {
dacPos=s->loopStart;
} else {
dacSample=-1;
}
}
dacPeriod-=rate;
} else {
dacSample=-1;
}
dacPeriod-=rate;
}
}

View file

@ -23,6 +23,10 @@ void DivPlatformPCE::acquire(short* bufL, short* bufR, size_t start, size_t len)
chan[i].dacPeriod-=6;
if (chan[i].dacPeriod<1) {
DivSample* s=parent->song.sample[chan[i].dacSample];
if (s->rendLength<=0) {
chan[i].dacSample=-1;
continue;
}
chWrite(i,0x07,0);
if (s->depth==8) {
chWrite(i,0x04,0xdf);