+ if (ch == 1 || ch == 3)
+ {
+ do_decode_bufs(spu.spuMem, ch/2, ns_to, work->decode_pos);
+ decode_dirty_ch |= 1 << ch;
+ }
+
+ if (s_chan->bFMod == 2) // fmod freq channel
+ memcpy(iFMod, &ChanBuf, ns_to * sizeof(iFMod[0]));
+ if (s_chan->bRVBActive && work->rvb_addr)
+ mix_chan_rvb(work->SSumLR, ns_to,
+ work->ch[ch].vol_l, work->ch[ch].vol_r, RVB);
+ else
+ mix_chan(work->SSumLR, ns_to, work->ch[ch].vol_l, work->ch[ch].vol_r);
+ }
+
+ if (work->rvb_addr)
+ REVERBDo(work->SSumLR, RVB, ns_to, work->rvb_addr);
+}
+
+static void sync_worker_thread(int force)
+{
+ struct work_item *work;
+ int done, used_space;
+
+ done = thread_get_i_done() - worker->i_reaped;
+ used_space = worker->i_ready - worker->i_reaped;
+ //printf("done: %d use: %d dsp: %u/%u\n", done, used_space,
+ // worker->boot_cnt, worker->i_done);
+
+ while ((force && used_space > 0) || used_space >= WORK_MAXCNT || done > 0) {
+ work = &worker->i[worker->i_reaped & WORK_I_MASK];
+ thread_work_wait_sync(work, force);
+
+ do_samples_finish(work->SSumLR, work->ns_to,
+ work->channels_silent, work->decode_pos);
+
+ worker->i_reaped++;
+ done = thread_get_i_done() - worker->i_reaped;
+ used_space = worker->i_ready - worker->i_reaped;
+ }
+ if (force)
+ thread_sync_caches();
+}
+
+#else
+
+static void queue_channel_work(int ns_to, int silentch) {}
+static void sync_worker_thread(int force) {}
+
+static const void * const worker = NULL;
+
+#endif // THREAD_ENABLED
+
+////////////////////////////////////////////////////////////////////////
+// MAIN SPU FUNCTION
+// here is the main job handler...
+////////////////////////////////////////////////////////////////////////
+
+void do_samples(unsigned int cycles_to, int do_direct)
+{
+ unsigned int silentch;
+ int cycle_diff;
+ int ns_to;
+
+ cycle_diff = cycles_to - spu.cycles_played;
+ if (cycle_diff < -2*1048576 || cycle_diff > 2*1048576)
+ {
+ //xprintf("desync %u %d\n", cycles_to, cycle_diff);
+ spu.cycles_played = cycles_to;
+ return;
+ }
+
+ silentch = ~(spu.dwChannelOn | spu.dwNewChannel) & 0xffffff;
+
+ do_direct |= (silentch == 0xffffff);
+ if (worker != NULL)
+ sync_worker_thread(do_direct);
+
+ if (cycle_diff < 2 * 768)
+ return;
+
+ ns_to = (cycle_diff / 768 + 1) & ~1;
+ if (ns_to > NSSIZE) {
+ // should never happen
+ //xprintf("ns_to oflow %d %d\n", ns_to, NSSIZE);
+ ns_to = NSSIZE;
+ }
+
+ //////////////////////////////////////////////////////