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,10 +10,11 @@ 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->rendLength>0) {
if (s->depth==8) {
chan[i].audDat=s->rendData[chan[i].audPos++];
} else {
@ -26,6 +27,9 @@ void DivPlatformAmiga::acquire(short* bufL, short* bufR, size_t start, size_t le
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,6 +18,7 @@ void DivPlatformGenesis::acquire(short* bufL, short* bufR, size_t start, size_t
dacPeriod-=6;
if (dacPeriod<1) {
DivSample* s=parent->song.sample[dacSample];
if (s->rendLength>0) {
if (!isMuted[5]) {
if (s->depth==8) {
immWrite(0x2a,(unsigned char)s->rendData[dacPos++]+0x80);
@ -33,6 +34,9 @@ void DivPlatformGenesis::acquire(short* bufL, short* bufR, size_t start, size_t
}
}
dacPeriod+=MAX(40,dacRate);
} else {
dacSample=-1;
}
}
}

View File

@ -15,6 +15,7 @@ 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 (s->rendLength>0) {
if (!isMuted[4]) {
if (s->depth==8) {
rWrite(0x4011,((unsigned char)s->rendData[dacPos++]+0x80)>>1);
@ -30,6 +31,9 @@ void DivPlatformNES::acquire(short* bufL, short* bufR, size_t start, size_t len)
}
}
dacPeriod-=rate;
} else {
dacSample=-1;
}
}
}

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);