X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=plugins%2Fdfsound%2Fspu.c;h=8f6ed1395ed27c5d7d88f044d9ee8aefd78d26d8;hp=a190b29b12c8fc2ce2f5a54cca1938756bbe3857;hb=e391d21cdbf06afd68d137537b7e82585ecffa1a;hpb=f9fe492349dcb13ca16e1c809bd2bd25f4a73f10 diff --git a/plugins/dfsound/spu.c b/plugins/dfsound/spu.c index a190b29b..8f6ed139 100644 --- a/plugins/dfsound/spu.c +++ b/plugins/dfsound/spu.c @@ -671,12 +671,13 @@ static void noinline do_decode_bufs(int which, int start, int count) { const int *src = ChanBuf + start; unsigned short *dst = &spuMem[0x800/2 + which*0x400/2]; - int cursor = decode_pos; + int cursor = decode_pos + start; while (count-- > 0) { + cursor &= 0x1ff; dst[cursor] = *src++; - cursor = (cursor + 1) & 0x1ff; + cursor++; } // decode_pos is updated and irqs are checked later, after voice loop @@ -691,7 +692,7 @@ static void noinline do_decode_bufs(int which, int start, int count) static int do_samples(int forced_updates) { int volmult = iVolume; - int ns,ns_from,ns_to; + int ns,ns_from,ns_to,ns_len; int ch,d,silentch; int bIRQReturn=0; @@ -706,8 +707,6 @@ static int do_samples(int forced_updates) while(!bIRQReturn) { - cycles_since_update = 0; - ns_from=0; ns_to=NSSIZE; ch=0; @@ -741,21 +740,22 @@ static int do_samples(int forced_updates) lastch=ch; lastns=ns_to=d; } + ns_len = ns_to - ns_from; MixADSR(ch, ns_from, ns_to); if(ch==1 || ch==3) { - do_decode_bufs(ch/2, ns_from, ns_to-ns_from); + do_decode_bufs(ch/2, ns_from, ns_len); decode_dirty_ch |= 1<busy()) break; } + + if(cycles_since_update <= -PSXCLK/60 / 4) + break; } + // this may cause desync, but help audio when the emu can't keep up.. + if(cycles_since_update < 0) + cycles_since_update = 0; + return 0; } @@ -899,7 +908,6 @@ static int do_samples(int forced_updates) void CALLBACK SPUasync(unsigned long cycle) { - static int old_ctrl; int forced_updates = 0; int do_update = 0; @@ -914,16 +922,8 @@ void CALLBACK SPUasync(unsigned long cycle) had_dma = 0; } - if((spuCtrl&CTRL_IRQ) && (((spuCtrl^old_ctrl)&CTRL_IRQ) // irq was enabled - || cycles_since_update > PSXCLK/60 / 4)) { + if(cycles_since_update > PSXCLK/60 * 5/4) do_update = 1; - forced_updates = cycles_since_update / (PSXCLK/44100) / NSSIZE; - } - // with no irqs, once per frame should be fine (using a bit more because of BIAS) - else if(cycles_since_update > PSXCLK/60 * 5/4) - do_update = 1; - - old_ctrl = spuCtrl; if(do_update) do_samples(forced_updates);