On my HTPC, XBMC outputs sound over HDMI to a Panasonic TX-37LZD70 TV. This works great in most respects. However, there is a 2-second delay between when XBMC starts playing audio (music or video with sound), and when it actually outputs from the TV speakers. The sound is in sync with the video; it just takes 2 seconds to start. It’s annoying to always hear a theme song start part-way into the first few notes.
This is a known issue, but isn’t really XBMC’s fault. Basically, this TV (and many like it) doesn’t start playing sound right away. But there is a simple workaround – keep the channel open, by always playing silence. You can do this without any performance penalty.
Run this in a terminal (or in /etc/rc.local, or ~/.gnomerc, or however you like):
aplay -c2 -r48000 -fS16_LE < /dev/zero &
This will constantly play silence to the ALSA sound system (in the case of Ubuntu, via Pulse). As far as I can tell, the sound server just drops it, or consumes very few resources to do it. The system load never increases nor does it appear as active in top
.
I've implemented this as a more sophisticated solution. I have created my own xbmc
script, which then calls the real XBMC.
#!/bin/bash # if xbmc already running, exit if (ps -ef | grep '[/]usr/lib/xbmc/xbmc.bin' >/dev/null 2>&1) ; then zenity --error --title "XBMC" --text "XBMC is already running. Please select it from the task bar above." die "XBMC is already running!" fi # Keep sound channel open (play silence), to prevent 2-second HDMI delay aplay -c2 -r48000 -fS16_LE < /dev/zero & APLAY_PID=$! /usr/bin/xbmc "$@" kill $APLAY_PID
Copy this script to ~/bin or /usr/local/bin and make it executable. It does two things:
- Prevent launching more than one copy of XBMC. An easy mistake to make since Gnome provides no launch feedback and XBMC takes some time to start. A more elegant solution would restore the other XBMC instance instead of nagging the user.
- Starts playing silence before starting XBMC, then kills it afterward.
A better solution would be for XBMC to maintain the channel itself (which must be what my DVD player does), but I'm happy with this until they release an official fix.
-
Unfortunately this doesn’t work for me. My decoderbox still doesn’t get any signal when I’m using aplay.
-
This kind of helps in my case. My starting point is no sound and really choppy video for a few seconds while my shittysonic TV syncs up. With this trick, the video isn’t choppy, but I still have no sound for two seconds.
-
I have tried this on my Ubuntu XBMC HTPC, to no avail. Should the command be different if one is using toslink/optical audio?
Thanks, hope you can help, this has been driving me mad for almost a year now..
-
Absolutely fantastic stuff! I have been seeing this problem with my raspberry pi / xbmc / sound bar set up for months now and had always pegged it to some issue with the rpi.
Many thanks for this workaround!
-
Thanks for this fix. Works on XBMC under Arch Linux
What I did is I created a screen session with just the command running in it.
-
Thanks a lot for this solution. I have an Onkyo AV receiver connected through HDMI to my laptop with nVidia graphic card, where I run Ubuntu 14.04 for the time being. I don’t use XBMC often, but the problem is very annoying during playing of any kind of audio, no matter if it’s music played in Clementine, YouTube video – first 2-3 seconds are always gone. The bug also “cuts off” all short system sounds.
Your short terminal command works like a charm, but it was tricky to have it automatically started on every boot. I’ve tried adding it in three places:
1. to crontab, with @reboot
2. to the /etc/rc.local
3. to the ~/.gnomerc1st and 2nd methods didn’t do anything good. I think that the silent stream has been active (AV receiver has been indicating that there is active signal), but it wasn’t possible to play any sound in Ubuntu. All output devices disappeared from sound settings (there’s been “dummy output” instead).
Luckily the 3rd option works like a charm :)-
Hı Tyler,
I have a android mini pc (mk908). Having the same first 2-3 seconds delay on playing f.e. youtube or after I have paused and play it again. Your solution should work, but I cannot figure it out how to write the script for Initial.d on android 4.2.2.
Script (filename: start-sound):
#!/bin/sh
# /etc/init.d/start-sound
echo “playing sound”
aplay -c2 -r48000 -fS16_LE < /dev/zero &To apply the scripts, I placed the script in the /system/etc/init.d folder and set permissions to rwxrwxrwx then rebooted the machine.
Can you help me out please. I am out of solutions.
Regards,
Riccardo-
Auto start (init.d) works well with other scripts. Aplay is installed on my (rooted) android system. I think the script doesn’t work. I am a noob with writing scripts. Hope you have an answer in steps.
Thx for the quick reply.
-
Any help?
-
Hi Tyler,
I have the exact same issue, except, I’m using a Dell Inspiron Laptop connected to a Dell Moniter via HDMI. I have no idea how to input any of those codes/commands. Would you mind giving me some direction?
-
-
-
-
-
-
21 comments
Comments feed for this article
Trackback link: https://www.tolaris.com/2011/07/03/solving-the-2-second-sound-delay-with-xbmc-and-hdmi/trackback/