You are not logged in.
I'm trying to get sound out of my TV via TOSLINK, decode it and play on my external speakers.
I tried with FFMPEG:
ffmpeg -f pulse -i alsa_input.pci-0000_04_00.0.iec958-stereo -f pulse alsa_output.pci-0000_04_00.0.analog-stereo
ffplay -fast -noinfbuf -loglevel warning -nodisp -vn -volume 100 -f pulse -i alsa_input.pci-0000_04_00.0.iec958-stereo
Unfortunately, I'm getting few seconds of latency (video is shown before I hear the sound).
Could you suggest what I can do to get as close as possible to real-time sound? It doesn't have to be FFMPEG.
Last edited by mkkot (2022-02-08 18:36:55)
Offline
You can directly feed your input into your output from pulseaudio instead of this intermediate step: https://www.freedesktop.org/wiki/Softwa … e-loopback
For testing this you can just do
pacmd load-module module-loopback source=alsa_input.pci-0000_04_00.0.iec958-stereo sink=alsa_output.pci-0000_04_00.0.analog-stereo #optional: latency-msec=60 or so to manipulate the latency if needed
Last edited by V1del (2021-12-20 13:05:07)
Offline
Thanks V1del. I forgot to mention that I already tried that. The result is no sound which is a bit weird because I would rather expect white noise instead. The digital input is not PCM, it is encoded in ac3 or other format. That's why ffmpeg is a good choice because it's intelligent enough to recognize input format automatically.
Offline
I'd also expect white noise, did you ensure the loopback sink isn't muted? If you try that suggestion, what's your output for
pacmd list-sinks
pacmd list-sink-inputs
pacmd list-sources
pacmd list-source-outputs
when trying that? Any error messages in
journalctl -b --user-unit=pulseaudio
?
A bit more googling turns up that pulse flat out doesn't do decoding, however I found https://github.com/jakemoroni/audio_async_loopback which might help/do what you need
Last edited by V1del (2021-12-20 13:48:06)
Offline
If this is the same problem i faced with ffmpeg, try to pass:
-fragment_size $FRAGMENT
Start with $FRAGMENT=1024 and go down while it works well.
As per ffplay, try:
-flags low_delay -nodisp -probesize 32 -fflags nobuffer+fastseek+flush_packets -analyzeduration 0 -sync ext -af aresample=async=1:min_comp=0.1:first_pts=$AUDIO_DELAY_COMPENSATION"
Start with AUDIO_DELAY_COMPENSATION="4000" and go down while it works well.
-EDIT-
I'm not sure if -fragment_size is accepted by ffplay
Last edited by kokoko3k (2021-12-20 14:03:57)
Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !
Offline
@V1del I tried https://github.com/jakemoroni/audio_async_loopback.
This gives the best effect in terms of delay (not noticeable). However, it cracks. Strangely enough, it cracks very heavily if pavucontrol is closed. I was trying to set real time priority to the process and its subproceseses but it didn't make much difference. I will try to play with config.h to see if it can be any better and let you know.
@kokoko3k The ffmpeg/ffplay is something that annoys me a bit because the parameters you pasted are not included in the manual. I read it before I started the topic because I wanted to figure it out myself. Anyway, I tried to play with the values you suggested but lowering them just increases cracking but not decreasing delay. But thanks for your input anyway.
Just a background what I'm trying to achieve here:
I'm building a media center - a pc, high-end soundcard, audio monitors and Tv with webOs. I plan to play movies from my PC but also, if desired, I want to be able to play content from Netflix/Amazon/Apple/whatever app installed on my TV on my speakers through my PC. The TV doesn't provide line output, only digital or bluetooth.
Offline
Did you set your sample rate to 48000 in pulse config? The readme of this project mentions that it works best if the sample rates are set to 48kHz
Offline
Yeah, I know, I was just too lazy to set it Tried it, now works perfectly without changing config.h contents.
The one thing that still wonders me is why I need to keep pavucontrol opened to have it working. If I turn the app off, I'm getting only short bursts of sound every 2 seconds.
Offline
Weird, sounds like sink suspension kicking in, possibly also an interaction issue with hda power saving. You can disable the latter with
echo 0 | sudo tee /sys/module/snd_hda_intel/parameters/power_save
and the former by removing module-suspend-on-idle or increasing the timeout value.
Offline
I'd consider cheap hardware solutions like toslink (or coax) to rca converters too.
Also, if you've not yet got the monitors, there's something i know from edifier with digital in too.
Last edited by kokoko3k (2021-12-20 16:44:07)
Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !
Offline
Instead of configuring your pc to decode ac3, try to set your tv to send pcm data over toslink, then pulseaudio/alsa doesn't have to do any decoding.
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |
Offline
@V1del
Tried to poke with this and other power saving settings but no avail. I actually noticed that during closing of pavucontrol lots of things happen:
pulseaudio -vvvv
I: [pulseaudio] module.c: Unloaded "module-dbus-protocol" (index: #8).
I: [pulseaudio] module.c: Unloading "module-alsa-card" (index: #7).
D: [pulseaudio] source.c: alsa_output.pci-0000_08_00.1.hdmi-stereo.monitor: state: IDLE -> UNLINKED
D: [pulseaudio] core-subscribe.c: Dropped redundant event due to remove event.
D: [pulseaudio] sink.c: alsa_output.pci-0000_08_00.1.hdmi-stereo: state: IDLE -> UNLINKED
D: [pulseaudio] core-subscribe.c: Dropped redundant event due to remove event.
D: [alsa-sink-HDMI 0] alsa-sink.c: Thread shutting down
I: [pulseaudio] sink.c: Freeing sink 1 "alsa_output.pci-0000_08_00.1.hdmi-stereo"
I: [pulseaudio] source.c: Freeing source 2 "alsa_output.pci-0000_08_00.1.hdmi-stereo.monitor"
I: [pulseaudio] card.c: Freed 1 "alsa_card.pci-0000_08_00.1"
I: [pulseaudio] module.c: Unloaded "module-alsa-card" (index: #7).
I: [pulseaudio] module.c: Unloading "module-alsa-card" (index: #6).
I: [pulseaudio] core.c: default_sink: alsa_output.pci-0000_04_00.0.analog-stereo -> (unset)
D: [pulseaudio] source.c: alsa_output.pci-0000_04_00.0.analog-stereo.monitor: state: IDLE -> UNLINKED
D: [pulseaudio] sink.c: alsa_output.pci-0000_04_00.0.analog-stereo: state: IDLE -> UNLINKED
D: [pulseaudio] core-subscribe.c: Dropped redundant event due to remove event.
D: [alsa-sink-CA0132 Analog] alsa-sink.c: Thread shutting down
I: [pulseaudio] sink.c: Freeing sink 0 "alsa_output.pci-0000_04_00.0.analog-stereo"
I: [pulseaudio] source.c: Freeing source 0 "alsa_output.pci-0000_04_00.0.analog-stereo.monitor"
I: [pulseaudio] core.c: default_source: alsa_input.pci-0000_04_00.0.iec958-stereo -> (unset)
D: [pulseaudio] core-subscribe.c: Dropped redundant event due to change event.
D: [pulseaudio] source.c: alsa_input.pci-0000_04_00.0.iec958-stereo: state: IDLE -> UNLINKED
D: [pulseaudio] core-subscribe.c: Dropped redundant event due to remove event.
D: [alsa-source-CA0132 Digital] alsa-source.c: Thread shutting down
I: [pulseaudio] source.c: Freeing source 1 "alsa_input.pci-0000_04_00.0.iec958-stereo"
I: [pulseaudio] card.c: Freed 0 "alsa_card.pci-0000_04_00.0"
I: [pulseaudio] module.c: Unloaded "module-alsa-card" (index: #6).
I: [pulseaudio] module.c: Unloading "module-udev-detect" (index: #5).
I: [pulseaudio] module.c: Unloaded "module-udev-detect" (index: #5).
I: [pulseaudio] module.c: Unloading "module-switch-on-port-available" (index: #4).
I: [pulseaudio] module.c: Unloaded "module-switch-on-port-available" (index: #4).
I: [pulseaudio] module.c: Unloading "module-augment-properties" (index: #3).
I: [pulseaudio] module.c: Unloaded "module-augment-properties" (index: #3).
I: [pulseaudio] module.c: Unloading "module-card-restore" (index: #2).
I: [pulseaudio] module.c: Unloaded "module-card-restore" (index: #2).
I: [pulseaudio] module.c: Unloading "module-stream-restore" (index: #1).
So having this app opened or closed definitely can have impact on the sound. I will try to investigate this list later.
I also found out that I still have some cracking during watching movies and found out in pulseaudio debugging output that there are some buffer underruns. I found this line in config.h:
#define PCM_SINK_PA_BUFFER_SIZE
and increased it 2.5 times. That helped (for now xD).
@kokoko3k
I've already bought the monitors and I don't want to go with any cheap converters as it decreases sound quality, adds latency, consumes electricity and takes space. I have a PC already, don't think I need anything else.
@progandy
Hah, good tip but there's no such feature in my tv (at least I haven't found that).
Offline
Pavucontrol wakes up every sink to be able to show it's bouncing volume monitors. If you have a problem with sink suspension for whatever reason then the real fix is to disable sink suspension so that this situation doesn't arise regardless of whether pavucontrol wakes the devices up incidentally by being open.
Last edited by V1del (2021-12-22 09:24:50)
Offline
The author of audio_async_loopback managed to fix this issue:
https://github.com/jakemoroni/audio_asy … k/issues/2
Thanks everyone for help!
Last edited by mkkot (2022-02-08 18:36:16)
Offline
Glad you solved it.
What hardware do you use to caprture the digital audio? I can use it for room correction purposes with a raspberry
Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !
Offline
I think it doesn't matter really but I have Sound Blaster ZxR.
Offline