Enable S/PDIF PCM with JACK Audio by adding IEC958 in KMix

Unofficial support for the KXStudio Linux distribution and applications.
More info at http://kxstudio.linuxaudio.org/

Moderators: MattKingUSA, khz

tbritton
Established Member
Posts: 33
Joined: Sun Jan 29, 2012 4:22 am
Been thanked: 2 times

Enable S/PDIF PCM with JACK Audio by adding IEC958 in KMix

Post by tbritton »

By default in this version of KXStudio (and in many other distibutions) the S/PDIF (or SPDIF) jack on the back of so many computers nowadays is inoperable, even though the "Digital" device appears in Jack's output choices -- but there is no sound even though programs act as if they are succeeding in sending data - meters bounce around, etc. (I thought I must be missing a driver or have lost it in a recent Kernel update, but it is much simpler!)

Here is how to enable it.

After selecting the digital device in JACK's output settings (for instance, mine is a Realtek card listed as hw:SB,1[ALC888-VD Digital], type in "KMix" into the application search.

EDIT-Better yet, scroll down a bit and read Todd's post about using alsamixer instead!)

From your audio card's tab (mine was listed as HDA ATI SB but it was obvious which one it was!), click on the little wrench icon on the bottom right. A dialog pops up allowing you to add more device sliders to the mixer.

Scroll down to the bottom on the right-hand column and highlight "IEC958" and then click the green left-arrow to move IEC958 to the left-hand column of active devices. You are almost done!

Close the dialog, and you will see there is no actual slider for the IEC968 device, but there IS a speaker-mute button, and by default it will be set to be muted. Un-mute it, and you'll instantly see the PCM indicator on your receiver or home-theater pre-amp light up showing that it is receiving a signal now.

That's it!

The IEC958 item is a protocol that drives S/PDIF and PCM output through it, among other things. Basically, it is what allows the hardware to "talk" to that output jack.

I'm certain this will be helpful to those who use their KXStudio or other similar setup even in their main listening environment!

Terry
Last edited by tbritton on Mon Feb 18, 2013 2:14 am, edited 2 times in total.
tbritton
Established Member
Posts: 33
Joined: Sun Jan 29, 2012 4:22 am
Been thanked: 2 times

Re: Enable S/PDIF PCM with JACK Audio by adding IEC958 in KM

Post by tbritton »

falkTX wrote:Perhaps there's a reason it's muted by default?

Anyway, thanks for the tip! :D
Heh... I'm sure that there is a reason it is muted, and even that it is not already an item in the sliders, but I never in 10-million years would have anticipated it could be not working because something called "IEC958" was missing from the sliders bank. I'm just not that intutitive! ;-)

It took me three hours to figure it out, so I figured I'd put up a keyword-rich title and explain it for the next person. Less frustration = more fun making music, of course.

I'm totally ecstatic with this installation now, falkTX! Thanks for everything!

Terry
tbritton
Established Member
Posts: 33
Joined: Sun Jan 29, 2012 4:22 am
Been thanked: 2 times

Re: Enable S/PDIF PCM with JACK Audio by adding IEC958 in KM

Post by tbritton »

BTW - Is there a "down-side" to using the digital outs that I should perhaps be aware of?

Terry
ToddMWorth
Established Member
Posts: 225
Joined: Tue Oct 23, 2012 3:59 am

Re: Enable S/PDIF PCM with JACK Audio by adding IEC958 in KM

Post by ToddMWorth »

Never be afraid to ask... I've been using IEC958 for SPDIF and ADAT in my kx setups for months now... I could have saved you a few hours! ... but then, you would not have learned as much, so you lost nothing :)

I should recommend that this is not done with kmix though - use alsamixer for this task, it's the most direct method to configure your soundcard.

Using IEC958/TOSLink is advantageous over analog, and is the same as SPDIF over coax (RCA connectors on copper wire). It's definitely an advantage, if you are maintaining the signal in it's digital form, until it can be converted to analog (DAC) by a high quality device.

