Page 1 of 1

Recording S/PDIF (SPDIF) under Linux

Posted: Wed Nov 14, 2012 9:54 am
by danboid
My band mate has a KORG D16 digital multitrack recorder but its only got a 2GB HD and he doesn't have the funds to shell out for a new, dedicated audio input device for his PC so we thought it would be a good idea to utilise the S/PDIF output on his D16 so that he may use it as a slightly oversized set of mic inputs and pre-amps when attached to a PC. Since I had noticed that there are USB SPDIF adapters available for as little as £8 I thought they were too cheap not to try this solution.

I've got a StarTech 7.1 USB audio device which currently retails for about £20-35 and uses the CM6206 chipset. It claims it can handle 48K but I haven't been able to get it to reliably operate under JACK at anything above 44.1Khz nor have I got JACK playback and capture to work without xruns at less than 512 frames/period and 3 periods/buffer so latency isn't too hot, at 32ms. Additionally, beware that this device features physical volume controls but they only operate under Windows (and I presume OSX too) after you've installed the driver for it. It worked with JACK with the L and R mic input sockets out of the box but I had to do a fair bit of reading and emailing before I discovered how to record from the SPDIF input instead of the mic.

In addition to separate L and R mic inputs, the Startech 7.1 also features line in and SPDIF input. What threw me initially is that I was expecting to see separate JACK capture ports for the mic, line and SPDIF inputs but thats not how this and supposedly many similar devices work. Instead, you will only ever seen one pair of stereo inputs in JACK and you must use either a mixer app that supports adjusting the PCM capture source - unlike alsamixer or GNOME-alsamixer - or use the amixer command to select the desired input. My fave ALSA mixer is qasmixer and I know that at least both that and kmix have the ability to modify the 'PCM capture source' setting of attached devices although this option is not shown by default under kmix so you may need to add that control in and make sure the recording options are un-hidden under qasmixer or you could miss it.

I'm not going to go into detail here on how to use a graphical or TUI mixer here to record S/PDIF because if you're using a suitable mixer app its simply a case of finding the PCM capture source setting and selecting IEC958 - just be aware not all mixers let you do this. Instead, this mini-HOWTO intends document how to achieve the same from the command line with little other than the standard ALSA tools installed as the below method should work in every situation.

If you're still reading then the first thing you need to know is ALSA's name for your device:

Code: Select all

aplay -l
In my case the relevant output says 'card 1: Device [USB Sound device]' or something so in my case the relevant ALSA device name is the stunningly imaginative 'Device'.

To see the ALSA controls available for this device:

Code: Select all

amixer -c Device scontrols
The control we're concerned with is called 'PCM Capture Source' so to see its options and current setting:

Code: Select all

amixer -c Device get 'PCM Capture Source'
So long as you know your ALSA device name (in this case 'Device') then in most cases all you actually need to do to select SPDIF input is:

Code: Select all

amixer -c Device set 'PCM Capture Source' 'IEC958 In'
I've seen even less expensive USB SPDIF adapters than mine so if someone finds such a device that works under JACK reliably @ 48Khz then please let me know!

Re: Recording S/PDIF (SPDIF) under Linux

Posted: Thu Nov 15, 2012 4:49 pm
by danboid
Just updated this mini-howto with info on (non) suitable graphical mixers and a bit more detail on my initial findings of the Startech devices performance under JACK.

Re: Recording S/PDIF (SPDIF) under Linux

Posted: Fri Nov 16, 2012 3:09 am
by j_e_f_f_g
haven't been able to get it to operate above 44.1Khz
I think that's a limitation of the Korg. It's spec sheet mentions only 24/16-bit 44.1KHz. (Page 108 of the manual). And a SPDIF input must sync to its source.

Re: Recording S/PDIF (SPDIF) under Linux

Posted: Fri Nov 16, 2012 7:49 am
by danboid
Hi Jeff!

Its nothing to do with the KORG as we've not tried hooking the KORG up yet although that is the aim. Until now all my SPDIF testing has been with my old CD deck but thanks for looking up and pointing out its recording specs as I'd not checked that yet and I was just presuming it would also do 48k recording too.

Re: Recording S/PDIF (SPDIF) under Linux

Posted: Fri Nov 16, 2012 10:29 am
by j_e_f_f_g
danboid wrote:testing has been with my old CD deck
Oh, audio CD sample rate is also 44.1KHz, so that's probably what that SPDIF outputs. In fact it would have to be if that's the rate your SPDIF input is syncing to.