- 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
This commit is contained in:
Ross Owen
2023-02-08 11:59:13 +00:00
parent 6c2e7e3042
commit f80d7647e0
3 changed files with 38 additions and 41 deletions

View File

@@ -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) static double dev_get_mixer_value(unsigned int mixer, unsigned int nodeId)
{ {
// MU_MIXER_CONTROL 0x01
short data; 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); return ((double) data / 256);
} }
@@ -868,8 +868,10 @@ int usb_mixer_set_value(unsigned int mixer, unsigned int nodeId, double val)
/* write to device */ /* write to device */
short value = (short) (val * 256); 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; return 0;

View File

@@ -1093,7 +1093,7 @@
#endif #endif
/* Handle in volume control in the mixer - disabled by default */ /* 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) #define IN_VOLUME_IN_MIXER (0)
#endif #endif

View File

@@ -282,12 +282,12 @@ void UpdateMixMap(chanend c_mix_ctl, int mix, int input, int src)
outct(c_mix_ctl, XS1_CT_END); 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, SET_MIX_MULT);
outuint(c_mix_ctl, mix); outuint(c_mix_ctl, mix);
outuint(c_mix_ctl, index); outuint(c_mix_ctl, index);
outuint(c_mix_ctl, val); outuint(c_mix_ctl, mult);
outct(c_mix_ctl, XS1_CT_END); 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: case ID_MIXER_1:
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */
{ {
unsigned volume = 0; int cs = sp.wValue >> 8; /* Control Selector - currently unused */
int cn = sp.wValue & 0xff; /* Channel number - used for mixer node index */
/* Expect OUT here with mute */
if((result = XUD_GetBuffer(ep0_out, (buffer, unsigned char[]), datalength)) != XUD_RES_OKAY) 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) mixer1Weights[cn] = (buffer, unsigned char[])[0] | (buffer, unsigned char[])[1] << 8;
{
volume = 0; 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 else
{ {
volume = db_to_mult(mixer1Weights[sp.wValue & 0xff], XUA_MIXER_DB_FRAC_BITS, XUA_MIXER_MULT_FRAC_BITS); short weight = mixer1Weights[cn];
} (buffer, unsigned char[])[0] = weight & 0xff;
if (!isnull(c_mix_ctl)) (buffer, unsigned char[])[1] = (weight >> 8) & 0xff;
{
//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);
}
/* Send 0 Length as status stage */ return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), sp.wLength, sp.wLength);
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);
} }
break; break;
#endif #endif
default: default:
/* We dont have a unit with this ID! */ /* We dont have a unit with this ID! */