ALSA: usb: Work around CM6631 sample rate change bug
PATCH v2 1/1 ALSA: usb: Work around CM6631 sample rate change bug
The C-Media CM6631 USB-to-S/PDIF receiver doesn't respond to changes in sample rate while the interface is active.
Reset the interface after setting the sampling frequency on sample rate changes, to ensure that the sample rate set by snd_usb_init_sample_rate() is used. Otherwise, the device will try to use the sample rate of the previous stream, causing distorted sound on sample rate changes.
--- sound/usb/clock.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
sound/usb/clock.c +25 -0
@@ -255,6 +255,7 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,unsigned char data[4 ];int err, crate;int clock =snd_usb_clock_find_source (chip, fmt->clock); +unsigned int previous_rate;if (clock <0 )return clock;
@@ -266,6 +267,18 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,return -ENXIO ; } +if ((err =snd_usb_ctl_msg (dev,usb_rcvctrlpipe (dev,0 ),UAC2_CS_CUR , +USB_TYPE_CLASS |USB_RECIP_INTERFACE |USB_DIR_IN , +UAC2_CS_CONTROL_SAM_FREQ <<8 , +snd_usb_ctrl_intf (chip) | (clock <<8 ), + data,sizeof (data))) <0 ) { +snd_printk (KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n" , + dev->devnum, iface, fmt->altsetting); +return err; + } + + previous_rate = data[0 ] | (data[1 ] <<8 ) | (data[2 ] <<16 ) | (data[3 ] <<24 ); + data[0 ] = rate; data[1 ] = rate >>8 ; data[2 ] = rate >>16 ;
@@ -294,6 +307,18 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,if (crate != rate)snd_printd (KERN_WARNING "current rate %d is different from the runtime rate %d\n" , crate, rate); +/* Some devices doesn't respond to sample rate changes while the +* interface is active. */ +if (crate != previous_rate) { +switch (chip->usb_id) { +case USB_ID (0x0d8c ,0x0304 ):/* C-Media - Schiit USB */ +case USB_ID (0x0d8c ,0x0309 ):/* C-Media CM6631 */ +usb_set_interface (dev, iface,0 ); +usb_set_interface (dev, iface, fmt->altsetting); +break ; + } + } +return 0 ; }
Signature · 1 line
1.7.10.4
Hi
Some comments:
Quoted 6 lines · Torstein Hegge
The C-Media CM6631 USB-to-S/PDIF receiver doesn't respond to changes in sample rate while the interface is active.
Reset the interface after setting the sampling frequency on sample rate changes, to ensure that the sample rate set by
snd_usb_init_sample_rate()
is
Quoted 1 line
used. Otherwise, the device will try to use the sample rate of the
previous
sound/usb/clock.c static int set_sample_rate_v2(struct snd_usb_audio
Quoted 12 lines
stream, causing distorted sound on sample rate changes.
Signed-off-by Torstein Hegge <[email protected]>--- sound/usb/clock.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)sound/usb/clock.c +0
-0@@ -255,6 +255,7 @@ static int set_sample_rate_v2(struct snd_usb_audio
*chip, int iface,
sound/usb/clock.c static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface, · line 259
Quoted 5 lines
sound/usb/clock.c +1
-0unsigned char data[4 ];int err, crate;int clock =snd_usb_clock_find_source (chip, fmt->clock); +unsigned int previous_rate;
crate and previous_rate are different types.
Why don't call it prate or change both name?
sound/usb/clock.c static int set_sample_rate_v2(struct snd_usb_audio
Quoted 3 lines
sound/usb/clock.c +0
-0if (clock <0 )return clock;@@ -266,6 +267,18 @@ static int set_sample_rate_v2(struct snd_usb_audio
*chip, int iface,
sound/usb/clock.c static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
Quoted 4 lines
sound/usb/clock.c +1
-0return -ENXIO ; } + if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
UAC2_CS_CUR,
Is it more clear to assign it and then test?
sound/usb/clock.c static int set_sample_rate_v2(struct snd_usb_audio · line 271
Quoted 1 line
sound/usb/clock.c +1
-0+ USB_TYPE_CLASS | USB_RECIP_INTERFACE |
USB_DIR_IN,
sound/usb/clock.c static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
Quoted 4 lines
sound/usb/clock.c +4
-0+ UAC2_CS_CONTROL_SAM_FREQ << 8, + snd_usb_ctrl_intf(chip) | (clock << 8), + data, sizeof(data))) < 0) { + snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq
(v2)\n",
sound/usb/clock.c static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
Quoted 5 lines
sound/usb/clock.c +5
-0+ dev->devnum, iface, fmt->altsetting); +return err; + } + + previous_rate = data[0] | (data[1] << 8) | (data[2] << 16) |
(data[3] << 24);
sound/usb/clock.c static int set_sample_rate_v2(struct snd_usb_audio
Quoted 5 lines
sound/usb/clock.c +1
-0+ data[0 ] = rate; data[1 ] = rate >>8 ; data[2 ] = rate >>16 ;@@ -294,6 +307,18 @@ static int set_sample_rate_v2(struct snd_usb_audio
*chip, int iface,
sound/usb/clock.c static int set_sample_rate_v2(struct snd_usb_audio · line 308
Quoted 2 lines
sound/usb/clock.c +0
-0if (crate != rate) snd_printd(KERN_WARNING "current rate %d is different
from the runtime rate %d\n", crate, rate);
Quoted 17 lines
sound/usb/clock.c +12
-1+/* Some devices doesn't respond to sample rate changes while the +* interface is active. */ +if (crate != previous_rate) { +switch (chip->usb_id) { +case USB_ID (0x0d8c ,0x0304 ):/* C-Media - Schiit USB */ +case USB_ID (0x0d8c ,0x0309 ):/* C-Media CM6631 */ +usb_set_interface (dev, iface,0 ); +usb_set_interface (dev, iface, fmt->altsetting); +break ; + } + } +return 0 ; } --
Quoted 3 lines
1.7.10.4
Michael
_______________________________________________
Quoted 3 lines
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 27 lines · Michael Trimarchi
Hi
Some comments:
Quoted 6 lines · Torstein Hegge
The C-Media CM6631 USB-to-S/PDIF receiver doesn't respond to changes in sample rate while the interface is active.
Reset the interface after setting the sampling frequency on sample rate changes, to ensure that the sample rate set by
snd_usb_init_sample_rate()is
Quoted 1 line
used. Otherwise, the device will try to use the sample rate of the
previous
sound/usb/clock.c static int set_sample_rate_v2(struct snd_usb_audio
Quoted 12 lines
stream, causing distorted sound on sample rate changes.
Signed-off-by Torstein Hegge <[email protected]>--- sound/usb/clock.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)sound/usb/clock.c +0
-0@@ -255,6 +255,7 @@ static int set_sample_rate_v2(struct snd_usb_audio*chip, int iface,
Quoted 8 lines
sound/usb/clock.c static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface, · line 259
Quoted 5 lines
sound/usb/clock.c +1
-0unsigned char data[4 ];int err, crate;int clock =snd_usb_clock_find_source (chip, fmt->clock); +unsigned int previous_rate;crate and
previous_rateare different types.
Why don't call it prate or change both name?
How about int cur_rate, prev_rate; ?
Quoted 9 lines
sound/usb/clock.c static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface, · line 270
Quoted 7 lines
sound/usb/clock.c +1
-0if (clock <0 )return clock;@@ -266,6 +267,18 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,return -ENXIO ; } + if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,Is it more clear to assign it and then test?
I agree that separate assign and test would be more readable, but this is consistent with the four other calls to snd_usb_ctl_msg() in clock.c.
Torstein