From f80d7647e0e9724e3f4909eeb935a8ab657f81b3 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 8 Feb 2023 11:59:13 +0000 Subject: [PATCH 1/5] - Make usage (of lack of) of CS when setting/getting mixer weights more clear in the implementation - Fix typo in IN_VOLUME_IN_MIXER define --- host_usb_mixer_control/OSX/usb_mixer.cpp | 10 +-- lib_xua/api/xua_conf_default.h | 2 +- lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc | 67 +++++++++---------- 3 files changed, 38 insertions(+), 41 deletions(-) diff --git a/host_usb_mixer_control/OSX/usb_mixer.cpp b/host_usb_mixer_control/OSX/usb_mixer.cpp index d7d99beb..be3b7740 100644 --- a/host_usb_mixer_control/OSX/usb_mixer.cpp +++ b/host_usb_mixer_control/OSX/usb_mixer.cpp @@ -250,9 +250,9 @@ static int get_num_mixer_units(const unsigned char *data, int length) { static double dev_get_mixer_value(unsigned int mixer, unsigned int nodeId) { - // MU_MIXER_CONTROL 0x01 short data; - usb_audio_class_get(CUR, ((unsigned char) (0x01<<8)), nodeId, usb_mixers->usb_mixer[mixer].id, 2,(unsigned char *) &data); + unsigned char cs = 0; /* Device doesnt use CS for getting/setting mixer weights */ + usb_audio_class_get(CUR, cs, nodeId, usb_mixers->usb_mixer[mixer].id, 2,(unsigned char *) &data); return ((double) data / 256); } @@ -868,8 +868,10 @@ int usb_mixer_set_value(unsigned int mixer, unsigned int nodeId, double val) /* write to device */ short value = (short) (val * 256); - - usb_audio_class_set(CUR, 1, 1<<8 | nodeId & 0xff, usb_mixers->usb_mixer[mixer].id, 2, (unsigned char *)&value); + + unsigned char cs = 0; /* Device doesnt use CS for setting/getting mixer nodes */ + unsigned char cn = nodeId & 0xff; + usb_audio_class_set(CUR, cs, cn, usb_mixers->usb_mixer[mixer].id, 2, (unsigned char *)&value); } return 0; diff --git a/lib_xua/api/xua_conf_default.h b/lib_xua/api/xua_conf_default.h index cd0dc98f..9e6ed31b 100644 --- a/lib_xua/api/xua_conf_default.h +++ b/lib_xua/api/xua_conf_default.h @@ -1093,7 +1093,7 @@ #endif /* Handle in volume control in the mixer - disabled by default */ -#ifdef IN_VOLUNE_IN_MIXER +#ifdef IN_VOLUME_IN_MIXER #define IN_VOLUME_IN_MIXER (0) #endif diff --git a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc index f0e440ec..fa6f39c0 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc +++ b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc @@ -282,12 +282,12 @@ void UpdateMixMap(chanend c_mix_ctl, int mix, int input, int src) outct(c_mix_ctl, XS1_CT_END); } -void UpdateMixerWeight(chanend c_mix_ctl, int mix, int index, unsigned val) +void UpdateMixerWeight(chanend c_mix_ctl, int mix, int index, unsigned mult) { outuint(c_mix_ctl, SET_MIX_MULT); outuint(c_mix_ctl, mix); outuint(c_mix_ctl, index); - outuint(c_mix_ctl, val); + outuint(c_mix_ctl, mult); outct(c_mix_ctl, XS1_CT_END); } @@ -798,50 +798,45 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c } case ID_MIXER_1: - - if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */ { - unsigned volume = 0; - - /* Expect OUT here with mute */ - if((result = XUD_GetBuffer(ep0_out, (buffer, unsigned char[]), datalength)) != XUD_RES_OKAY) + int cs = sp.wValue >> 8; /* Control Selector - currently unused */ + int cn = sp.wValue & 0xff; /* Channel number - used for mixer node index */ + + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */ { - return result; - } + unsigned weightMult = 0; - mixer1Weights[sp.wValue & 0xff] = (buffer, unsigned char[])[0] | (buffer, unsigned char[])[1] << 8; + /* Expect OUT here with weight */ + if((result = XUD_GetBuffer(ep0_out, (buffer, unsigned char[]), datalength)) != XUD_RES_OKAY) + { + return result; + } - if (mixer1Weights[sp.wValue & 0xff] == 0x8000) - { - volume = 0; + mixer1Weights[cn] = (buffer, unsigned char[])[0] | (buffer, unsigned char[])[1] << 8; + + if (mixer1Weights[cn] != 0x8000) + { + weightMult = db_to_mult(mixer1Weights[cn], XUA_MIXER_DB_FRAC_BITS, XUA_MIXER_MULT_FRAC_BITS); + } + + if (!isnull(c_mix_ctl)) + { + UpdateMixerWeight(c_mix_ctl, (cn) % 8, (cn) / 8, weightMult); + } + + /* Send 0 Length as status stage */ + return XUD_DoSetRequestStatus(ep0_in); } else { - volume = db_to_mult(mixer1Weights[sp.wValue & 0xff], XUA_MIXER_DB_FRAC_BITS, XUA_MIXER_MULT_FRAC_BITS); - } - if (!isnull(c_mix_ctl)) - { - //outuint(c_mix_ctl, SET_MIX_MULT); - //outuint(c_mix_ctl, (sp.wValue & 0xff) % 8); - //outuint(c_mix_ctl, (sp.wValue & 0xff) / 8); - //outuint(c_mix_ctl, volume); - //outct(c_mix_ctl, XS1_CT_END); - UpdateMixerWeight(c_mix_ctl, (sp.wValue & 0xff) % 8, (sp.wValue & 0xff) / 8, volume); - } + short weight = mixer1Weights[cn]; + (buffer, unsigned char[])[0] = weight & 0xff; + (buffer, unsigned char[])[1] = (weight >> 8) & 0xff; - /* Send 0 Length as status stage */ - return XUD_DoSetRequestStatus(ep0_in); - } - else - { - short weight = mixer1Weights[sp.wValue & 0xff]; - (buffer, unsigned char[])[0] = weight & 0xff; - (buffer, unsigned char[])[1] = (weight >> 8) & 0xff; - - return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), sp.wLength, sp.wLength); + return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), sp.wLength, sp.wLength); + } } break; - #endif default: /* We dont have a unit with this ID! */ From 58f691078d73c8d0814e54b7dad43e9861534bc0 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 8 Feb 2023 12:04:38 +0000 Subject: [PATCH 2/5] Added range checking when getting/setting mixer weights --- lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc index fa6f39c0..6b15e471 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc +++ b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc @@ -811,17 +811,20 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c { return result; } - - mixer1Weights[cn] = (buffer, unsigned char[])[0] | (buffer, unsigned char[])[1] << 8; - - if (mixer1Weights[cn] != 0x8000) + + if(cn < sizeof(mixer1Weights)/sizeof(mixer1Weights[0])) { - weightMult = db_to_mult(mixer1Weights[cn], XUA_MIXER_DB_FRAC_BITS, XUA_MIXER_MULT_FRAC_BITS); - } + mixer1Weights[cn] = (buffer, unsigned char[])[0] | (buffer, unsigned char[])[1] << 8; - if (!isnull(c_mix_ctl)) - { - UpdateMixerWeight(c_mix_ctl, (cn) % 8, (cn) / 8, weightMult); + if (mixer1Weights[cn] != 0x8000) + { + weightMult = db_to_mult(mixer1Weights[cn], XUA_MIXER_DB_FRAC_BITS, XUA_MIXER_MULT_FRAC_BITS); + } + + if (!isnull(c_mix_ctl)) + { + UpdateMixerWeight(c_mix_ctl, (cn) % 8, (cn) / 8, weightMult); + } } /* Send 0 Length as status stage */ @@ -829,7 +832,13 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c } else { - short weight = mixer1Weights[cn]; + short weight = 0x8000; + + if(cn < sizeof(mixer1Weights)/sizeof(mixer1Weights[0])) + { + weight = mixer1Weights[cn]; + } + (buffer, unsigned char[])[0] = weight & 0xff; (buffer, unsigned char[])[1] = (weight >> 8) & 0xff; From 22a3d5e0434e9ec930b8e0311ba5822d0cc084dc Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 8 Feb 2023 12:20:42 +0000 Subject: [PATCH 3/5] Added array to size to extern to fix sizeof usage error --- lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc index 6b15e471..c27ae9a8 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc +++ b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc @@ -30,9 +30,9 @@ extern unsigned int mutesOut[]; extern int volsIn[]; extern unsigned int mutesIn[]; -/* Mixer settings */ #if (MIXER) -extern short mixer1Weights[]; +/* Mixer weights */ +extern short mixer1Weights[MIX_INPUTS * MAX_MIX_COUNT]; /* Device channel mapping */ extern unsigned char channelMapAud[NUM_USB_CHAN_OUT]; From c5e944d73df432343884993be06df4a79af39fe8 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 8 Feb 2023 13:18:28 +0000 Subject: [PATCH 4/5] Use of storeShort function in mixer weight read and comment updates --- lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc index c27ae9a8..2a78b5c3 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc +++ b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc @@ -726,7 +726,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c case ID_XU_MIXSEL: { int cs = sp.wValue >> 8; /* Control Selector */ - int cn = sp.wValue & 0xff; /* Channel number */ + int cn = sp.wValue & 0xff; /* Channel Number */ /* Check for Get or Set */ if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) @@ -739,7 +739,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c if(datalength > 0) { - /* cn bounds check for safety..*/ + /* CN bounds check for safety..*/ if(cn < MIX_INPUTS) { //if(cs == CS_XU_MIXSEL) @@ -839,8 +839,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c weight = mixer1Weights[cn]; } - (buffer, unsigned char[])[0] = weight & 0xff; - (buffer, unsigned char[])[1] = (weight >> 8) & 0xff; + storeShort((buffer, unsigned char[]), 0, weight); return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), sp.wLength, sp.wLength); } @@ -934,7 +933,6 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c num_freqs++; } #endif - storeShort((buffer, unsigned char[]), 0, num_freqs); return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), i, sp.wLength); @@ -982,7 +980,6 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), sp.wLength, sp.wLength); break; #endif - default: /* Unknown Unit ID in Range Request selector for FU */ break; From 950beb55cbf050727c8a9f3db750623b8de20b3f Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 8 Feb 2023 17:05:00 +0000 Subject: [PATCH 5/5] - Fixed ifndef check - Fixed mix map update --- lib_xua/api/xua_conf_default.h | 2 +- lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc | 2 +- lib_xua/src/core/mixer/mixer.xc | 3 --- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib_xua/api/xua_conf_default.h b/lib_xua/api/xua_conf_default.h index 9e6ed31b..b501b982 100644 --- a/lib_xua/api/xua_conf_default.h +++ b/lib_xua/api/xua_conf_default.h @@ -1093,7 +1093,7 @@ #endif /* Handle in volume control in the mixer - disabled by default */ -#ifdef IN_VOLUME_IN_MIXER +#ifndef IN_VOLUME_IN_MIXER #define IN_VOLUME_IN_MIXER (0) #endif diff --git a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc index a7ae87ec..c065daf3 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc +++ b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc @@ -768,7 +768,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c else { /* Update relevant mix map */ - mixSel[cn-1][cn] = source; + mixSel[cs-1][cn] = source; UpdateMixMap(c_mix_ctl, cs-1, cn, mixSel[cs-1][cn]); } diff --git a/lib_xua/src/core/mixer/mixer.xc b/lib_xua/src/core/mixer/mixer.xc index 5a4176eb..088e8b13 100644 --- a/lib_xua/src/core/mixer/mixer.xc +++ b/lib_xua/src/core/mixer/mixer.xc @@ -125,15 +125,12 @@ int doMix5(volatile int * const unsafe samples, volatile int * const unsafe mult int doMix6(volatile int * const unsafe samples, volatile int * const unsafe mult); int doMix7(volatile int * const unsafe samples, volatile int * const unsafe mult); #else -/* DO NOT inline, causes 10.4.2 tools to add extra loads in loop */ -/* At 18 x 12dB we could get 64 x bigger */ #pragma unsafe arrays static inline int doMix(volatile int * unsafe samples, volatile int * unsafe const mixMap, volatile int * const unsafe mult) { int h=0; int l=0; -/* By breaking up the loop we keep things in the encoding for ldw (0-11) */ #pragma loop unroll for (int i=0; i