+ unsigned char *start = s_chan[ch].pCurr;
+ int flags = start[1];
+ int ret = check_irq(ch, start);
+
+ if(s_chan[ch].prevflags & 1)
+ start = s_chan[ch].pLoop;
+
+ if(flags & 4)
+ s_chan[ch].pLoop = start;
+
+ start += 16;
+
+ if(flags & 1)
+ start = s_chan[ch].pLoop;
+
+ s_chan[ch].pCurr = start;
+ s_chan[ch].prevflags = flags;
+
+ return ret;
+}
+
+#define make_do_samples(name, fmod_code, interp_start, interp1_code, interp2_code, interp_end) \
+static int do_samples_##name(int ch, int ns, int ns_to) \
+{ \
+ int sinc = s_chan[ch].sinc; \
+ int spos = s_chan[ch].spos; \
+ int sbpos = s_chan[ch].iSBPos; \
+ int *SB = s_chan[ch].SB; \
+ int ret = -1; \
+ int d, fa; \
+ interp_start; \
+ \
+ for (; ns < ns_to; ns++) \
+ { \
+ fmod_code; \
+ \
+ while (spos >= 0x10000) \
+ { \
+ if(sbpos == 28) \
+ { \
+ sbpos = 0; \
+ d = decode_block(ch); \
+ if(d) \
+ ret = ns_to = ns + 1; \
+ } \
+ \
+ fa = SB[sbpos++]; \
+ interp1_code; \
+ spos -= 0x10000; \
+ } \
+ \
+ interp2_code; \
+ spos += sinc; \
+ } \
+ \
+ s_chan[ch].sinc = sinc; \
+ s_chan[ch].spos = spos; \
+ s_chan[ch].iSBPos = sbpos; \
+ interp_end; \
+ \
+ return ret; \
+}
+
+#define fmod_recv_check \
+ if(s_chan[ch].bFMod==1 && iFMod[ns]) \
+ sinc = FModChangeFrequency(ch,ns)
+
+make_do_samples(default, fmod_recv_check, ,
+ StoreInterpolationVal(ch, fa),
+ ChanBuf[ns] = iGetInterpolationVal(ch, spos), )
+make_do_samples(noint, , fa = s_chan[ch].SB[29], , ChanBuf[ns] = fa, s_chan[ch].SB[29] = fa)
+
+#define simple_interp_store \
+ s_chan[ch].SB[28] = 0; \
+ s_chan[ch].SB[29] = s_chan[ch].SB[30]; \
+ s_chan[ch].SB[30] = s_chan[ch].SB[31]; \
+ s_chan[ch].SB[31] = fa; \
+ s_chan[ch].SB[32] = 1
+
+#define simple_interp_get \
+ if(sinc<0x10000) /* -> upsampling? */ \
+ InterpolateUp(ch); /* --> interpolate up */ \
+ else InterpolateDown(ch); /* --> else down */ \
+ ChanBuf[ns] = s_chan[ch].SB[29]
+
+make_do_samples(simple, , ,
+ simple_interp_store, simple_interp_get, )
+
+static int do_samples_noise(int ch, int ns, int ns_to)
+{
+ int level, shift, bit;
+ int ret = -1, d;
+
+ s_chan[ch].spos += s_chan[ch].sinc * (ns_to - ns);
+ while (s_chan[ch].spos >= 28*0x10000)
+ {
+ d = skip_block(ch);
+ if (d)
+ ret = ns_to;
+ s_chan[ch].spos -= 28*0x10000;
+ }
+
+ // modified from DrHell/shalma, no fraction
+ level = (spuCtrl >> 10) & 0x0f;
+ level = 0x8000 >> level;
+
+ for (; ns < ns_to; ns++)
+ {
+ dwNoiseCount += 2;
+ if (dwNoiseCount >= level)
+ {
+ dwNoiseCount -= level;
+ shift = (dwNoiseVal >> 10) & 0x1f;
+ bit = (0x69696969 >> shift) & 1;
+ if (dwNoiseVal & 0x8000)
+ bit ^= 1;
+ dwNoiseVal = (dwNoiseVal << 1) | bit;
+ }
+
+ ChanBuf[ns] = (signed short)dwNoiseVal;
+ }
+
+ return ret;
+}
+
+#ifdef HAVE_ARMV5
+// asm code; lv and rv must be 0-3fff
+extern void mix_chan(int start, int count, int lv, int rv);
+extern void mix_chan_rvb(int start, int count, int lv, int rv);