My main MythTV system (AKA “backend”) is in my entertainment system rack in the old family room. My office is merging into that room and I needed to move the system rack a bit to make room for additional furniture. And the rack had a few things that were no longer in use (like ReplayTV [still mourning that]) and a bunch of wires that had been used for things and hadn’t been pulled out. Also, my APC UPS had proven defective (what good is a UPS if you can’t rely on it) so I removed it but needed to rework some stuff to get in the new one. For all of these reasons, it made sense to disassemble the whole entertainment system and rebuild it clean – figuratively and literally. Lots of dust to vanquish.
I put it all back together meticulously tying cables together and running cables in layers so everything was neat. Once I got to the point when it was time to power everything up, I hadn’t gotten the TV put back on top yet. (That old Panasonic plasma weighs 250 pounds and I needed to make sure I only moved that when I was sure I was done.) I wanted to give MythTV a chance to catch up on database activity since it had been off for the better part of a day and I didn’t need to see that happen. I made sure I had the MythTV parts set up and connected before I powered it on and the attached the Comcast cable box and HD-PVR. And When I was certain everything else was working, I hoisted the TV back in place and hooked up all the HDMI. Then I could test out the whole setup. Everything worked with the exception of two problems with MythTV: the network didn’t come up and I didn’t hear any sound. The network problem turned out to be because my Panamax power protector doesn’t work with Gigabit so I’ve ordered a separate network protector and in the meantime, I have the network cable skipping surge protection which is how I had it before – easy resolution. But the sound problem turned out to be a bear to resolve.
When problem solving anything like this, the mission is to figure out what has changed and to undo it. But I didn’t change anything about the physical configuration. I had audio output bridged through an asound.conf file to output to both HDMI and analog rear green output jack. That’s because I have two TVs hooked up to the one output and for one, I use HDMI for audio on the TV while in the other room I use an analog audio connection to the AV receiver which predates HDMI. (It’s a Harman Kardon AVR30 which still kicks ass.) So I need both audio outputs and I was only getting the HDMI one. But again, nothing was different about the setup. Same wires hooked back in to the same devices. Same connections made. I have auto-updating shut off on MythTV so it didn’t update when it rebooted. Everything should have been identical when it came back up as when it went off. And yet, MythTV is behaving badly.
This is why I hate Linux. It always seems so fragile. I feel like I spend ages fixing something only to discover it gets all flaky on me later. And searching for problems ferquently turns up lots of people with the same issue but fixes are not documented well or work for some but not for others. Other times, I’m the only person with the problem. So here I am trying to figure out what could have changed when it is known that nothing did. So I have to divine what Linux might have arbitrarily done to me.
The only way to debug is to revisit all of the nonsense I had done when setting it up in the first place. And the second place. I also checked backup versions of the asound.conf file. Everything looks fine there too. I had created a special device in my asound.conf file to handle sending the audio to two different outputs. When I ran speaker-test before, I’d get sound out of both. But as of today, I would get an error saying
Channels count (2) not available for playbacks: Invalid argument Setting of hwparams failed: Invalid argument
Why did this work yesterday but not today? Okay, technically, I wasn’t running speaker-test yesterday; I was just using MythTV. But my thinking was that MythTV was failing today for the same reason speaker-test was failing.
Eventually, I found a way to fix my problem with my asound.conf file so the speaker-test wouldn’t fail any more. I needed to add a line into my asound.conf file before the “ttable” commands: “slave.channels 4”.
But that didn’t fix the default audio device! That only made it so I could directly call “both” which was my audio object to send output to both devices. Then “both” would correctly work and send the output to both the HDMI and the analog output. But I couldn’t get that to be the default. And MythTV can’t see the device named “both”. But even if it could, I still wanted to get the default working so I can play audio from programs other than MythTV.
I then noticed that on my listing of “aplay -L”, it showed that the default device was actually listed as “Playback/recording through the PulseAudio sound server”. Hmmm… interesting. So where is the Pulse Audio configuration? Not in asound.conf? No, it’s somewhere else. And I never found where the files are stored but I did find the tool “pacmd” that lets you see what’s going on. And using that tool I was able to switch the default output from the HDMI to the analog. Many thanks to Eliot Eshelman and his blog for the post. And I confirmed that speaker-test now switched from HDMI to analog. Finally progress.
Now all I had to do was figure out how to get pulse to output to multiple devices. Fortunately, this is a bit better documented than for ALSA. The Placebo blog had the post I needed that detailed what to do. I added the lines (my analog device is “hw:0,0” though yours may not be so check that):
### Load analog device load-module module-alsa-sink device=hw:0,0 load-module module-combine-sink sink_name=combined set-default-sink combinedthen run pulseaudio --kill and pulseaudio --start
Now the speaker-test worked! Audio from both HDMI and analog and no errors. Which means for the most part, the asound.conf file is now being ignored. Back to MythTV, I changed the audio output to the default Pulse device and it worked there too! Well, almost. It seemed like it worked at first but I ran into trouble later. Playing recorded shows was fine, but live TV would sometimes switch to just loud static. Either it was loud static when simply watching and the static would go away when bringing up the program guide or vice versa! Very buggy. I then switched the audio output for MythTV from the default Pulse device to the default ALSA device. The loud static problem went away.
Finally, I wasn’t happy with the output level. The HDMI level seemed okay but the analog level was really low. In the pavucontrol tool (“PulseAudio Volume Control” in the menu), you can adjust any output to as much as 153% of the original level so I tried maxing that out. It did increase the level but not by enough. Further digging turned up info about how you can use pacmd to change the max limit:
pacmd set-sink-volume <sink> <value> The value field is 65536 for 100% so I tried doubling it to get 200% and that wasn’t enough. Tripling it to an effective 300% did get the right volume. But it was really distorted. So that wasn’t the answer. Then I checked the alsamixer and discovered that the master volume was only at 47% (when did that drop down!?). I reverted to the 100% in pavucontrol and turned up alsamixer to 100% and then everything worked. Finally.