Skip to contentSkip to conversation

ALSA: snd-usb: sample rate detection workaround for Axe-Fx II

PATCH In review Daniel Mack 1 participant 2 messages Sep 8, 2013 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: snd-usb: sample rate detection workaround for Axe-Fx II

Fractal Audio Systems Axe-Fx II and maybe other devices fail to return their sample rate range descriptor when only asked for the first two bytes.

Add a workaround and assume exactly one sample rate in this case, and continue with the full descriptor fetch.

---
 sound/usb/format.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
sound/usb/format.c +13 -8
index 3525231..d9de43d 100644
@@ -297,13 +297,17 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
 			      snd_usb_ctrl_intf(chip) | (clock << 8),
 			      tmp, sizeof(tmp));
 
-	if (ret < 0) {
-		snd_printk(KERN_ERR "%s(): unable to retrieve number of sample rates (clock %d)\n",
-				__func__, clock);
-		goto err;
-	}
+	/*
+	 * Some devices, including Fractal Audio Systems Axe-Fx II, fail to
+	 * return only a fraction of this descriptor. If that happens, assume
+	 * we have only one sample rate and continue. In case of any other
+	 * error, we will bail on the full descriptor fetch below.
+	 */
+	if (ret < 0)
+		nr_triplets = 1;
+	else
+		nr_triplets = combine_word(tmp);
 
-	nr_triplets = (tmp[1] << 8) | tmp[0];
 	data_size = 2 + 12 * nr_triplets;
 	data = kzalloc(data_size, GFP_KERNEL);
 	if (!data) {
@@ -319,8 +323,9 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
 			      data, data_size);
 
 	if (ret < 0) {
-		snd_printk(KERN_ERR "%s(): unable to retrieve sample rate range (clock %d)\n",
-				__func__, clock);
+		snd_printk(KERN_ERR "%s(): unable to retrieve sample rate range "
+				    "(clock %d, nr_triplets %d)\n",
+				    __func__, clock, nr_triplets);
 		ret = -EINVAL;
 		goto err_free;
 	}
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 6 lines · Daniel Mack

Fractal Audio Systems Axe-Fx II and maybe other devices fail to return their sample rate range descriptor when only asked for the first two bytes.

Add a workaround and assume exactly one sample rate in this case, and continue with the full descriptor fetch.

Please ignore this patch for now. In an off-list discussion, it turned out that this device needs a manual firmware download each time it is connected, and the vendor is willing to fix that bug on the firmware side. Hence, that issue can be fixed for all users at once, and so we won't need that nasty workaround eventually.

Thanks,
Daniel

Quoted 48 lines
---
 sound/usb/format.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
sound/usb/format.c +13 -8
index 3525231..d9de43d 100644
@@ -297,13 +297,17 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
 			      snd_usb_ctrl_intf(chip) | (clock << 8),
 			      tmp, sizeof(tmp));
 
-	if (ret < 0) {
-		snd_printk(KERN_ERR "%s(): unable to retrieve number of sample rates (clock %d)\n",
-				__func__, clock);
-		goto err;
-	}
+	/*
+	 * Some devices, including Fractal Audio Systems Axe-Fx II, fail to
+	 * return only a fraction of this descriptor. If that happens, assume
+	 * we have only one sample rate and continue. In case of any other
+	 * error, we will bail on the full descriptor fetch below.
+	 */
+	if (ret < 0)
+		nr_triplets = 1;
+	else
+		nr_triplets = combine_word(tmp);
 
-	nr_triplets = (tmp[1] << 8) | tmp[0];
 	data_size = 2 + 12 * nr_triplets;
 	data = kzalloc(data_size, GFP_KERNEL);
 	if (!data) {
@@ -319,8 +323,9 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
 			      data, data_size);
 
 	if (ret < 0) {
-		snd_printk(KERN_ERR "%s(): unable to retrieve sample rate range (clock %d)\n",
-				__func__, clock);
+		snd_printk(KERN_ERR "%s(): unable to retrieve sample rate range "
+				    "(clock %d, nr_triplets %d)\n",
+				    __func__, clock, nr_triplets);
 		ret = -EINVAL;
 		goto err_free;
 	}