From d3fafdfbac39e679d70d84685a75eec039a7e29c Mon Sep 17 00:00:00 2001 From: Luciano Martin Date: Mon, 30 May 2022 11:25:48 +0100 Subject: [PATCH 1/4] Overwrite output channel descriptors only if output channels are defined (#269) Overwrite output channel descriptors only if output channels are defined --- CHANGELOG.rst | 2 ++ lib_xua/src/core/endpoint0/xua_endpoint0.c | 37 +++++++++++++--------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6cd9a43b..66017cb4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,8 @@ UNRELEASED * CHANGED: Exclude HID Report functions unless the HID feature is enabled * CHANGED: Explicit feedback EP enabled by default (see UAC_FORCE_FEEDBACK_EP) * FIXED: Incorrect conditional compilation of HID report code + * FIXED: Input/output descriptors written when input/output not enabled. (Audio + class 1.0 mode using XUA_USB_DESCRIPTOR_OVERWRITE_RATE_RES) * Changes to dependencies: diff --git a/lib_xua/src/core/endpoint0/xua_endpoint0.c b/lib_xua/src/core/endpoint0/xua_endpoint0.c index b282319b..6121effc 100755 --- a/lib_xua/src/core/endpoint0/xua_endpoint0.c +++ b/lib_xua/src/core/endpoint0/xua_endpoint0.c @@ -1,4 +1,4 @@ -// Copyright 2011-2021 XMOS LIMITED. +// Copyright 2011-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. /** * @brief Implements endpoint zero for an USB Audio 1.0/2.0 device @@ -492,37 +492,44 @@ void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, NULLABLE_RESOURCE(c } #endif -#ifdef XUA_USB_DESCRIPTOR_OVERWRITE_RATE_RES //change USB descriptor frequencies and bit resolution values here +#ifdef XUA_USB_DESCRIPTOR_OVERWRITE_RATE_RES //change USB descriptor frequencies and bit resolution values here - cfgDesc_Audio1[USB_AS_IN_INTERFACE_DESCRIPTOR_OFFSET_SUB_FRAME] = get_device_to_usb_bit_res() >> 3; //sub frame rate = bit rate /8 - cfgDesc_Audio1[USB_AS_IN_INTERFACE_DESCRIPTOR_OFFSET_SUB_FRAME + 1] = (get_device_to_usb_bit_res() & 0xff); //bit resolution + const int num_of_usb_descriptor_freq = 3; //This should be =3 according to the comments "using a value of <=2 or > 7 for num_freqs_a1 causes enumeration issues on Windows" in xua_ep0_descriptors.h - cfgDesc_Audio1[USB_AS_OUT_INTERFACE_DESCRIPTOR_OFFSET_SUB_FRAME] = get_usb_to_device_bit_res() >> 3; //sub frame rate = bit rate /8 - cfgDesc_Audio1[USB_AS_OUT_INTERFACE_DESCRIPTOR_OFFSET_SUB_FRAME + 1] = (get_usb_to_device_bit_res() & 0xff); //bit resolution +#if( 0 < NUM_USB_CHAN_IN ) - const unsigned num_of_usb_descriptor_freq=3; //This should be =3 according to the comments "using a value of <=2 or > 7 for num_freqs_a1 causes enumeration issues on Windows" in xua_ep0_descriptors.h - int i=0; - for(i=0;i> 3; //sub frame rate = bit rate /8 + cfgDesc_Audio1[USB_AS_IN_INTERFACE_DESCRIPTOR_OFFSET_SUB_FRAME + 1] = (get_device_to_usb_bit_res() & 0xff); //bit resolution + + for(int i=0;i> 8; cfgDesc_Audio1[USB_AS_IN_INTERFACE_DESCRIPTOR_OFFSET_FREQ + 3*i + 2] = (get_device_to_usb_rate() & 0xff0000)>> 16; } + cfgDesc_Audio1[USB_AS_IN_EP_DESCRIPTOR_OFFSET_MAXPACKETSIZE] = ((get_device_to_usb_bit_res() >> 3) * MAX_PACKET_SIZE_MULT_IN_FS) & 0xff; //max packet size + cfgDesc_Audio1[USB_AS_IN_EP_DESCRIPTOR_OFFSET_MAXPACKETSIZE + 1] = (((get_device_to_usb_bit_res() >> 3) * MAX_PACKET_SIZE_MULT_IN_FS) & 0xff00) >> 8; //max packet size - for(i=0;i> 3; //sub frame rate = bit rate /8 + cfgDesc_Audio1[USB_AS_OUT_INTERFACE_DESCRIPTOR_OFFSET_SUB_FRAME + 1] = (get_usb_to_device_bit_res() & 0xff); //bit resolution + + for(int i=0;i> 8; cfgDesc_Audio1[USB_AS_OUT_INTERFACE_DESCRIPTOR_OFFSET_FREQ + 3*i + 2] = (get_usb_to_device_rate() & 0xff0000)>> 16; } - cfgDesc_Audio1[USB_AS_IN_EP_DESCRIPTOR_OFFSET_MAXPACKETSIZE] = ((get_device_to_usb_bit_res() >> 3) * MAX_PACKET_SIZE_MULT_IN_FS) & 0xff; //max packet size - cfgDesc_Audio1[USB_AS_IN_EP_DESCRIPTOR_OFFSET_MAXPACKETSIZE + 1] = (((get_device_to_usb_bit_res() >> 3) * MAX_PACKET_SIZE_MULT_IN_FS) & 0xff00) >> 8; //max packet size - cfgDesc_Audio1[USB_AS_OUT_EP_DESCRIPTOR_OFFSET_MAXPACKETSIZE] = ((get_usb_to_device_bit_res() >> 3) * MAX_PACKET_SIZE_MULT_OUT_FS) & 0xff; //max packet size - cfgDesc_Audio1[USB_AS_OUT_EP_DESCRIPTOR_OFFSET_MAXPACKETSIZE + 1] = (((get_usb_to_device_bit_res() >> 3) * MAX_PACKET_SIZE_MULT_OUT_FS) & 0xff00) >> 8; //max packet size + cfgDesc_Audio1[USB_AS_OUT_EP_DESCRIPTOR_OFFSET_MAXPACKETSIZE] = ((get_usb_to_device_bit_res() >> 3) * MAX_PACKET_SIZE_MULT_OUT_FS) & 0xff; //max packet size + cfgDesc_Audio1[USB_AS_OUT_EP_DESCRIPTOR_OFFSET_MAXPACKETSIZE + 1] = (((get_usb_to_device_bit_res() >> 3) * MAX_PACKET_SIZE_MULT_OUT_FS) & 0xff00) >> 8; //max packet size +#endif // NUM_USB_CHAN_OUT -#endif +#endif // XUA_USB_DESCRIPTOR_OVERWRITE_RATE_RES #if( 0 < HID_CONTROLS ) hidReportInit(); From d5946b91a49042906f4181d7ca6216af771e3882 Mon Sep 17 00:00:00 2001 From: xross Date: Fri, 20 May 2022 16:19:07 +0100 Subject: [PATCH 2/4] Resolve device hang on sample rate cange when both mixer cores are running and NUM_USB_CHAN_OUT = 0 --- lib_xua/src/core/mixer/mixer.xc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib_xua/src/core/mixer/mixer.xc b/lib_xua/src/core/mixer/mixer.xc index 7f8b6e05..d14504aa 100644 --- a/lib_xua/src/core/mixer/mixer.xc +++ b/lib_xua/src/core/mixer/mixer.xc @@ -252,6 +252,9 @@ static inline void GetSamplesFromHost(chanend c) #pragma unsafe arrays static inline void GiveSamplesToDevice(chanend c, xc_ptr ptr, xc_ptr multOut) { +#if(NUM_USB_CHAN_OUT == 0) + outuint(c, 0); +#else { #pragma loop unroll for (int i=0; i 0 */ /* No mixes, this thread runs on its own doing just volume */ -#if(NUM_USB_CHAN_OUT == 0) - outuint(c_mixer2, 0); -#endif GiveSamplesToDevice(c_mixer2, samples_to_device_map, multOut); GetSamplesFromDevice(c_mixer2); GetSamplesFromHost(c_host); From 0f8b9dae8cefd1e5a47023e8c00bf8844cd64b4f Mon Sep 17 00:00:00 2001 From: xross Date: Fri, 20 May 2022 16:19:40 +0100 Subject: [PATCH 3/4] Removed extra bracing and fixed bad comment --- lib_xua/src/core/clocking/clockgen.xc | 2 +- lib_xua/src/core/mixer/mixer.xc | 52 +++++++++++++-------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/lib_xua/src/core/clocking/clockgen.xc b/lib_xua/src/core/clocking/clockgen.xc index eb294057..f2dcecf9 100644 --- a/lib_xua/src/core/clocking/clockgen.xc +++ b/lib_xua/src/core/clocking/clockgen.xc @@ -665,7 +665,7 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, out port p, ch /* Inspect for if we need to produce an edge */ if ((adatCounters.receivedSamples >= adatCounters.samplesPerTick)) { - /* Check edge is about right... S/PDIF may have changed freq... */ + /* Check edge is about right... ADAT may have changed freq... */ if (timeafter(adatReceivedTime, (timeLastEdge + LOCAL_CLOCK_INCREMENT - LOCAL_CLOCK_MARGIN))) { /* Record edge time */ diff --git a/lib_xua/src/core/mixer/mixer.xc b/lib_xua/src/core/mixer/mixer.xc index d14504aa..66123804 100644 --- a/lib_xua/src/core/mixer/mixer.xc +++ b/lib_xua/src/core/mixer/mixer.xc @@ -255,50 +255,48 @@ static inline void GiveSamplesToDevice(chanend c, xc_ptr ptr, xc_ptr multOut) #if(NUM_USB_CHAN_OUT == 0) outuint(c, 0); #else - { #pragma loop unroll - for (int i=0; i 0 - /* If mixer turned on sort out the channel mapping */ + /* If mixer turned on sort out the channel mapping */ - /* Read pointer to sample from the map */ - read_via_xc_ptr_indexed(index, ptr, i); + /* Read pointer to sample from the map */ + read_via_xc_ptr_indexed(index, ptr, i); - /* Read the actual sample value */ - read_via_xc_ptr_indexed(sample, samples, index); + /* Read the actual sample value */ + read_via_xc_ptr_indexed(sample, samples, index); #else - unsafe - { - /* Read the actual sample value */ - sample = ptr_samples[i]; - } + unsafe + { + /* Read the actual sample value */ + sample = ptr_samples[i]; + } #endif #if defined(OUT_VOLUME_IN_MIXER) && defined(OUT_VOLUME_AFTER_MIX) - /* Do volume control processing */ + /* Do volume control processing */ #warning OUT Vols in mixer, AFTER mix & map - read_via_xc_ptr_indexed(mult, multOut, i); - {h, l} = macs(mult, sample, 0, 0); - h<<=3; // Shift used to be done in audio thread but now done here incase of 32bit support + read_via_xc_ptr_indexed(mult, multOut, i); + {h, l} = macs(mult, sample, 0, 0); + h<<=3; // Shift used to be done in audio thread but now done here incase of 32bit support #error #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, h); + outuint(c, h); #else - outuint(c, sample); + outuint(c, sample); #endif - } } #endif } From fca2ec205859abca0ff45fab42c5abca8df93696 Mon Sep 17 00:00:00 2001 From: xross Date: Mon, 30 May 2022 11:22:01 +0100 Subject: [PATCH 4/4] Comment only --- lib_xua/src/core/clocking/clockgen.xc | 2 +- lib_xua/src/core/mixer/mixer.xc | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib_xua/src/core/clocking/clockgen.xc b/lib_xua/src/core/clocking/clockgen.xc index f2dcecf9..524c4dd2 100644 --- a/lib_xua/src/core/clocking/clockgen.xc +++ b/lib_xua/src/core/clocking/clockgen.xc @@ -1,4 +1,4 @@ -// Copyright 2011-2021 XMOS LIMITED. +// Copyright 2011-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #include diff --git a/lib_xua/src/core/mixer/mixer.xc b/lib_xua/src/core/mixer/mixer.xc index 66123804..4e982259 100644 --- a/lib_xua/src/core/mixer/mixer.xc +++ b/lib_xua/src/core/mixer/mixer.xc @@ -1,7 +1,5 @@ -// Copyright 2011-2021 XMOS LIMITED. +// Copyright 2011-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. - - #include #include #include "xua.h" @@ -15,7 +13,6 @@ /* FAST_MIXER has a bit of a nasty implentation but is more effcient */ #define FAST_MIXER 1 - //#ifdef OUT_VOLUME_IN_MIXER static unsigned int multOut_array[NUM_USB_CHAN_OUT + 1]; static xc_ptr multOut;