[LINUX] Problems switching from Analog to Digital over SPDIF?
#1
I've read all the relevant threads here but couldn't find a working solution.

version: 9.11 alpha 2, ubuntu 9.10

This is the situation:
  • I'm using optical spdif to output all audio to a DTS capable receiver.
  • I can get both analog and digital audio to play correctly on the receiver
  • When I switch from an analog stream to a digital one (which uses passthrough) I get an error "failed to initialize audio settings".
  • However, when i set the audio output device to iec958 and load DTS content it works, but after switching to an analog stream and then switching back to DTS I get the error again. The menu sounds don't work at all in iec958 output mode
  • All of this switching works without a problem using VLC

Here is the log where i successfully played DTS content(Eastern.Promises), then successfully switched to analog audio content(Happiness) and failed to switch back to the same DTS content(Eastern.Promises).

http://pastebin.com/pastebin.php?dl=m767fda9c

this is where it goes wrong (seems it doesn't even try to switch to passthrough here):

Code:
02:37:49 T:2928397168 M:1889439744   DEBUG: CDVDPlayerAudio - CDVDMsg::GENERAL_RESYNC(484414693.877551, 0)
02:37:49 T:2928397168 M:1889439744  NOTICE: Creating audio device with codec id: 86017, channels: 2, sample rate: 44100, no pass-through
02:37:49 T:2928397168 M:1889439744   DEBUG: PulseAudio: Opening Channels: 2 - SampleRate: 44100 - SampleBit: 16 - Resample false - Codec PCM - IsMusic false - IsPassthrough false - device: [email protected]efault
02:37:49 T:2928397168 M:1889439744   DEBUG: PulseAudio: Context failed
02:37:49 T:2928397168 M:1889439744   ERROR: PulseAudio: Waited for the Context but it failed
02:37:49 T:2928397168 M:1889439744   ERROR: PulseAudio: Failed to create context
02:37:49 T:2928397168 M:1889312768    INFO: AudioRendererFactory: [email protected]efault not a explicit device, trying to autodetect.
02:37:49 T:2928397168 M:1889312768   DEBUG: PulseAudio: Opening Channels: 2 - SampleRate: 44100 - SampleBit: 16 - Resample false - Codec PCM - IsMusic false - IsPassthrough false - device: pulse:[email protected]efault
02:37:49 T:2928397168 M:1889312768   DEBUG: PulseAudio: Context failed
02:37:49 T:2928397168 M:1889312768   ERROR: PulseAudio: Waited for the Context but it failed
02:37:49 T:2928397168 M:1889312768   ERROR: PulseAudio: Failed to create context
02:37:49 T:2928397168 M:1889312768   DEBUG: CALSADirectSound::CALSADirectSound - Channels: 2 - SampleRate: 44100 - SampleBit: 16 - Resample false - Codec PCM - IsMusic false - IsPassthrough false - audioDevice: pulse:[email protected]efault
02:37:49 T:2928397168 M:1889312768   DEBUG: Initialize - using alsa device pulse:[email protected]efault
02:37:49 T:2928397168 M:1889312768   ERROR: Initialize - pcm_open_lconf, alsa error: -2 - No such file or directory
02:37:49 T:2928397168 M:1889312768   ERROR: Creating a Null Audio Renderer, Check your audio settings as this should not happen
02:37:49 T:2928397168 M:1889312768   DEBUG: CDVDPlayerAudio:: synctype set to 0: clock feedback
02:37:49 T:2928397168 M:1889312768   DEBUG: CDVDPlayerAudio:: Discontinuty - was:484436040.884942, should be:484440838.059010, error:4797.174068

All help appreciated!
Reply
#2
Exact same problem here, so bump.
Reply
#3
Ok I got it to work by explicitly stating the same device for audio and passthrough. In my case SPDIF is on card 0 device 1:

custom audio device: plughw:0,1

custom passthrough device: plughw:0,1

This way normal audo and passthrough seems to work via the same SPDIF device without error. The only problem with this setup is that crossfading now fails with the audio init error.

So this will work only when disabling crossfading for music :/
Reply
#4
F3d0r Wrote:Ok I got it to work by explicitly stating the same device for audio and passthrough. In my case SPDIF is on card 0 device 1:

custom audio device: plughw:0,1

custom passthrough device: plughw:0,1

This way normal audo and passthrough seems to work via the same SPDIF device without error. The only problem with this setup is that crossfading now fails with the audio init error.

So this will work only when disabling crossfading for music :/

tried that and same result here. crossfading breaks, but switching digital/analog works. Still annoying but it's a step forward Smile
Reply
#5
With the help of the alsa dmix plugin I also managed to get crossfade working.

I just put the following in ~/.asoundrc
Code:
pcm.dmixer {
    type dmix
    ipc_key 1024
    slave {
        pcm "hw:0,1"
        period_time 0
        period_size 1024
        buffer_size 8192
        #periods 128
        #rate 44100
        rate 48000
     }
     bindings {
        0 0
        1 1
     }
}

After this I specified plug:dmixer as audio output device.

Result: Anlaog Audio + Crossfading + Passthrough via a single SPDIF device Smile
Reply
#6
I also ran into some failiures with the stereo / passthrough too.
Now after some trying i figured out that for movies my xbmc (9.11 alpha 2 on ubuntu karmic too) for stereo i should use custom iec958 and for passthrough i use the preconfigured iec958 for playing movies just fine.
when playing mp3 music i still get this could initialize audio device error.

none of the solutions above fixed this for me.
Reply
#7
Some additional notes:

The described solution bypasses PulseAudio and forces XBMC to directly use ALSA. However, there is no need to uninstall or mess with PulseAudio on Ubuntu in any way.

@razo
Of course youhave to specify the correct device on audio and passthrough for this to work. I really recommend to test the device with aplay -d<device> <yoursample>.wav before messing around in XBMC.
Reply
#8
F3d0r Wrote:Some additional notes:

The described solution bypasses PulseAudio and forces XBMC to directly use ALSA. However, there is no need to uninstall or mess with PulseAudio on Ubuntu in any way.

@razo
Of course youhave to specify the correct device on audio and passthrough for this to work. I really recommend to test the device with aplay -d<device> <yoursample>.wav before messing around in XBMC.

you know what? YOU ARE AWESOME!!

All but menu sounds (which work unless switching to a digtial source) work!

Took the liberty to throw your solution on the wiki. Thanks again!
Reply
#9
Another note:
The solution described here is not limited to SPDIF, it will also work for other digital audio sinks like HDMI.
Reply
#10
F3d0r Wrote:Ok I got it to work by explicitly stating the same device for audio and passthrough. In my case SPDIF is on card 0 device 1:

custom audio device: plughw:0,1

custom passthrough device: plughw:0,1

This way normal audo and passthrough seems to work via the same SPDIF device without error. The only problem with this setup is that crossfading now fails with the audio init error.

So this will work only when disabling crossfading for music :/

In my case, I had to add iec98 instead of plughw:0,1 (wich is the same device, according to aplay -l).
By the way, I can hear dts and stereo sounds, but no dolby digital. XBMC gives me "failed to initialize audio settings".
Reply
#11
dongioia Wrote:In my case, I had to add iec98 instead of plughw:0,1 (wich is the same device, according to aplay -l).
By the way, I can hear dts and stereo sounds, but no dolby digital. XBMC gives me "failed to initialize audio settings".

The alsa hw plugin communicates directly with the ALSA kernel driver. It depends on the configuration of your virtual iec958 device if this is really the same (I doubt it).

If DTS works but DD not you have either unchecked "DD capable receiver" or your receiver is just not capable or does not get the signal. However, if using ubuntu try to configure PulseAudio to not use the SPDIF as output device (sound hardware settings).
Reply
#12
F3d0r Wrote:The alsa hw plugin communicates directly with the ALSA kernel driver. It depends on the configuration of your virtual iec958 device if this is really the same (I doubt it).

If DTS works but DD not you have either unchecked "DD capable receiver" or your receiver is just not capable or does not get the signal.

My receiver is capable to play DD sounds. This problem starts to happen when I switch from Jaunty to Karmic, upgrading xbmc to the latest beta.
Previously (jaunty, no pulse, xbmc 9.10, alsa 1.20), using iec958 as output device, I was able to hear everything.
I'll try to disable iec958 output in pulseaudio.
Thanks for the clue.
Reply
#13
@ F3d0r

You were right.

I disabled the iec958 output in pulseaudio settings, and everything now is just fine: xbmc plays every kind of audio streams. The downside is that now I can't hear system sounds or sounds from youtube, for example, because my only audio output is the digital one.
Reply
#14
YES! My problems with sound are finally solved, thanks to this solution. Thanks!
Reply
#15
can somebody help me>?

[email protected]:~$ aplay -l
**** Lijst van PLAYBACK hardware-apparaten ****
kaart 0: NVidia [HDA NVidia], apparaat 0: ALC662 rev1 Analog [ALC662 rev1 Analog]
Sub-apparaten: 1/1
Sub-apparaat #0: subdevice #0
kaart 0: NVidia [HDA NVidia], apparaat 1: ALC662 rev1 Digital [ALC662 rev1 Digital]
Sub-apparaten: 0/1
Sub-apparaat #0: subdevice #0
kaart 0: NVidia [HDA NVidia], apparaat 3: NVIDIA HDMI [NVIDIA HDMI]
Sub-apparaten: 1/1
Sub-apparaat #0: subdevice #0

but in xbmc i have no dts and dd.
i have chosen iec958 as output, digital and passtrough
i use an optical cable to my receiver

Iḿ a linux noob and spend all night Sad I hope I can explain my problem.
Reply



Logout Mark Read Team Forum Stats Members Help
[LINUX] Problems switching from Analog to Digital over SPDIF?1
This forum uses Lukasz Tkacz MyBB addons.