Skip to content

Commit be157c4

Browse files
geoffreybennetttiwai
authored andcommitted
ALSA: scarlett2: Fix Scarlett 4th Gen autogain status values
The meanings of the raw_auto_gain_status values were originally guessed through experimentation, but the official names have now been discovered. Update the autogain status control strings accordingly. Signed-off-by: Geoffrey D. Bennett <g@b4.vu> Fixes: 0a995e3 ("ALSA: scarlett2: Add support for software-controllable input gain") Signed-off-by: Takashi Iwai <tiwai@suse.de> Message-ID: <8bd12a5e7dc714801dd9887c4bc5cb35c384e27c.1710047969.git.g@b4.vu>
1 parent 6ef1f08 commit be157c4

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

sound/usb/mixer_scarlett2.c

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,22 @@ static const char *const scarlett2_dim_mute_names[SCARLETT2_DIM_MUTE_COUNT] = {
284284
"Mute Playback Switch", "Dim Playback Switch"
285285
};
286286

287-
/* Autogain Status Values */
288-
enum {
289-
SCARLETT2_AUTOGAIN_STATUS_STOPPED,
290-
SCARLETT2_AUTOGAIN_STATUS_RUNNING,
291-
SCARLETT2_AUTOGAIN_STATUS_FAILED,
292-
SCARLETT2_AUTOGAIN_STATUS_CANCELLED,
293-
SCARLETT2_AUTOGAIN_STATUS_UNKNOWN,
294-
SCARLETT2_AUTOGAIN_STATUS_COUNT
287+
/* The autogain_status is set based on the autogain_switch and
288+
* raw_autogain_status values.
289+
*
290+
* If autogain_switch is set, autogain_status is set to 0 (Running).
291+
* The other status values are from the raw_autogain_status value + 1.
292+
*/
293+
static const char *const scarlett2_autogain_status_texts[] = {
294+
"Running",
295+
"Success",
296+
"SuccessDRover",
297+
"WarnMinGainLimit",
298+
"FailDRunder",
299+
"FailMaxGainLimit",
300+
"FailClipped",
301+
"Cancelled",
302+
"Invalid"
295303
};
296304

297305
/* Power Status Values */
@@ -2835,9 +2843,9 @@ static int scarlett2_autogain_is_running(struct scarlett2_data *private)
28352843
{
28362844
int i;
28372845

2846+
/* autogain_status[] is 0 if autogain is running */
28382847
for (i = 0; i < private->info->gain_input_count; i++)
2839-
if (private->autogain_status[i] ==
2840-
SCARLETT2_AUTOGAIN_STATUS_RUNNING)
2848+
if (!private->autogain_status[i])
28412849
return 1;
28422850

28432851
return 0;
@@ -2867,25 +2875,25 @@ static int scarlett2_update_autogain(struct usb_mixer_interface *mixer)
28672875
return err;
28682876

28692877
/* Translate autogain_switch and raw_autogain_status into
2870-
* autogain_status
2878+
* autogain_status.
2879+
*
2880+
* When autogain_switch[] is set, the status is the first
2881+
* element in scarlett2_autogain_status_texts[] (Running). The
2882+
* subsequent elements correspond to the status value from the
2883+
* device (raw_autogain_status[]) + 1. The last element is
2884+
* "Invalid", in case the device reports a status outside the
2885+
* range of scarlett2_autogain_status_texts[].
28712886
*/
28722887
for (i = 0; i < info->gain_input_count; i++)
28732888
if (private->autogain_switch[i])
2889+
private->autogain_status[i] = 0;
2890+
else if (raw_autogain_status[i] <
2891+
ARRAY_SIZE(scarlett2_autogain_status_texts) - 1)
28742892
private->autogain_status[i] =
2875-
SCARLETT2_AUTOGAIN_STATUS_RUNNING;
2876-
else if (raw_autogain_status[i] == 0)
2877-
private->autogain_status[i] =
2878-
SCARLETT2_AUTOGAIN_STATUS_STOPPED;
2879-
else if (raw_autogain_status[i] >= 2 &&
2880-
raw_autogain_status[i] <= 5)
2881-
private->autogain_status[i] =
2882-
SCARLETT2_AUTOGAIN_STATUS_FAILED;
2883-
else if (raw_autogain_status[i] == 6)
2884-
private->autogain_status[i] =
2885-
SCARLETT2_AUTOGAIN_STATUS_CANCELLED;
2893+
raw_autogain_status[i] + 1;
28862894
else
28872895
private->autogain_status[i] =
2888-
SCARLETT2_AUTOGAIN_STATUS_UNKNOWN;
2896+
ARRAY_SIZE(scarlett2_autogain_status_texts) - 1;
28892897

28902898
return 0;
28912899
}
@@ -3111,12 +3119,10 @@ static int scarlett2_autogain_switch_ctl_put(
31113119
static int scarlett2_autogain_status_ctl_info(
31123120
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
31133121
{
3114-
static const char *const values[SCARLETT2_AUTOGAIN_STATUS_COUNT] = {
3115-
"Stopped", "Running", "Failed", "Cancelled", "Unknown"
3116-
};
3117-
31183122
return snd_ctl_enum_info(
3119-
uinfo, 1, SCARLETT2_AUTOGAIN_STATUS_COUNT, values);
3123+
uinfo, 1,
3124+
ARRAY_SIZE(scarlett2_autogain_status_texts),
3125+
scarlett2_autogain_status_texts);
31203126
}
31213127

31223128
static const struct snd_kcontrol_new scarlett2_autogain_switch_ctl = {

0 commit comments

Comments
 (0)