The outputs are muted by default because some cards can ONLY run IEC958 OR analog, but NOT BOTH at the same time... As the vast majority use analog, it would be foolish to ship alsa drivers configured so that analog sound may be disabled... It's one of those "if you're serious enough to need optical, you can enable it yourself" situatons. As you have discovered, sometimes one must be quite "serious" indeed, to get this working.

You actually have it easy, if the device shows up in the list in cadence. I've read that cadence uses aplay -l to get the list of devices, but that list is not always as complete, as aplay -L is. You obviously have something like hw:0,0 (analog) and hw:0,1(digital), and, once the card is unmuted, it actually works. I and many others do not. I have the hw:0,1 (or hw:NVidia_1) device, but I must manually type in plughw:0,1 (plughw:NVidia_1) or iec958:0,1 (iec958:NVidia_1) - I have to change from hw, to plughw or iec958, for it to work. This is a flaw in the driver for my card but it's fairly common especially amongst HDA cards. As there's no expectation of these quirks ever being fixed, it has to be accepted as a part of vendors not supporting open source drivers for their hardware. I highly recommend the 'vlc cheat', to find device names where cadence's list is not complete due to buggy drivers - find what works in vlc, using the alsa driver, then copy/paste the device from the .vlcrc file into cadence.

You can get compressed 5.1 channels over either coax or optical spdif, by using AC3. I've had this working (nice to see your PC take 6 discrete channels of audio, mash them into spdif, and make the dolby LED light up on the receiver) Sadly, due to shifting performance at the alsa driver caused by the compression, this DOES NOT work with jack, and their devs have zero interest in it. (rant) Bloody annoying given that it's the standard in high def consumer audio, and we are making media for that audience, but I guess we can always stop jack and audition our stuff direct via alsa until the jack devs clue in. (/rant)

So, TL;DR:

Yes you must un-mute optical or coaxial spdif outs.
You should do it with alsamixer, rather than kmix.
Yes there can be advantages, if your hardware supports it.
But not all advantages of spdif are available in jack.


Does anyone else have some good digital output related info to add to this thread?
tbritton
Established Member
Posts: 33
Joined: Sun Jan 29, 2012 4:22 am
Been thanked: 2 times

Re: Enable S/PDIF PCM with JACK Audio by adding IEC958 in KM

Post by tbritton »

Thanks, Todd!

I turned it off in Kmix and installed alsamixergui and switched it on. I'm not sure what the benefit is over using Kmix but I was concerned that I was seeing xruns pop up the other way. Only one so far - with the same settings - using alsamixergui. Is it routing things differently?

Terry
ToddMWorth
Established Member
Posts: 225
Joined: Tue Oct 23, 2012 3:59 am

Re: Enable S/PDIF PCM with JACK Audio by adding IEC958 in KM

Post by ToddMWorth »

I'm unsure of the fine details of *how* it happens, but I can tell *what* is happening, by the machines' behaviour. I have seen kmix and pulse, when trying to interface directly to the sound card's registers to set volume, seem to also set some other registers...

For example, if you use kmix on my HTPC, which uses SPDIF outputs, and you use the main volume slider in kmix to turn the volume down, it also somehow mutes the left channel. Turning the volume back up doesn't help either, you actually need to reboot (probably modprobe would do) to reinitialise the registers on the card. I used to have similar issues with my Echo pro audio cards, with older versions of linux.

Using alsamixer (the non gui one, the ncurses one, preferably) or alsactl to configure your card is as low-level as possible, and cuts out the kmix/pulse/phonon/gstreamer/whatever middle-men that can sometimes cause drama (especially in these rare use cases like ours, which go untested for years) and I've found it to be most reliable.


Edit: if you don't know what I mean with these 'registers', basically it's memory on your sound card that holds the card's configuration. If you want to configure the card in hardware, like say muting a channel, you have to write the correct bytes, to the correct location, on your soundcard's memory. Defining these 'correct' data and locations, is the job of the kernel module (driver) for your card -you don't need to know about it, it's just what goes on under the hood.
tbritton
Established Member
Posts: 33
Joined: Sun Jan 29, 2012 4:22 am
Been thanked: 2 times

Re: Enable S/PDIF PCM with JACK Audio by adding IEC958 in KM

Post by tbritton »

