clamp wave data

issue #267
This commit is contained in:
tildearrow 2022-03-11 16:58:43 -05:00
parent 5fadcf4891
commit ab3884e5aa
4 changed files with 20 additions and 6 deletions

View File

@ -97,8 +97,12 @@ void DivPlatformGB::updateWave() {
if (wt->max<1 || wt->len<1) { if (wt->max<1 || wt->len<1) {
rWrite(0x30+i,0); rWrite(0x30+i,0);
} else { } else {
unsigned char nibble1=15-((wt->data[(i*2)*wt->len/32]*15)/wt->max); int nibble1=15-((wt->data[(i*2)*wt->len/32]*15)/wt->max);
unsigned char nibble2=15-((wt->data[(1+i*2)*wt->len/32]*15)/wt->max); int nibble2=15-((wt->data[(1+i*2)*wt->len/32]*15)/wt->max);
if (nibble1<0) nibble1=0;
if (nibble1>15) nibble1=15;
if (nibble2<0) nibble2=0;
if (nibble2>15) nibble2=15;
rWrite(0x30+i,(nibble1<<4)|nibble2); rWrite(0x30+i,(nibble1<<4)|nibble2);
} }
} }

View File

@ -138,7 +138,10 @@ void DivPlatformPCE::updateWave(int ch) {
if (wt->max<1 || wt->len<1) { if (wt->max<1 || wt->len<1) {
chWrite(ch,0x06,0); chWrite(ch,0x06,0);
} else { } else {
chWrite(ch,0x06,wt->data[i*wt->len/32]*31/wt->max); int data=wt->data[i*wt->len/32]*31/wt->max;
if (data<0) data=0;
if (data>31) data=31;
chWrite(ch,0x06,data);
} }
} }
if (chan[ch].active) { if (chan[ch].active) {

View File

@ -119,8 +119,12 @@ void DivPlatformSwan::updateWave(int ch) {
} }
} else { } else {
for (int i=0; i<16; i++) { for (int i=0; i<16; i++) {
unsigned char nibble1=(wt->data[(i*2)*wt->len/32]*15)/wt->max; int nibble1=(wt->data[(i*2)*wt->len/32]*15)/wt->max;
unsigned char nibble2=(wt->data[(1+i*2)*wt->len/32]*15)/wt->max; int nibble2=(wt->data[(1+i*2)*wt->len/32]*15)/wt->max;
if (nibble1<0) nibble1=0;
if (nibble1>15) nibble1=15;
if (nibble2<0) nibble2=0;
if (nibble2>15) nibble2=15;
rWrite(addr+i,nibble1|(nibble2<<4)); rWrite(addr+i,nibble1|(nibble2<<4));
} }
} }

View File

@ -282,7 +282,10 @@ void DivPlatformX1_010::updateWave(int ch) {
if (wt->max<1 || wt->len<1) { if (wt->max<1 || wt->len<1) {
waveWrite(ch,i,0); waveWrite(ch,i,0);
} else { } else {
waveWrite(ch,i,wt->data[i*wt->len/128]*255/wt->max); int data=wt->data[i*wt->len/128]*255/wt->max;
if (data<0) data=0;
if (data>255) data=255;
waveWrite(ch,i,data);
} }
} }
if (!chan[ch].pcm) { if (!chan[ch].pcm) {