From 2e9b605776dbee76c105f034d54364f64e3dc644 Mon Sep 17 00:00:00 2001 From: Cuda-Chen Date: Tue, 17 Dec 2024 17:30:25 +0800 Subject: [PATCH] Let sound playing continuously in pcm_start state --- virtio-snd.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/virtio-snd.c b/virtio-snd.c index fc7fc95..50cb3ce 100644 --- a/virtio-snd.c +++ b/virtio-snd.c @@ -8,9 +8,9 @@ #include "CNFA_sf.h" #include "device.h" -#include "utils.h" #include "riscv.h" #include "riscv_private.h" +#include "utils.h" #include "virtio.h" #define VSND_DEV_CNT_MAX 1 @@ -622,29 +622,23 @@ static void virtio_snd_cb(struct CNFADriver *dev, { (void) in; /* reversed for future recording use */ vsnd_stream_sel_t *v_ptr = (vsnd_stream_sel_t *) dev->opaque; + int channels = dev->channelsPlay; + uint32_t out_buf_sz = framesp * channels; pthread_mutex_lock(&virtio_snd_ctrl_mutex); - while (v_ptr->guest_playing <= 0) { + while (v_ptr->guest_playing == 0) { fprintf(stderr, "wait ctrl cond\n"); + memset(out, 0, sizeof(*out) * out_buf_sz); pthread_cond_wait(&virtio_snd_ctrl_cond, &virtio_snd_ctrl_mutex); } - v_ptr->guest_playing--; - totalframesr += framesr; totalframesp += framesp; - int channels = dev->channelsPlay; uint32_t id = v_ptr->stream_id; - uint32_t out_buf_sz = framesp * channels; fprintf(stderr, "start to play with out_buf_sz %" PRIu32 "\n", out_buf_sz); - /*if (!(playing)) { - memset(out, 0, sizeof(short) * out_buf_sz); - return; - }*/ - /* TODO: add single consumer */ __virtio_snd_frame_dequeue(out, out_buf_sz, id); #if 0