I just figured the gui version of alsamixer reads and writes the config file for you. Which one is it for alsamixer? And where is it?

I'll look for the version you mentioned. EDIT - looked it up - what the heck is this thing??? http://www.gnu.org/software/ncurses/ I ran away with my tail between my legs!!! EDIT-2 - OK, I'm not so afraid now... https://www.youtube.com/watch?v=x1YUp_g6JMw

The worst thing about linux is knowing where all the config files are hidden! Some in user, some in home, some in etc - it is enough to drive you batty! Is there a guide where you can look up these things? And, of course, you'd need to have some cross-reference to the filenames from some "plain english" description, I'd imagine.

What kind of buffer and periods/buffer settings can you get away with? I am getting xruns if I have anything lower than 2048 and 3 periods. Plus, it goes "out of sync" somehow, starts making noise and cuts out with an xrun at a regular, almost timed interval. I've even tried 4 periods. Needless to say, that pushes latency pretty high, but for just media playback I'm not so concerned. Not sure if I should un-check Realtime in that instance.

As a comparison: Connecting instead to the FocusRite 2i2 USB interface, at 48000 sample rate I can accomplish buffer of 256 and 2 periods with 5.3ms latency, never an xrun so far. I use Realtime for that setup. (that unit's analog-outs into the amp are pretty sweet, as I've come to expect from FocusRite...) [EDIT: OK, now I'm totally impressed with the FocusRite 2i2 - at 96000 sample rate, 256 samples and 3 periods, 1 xrun in 45 minutes with 2.7ms latency. That's incredible! But let's see how it handles being under the load of a DAW with effects and instruments running!]

Explaining JACK will be a video of its own when I get to doing a tutorial series!! (...after I know a bit more!)

Terry
Last edited by tbritton on Tue Feb 19, 2013 5:52 am, edited 1 time in total.
ToddMWorth
Established Member
Posts: 225
Joined: Tue Oct 23, 2012 3:59 am

Re: Enable S/PDIF PCM with JACK Audio by adding IEC958 in KM

Post by ToddMWorth »

tbritton wrote: OK, I'm not so afraid now... https://www.youtube.com/watch?v=x1YUp_g6JMw
:) Sorry mate, I guess I'm a little late explaining that ncurses is that whole ASCII-GUI thing!
The worst thing about linux is knowing where all the config files are hidden! Some in user, some in home, some in etc - it is enough to drive you batty! Is there a guide where you can look up these things? And, of course, you'd need to have some cross-reference to the filenames from some "plain english" description, I'd imagine.
I agree. There *is* a document which clearly defines the locations of files in a unix-like system....Sadly it's not always adhered to, and not always interpreted the same way, so there's a bit of movement.....
The catch here is that different apps will have different handling... like say alsa, which allows you to put a config file in the user home dir, which will override one in a system dir (/etc). This is why, properly documented projects will specify all config files in the man page (you know about man? It's short for manual. Try 'man alsamixer' (without the quotes) at the terminal for an example.)

Now as it happens this is hardware configuration we're talking about, rather than software config - so we aren't writing to a config file stored in your PC's disk, we're writing to those registers stored on the actual soundcard. You can see you alsa config by typing (without the quotes) ' cat ~/.asoundrc' and you'll see falk's magic loopbacks and such in there; telling alsa what cards exist and how to use them - but you'll notice, your volume/mutes/etc are not there. If you want to get at that, you have to use alsamixer/alsactl(/kmix/pulse/etc who use the alsa APIs to read/write the registers on the card).
What kind of buffer and periods/buffer settings can you get away with? I am getting xruns if I have anything lower than 2048 and 3 periods.


This really varies from card to card. A hint though - bigger buffers / more periods, can in some cases actually *cause* xruns. Turning those up may not be the best solution. Sadly I don't know any tricks other than to toy with the numbers till it behaves.
Explaining JACK will be a video of its own when I get to doing a tutorial series!! (...after I know a bit more!)
Sounds awesome :)
tbritton
Established Member
Posts: 33
Joined: Sun Jan 29, 2012 4:22 am
Been thanked: 2 times

Re: Enable S/PDIF PCM with JACK Audio by adding IEC958 in KM

