+static void do_channels(int ns_to)
+{
+ unsigned int mask;
+ int do_rvb, ch, d;
+ SPUCHAN *s_chan;
+ int *SB, sinc;
+
+ do_rvb = spu.rvb->StartAddr && spu_config.iUseReverb;
+ if (do_rvb)
+ memset(RVB, 0, ns_to * sizeof(RVB[0]) * 2);
+
+ mask = spu.dwNewChannel & 0xffffff;
+ for (ch = 0; mask != 0; ch++, mask >>= 1) {
+ if (mask & 1)
+ StartSound(ch);
+ }
+
+ mask = spu.dwChannelsAudible & 0xffffff;
+ for (ch = 0; mask != 0; ch++, mask >>= 1) // loop em all...
+ {
+ if (!(mask & 1)) continue; // channel not playing? next
+
+ s_chan = &spu.s_chan[ch];
+ SB = spu.SB + ch * SB_SIZE;
+ sinc = s_chan->sinc;
+ if (spu.s_chan[ch].bNewPitch)
+ SB[32] = 1; // reset interpolation
+ spu.s_chan[ch].bNewPitch = 0;
+
+ if (s_chan->bNoise)
+ d = do_samples_noise(ch, ns_to);
+ else if (s_chan->bFMod == 2
+ || (s_chan->bFMod == 0 && spu_config.iUseInterpolation == 0))
+ d = do_samples_noint(decode_block, NULL, ch, ns_to,
+ SB, sinc, &s_chan->spos, &s_chan->iSBPos);
+ else if (s_chan->bFMod == 0 && spu_config.iUseInterpolation == 1)
+ d = do_samples_simple(decode_block, NULL, ch, ns_to,
+ SB, sinc, &s_chan->spos, &s_chan->iSBPos);
+ else
+ d = do_samples_default(decode_block, NULL, ch, ns_to,
+ SB, sinc, &s_chan->spos, &s_chan->iSBPos);
+
+ d = MixADSR(&s_chan->ADSRX, d);
+ if (d < ns_to) {
+ spu.dwChannelsAudible &= ~(1 << ch);
+ s_chan->ADSRX.State = ADSR_RELEASE;
+ s_chan->ADSRX.EnvelopeVol = 0;
+ memset(&ChanBuf[d], 0, (ns_to - d) * sizeof(ChanBuf[0]));
+ }