From b695192f3483a610cecbd00cb1f657d543bda704 Mon Sep 17 00:00:00 2001 From: Zachary Hall Date: Tue, 15 Oct 2024 16:17:23 -0700 Subject: [PATCH] Implement reset FIFO for ZSM commands --- backends/playback/zsm/zsm_backend.cpp | 6 +++++- backends/playback/zsm/zsm_backend.hpp | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/backends/playback/zsm/zsm_backend.cpp b/backends/playback/zsm/zsm_backend.cpp index c7e10bd..67d7938 100644 --- a/backends/playback/zsm/zsm_backend.cpp +++ b/backends/playback/zsm/zsm_backend.cpp @@ -155,7 +155,11 @@ void ZsmBackend::tick(bool step) { for (size_t i = 0; i < cmd.extcmd.bytes; i += 2) { switch (cmd.extcmd.pcm[i]) { case 0: { // ctrl - pcm_write_ctrl(cmd.extcmd.pcm[i + 1]); + uint8_t ctrl = cmd.extcmd.pcm[i + 1]; + if (ctrl & 0x80) { + remain = 0; + } + pcm_write_ctrl(ctrl); } break; case 1: { // rate pcm_write_rate(cmd.extcmd.pcm[i + 1]); diff --git a/backends/playback/zsm/zsm_backend.hpp b/backends/playback/zsm/zsm_backend.hpp index 702c6ea..f03cca4 100644 --- a/backends/playback/zsm/zsm_backend.hpp +++ b/backends/playback/zsm/zsm_backend.hpp @@ -85,12 +85,12 @@ class ZsmBackend : public PlaybackBackend { } void audio_step(size_t samples) { if (samples == 0) return; - while (pcm_fifo_avail() < samples && remain > 0) { + while (pcm_fifo_avail() < samples) { if (pcm_read_rate() == 0) break; if ((--remain) == 0) { if (islooped) { cur = loop; - remain = loop_rem - 1; + remain = loop_rem; } else { break; }