--- a/audio/audio.c    2022-12-13 19:14:31.793153558 +0100
+++ b/audio/audio.c    2022-12-11 16:24:48.842649711 +0100
@@ -1228,6 +1228,10 @@ static void audio_run_out (AudioState *s
  #ifdef DEBUG_OUT
          dolog("played=%zu\n", played);
  #endif
+        if (hw_free - played) {
+            fprintf(stderr, "%s: free %zu, played %zu\n",
+                    __func__, hw_free, played);
+        }

          if (played) {
              hw->ts_helper += played;
@@ -1318,6 +1322,7 @@ static void audio_run_in (AudioState *s)
              if (sw->active) {
                  size_t sw_avail = audio_get_avail(sw);
                  size_t avail;
+                size_t prev_acquired = sw->total_hw_samples_acquired;

                  avail = st_rate_frames_out(sw->rate, sw_avail);
                  if (avail > 0) {
@@ -1325,6 +1330,11 @@ static void audio_run_in (AudioState *s)
                      sw->callback.fn(sw->callback.opaque,
                                      avail * sw->info.bytes_per_frame);
                  }
+
+                if (sw_avail + prev_acquired - 
sw->total_hw_samples_acquired) {
+                    fprintf(stderr, "%s: avail %zu, acquired %zu\n", 
__func__,
+                            sw_avail, sw->total_hw_samples_acquired - 
prev_acquired);
+                }
              }
          }
      }
--- a/hw/audio/hda-codec.c    2023-01-04 14:07:31.954304889 +0100
+++ b/hw/audio/hda-codec.c    2023-01-04 13:57:47.687320406 +0100
@@ -265,20 +265,28 @@ static void hda_audio_input_cb(void *opa
      int64_t rpos = st->rpos;

      int64_t to_transfer = MIN(B_SIZE - (wpos - rpos), avail);
+    unsigned int total_read = 0;

      while (to_transfer) {
          uint32_t start = (uint32_t) (wpos & B_MASK);
          uint32_t chunk = (uint32_t) MIN(B_SIZE - start, to_transfer);
          uint32_t read = AUD_read(st->voice.in, st->buf + start, chunk);
          wpos += read;
+        total_read += read;
          to_transfer -= read;
          st->wpos += read;
          if (chunk != read) {
+            fprintf(stderr, "%s: could not read %u bytes\n", __func__,
+                    chunk - read);
              break;
          }
      }

      hda_timer_sync_adjust(st, -((wpos - rpos) - (B_SIZE >> 1)));
+    if (avail != total_read) {
+        fprintf(stderr, "%s: to read %d, read %u\n", __func__,
+                avail, total_read);
+    }
  }

  static void hda_audio_output_timer(void *opaque)
@@ -329,6 +337,7 @@ static void hda_audio_output_cb(void *op
      int64_t rpos = st->rpos;

      int64_t to_transfer = MIN(wpos - rpos, avail);
+    unsigned int total_written = 0;

      if (wpos - rpos == B_SIZE) {
          /* drop buffer, reset timer adjust */
@@ -343,15 +352,22 @@ static void hda_audio_output_cb(void *op
          uint32_t start = (uint32_t) (rpos & B_MASK);
          uint32_t chunk = (uint32_t) MIN(B_SIZE - start, to_transfer);
          uint32_t written = AUD_write(st->voice.out, st->buf + start, 
chunk);
+        total_written += written;
          rpos += written;
          to_transfer -= written;
          st->rpos += written;
          if (chunk != written) {
+            fprintf(stderr, "%s: could not write %u bytes\n", __func__,
+                    chunk - written);
              break;
          }
      }

      hda_timer_sync_adjust(st, (wpos - rpos) - (B_SIZE >> 1));
+    if (avail != total_written) {
+        fprintf(stderr, "%s: to write %d, written %u\n", __func__,
+                avail, total_written);
+    }
  }

