SPDIF with VIA M10000 and MythTV

This spring I finally bought a modern receiver. My new receiver, like nearly all modern receivers, has multiple digital inputs. My Myth frontend machine is based on a VIA M10000 board which has a SPDIF (digital) output. There are a lot of reasons to use a digital output. One is that I suspect the digital to analog converters in the receiver are much higher quality than the cheap on-board ones found in most computer systems. Also if you watch DVDs or HDTV through Myth you can get Dolby Digital (AC3) and DTS multi-channel audio. I personally do not use MythTV for DVD watching nor for HDTV (without transcoding which trashes the AC3 audio stream) but I still wanted to use the digital audio output.

The basic setup steps are:

  1. Identify the correct jumper settings to enable SPDIF output on the VIA M10000.
  2. Test digital audio connection using basic ALSA tools.
  3. Setup MythTV to use SPDIF output device.
  4. Setup alsa to re-sample audio to 48000Hz.

    Jumper Setting

    I remember when I originally built the frontend that there was a jumper that allowed you to select between SPDIF and Composite Video for the RCA style jack on the back of the board. I consulted the manual and set the jumper accordingly. Next I hit the net to learn what I needed to do to get the SPDIF output working. Try as I might the receiver would never output a peep. It didn’t even detect a digital connection. In desperation I set the jumper the opposite of what the manual said I should do for SPDIF. That worked. The version of the manual that I have for the M10000 is wrong. Don’t set the jumper based on your manual. Instead look at the printing on the circuit board. On mine one of the jumpers is marked as the SPDIF setting.

    Testing Digital Connection

    Since Myth, like any app, relies on the OS for sound output it makes sense to get the sound working using simpler tools before attempting to get it working correctly in Myth. ALSA includes a really handy tool called speaker-test that you can use to test your setup. This tool is found in the package alsa-utils on Debian systems. It generates a pink-noise signal alternating between channels. You can tell it the number of channels to generate. When it outputs to a channel it prints to stdout where it is sending audio to so you can be sure that you have everything wired correctly. You can also tell it what audio device to direct output to.

    This is the command I used to test my connection:

    speaker-test --channels 2 --device ALSA:iec958 --rate 48000

    Setting up MythTV for SPDIF Output

    Setting up MythTV for SPDIF output is pretty simple. All you have to do is tell MythTV what ALSA device to direct audio to. There’s almost nothing beyond that (well there is, see the next section). This setting for Myth is on the third page of the general setup section. The SPDIF output for the VIA M10000 with a default ALSA configuration is ALSA:cards.pcm.iec958. You can determine what ALSA devices are availble using the command aplay -L. Apparently iec958 is a spec that means SPDIF. You will have to type this in it is not automatically populated in the drop down box.

    You should enable pass-through for DTS and AC3 so that if you watch sources with multi-channel audio your receiver will be able to play it. I don’t use Myth to watch DVDs or HDTV content but if I did I’d be extremely happy using this option!

    If you use MythVideo with mplayer you may need or want to change your configuration to tell mplayer to use the correct output device, to do AC3 and DTS passthrough, and to resample the audio (possible). I found that mplayer would play videos and audio too quickly. This is because, apparently, it uses the sound card driver for timing. The videos had 44100 Hz sampling but the audio driver in the M10000 runs only at 48000 Hz. This results in a chipmunk effect. You can force mplayer to resample to 48000 Hz by specifying -srate 48000. This step isn’t strictly necessary if you have resampling done by ALSA (see the next section). An example configuration is mplayer -ao alsa:device=cards.pcm.iec958 -ac hwac3 -srate 48000.

    Configuring ALSA to Re-sample audio to 48000Hz

    The sound hardware in the Epia M10000 board from VIA supports only 48Khz output on the SPDIF output. This can be frustrating as software playing back 44.1 Khz audio or other sampling rates will be played back too fast. Luckily there is a way to have ALSA resample all of the audio. This will result in a loss of fidelity but I can’t tell the difference.

    I created a file ~mythtv/.asoundrc. You could also, and probably more appropriately put this in /etc/asound.conf. Inside the file is:

    pcm.!default {
            type plug
            slave.pcm "cards.pcm.iec958"
            slave {
                    pcm "cards.pcm.iec958"
                    rate 48000
            }
    }

    I believe this instructs ALSA to resample all audio coming into ALSA:default to 48000 Hz and direct it to the ALSA device cards.pcm.iec958 (the SPDIF output). I find the confiuration syntax to be very cryptic. In particular, if my interpretation is correct, then I’m perplexed by “!default” as I would normally interpret that as “not default.”

    If you use this technique be sure to change the Myth audio settings to use ALSA:default as the output device. Once you do this playback in Myth will be correct. You can also instruct mplayer and other ALSA capable software to use this device and playback should be correct.

    References

    I had a lot of help getting this to work.

    Advertisements
    This entry was posted in Geek, MythTV. Bookmark the permalink.

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s