From ec3b8a2832b025a6f5db92ac8c06f799bf41752f Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Thu, 16 May 2024 16:03:08 +0100 Subject: [PATCH 1/6] Update g_numUsbChan_Out to the selected interface out channel count --- lib_xua/src/core/buffer/decouple/decouple.xc | 4 ++-- lib_xua/src/core/endpoint0/xua_endpoint0.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib_xua/src/core/buffer/decouple/decouple.xc b/lib_xua/src/core/buffer/decouple/decouple.xc index b5405fa2..fe730776 100644 --- a/lib_xua/src/core/buffer/decouple/decouple.xc +++ b/lib_xua/src/core/buffer/decouple/decouple.xc @@ -158,11 +158,11 @@ unsigned packData = 0; static inline void SendSamples4(chanend c_mix_out) { /* Doing this checking allows us to unroll */ - if(g_numUsbChan_Out == NUM_USB_CHAN_OUT) + if(1)//(g_numUsbChan_Out == NUM_USB_CHAN_OUT) { /* Buffering not underflow condition send out some samples...*/ #pragma loop unroll - for(int i = 0; i < NUM_USB_CHAN_OUT; i++) + for(int i = 0; i < g_numUsbChan_Out; i++) { int sample; int mult; diff --git a/lib_xua/src/core/endpoint0/xua_endpoint0.c b/lib_xua/src/core/endpoint0/xua_endpoint0.c index 1f23a457..d0645380 100755 --- a/lib_xua/src/core/endpoint0/xua_endpoint0.c +++ b/lib_xua/src/core/endpoint0/xua_endpoint0.c @@ -245,7 +245,6 @@ const unsigned g_dataFormat_In[INPUT_FORMAT_COUNT] = {STREAM_FORMAT_INPUT_1 }; /* Channel count */ -/* Note, currently only input changes.. */ const unsigned g_chanCount_In_HS[INPUT_FORMAT_COUNT] = {HS_STREAM_FORMAT_INPUT_1_CHAN_COUNT, #if(INPUT_FORMAT_COUNT > 1) HS_STREAM_FORMAT_INPUT_2_CHAN_COUNT, @@ -255,6 +254,15 @@ const unsigned g_chanCount_In_HS[INPUT_FORMAT_COUNT] = {HS_STREAM_FORMAT_I #endif }; +const unsigned g_chanCount_Out_HS[OUTPUT_FORMAT_COUNT] = {HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT, +#if(OUTPUT_FORMAT_COUNT > 1) + HS_STREAM_FORMAT_OUTPUT_2_CHAN_COUNT, +#endif +#if(OUTPUT_FORMAT_COUNT > 2) + HS_STREAM_FORMAT_OUTPUT_3_CHAN_COUNT +#endif +}; + XUD_ep ep0_out; XUD_ep ep0_in; @@ -580,7 +588,7 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0 if(g_curUsbSpeed == XUD_SPEED_HS) { - outuint(c_audioControl, NUM_USB_CHAN_OUT); /* Channel count */ + outuint(c_audioControl, g_chanCount_Out_HS[sp.wValue-1]); /* Channel count */ outuint(c_audioControl, g_subSlot_Out_HS[sp.wValue-1]); /* Subslot */ outuint(c_audioControl, g_sampRes_Out_HS[sp.wValue-1]); /* Resolution */ } From 4b2cd1c5ca95a2c47aafdb5f7dc766cae7a412d9 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Fri, 17 May 2024 16:15:04 +0100 Subject: [PATCH 2/6] Add known pattern in underflow buffers --- lib_xua/src/core/buffer/decouple/decouple.xc | 5 +++++ lib_xua/src/core/clocking/clockgen.xc | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib_xua/src/core/buffer/decouple/decouple.xc b/lib_xua/src/core/buffer/decouple/decouple.xc index fe730776..f358d0f3 100644 --- a/lib_xua/src/core/buffer/decouple/decouple.xc +++ b/lib_xua/src/core/buffer/decouple/decouple.xc @@ -772,6 +772,11 @@ void XUA_Buffer_Decouple(chanend c_mix_out aud_to_host_flag = 0; SET_SHARED_GLOBAL(g_aud_to_host_flag, aud_to_host_flag); + for(int i=1; i<(MAX_DEVICE_AUD_PACKET_SIZE_IN >> 2); i++) + { + inZeroBuff[i] = 5678 << 8; + } + /* NOTE: For UAC2 IN EP not marked ready at this point - Initial size of zero buffer not known * since we don't know the USB bus-speed yet. * The host will send a SetAltInterface before streaming which will lead to this core diff --git a/lib_xua/src/core/clocking/clockgen.xc b/lib_xua/src/core/clocking/clockgen.xc index ac172b8f..55c14baf 100644 --- a/lib_xua/src/core/clocking/clockgen.xc +++ b/lib_xua/src/core/clocking/clockgen.xc @@ -833,13 +833,13 @@ void clockGen ( streaming chanend ?c_spdif_rx, if (adatUnderflow) { /* ADAT underflowing, send out zero samples */ - g_digData[2] = 0; - g_digData[3] = 0; - g_digData[4] = 0; - g_digData[5] = 0; - g_digData[6] = 0; - g_digData[7] = 0; - g_digData[8] = 0; + g_digData[2] = 1234 << 8; + g_digData[3] = 1234 << 8; + g_digData[4] = 1234 << 8; + g_digData[5] = 1234 << 8; + g_digData[6] = 1234 << 8; + g_digData[7] = 1234 << 8; + g_digData[8] = 1234 << 8; g_digData[9] = 0; } else From 0595d8c8f790df02552ba2b86a2d65b75090ed3a Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Mon, 20 May 2024 14:30:56 +0100 Subject: [PATCH 3/6] Bring back loop unroll in decoupler SendSamples4 --- lib_xua/src/core/buffer/decouple/decouple.xc | 95 ++++++++++---------- 1 file changed, 46 insertions(+), 49 deletions(-) diff --git a/lib_xua/src/core/buffer/decouple/decouple.xc b/lib_xua/src/core/buffer/decouple/decouple.xc index f358d0f3..4276d493 100644 --- a/lib_xua/src/core/buffer/decouple/decouple.xc +++ b/lib_xua/src/core/buffer/decouple/decouple.xc @@ -155,68 +155,65 @@ unsigned unpackData = 0; unsigned packState = 0; unsigned packData = 0; -static inline void SendSamples4(chanend c_mix_out) +static inline void _send_sample_4(chanend c_mix_out) { - /* Doing this checking allows us to unroll */ - if(1)//(g_numUsbChan_Out == NUM_USB_CHAN_OUT) - { - /* Buffering not underflow condition send out some samples...*/ -#pragma loop unroll - for(int i = 0; i < g_numUsbChan_Out; i++) - { - int sample; - int mult; - int h; - unsigned l; - - read_via_xc_ptr(sample, g_aud_from_host_rdptr); - g_aud_from_host_rdptr+=4; + int sample; + read_via_xc_ptr(sample, g_aud_from_host_rdptr); + g_aud_from_host_rdptr+=4; #if (OUTPUT_VOLUME_CONTROL == 1) && (!OUT_VOLUME_IN_MIXER) - unsafe - { - mult = multOutPtr[i]; - } - {h, l} = macs(mult, sample, 0, 0); - h <<= 3; + int mult; + int h; + unsigned l; + unsafe + { + mult = multOutPtr[i]; + } + {h, l} = macs(mult, sample, 0, 0); + h <<= 3; #if (STREAM_FORMAT_OUTPUT_RESOLUTION_32BIT_USED == 1) - h |= (l >>29) & 0x7; // Note: This step is not required if we assume sample depth is 24bit (rather than 32bit) - // Note: We need all 32bits for Native DSD + h |= (l >>29) & 0x7; // Note: This step is not required if we assume sample depth is 24bit (rather than 32bit) + // Note: We need all 32bits for Native DSD #endif - outuint(c_mix_out, h); + outuint(c_mix_out, h); #else - outuint(c_mix_out, sample); + outuint(c_mix_out, sample); #endif +} + +static inline void SendSamples4(chanend c_mix_out) +{ + /* Doing this allows us to unroll */ + if(g_numUsbChan_Out == HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT) + { + #pragma loop unroll + for(int i = 0; i < HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT; i++) + { + _send_sample_4(c_mix_out); + } + } + else if(g_numUsbChan_Out == HS_STREAM_FORMAT_OUTPUT_2_CHAN_COUNT) + { + #pragma loop unroll + for(int i = 0; i < HS_STREAM_FORMAT_OUTPUT_2_CHAN_COUNT; i++) + { + _send_sample_4(c_mix_out); + } + } + else if(g_numUsbChan_Out == HS_STREAM_FORMAT_OUTPUT_3_CHAN_COUNT) + { + #pragma loop unroll + for(int i = 0; i < HS_STREAM_FORMAT_OUTPUT_3_CHAN_COUNT; i++) + { + _send_sample_4(c_mix_out); } } else { -#pragma loop unroll + #pragma loop unroll for(int i = 0; i < NUM_USB_CHAN_OUT_FS; i++) { - int sample; - int mult; - int h; - unsigned l; - - read_via_xc_ptr(sample, g_aud_from_host_rdptr); - g_aud_from_host_rdptr+=4; - -#if (OUTPUT_VOLUME_CONTROL == 1) && (!OUT_VOLUME_IN_MIXER) - unsafe - { - mult = multOutPtr[i]; - } - {h, l} = macs(mult, sample, 0, 0); - h <<= 3; -#if (STREAM_FORMAT_OUTPUT_RESOLUTION_32BIT_USED == 1) - h |= (l >>29) & 0x7; // Note: This step is not required if we assume sample depth is 24bit (rather than 32bit) - // Note: We need all 32bits for Native DSD -#endif - outuint(c_mix_out, h); -#else - outuint(c_mix_out, sample); -#endif + _send_sample_4(c_mix_out); } } } From a9f4f51f033d5c4140ac6c456689f9c227e33819 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Mon, 20 May 2024 14:34:23 +0100 Subject: [PATCH 4/6] Remove underflow debug stuff --- lib_xua/src/core/buffer/decouple/decouple.xc | 5 ----- lib_xua/src/core/clocking/clockgen.xc | 14 +++++++------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib_xua/src/core/buffer/decouple/decouple.xc b/lib_xua/src/core/buffer/decouple/decouple.xc index 4276d493..c4a6566c 100644 --- a/lib_xua/src/core/buffer/decouple/decouple.xc +++ b/lib_xua/src/core/buffer/decouple/decouple.xc @@ -769,11 +769,6 @@ void XUA_Buffer_Decouple(chanend c_mix_out aud_to_host_flag = 0; SET_SHARED_GLOBAL(g_aud_to_host_flag, aud_to_host_flag); - for(int i=1; i<(MAX_DEVICE_AUD_PACKET_SIZE_IN >> 2); i++) - { - inZeroBuff[i] = 5678 << 8; - } - /* NOTE: For UAC2 IN EP not marked ready at this point - Initial size of zero buffer not known * since we don't know the USB bus-speed yet. * The host will send a SetAltInterface before streaming which will lead to this core diff --git a/lib_xua/src/core/clocking/clockgen.xc b/lib_xua/src/core/clocking/clockgen.xc index 55c14baf..ac172b8f 100644 --- a/lib_xua/src/core/clocking/clockgen.xc +++ b/lib_xua/src/core/clocking/clockgen.xc @@ -833,13 +833,13 @@ void clockGen ( streaming chanend ?c_spdif_rx, if (adatUnderflow) { /* ADAT underflowing, send out zero samples */ - g_digData[2] = 1234 << 8; - g_digData[3] = 1234 << 8; - g_digData[4] = 1234 << 8; - g_digData[5] = 1234 << 8; - g_digData[6] = 1234 << 8; - g_digData[7] = 1234 << 8; - g_digData[8] = 1234 << 8; + g_digData[2] = 0; + g_digData[3] = 0; + g_digData[4] = 0; + g_digData[5] = 0; + g_digData[6] = 0; + g_digData[7] = 0; + g_digData[8] = 0; g_digData[9] = 0; } else From d32ff7b3f691f0646564bde792fac5d41fc1792a Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Mon, 20 May 2024 14:40:41 +0100 Subject: [PATCH 5/6] Fix build error --- lib_xua/src/core/buffer/decouple/decouple.xc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib_xua/src/core/buffer/decouple/decouple.xc b/lib_xua/src/core/buffer/decouple/decouple.xc index c4a6566c..4b7dc0cf 100644 --- a/lib_xua/src/core/buffer/decouple/decouple.xc +++ b/lib_xua/src/core/buffer/decouple/decouple.xc @@ -155,7 +155,7 @@ unsigned unpackData = 0; unsigned packState = 0; unsigned packData = 0; -static inline void _send_sample_4(chanend c_mix_out) +static inline void _send_sample_4(chanend c_mix_out, int ch) { int sample; read_via_xc_ptr(sample, g_aud_from_host_rdptr); @@ -167,7 +167,7 @@ static inline void _send_sample_4(chanend c_mix_out) unsigned l; unsafe { - mult = multOutPtr[i]; + mult = multOutPtr[ch]; } {h, l} = macs(mult, sample, 0, 0); h <<= 3; @@ -189,7 +189,7 @@ static inline void SendSamples4(chanend c_mix_out) #pragma loop unroll for(int i = 0; i < HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT; i++) { - _send_sample_4(c_mix_out); + _send_sample_4(c_mix_out, i); } } else if(g_numUsbChan_Out == HS_STREAM_FORMAT_OUTPUT_2_CHAN_COUNT) @@ -197,7 +197,7 @@ static inline void SendSamples4(chanend c_mix_out) #pragma loop unroll for(int i = 0; i < HS_STREAM_FORMAT_OUTPUT_2_CHAN_COUNT; i++) { - _send_sample_4(c_mix_out); + _send_sample_4(c_mix_out, i); } } else if(g_numUsbChan_Out == HS_STREAM_FORMAT_OUTPUT_3_CHAN_COUNT) @@ -205,7 +205,7 @@ static inline void SendSamples4(chanend c_mix_out) #pragma loop unroll for(int i = 0; i < HS_STREAM_FORMAT_OUTPUT_3_CHAN_COUNT; i++) { - _send_sample_4(c_mix_out); + _send_sample_4(c_mix_out, i); } } else @@ -213,7 +213,7 @@ static inline void SendSamples4(chanend c_mix_out) #pragma loop unroll for(int i = 0; i < NUM_USB_CHAN_OUT_FS; i++) { - _send_sample_4(c_mix_out); + _send_sample_4(c_mix_out, i); } } } From cf80a9aeaf0ed1df3d2d2f3912c2480164dc42ac Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Mon, 20 May 2024 15:26:32 +0100 Subject: [PATCH 6/6] changelog --- CHANGELOG.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0dcbab5f..3d6e5199 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -16,6 +16,8 @@ UNRELEASED * CHANGED: aud_to_host buffer size and the condition to come out of underflow in decoupler to fix buffer underflow seen in ADAT tests * FIXED: Initialise SMUX based on DEFAULT_FREQ in clockgen + * FIXED: Update g_numUsbChan_Out to the number of channels for the selected + interface when receiving a set interface request over EP0 4.0.0 -----