Skip to contentSkip to conversation

Workaround for misdetected sample rate with CM6207

PATCH In review Joris van Rantwijk 2 participants 4 messages Feb 14, 2009 – Feb 16, 2009 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Workaround for misdetected sample rate with CM6207

Summary: Workaround for misdetected sample rate with CM6207

The CM6207 incorrectly advertises its 96 kHz playback setting as 48 kHz in its USB device descriptor. This patch extends an existing workaround in usbaudio.c to also cover the CM6207.

This resolves issue 0004249 in the ALSA bug tracker.

Signed-off by: Joris van Rantwijk <[email protected]>

sound/usb/usbaudio.c +5 -4
diff -ur linux-2.6.28.4/sound/usb/usbaudio.c linux-2.6.28.4_j/sound/usb/usbaudio.c
@@ -2533,19 +2533,20 @@
 		}
 
 		fp->nr_rates = nr_rates;
-		fp->rate_min = fp->rate_max = combine_triple(&fmt[8]);
+		fp->rate_min = fp->rate_max = 0;
 		for (r = 0, idx = offset + 1; r < nr_rates; r++, idx += 3) {
 			unsigned int rate = combine_triple(&fmt[idx]);
 			/* C-Media CM6501 mislabels its 96 kHz altsetting */
 			if (rate == 48000 && nr_rates == 1 &&
-			    chip->usb_id == USB_ID(0x0d8c, 0x0201) &&
+                            (chip->usb_id == USB_ID(0x0d8c, 0x0201) ||
+                             chip->usb_id == USB_ID(0x0d8c, 0x0102)) &&
 			    fp->altsetting == 5 && fp->maxpacksize == 392)
 				rate = 96000;
 			fp->rate_table[r] = rate;
 			nonzero_rates |= rate;
-			if (rate < fp->rate_min)
+			if (r == 0 || rate < fp->rate_min)
 				fp->rate_min = rate;
-			else if (rate > fp->rate_max)
+			else if (r == 0 || rate > fp->rate_max)
 				fp->rate_max = rate;
 			fp->rates |= snd_pcm_rate_to_rate_bit(rate);
 		}
#1 lore raw

At Sat, 14 Feb 2009 22:22:05 +0100,

Quoted 10 lines · Joris van Rantwijk

Summary: Workaround for misdetected sample rate with CM6207

The CM6207 incorrectly advertises its 96 kHz playback setting as 48 kHz in its USB device descriptor. This patch extends an existing workaround in usbaudio.c to also cover the CM6207.

This resolves issue 0004249 in the ALSA bug tracker.

Signed-off by: Joris van Rantwijk <[email protected]>

Thanks for the patch.
Basically your patch tries to fix multiple thing at once. It should be better split.

For example, try the patch, and add 0d8c:0102 on that. Does it work?

Takashi

---

sound/usb/usbaudio.c +9 -8
index be47d89..5a09621 100644
@@ -2514,7 +2514,6 @@ static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioform
 		 * build the rate table and bitmap flags
 		 */
 		int r, idx;
-		unsigned int nonzero_rates = 0;
 
 		fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL);
 		if (fp->rate_table == NULL) {
@@ -2522,24 +2521,26 @@ static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioform
 			return -1;
 		}
 
-		fp->nr_rates = nr_rates;
-		fp->rate_min = fp->rate_max = combine_triple(&fmt[8]);
+		fp->nr_rates = 0;
+		fp->rate_min = fp->rate_max = 0;
 		for (r = 0, idx = offset + 1; r < nr_rates; r++, idx += 3) {
 			unsigned int rate = combine_triple(&fmt[idx]);
+			if (!rate)
+				continue;
 			/* C-Media CM6501 mislabels its 96 kHz altsetting */
 			if (rate == 48000 && nr_rates == 1 &&
 			    chip->usb_id == USB_ID(0x0d8c, 0x0201) &&
 			    fp->altsetting == 5 && fp->maxpacksize == 392)
 				rate = 96000;
-			fp->rate_table[r] = rate;
-			nonzero_rates |= rate;
-			if (rate < fp->rate_min)
+			fp->rate_table[fp->nr_rates] = rate;
+			if (!fp->rate_min || rate < fp->rate_min)
 				fp->rate_min = rate;
-			else if (rate > fp->rate_max)
+			if (!fp->rate_max || rate > fp->rate_max)
 				fp->rate_max = rate;
 			fp->rates |= snd_pcm_rate_to_rate_bit(rate);
+			fp->nr_rates++;
 		}
-		if (!nonzero_rates) {
+		if (!fp->nr_rates) {
 			hwc_debug("All rates were zero. Skipping format!\n");
 			return -1;
 		}
#2 lore raw

Hello Takashi,

Quoted 7 lines · Takashi Iwai
Quoted 5 lines

The CM6207 incorrectly advertises its 96 kHz playback setting as 48 kHz
in its USB device descriptor. This patch extends an existing workaround
in usbaudio.c to also cover the CM6207.

Basically your patch tries to fix multiple thing at once. It should be better split.

Thanks for picking this up.
Yes, I thought the min/max-rate fix was trivial enough to put in. I had no idea that you had something planned for it.

Quoted 2 lines

For example, try the patch, and add 0d8c:0102 on that. Does it work?

Yes, that works fine. Could you make it like that?

Greetings, Joris.

#3 lore raw

At Mon, 16 Feb 2009 20:05:17 +0100,

Quoted 12 lines · Joris van Rantwijk

Hello Takashi,

Quoted 7 lines · Takashi Iwai
Quoted 5 lines

The CM6207 incorrectly advertises its 96 kHz playback setting as 48 kHz
in its USB device descriptor. This patch extends an existing workaround
in usbaudio.c to also cover the CM6207.

Basically your patch tries to fix multiple thing at once. It should be better split.

Quoted 8 lines

Thanks for picking this up.
Yes, I thought the min/max-rate fix was trivial enough to put in. I had no idea that you had something planned for it.

Quoted 2 lines

For example, try the patch, and add 0d8c:0102 on that. Does it work?

Yes, that works fine. Could you make it like that?

Applied now with your fix. Thanks for a quick test!

Takashi