@@ -547,6 +547,7 @@ static void virtio_snd_read_pcm_prepare(const virtio_snd_pcm_hdr_t *query,
547547 "bps_rate %" PRIu32 " cnfa_period_bytes %" PRIu32
548548 " cnfa_period_frames %" PRIu32 "\n" ,
549549 bps_rate , cnfa_period_bytes , cnfa_period_frames );
550+ uint32_t period_frames = period_bytes / VSND_CNFA_FRAME_SZ ;
550551
551552 /* The buffer size in frames when calling CNFAInit()
552553 * is actually period size (i.e., period size then divide
@@ -556,7 +557,7 @@ static void virtio_snd_read_pcm_prepare(const virtio_snd_pcm_hdr_t *query,
556557 CNFAInit (NULL , "semu-virtio-snd" , virtio_snd_cb , rate , 0 , channels , 0 ,
557558 cnfa_period_frames , NULL , NULL , & props -> v );
558559 uint32_t sz = props -> pp .buffer_bytes ;
559- props -> ring .buffer = (void * ) malloc (sizeof (void ) * sz );
560+ props -> ring .buffer = (void * ) malloc (sizeof (* props -> ring . buffer ) * sz );
560561 props -> ring .prod .head = 0 ;
561562 props -> ring .prod .tail = 0 ;
562563 props -> ring .cons .head = 0 ;
@@ -569,9 +570,10 @@ static void virtio_snd_read_pcm_prepare(const virtio_snd_pcm_hdr_t *query,
569570 pthread_cond_init (& props -> ring .readable , NULL );
570571 pthread_cond_init (& props -> ring .writable , NULL );
571572 INIT_LIST_HEAD (& props -> buf_queue_head );
572- props -> immediate = (void * )malloc (sizeof (void ) * cnfa_period_bytes );
573+ props -> immediate =
574+ (void * ) malloc (sizeof (* props -> immediate ) * cnfa_period_bytes );
573575#if WRITEOUT
574- outfile = fopen ("out_enque .bin" , "wb" );
576+ outfile = fopen ("out_deque .bin" , "wb" );
575577#endif
576578
577579 * plen = 0 ;
@@ -727,32 +729,34 @@ static void __virtio_snd_frame_dequeue(short *out,
727729 props -> ring .cons .tail = cons_next ;
728730
729731 uint32_t written_bytes = 0 ;
730- memset (props -> immediate , 0 , sizeof (void ) * n );
732+ memset (props -> immediate , 0 , sizeof (* props -> immediate ) * n );
731733 while (!list_empty (& props -> buf_queue_head ) && written_bytes < n ) {
732734 vsnd_buf_queue_node_t * node =
733735 list_first_entry (& props -> buf_queue_head , vsnd_buf_queue_node_t , q );
734736 uint32_t left = n - written_bytes ;
735737 uint32_t actual = node -> len - node -> pos ;
736- uint32_t len = left < actual ? left : actual ; /* Naive min implementation */
738+ uint32_t len =
739+ left < actual ? left : actual ; /* Naive min implementation */
737740
738741 fprintf (stderr ,
739- "--- left %" PRIu32 " actual %" PRIu32 " len %" PRIu32 " written %" PRIu32 "\n" ,
740- left ,
741- actual ,
742- len ,
743- written_bytes );
742+ "--- left %" PRIu32 " actual %" PRIu32 " len %" PRIu32
743+ " written %" PRIu32 " node->pos %" PRIu32 " node->len %" PRIu32
744+ "\n" ,
745+ left , actual , len , written_bytes , node -> pos , node -> len );
744746
745- memcpy (
746- props -> immediate + written_bytes ,
747- node -> addr ,
748- len );
747+ memcpy (props -> immediate + written_bytes , node -> addr + node -> pos , len );
748+
749+ #if WRITEOUT
750+ fwrite (node -> addr + node -> pos , sizeof (void ), len , outfile );
751+ #endif
749752
750753 written_bytes += len ;
751754 node -> pos += len ;
752- if (node -> pos >= node -> len )
755+ if (node -> pos >= node -> len )
753756 list_del (& node -> q );
754757 }
755- fprintf (stderr , "*** written %" PRIu32 " out n %" PRIu32 "\n" , written_bytes , n );
758+ fprintf (stderr , "*** written %" PRIu32 " out n %" PRIu32 "\n" ,
759+ written_bytes , n );
756760 memcpy (out , props -> immediate , n );
757761
758762 props -> ring .buf_ev_notity -- ;
@@ -956,9 +960,6 @@ static void __virtio_snd_frame_enqueue(void *payload,
956960 node -> len = n ;
957961 node -> pos = 0 ;
958962 list_push (& node -> q , & props -> buf_queue_head );
959- #if WRITEOUT
960- fwrite (node -> addr , sizeof (void ), node -> len , outfile );
961- #endif
962963
963964 /*uint32_t period_bytes = props->pp.period_bytes;
964965 if (prod_next - cons_tail >= period_bytes) {
0 commit comments