Skip to contentSkip to conversation

Status of CM6631 USB

Alsa-user Daniel Mack 2 participants 2 messages Mar 2, 2013 – Mar 4, 2013 4 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Hi Torstein,

(+ alsa-devel)

Quoted 23 lines · Torstein Hegge
Quoted 5 lines · Daniel Mack <zonque <at> gmail.com> writes:
Quoted 5 lines
Quoted 4 lines

This is a known bug, also most probably flaw in the CMEDIA chip, and not yet properly worked around in the snd-usb driver. If you want to investigate, have a look at the feedback format autodetection code in sound/usb/endpoint.c.

Quoted 8 lines
Quoted 1 line

Thanks, I'll have a look.

I believe what's going on here is that the device is confused after sample rate changes and keeps sending back feedback data for the old rate on its feedback endpoint. That causes the autodetection algorithm, which kicks in on every first packet of a stream, to go nuts, which causes the part of the driver that sends the data assume a very wrong rate. Some printk() there should give you a hint.

I had a look at this using another C-Media CM6631 based device, the Corda Daccord (usbid 0x0d8c, 0x0309). As far as I can see, what happens in the feedback format auto-detection is:

When starting playback of a file with a different sampling frequency than the previous file, the reported feedback frequency is in the same range as the previously played file, varying within +-1%.

Quoted 5 lines

The feedback format detection gives a shift of -1 and reports the feedback frequency as ~48kHz when playing a 44.1kHz file after a 96kHz file. Same thing happens when playing a 96kHz file after a 44.1kHz file, the device reports feedback frequency in the 44.1kHz range, the feedback format detection gives a shift of +1 and reports the feedback frequency as ~88kHz.

That's what I suspected.

Quoted 9 lines

Bypassing the feedback format detection by hard-coding the frequency shift to zero and setting the feedback frequency ep->freqm equal to the nominal frequency ep->freqn if the feedback frequency is far off from the expected value (like 48kHz when expecting 44.1kHz) does not change the distortion.

Similarly, forcing the feedback detection to run multiple times until it reaches an acceptable value just keeps the feedback detection to repeatedly until playback is stopped. This probably means any amount of skipping packages early in the stream won't work.

Ok.

Quoted 3 lines

It seems like the device stays in the previous frequency until the interface is reset. One possible workaround is to call usb_set_interface() again after snd_usb_init_sample_rate(), like this:

I see - that also explains why explicitly stopping and restarting the stream fixes the problem in most cases, right?

Quoted 24 lines
sound/usb/pcm.c +10 -0
index d82e378..01978a6 100644
@@ -710,6 +710,16 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream
 *substream)
                subs->need_setup_ep = false;
        }
 
+       /* Some devices doesn't respond to sample rate changes while the 
+        * interface is active. */
+       switch (subs->stream->chip->usb_id) {
+       case USB_ID(0x0d8c, 0x0304): /* C-Media - Schiit USB Interface */
+       case USB_ID(0x0d8c, 0x0309): /* C-Media CM6631 */
+               usb_set_interface(subs->dev, subs->cur_audiofmt->iface,
+                                       subs->cur_audiofmt->altset_idx);
+               break;
+       }   
+
        /* some unit conversions in runtime */
        subs->data_endpoint->maxframesize =
                bytes_to_frames(runtime, subs->data_endpoint->maxpacksize);
Quoted 3 lines

This fixes all problems related to sample rate changes for me. I have only tested with the Daccord, but it should work for the Schiit and other CM6631 based devices as well.

Many thanks for looking into this! Much appreciated.

Could you cook a real patch please and send it to alsa-devel? Have a look at Documentation/SubmittingPatches if that's your first submission.

Best,
Daniel

#5 lore raw

Gentlemen;

Quoted 95 lines · Daniel Mack

Hi Torstein,

(+ alsa-devel)

Quoted 15 lines · Torstein Hegge
Quoted 5 lines · Daniel Mack <zonque <at> gmail.com> writes:
Quoted 5 lines
Quoted 4 lines

This is a known bug, also most probably flaw in the CMEDIA chip, and not yet properly worked around in the snd-usb driver. If you want to investigate, have a look at the feedback format autodetection code in sound/usb/endpoint.c.

