@@ -298,7 +298,10 @@ typedef struct {
298298 // PCM frame ring buffer
299299 virtio_snd_ring_buffer_t ring ;
300300} virtio_snd_prop_t ;
301- #define VSND_COMPILER_BARRIER asm("" ::: "memory")
301+ #define VSND_COMPILER_BARRIER \
302+ do { \
303+ asm("" ::: "memory"); \
304+ } while (0)
302305
303306static virtio_snd_config_t vsnd_configs [VSND_DEV_CNT_MAX ];
304307static virtio_snd_prop_t vsnd_props [VSND_DEV_CNT_MAX ] = {
@@ -505,7 +508,7 @@ static void virtio_snd_read_pcm_prepare(const virtio_snd_pcm_hdr_t *query,
505508 CNFAInit (NULL , "semu-virtio-snd" , virtio_snd_cb ,
506509 pcm_rate_tbl [vsnd_props [stream_id ].pp .rate ], 0 , 1 , 0 ,
507510 buffer_bytes , NULL , NULL , & v );
508- uint32_t sz = buffer_bytes ;
511+ uint32_t sz = buffer_bytes * 3 ;
509512 vsnd_props [stream_id ].ring .buffer = (void * ) malloc (sizeof (void ) * sz );
510513 vsnd_props [stream_id ].ring .prod .head = 0 ;
511514 vsnd_props [stream_id ].ring .prod .tail = 0 ;
@@ -598,7 +601,7 @@ static void virtio_snd_read_pcm_release(const virtio_snd_pcm_hdr_t *query,
598601double omega = 0.0 ;
599602int totalframesp = 0 ;
600603int totalframesr = 0 ;
601- static void __virtio_snd_frame_dequeue (void * out ,
604+ static void __virtio_snd_frame_dequeue (short * out ,
602605 uint32_t n ,
603606 uint32_t stream_id )
604607{
@@ -616,7 +619,10 @@ static void __virtio_snd_frame_dequeue(void *out,
616619 entries = prod_tail - cons_head ;
617620
618621 if (n > entries )
619- fprintf (stderr , "copy length is larget than entries\n" );
622+ fprintf (stderr ,
623+ "consumer payload length %" PRIu32
624+ " larger than entries %" PRIu32 "\n" ,
625+ n , entries );
620626
621627 cons_next = cons_head + n ;
622628 props -> ring .cons .head = cons_next ;
@@ -630,12 +636,9 @@ static void __virtio_snd_frame_dequeue(void *out,
630636 cons_head , cons_next , mask , idx );
631637 if (idx + n < size ) {
632638 memcpy (out , props -> ring .buffer + idx , n );
633- // out += n;
634639 } else {
635640 memcpy (out , props -> ring .buffer + idx , size - idx );
636- // out += (size - idx);
637641 memcpy (out + (size - idx ), props -> ring .buffer , n - (size - idx ));
638- // out += (n - (size - idx));
639642 }
640643 VSND_COMPILER_BARRIER ;
641644
@@ -802,19 +805,19 @@ static void __virtio_snd_frame_enqueue(void *payload,
802805 /* Move prod_head. */
803806 if (n > free_entries )
804807 fprintf (stderr ,
805- "payload length %" PRIu32 " larger than free_entries %" PRIu32
806- "\n" ,
808+ "producer payload length %" PRIu32
809+ " larger than free_entries %" PRIu32 " \n" ,
807810 n , free_entries );
808811 prod_next = prod_head + n ;
809812 props -> ring .prod .head = prod_next ;
810813
811814 /* Write payload to ring buffer. */
812815 uint32_t size = props -> ring .prod .size ;
813816 uint32_t idx = prod_head % size ;
814- fprintf (stderr ,
817+ /* fprintf(stderr,
815818 "prod_head %" PRIu32 " prod_next %" PRIu32 " mask %" PRIu32
816819 " idx %" PRIu32 "\n",
817- prod_head , prod_next , mask , idx );
820+ prod_head, prod_next, mask, idx);*/
818821 if (idx + n < size ) {
819822 memcpy (props -> ring .buffer + idx , payload , n );
820823 } else {
0 commit comments