VERA: fix possible PCM crash

This commit is contained in:
tildearrow 2023-11-25 17:28:30 -05:00
parent dff445fa41
commit a7be3e9514
2 changed files with 13 additions and 5 deletions

View file

@ -70,10 +70,18 @@ void DivPlatformVERA::acquire(short** buf, size_t len) {
if (!isMuted[16]) {
// TODO stereo samples once DivSample has a support for it
if (chan[16].pcm.depth16) {
tmp_l=s->data16[chan[16].pcm.pos];
if (chan[16].pcm.pos<s->samples) {
tmp_l=s->data16[chan[16].pcm.pos];
} else {
tmp_l=0;
}
tmp_r=tmp_l;
} else {
tmp_l=s->data8[chan[16].pcm.pos];
if (chan[16].pcm.pos<s->samples) {
tmp_l=s->data8[chan[16].pcm.pos];
} else {
tmp_l=0;
}
tmp_r=tmp_l;
}
if (!(chan[16].pan&1)) tmp_l=0;

View file

@ -30,13 +30,13 @@ class DivPlatformVERA: public DivDispatch {
protected:
struct Channel: public SharedChannel<int> {
unsigned char pan;
unsigned accum;
unsigned int accum;
int noiseval;
struct PCMChannel {
int sample;
unsigned pos;
unsigned len;
unsigned int pos;
unsigned int len;
unsigned char freq;
bool depth16;
PCMChannel(): sample(-1), pos(0), len(0), freq(0), depth16(false) {}