Quoted 8 lines
Quoted 1 line

Thanks, I'll have a look.

I believe what's going on here is that the device is confused after sample rate changes and keeps sending back feedback data for the old rate on its feedback endpoint. That causes the autodetection algorithm, which kicks in on every first packet of a stream, to go nuts, which causes the part of the driver that sends the data assume a very wrong rate. Some printk() there should give you a hint.

Quoted 5 lines

I had a look at this using another C-Media CM6631 based device, the Corda Daccord (usbid 0x0d8c, 0x0309). As far as I can see, what happens in the feedback format auto-detection is:

When starting playback of a file with a different sampling frequency

than the

Quoted 1 line

previous file, the reported feedback frequency is in the same range as

the

Quoted 3 lines

previously played file, varying within +-1%.

The feedback format detection gives a shift of -1 and reports the

feedback

Quoted 1 line

frequency as ~48kHz when playing a 44.1kHz file after a 96kHz file. Same

thing

Quoted 1 line

happens when playing a 96kHz file after a 44.1kHz file, the device

reports

Quoted 1 line

feedback frequency in the 44.1kHz range, the feedback format detection

gives a

Quoted 1 line

shift of +1 and reports the feedback frequency as ~88kHz.

That's what I suspected.

Quoted 1 line

Bypassing the feedback format detection by hard-coding the frequency

shift to

Quoted 2 lines

zero and setting the feedback frequency ep->freqm equal to the nominal frequency ep->freqn if the feedback frequency is far off from the

expected

Quoted 4 lines

value (like 48kHz when expecting 44.1kHz) does not change the distortion.

Similarly, forcing the feedback detection to run multiple times until it reaches an acceptable value just keeps the feedback detection to

repeatedly

Quoted 1 line

until playback is stopped. This probably means any amount of skipping

packages

Quoted 1 line

early in the stream won't work.

Ok.

Quoted 1 line

It seems like the device stays in the previous frequency until the

interface

Quoted 1 line

is reset. One possible workaround is to call usb_set_interface() again

after

Quoted 1 line

snd_usb_init_sample_rate(), like this:

I see - that also explains why explicitly stopping and restarting the stream fixes the problem in most cases, right?

sound/usb/pcm.c static int snd_usb_pcm_prepare(struct

Quoted 6 lines
sound/usb/pcm.c +0 -0
index d82e378..01978a6 100644
@@ -710,6 +710,16 @@ static int snd_usb_pcm_prepare(struct

snd_pcm_substream

Quoted 16 lines
sound/usb/pcm.c +10 -0
 *substream)
                subs->need_setup_ep = false;
        }
 
+       /* Some devices doesn't respond to sample rate changes while the
+        * interface is active. */
+       switch (subs->stream->chip->usb_id) {
+       case USB_ID(0x0d8c, 0x0304): /* C-Media - Schiit USB Interface */
+       case USB_ID(0x0d8c, 0x0309): /* C-Media CM6631 */
+               usb_set_interface(subs->dev, subs->cur_audiofmt->iface,
+                                       subs->cur_audiofmt->altset_idx);
+               break;
+       }
+
        /* some unit conversions in runtime */
        subs->data_endpoint->maxframesize =
Quoted 1 line

bytes_to_frames(runtime,

subs->data_endpoint->maxpacksize);

Quoted 2 lines

This fixes all problems related to sample rate changes for me. I have

only

Quoted 9 lines
Quoted 1 line

tested with the Daccord, but it should work for the Schiit and other

CM6631

Quoted 1 line

based devices as well.

Many thanks for looking into this! Much appreciated.

Could you cook a real patch please and send it to alsa-devel? Have a look at Documentation/SubmittingPatches if that's your first submission.

I would be happy to test this on my Schiit Bifrost as well. I'm currently using the TOSLINK connection but it would be easy peasy to hook up a laptop via the USB.

Signature · 3 lines
Chris Hermansen · clhermansen "at" gmail "dot" com

C'est ma façon de parler.

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb

_______________________________________________
Alsa-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-user