[mythtv] Fwd: iec958 output (not passthrough) with Alsa rate pluginproblem

Lawrence Freil lef at freil.com
Tue Jan 16 13:14:25 UTC 2007


Robin,

The pcm listed below is pretty much what you need, however depending
on your distribution you may not even have the rate plugin.  You first
need the libsamplerate from 

http://www.mega-nerd.com/libsamplerate/

After installing that you need to recompile alsa-plugins, preferably 
matching the version of the rest of alsa installed (I am using 
alsa-plugins-1.0.14rc1) It should show the rate plugin being built and when 
installed should live in 
/usr/lib/alsa-lib/libasound_module_rate_samplerate*

Now you need to identify your SPDIF connector.  If passthrough is already
working then odds are it is already called iec958 since that is what is
hard-coded into the bypass code in mythtv.  It can go by iec958 or by
the name spdif, but the program "aplay -L" will list the pcm's.  It is good
to have a .wav or two around at this point for testing, one at 44.1Kz and
one at 48Kz.  You can use madplay, mpg123 or ogg123 to decode mp3's or
ogg vorbis files to a .wav on the disk.  For the sake of this example
I am calling them sound48k.wav and sound44k.wav.  To test the digital
output device first run.

aplay -D <pcmname> sound48k.wav

Where pcmname is probably iec958 or slightly less likely spdif.

This should work as it would be the same thing Myth does for passthrough.

Some hardware will directly pass through a 44.1K to the digital output
device.  To test if yours will work try
aplay -D <pcmname> sound44k.wav

If this works, you are in luck and didn't need the samplerate plugin to
begin with, so just set your audio output device in myth to "ALSA:iec958"
and you are done. You have to type it in, as there is no default for alsa
devices in the pull down on the setup->general page.  If it does not
output then proceed with the following.

To install a rate plugin copy the following lines into your 
/etc/asound.conf file (or your home directory .asoundrc, but I recommend 
here only for testing since myth may be run as a different user if started 
at boot like I do on my box):

pcm.hq48k {
      type rate
      slave.pcm "iec958"
      slave.rate 48000
      converter "samplerate_best"
}

If you determined your output device was "spdif" then change the iec958 to
spdif in the above lines.

You should now be able to play the 44.1Kz sample with the command:

aplay -D hq48k sound44k.wav

And the sound should come out on the digital reciever.  At this point you
should be able to tell myth to use "ALSA:hq48k" in the sound device on the
setup->general page and it should come out on the digital reciever even for
non-passthrough sound, however you are now very likely to encounter the
bug that prompted my origonal post.  I emperically determined the offset
for the flow control fix by using a modified aplay with the following
patch:
*** aplay.c~    2006-12-07 09:24:05.000000000 -0500
--- aplay.c     2007-01-12 19:38:20.560950911 -0500
***************
*** 1248,1253 ****
--- 1248,1258 ----
        ssize_t r;
        ssize_t result = 0;

+       snd_pcm_sframes_t delay, avail;
+       snd_pcm_delay(handle, &delay);
+       avail = snd_pcm_avail_update(handle);
+       printf("pcm delay currently at %d, %d\n", delay, avail);
+       fflush(stdout);
        if (sleep_min == 0 &&
            count < chunk_size) {
                snd_pcm_format_set_silence(hwparams.format, data + count * 
bits_per_frame / 8, (chunk_size - count) * hwparams.channels);



More information about the mythtv-dev mailing list