From ac0e1ebe7b6b988b34f35c6d124edc5c55a663d0 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Mon, 13 May 2024 09:40:33 +0100 Subject: [PATCH 1/3] fix for aud_to_host buffer underflow seen in 44_48 adat input tests --- lib_xua/src/core/buffer/decouple/decouple.xc | 25 +++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib_xua/src/core/buffer/decouple/decouple.xc b/lib_xua/src/core/buffer/decouple/decouple.xc index cadebd21..e52349c0 100644 --- a/lib_xua/src/core/buffer/decouple/decouple.xc +++ b/lib_xua/src/core/buffer/decouple/decouple.xc @@ -42,8 +42,13 @@ #define MAX_DEVICE_AUD_PACKET_SIZE_OUT (MAX(MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS, MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS)) /*** BUFFER SIZES ***/ - -#define BUFFER_PACKET_COUNT (4) /* How many packets too allow for in buffer - minimum is 4 */ +/* How many packets too allow for in buffer - minimum is 5. +2 for having in the aud_to_host buffer when it comes out of underflow, space available for 2 more for to accomodate cases when +2 pkts from audio hub get written into the aud_to_host buffer within 1 SOF period, and space for 1 extra packet to ensure that +when the 4th packet gets written to the buffer, there's space to accomodate the next packet, otherwise handle_audio_request() will +drop packets after writing the 4th packet in the buffer +*/ +#define BUFFER_PACKET_COUNT (5) #define BUFF_SIZE_OUT_HS MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS * BUFFER_PACKET_COUNT #define BUFF_SIZE_OUT_FS MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS * BUFFER_PACKET_COUNT @@ -1054,7 +1059,21 @@ void XUA_Buffer_Decouple(chanend c_mix_out assert(fillLevel <= BUFF_SIZE_IN); /* Check if we have come out of underflow */ - if (fillLevel >= IN_BUFFER_PREFILL) + unsigned sampFreq; + GET_SHARED_GLOBAL(sampFreq, g_freqChange_sampFreq); + int min, mid, max; + GetADCCounts(sampFreq, min, mid, max); + const int min_pkt_size = ((min * g_curSubSlot_In * g_numUsbChan_In + 3) & ~0x3) + 4; + + /* + Come out of underflow if there are exactly 2 packets in the buffer. + This ensures that handle_audio_request() does not drop packets when writing packets into the aud_to_host buffer + when aud_to_host buffer is not in underflow. + For example, coming out of underflow with 3 packets in the buffer would mean handle_audio_request() + drops packets if 2 pkts are received from audio hub in 1 SOF period. Coming out of underflow with 4 + packets would mean handle_audio_request would drop packets after writing 1 packet to the aud_to_host buffer. + */ + if ((fillLevel >= (min_pkt_size*2)) && (fillLevel < (min_pkt_size*3))) { int aud_to_host_rdptr; GET_SHARED_GLOBAL(aud_to_host_rdptr, g_aud_to_host_rdptr); From e4517f3776113689f095c3eaec80e53afc656194 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Mon, 13 May 2024 09:48:49 +0100 Subject: [PATCH 2/3] copyright --- lib_xua/src/core/buffer/decouple/decouple.xc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_xua/src/core/buffer/decouple/decouple.xc b/lib_xua/src/core/buffer/decouple/decouple.xc index e52349c0..b5405fa2 100644 --- a/lib_xua/src/core/buffer/decouple/decouple.xc +++ b/lib_xua/src/core/buffer/decouple/decouple.xc @@ -1,4 +1,4 @@ -// Copyright 2011-2023 XMOS LIMITED. +// Copyright 2011-2024 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xua.h" From 70a45d219c8a822e6c4ea6e5b0fcb96cb5860643 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Mon, 13 May 2024 10:38:50 +0100 Subject: [PATCH 3/3] changelog --- CHANGELOG.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e14cfd90..63788e0f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -11,6 +11,8 @@ UNRELEASED * FIXED: Incorrect internal input EP count for input only devices * ADDED: MIDI unit and subsystem tests * FIXED: ADAT Tx called too frequently + * CHANGED: aud_to_host buffer size and the condition to come out of underflow + in decoupler to fix buffer underflow seen in ADAT tests 4.0.0 -----