Audio delay with hdmi and analog audio

  • Hi there, using kszaqs latest build on s905x box. Connected my box to TV via hdmi and active speakers to analog out jack. Both outputs have audio, but...
    There's a delay, possibly caused by TV's picture processing resulting in delayed audio over hdmi in contrast to analog out.

    I like to setup for having both outputs working without delay while TV is on and analog always on, for to have audio still when TV is off.

    So I've got a few issues here...

    1.) I can't understand how it is handled, that analog and hdmi are on at the same time, hardware related or using alsa?

    2.) is there a way with alsa or pulseaudio, to set a delay on analog out?

    I've got 3 sinks in kodi. Hdmi, pcm (both alsa) and bluetooth (pulseaudio). There no difference between switching the first two

    Read, that pulseaudio should be able to delay an audio sink, but therefore it needs pulseaudio enabled (see 2.) and I don't know what's best way to go...

    Another option would be to suspend the output videowise. If I connect the speakers to TV's analog output, audio is in sync, but switching off TV switches off audio, too :(

    Any tipps welcome! Thx in advance

    P. S. I know this thread: LibreELEC

    Edited once, last by uatschitchun (January 12, 2017 at 4:54 PM).

  • "Go into the Video OSD, choose Audio and Subtitles settings, go to Audio offset, select your delay, set default for all media" should be is probably the only solution. Selecting a delay per audio output is not yet a Kodi feature.

  • As this is not a kodi forum, I'm aware that this isn't a kodi problem :)

    I know it's possible with the use of pulseaudio to define a new audio sink with delay or use alsa with ladspa plugin (I don't know in detail, but read about it), but I don't know how audio is handled within libreelec, as kodi handels it alone.

    Edited once, last by uatschitchun (January 13, 2017 at 1:00 PM).

  • Ok, tried the following:

    Code
    systemctl stop kodi
    pactl load-module module-udev-detect
    pactl list cards
    pactl set-port-latency-offset alsa_card.platform-aml_m8_snd.46 analog-output 28000

    That's sadly not working, as audio is only using pulse with Bluetooth, else this would be the solution :(

    Both, pulse and alsa have the ability to use 'ladspa' to set a delay, but it seems neither Pas nor alsa's ladspa is shipped with LibreElec?

    As experiments go further, I added /storage/.config/asound.conf

    Code
    pcm.pulse { type pulse }
    ctl.pulse { type pulse }
    pcm.!default { type pulse }
    ctl.!default { type pulse }


    For to use make alsa use pulseaudio

    All to no avail. Setting whatever I want doesn't change anything, sadly
    Maybe because of:

    Code
    # amixer
    ALSA lib /home/kszaq/LibreELEC.tv/build.LibreELEC-S905.arm-7.0-devel/alsa-lib-1.1.1/src/dlmisc.c:254:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa/libasound_module_ctl_pulse.so
    amixer: Mixer attach default error: No such device or address


    Trying something different:

    Code
    pactl load-module module-ladspa-sink sink_name=midDelay sink_properties=device.description=midDelay master=mid plugin=cmt label=delay_0.01s control=0.0001,0.00006
    Failure: Module initialization failed

    So, someone able to enlighten me, on how to make libreelec being able to use pulse audio (or I am overseeing something) and respect set-port-latency-offset?
    Or how to make ladspa work?

    Edited once, last by uatschitchun (January 13, 2017 at 9:25 PM).

  • The "Bluetooth" label for the pulseaudio device in kodi is just a label. It is just using the "default" pulse device. So you can set the default device in pulseaudio then use that "Bluetooth" device in kodi

    Code
    pactl set-default-sink <device name>


    That's it as for the ladspa module I have no idea if we even support it. I'll have to check it out later.

  • Thanks, will try that for to see if I am able so set latency with another default-sink.

    Regarding ladspa, the module (.so) is there, but it seems no plugins, neither also nor pulse.

    I can't even get analog audio only. Hdmi only works, but all other outputs that use analog also use hdmi. As from kszaqs commits it seems audio is hardwired within dtb

  • Once you're Bluetooth device is paired you can see it via pulseaudio with the command

    Code
    pactl list short sinks


    Then set it

    Code
    pactl set-default-sink <sink-name>

    Then in kodi just select the pulseaudio device as the audio output

  • I am also interested in this. I have Minix Neo U9-H.

    Optical audio out and headphone jack both work at the same time.

    The headphone audio jack needs delay adjustment. Is it possible to have different delay on headphone jack only?