games/snes: audio improvements

This commit is contained in:
aiju 2014-03-19 20:25:06 +01:00
parent 5b7ebd7be3
commit 90148cbe87

View file

@ -159,7 +159,7 @@ typedef struct {
u8int *r; u8int *r;
u16int hdrp, dp, sp; u16int hdrp, dp, sp;
u8int hdr; u8int hdr, bp;
u16int brr; u16int brr;
u8int envst; u8int envst;
@ -167,7 +167,7 @@ typedef struct {
u8int init; u8int init;
u16int interp; u16int interp;
s16int buf[12]; s16int buf[24];
u16int pitch; u16int pitch;
s16int sample, modin; s16int sample, modin;
@ -243,8 +243,8 @@ decode(vctxt *p)
f = (p->hdr >> 2) & 3; f = (p->hdr >> 2) & 3;
s = p->hdr >> 4; s = p->hdr >> 4;
brr = p->brr; brr = p->brr;
s1 = p->buf[7]; s1 = p->buf[p->bp + 11];
s2 = p->buf[6]; s2 = p->buf[p->bp + 10];
for(i = 0; i < 4; i++){ for(i = 0; i < 4; i++){
d = brr >> 12; d = brr >> 12;
if(s >= 13) if(s >= 13)
@ -273,11 +273,14 @@ decode(vctxt *p)
break; break;
} }
d = (s16int)(clamp16(d) << 1); d = (s16int)(clamp16(d) << 1);
p->buf[8 + i] = d; p->buf[p->bp] = d;
p->buf[p->bp++ + 12] = d;
s1 = d; s1 = d;
s2 = s1; s2 = s1;
brr <<= 4; brr <<= 4;
} }
if(p->bp == 12)
p->bp = 0;
} }
static s16int static s16int
@ -337,6 +340,8 @@ voice(int n, int s)
} }
if((dsp[INT|NON] & 1<<n) != 0) if((dsp[INT|NON] & 1<<n) != 0)
p->sample = noise; p->sample = noise;
else
p->sample = interp(p->interp, p->buf + p->bp);
p->sample = (((int)p->sample * p->env) >> 11) & ~1; p->sample = (((int)p->sample * p->env) >> 11) & ~1;
p->modin = p->sample; p->modin = p->sample;
r[INT|OUTX] = p->sample >> 8; r[INT|OUTX] = p->sample >> 8;
@ -362,10 +367,11 @@ voice(int n, int s)
if(p->init == 1){ if(p->init == 1){
p->hdrp = p->sp; p->hdrp = p->sp;
p->dp = p->hdrp + 1; p->dp = p->hdrp + 1;
p->bp = 0;
} }
if(p->interp >= 0x4000 || p->init <= 4 && p->init >= 2){ if(p->interp >= 0x4000 || p->init <= 4 && p->init >= 2){
memmove(p->buf, p->buf + 4, 8 * sizeof(s16int));
p->brr |= spcmem[++p->dp]; p->brr |= spcmem[++p->dp];
decode(p);
if(++p->dp == p->hdrp + 9){ if(++p->dp == p->hdrp + 9){
if((p->hdr & 1) != 0){ if((p->hdr & 1) != 0){
dsp[INT|ENDX] |= 1<<n; dsp[INT|ENDX] |= 1<<n;
@ -374,11 +380,8 @@ voice(int n, int s)
p->hdrp += 9; p->hdrp += 9;
p->dp = p->hdrp + 1; p->dp = p->hdrp + 1;
} }
decode(p);
} }
if(p->interp >= 0x4000) p->interp = (p->interp & 0x3fff) + p->pitch;
p->interp -= 0x4000;
p->interp += p->pitch;
if(p->interp >= 0x7fff) if(p->interp >= 0x7fff)
p->interp = 0x7fff; p->interp = 0x7fff;
break; break;
@ -387,7 +390,6 @@ voice(int n, int s)
samp[1] = clamp16(samp[1] + v); samp[1] = clamp16(samp[1] + v);
if((dsp[INT|EON] & (1<<n)) != 0) if((dsp[INT|EON] & (1<<n)) != 0)
echoin[1] = clamp16(echoin[1] + v); echoin[1] = clamp16(echoin[1] + v);
p->sample = interp(p->interp, p->buf);
break; break;
case 7: case 7:
m = 1<<n; m = 1<<n;
@ -503,13 +505,13 @@ dspstep(void)
break; break;
case 29: case 29:
echo(29); echo(29);
if((dspstate & 64) == 0) if((dspstate & 32) == 0)
dsp[NEWKON] &= ~dsp[INT|KON]; dsp[NEWKON] &= ~dsp[INT|KON];
break; break;
case 30: case 30:
voice(0, 0x32); voice(0, 0x32);
echo(30); echo(30);
if((dspstate & 64) == 0){ if((dspstate & 32) == 0){
dsp[INT|KOFF] = dsp[KOFF]; dsp[INT|KOFF] = dsp[KOFF];
dsp[INT|KON] = dsp[NEWKON]; dsp[INT|KON] = dsp[NEWKON];
} }