Post by tbritton »

AutoStatic just helped me out hugely by sharing this post:

http://www.linuxmusicians.com/viewtopic ... 495#p32773

He explains the formula for USB devices.

(frames/sample rate)*period = theoretical latency. With USB devices, he says, you want this number to be an even multiple of 1ms.

It works on my Focusrite 2i2 - (64 frames / 48000 sample rate) * 3 periods == 4ms - rock steady.

Terry

PS - I also posted some of my other findings later in that same thread:
http://www.linuxmusicians.com/viewtopic ... 495#p37495
ToddMWorth
Established Member
Posts: 225
Joined: Tue Oct 23, 2012 3:59 am

Re: Enable S/PDIF PCM with JACK Audio by adding IEC958 in KM

Post by ToddMWorth »

That formula is applicable to all sound cards, btw - but the 1ms trick is USB specific.... It's about polling rates IIRC. USB was never intended for realtime stuff..... We just get away with it thanks to excess bandwidth ;)
tbritton
Established Member
Posts: 33
Joined: Sun Jan 29, 2012 4:22 am
Been thanked: 2 times

Re: Enable S/PDIF PCM with JACK Audio by adding IEC958 in KM

Post by tbritton »

ToddMWorth wrote:That formula is applicable to all sound cards, btw - but the 1ms trick is USB specific.... It's about polling rates IIRC. USB was never intended for realtime stuff..... We just get away with it thanks to excess bandwidth ;)
Ahh! Well, I'm not surprised hearing that.

I wonder why Cadence reports a different, usually lower latency value in every case I've observed so far?

Terry
tbritton
Established Member
Posts: 33
Joined: Sun Jan 29, 2012 4:22 am
Been thanked: 2 times

Re: Enable S/PDIF PCM with JACK Audio by adding IEC958 in KM

Post by tbritton »

Thanks, falkTX. So, the numbers to go with are the ones the formula derives, then. That is handy to know!

Terry
danboid
Established Member
Posts: 1327
Joined: Sun Aug 26, 2012 11:28 am
Location: England
Has thanked: 1 time
Been thanked: 4 times

Re: Enable S/PDIF PCM with JACK Audio by adding IEC958 in KM

Post by danboid »

I've only just seen this thread and its quite sad that you say you spent 3 hours trying to enable SPDIF because a few months before you started this thread I had already posted a keyword-laden guide to this same process on these forums:

http://www.linuxmusicians.com/viewtopic ... 19&t=10271

So I can only presume you didn't search these forums for SPDIF before you created this thread? Oh well! :/
tbritton
Established Member
Posts: 33
Joined: Sun Jan 29, 2012 4:22 am
Been thanked: 2 times

Re: Enable S/PDIF PCM with JACK Audio by adding IEC958 in KM

Post by tbritton »

It was fate.

Terry
danboid wrote:I've only just seen this thread and its quite sad that you say you spent 3 hours trying to enable SPDIF because a few months before you started this thread I had already posted a keyword-laden guide to this same process on these forums:

http://www.linuxmusicians.com/viewtopic ... 19&t=10271

So I can only presume you didn't search these forums for SPDIF before you created this thread? Oh well! :/
zth
Established Member
Posts: 94
Joined: Mon Jan 16, 2012 9:06 pm

Re: Enable S/PDIF PCM with JACK Audio by adding IEC958 in KM

Post by zth »

I'm having issues with this.
I own a Juli@ XTe PCIe card, and I'm trying to use the S/PDIF in to record my guitar, which is connected to the S/PDIF in via its FX-unit. This all worked fine with a Lexicon Omega USB, as that did the mixing itself.

I just can't get it to work. I followed this guide, but I have no "PCM Input Source". Here's a couple of informational pictures from both JACK and QASMixer:

Image
Here's my Cadence settings. I note that there's an additional entry for the hw:Juli,1 but that effectively doesn't work using, at least not by itself like that.

Image
My alsamixer.

Image
My QASMixer. Super-kudos to anyone that can explain to me what the different controls mean/do btw :D

I'm in desperate need of help here, I just simply _can't_ figure out how to do this. Thanks a ton in advance!
Post Reply