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! */