mariotaku / moonlight-tv

Lightweight NVIDIA GameStream Client, for LG webOS TV and embedded devices like Raspberry Pi
GNU General Public License v3.0
811 stars 30 forks source link

Surround sound #49

Closed mariotaku closed 5 months ago

mariotaku commented 3 years ago

Moonlight is almost able to handle it, but hard to test yet.

royka1 commented 3 years ago

I could test it, have a receiver connected with hdmi arc

ryang3d commented 3 years ago

Moonlight is almost able to handle it, but hard to test yet.

@mariotaku Could you elaborate on what makes surround sound hard to test? Like @roykaandorp, I (and surely many other people) have the equipment necessary to test this and would be happy to help test if that really is the only thing getting in your way of testing surround sound.

ryang3d commented 3 years ago

For what it's worth, I just tried running the built in "Speaker Setup" in Windows 10 while running moonlight-tv v0.6.8. The L/R channels sounded correct, but the other 4 test tones came out of the same L/R speakers (not my surround/center/sub speakers). I have my 65SM8600PUA hooked up via optical cable to a Denon AVR-S510BT, which does provide working surround sound with other WebOS Apps such as Plex. image

mariotaku commented 3 years ago

@ryang3d I don't have surround sound device for verification, which is the reason.

ryang3d commented 3 years ago

Understood. We're definitely happy to help test surround as needed. Thanks again for all the effort!

circoloco696 commented 3 years ago

I could help test surround sound too if needed with a full 7.2 setup.

royka1 commented 3 years ago

I've tested surround with version 0.7.5 and I can say it's working! Used the following video to test: https://www2.iis.fraunhofer.de/AAC/ChID-BLITS-EBU.mp4

ryang3d commented 3 years ago

I've tested surround with version 0.7.5 and I can say it's working! Used the following video to test: https://www2.iis.fraunhofer.de/AAC/ChID-BLITS-EBU.mp4

Nice! @roykaandorp, can you share any details about your home theatre configuration? What receiver are you using, what TV are you using, what cable (optical or hdmi) are you using between your TV and receiver, etc.

UPDATE: I just tested surround sound using 0.7.5 (again using my same setup: 65SM8600PUA hooked up via optical cable to a Denon AVR-S510BT), but all the surround test tones are coming out of my front left and right channel speakers. No sound comes out of my center, rear left, rear right, or sub woofer. Definitely curious to hear about your working setup.

mariotaku commented 3 years ago

Not sure if @roykaandorp is using local builds. This feature is work in progress and only available in debug builds (not in releases). But if it can play surround successfully, would be a great news indeed!

royka1 commented 3 years ago

I'd tested with the release 0.7.5 Tv model is 75uk6200, amp is a marantz nr1609 connected to the hdmi ARC port. As decoder I use webOS NDL. The amp recognizes the signal as Multichannel, so do'n set it manual at dolby or something but set it at auto.

royka1 commented 3 years ago

I've tested surround with version 0.7.5 and I can say it's working! Used the following video to test: https://www2.iis.fraunhofer.de/AAC/ChID-BLITS-EBU.mp4

Nice! @roykaandorp, can you share any details about your home theatre configuration? What receiver are you using, what TV are you using, what cable (optical or hdmi) are you using between your TV and receiver, etc.

UPDATE: I just tested surround sound using 0.7.5 (again using my same setup: 65SM8600PUA hooked up via optical cable to a Denon AVR-S510BT), but all the surround test tones are coming out of my front left and right channel speakers. No sound comes out of my center, rear left, rear right, or sub woofer. Definitely curious to hear about your working setup.

Correct me if i'm wrong, moonlight uses multichannel pcm for surround, optical out doesn't support that (not enough bandwidth). So unless the tv first transcodes it to a dts/dolby digital stream (that I assume will give noticeable latency) it won't work. I think it will only work with ARC. Edit: After some reading it seems to be possible (at least with a raspberry) https://www.raspberrypi.org/forums/viewtopic.php?t=172536#p1425779

mariotaku commented 3 years ago

@roykaandorp Just a bit curious, because I don't remember I have provided enabled surround sound yet. I'll do in next release though.

royka1 commented 3 years ago

@roykaandorp Just a bit curious, because I don't remember I have provided enabled surround sound yet. I'll do in next release though.

Yes I was surprised too, because you didn't mentioned it in that release, but i'd seen you was busy with that so I tried and it worked. With the older release I was using (0.6.8) my amp recognized the audio as stereo, now with 0.7.5 as multi in, the test video confirmed every channel works. Edit: As weird as this sounds, when I try again it gives only stereo, I'm pretty shure it did work as I saw it on my amp, test file worked correctly en looked at which decoder moonlight was using. Maybe an error at the desktop side, because I used moonlight before on an sbc with surround? I'm sorry for the confusion.

mariotaku commented 3 years ago

@roykaandorp I can confirm that none of previous version has correct setup parameter for surround sound. BUT, v0.7.7 comes with correctly configured one. PulseAudio with 5.1ch works flawlessly.

root@LGTV:~# pactl list sink-inputs
Sink Input #16
        Driver: protocol-native.c
        Owner Module: 1
        Client: 53
        Sink: 1
        Sample Specification: s16le 6ch 48000Hz
        Channel Map: front-left,front-right,front-center,lfe,rear-left,rear-right
        Format: pcm, format.sample_format = "\"s16le\""  format.rate = "48000"  format.channels = "6"  format.channel_map = "\"front-left,front-right,front-center,lfe,rear-left,rear-right\""
        Corked: no
        Mute: no
        Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB,   front-center: 65536 / 100% / 0.00 dB,   lfe: 65536 / 100% / 0.00 dB,   rear-left: 65536 / 100% / 0.00 dB,   rear-right: 65536 / 100% / 0.00 dB
                balance 0.00
        Buffer Latency: 18333 usec
        Sink Latency: 15852 usec
        Resample method: copy
        Properties:
                media.name = "Streaming"
                application.name = "Moonlight TV"
                native-protocol.peer = "UNIX socket client"
                native-protocol.version = "31"
                application.process.id = "9255"
                application.process.user = "prisoner"
                application.process.host = "LGTV"
                application.process.binary = "moonlight"
                application.language = "C"
                application.process.machine_id = "LGTV"
                media.type = "pdefaultapp"
                module-stream-restore.id = "sink-input-by-application-name:Moonlight TV"
mariotaku commented 3 years ago

To use surround sound,

  1. Set "Audio backend" to "PulseAudio" in Settings -> Decoder Settings
  2. Set "Audio channels" to "5.1 Surround" in Settings -> Basic Settings

And enjoy! PulseAudio comes with acceptable audio latency, and I'll be trying to improve it in future releases.

ryang3d commented 3 years ago

Correct me if i'm wrong, moonlight uses multichannel pcm for surround, optical out doesn't support that (not enough bandwidth). So unless the tv first transcodes it to a dts/dolby digital stream (that I assume will give noticeable latency) it won't work. I think it will only work with ARC. Edit: After some reading it seems to be possible (at least with a raspberry) https://www.raspberrypi.org/forums/viewtopic.php?t=172536#p1425779

You might be onto something there... I enjoy surround sound, but I'm not much of an audiophile and my knowledge of requirements and compatibility are limited. Out of curiosity, I did try loading up the fraunhofer.de video in my TV's built-in web browser, and the surround sound worked perfectly (but when run through moonlight-tv it still comes out stereo only, even with v0.7.7 with PulseAudio and 5.1 enabled). But from what it sounds like you are saying, is that moonlight's potential use of multichannel PCM may be why it is not working in my case (makes sense!). Looks like it may be time for some system upgrades here!

Definitely curious about the experiments in that raspi link, but not gonna get my hopes up there.

Stoked to see this all come together. Keep up the amazing work!

EDIT: Just thought I'd add that there is a good amount of discussion on this topic now that I've looked around more myself. Everything looks to confirm @roykaandorp's suggestion. One good example is here: https://github.com/moonlight-stream/moonlight-android/issues/482#issuecomment-353716499

royka1 commented 3 years ago

You might be onto something there... I enjoy surround sound, but I'm not much of an audiophile and my knowledge of requirements and compatibility are limited. Out of curiosity, I did try loading up the fraunhofer.de video in my TV's built-in web browser, and the surround sound worked perfectly (but when run through moonlight-tv it still comes out stereo only, even with v0.7.7 with PulseAudio and 5.1 enabled). But from what it sounds like you are saying, is that moonlight's potential use of multichannel PCM may be why it is not working in my case (makes sense!). Looks like it may be time for some system upgrades here!

Definitely curious about the experiments in that raspi link, but not gonna get my hopes up there.

Stoked to see this all come together. Keep up the amazing work!

EDIT: Just thought I'd add that there is a good amount of discussion on this topic now that I've looked around more myself. Everything looks to confirm @roykaandorp's suggestion. One good example is here: moonlight-stream/moonlight-android#482 (comment)

As seen here https://fwd.nl/app/uploads/HDMI21-earc-1024x459.jpg it only seems to be possible to get multichannel pcm with eARC. Read somewhere that LG tv models of 2020 or newer support that. Maybe take a look at transcoding it to ac3 isn't a bad idea?

mariotaku commented 3 years ago

Please keep in mind that encoding audio via software is much slower especially for multiple channels. Too much processing will make latency unbearable, especially for gaming purposes. Currently there are only 2 ways reasonable, one is to play 5.1ch PCM, another is feed opus audio directly, although I'm not sure how well webOS can handle.

mariotaku commented 3 years ago

For the second way I've been investigating for quite a long time, but seems the channels are always incorrect for webOS.

royka1 commented 3 years ago

Please keep in mind that encoding audio via software is much slower especially for multiple channels. Too much processing will make latency unbearable, especially for gaming purposes. Currently there are only 2 ways reasonable, one is to play 5.1ch PCM, another is feed opus audio directly, although I'm not sure how well webOS can handle.

I'm afraid you're right, however I found a post of someone who said he's using it succesful (didn't mention about latency), but for that the alsa plugin a52 is needed, I don't know if it's possible to use that with the read only file system? I've been trying to compile it, but didn't succeed

Another option I was thinking about, encoding it as ac3 on the host. Did a request for that as option at the Sunshine github, but probably then the client needs an adjustment too?

mariotaku commented 3 years ago

@roykaandorp Alsa is not working by any attempt on webOS. So this couldn't be an option. Also transmitting other audio codec then opus is not possible, as this whole protocol should be exact same to NVIDIA's official implementation.

royka1 commented 3 years ago

@mariotaku There is also a dts encoder that should work with pulseaudio and could also be integrated. But I can imagine that it would take too much effort, as there is no guarantee the latency will be acceptable. https://github.com/darealshinji/dcaenc About transmitting it as a ac3 stream from the host, I was talking about an open source host. Edit: a DTS frame seems to be 10.666ms, so that would be at least the delay, ac3 frames are 32ms

mariotaku commented 3 years ago

I was thinking about doing some experiments about performing opus -> pcm -> ac3/aac conversion, but this will bring a whole lot tasks. Maybe this will be my final attempt to bring surround sound on my own, if this approach not working, I'll have to close this issue and waiting for contributors' patches.

mariotaku commented 3 years ago

A little bit update: opus -> pcm -> fdk-aac can have sounds, but have some problems. I'll fix this then you can try on your TV.

mariotaku commented 3 years ago

So I have implemented AAC encoded playback on webOS 4 (NDL Audio). But there are few problems:

  1. on webOS 5, NDL only support PCM, Opus and MP3. No AAC/AC3 usage found in NDL
  2. AAC Encode + Playback brings nearly 100ms of latency. While it's not bad for playing videos, it's not optimal for gaming.

If AAC playback doesn't have surround sound, then I can say it's nearly not possible for Moonlight to have surround sound on webOS.

royka1 commented 3 years ago

Would like to try out, but have some difficulties with building the NDK, hopefully fixed now. Ubuntu 16.04 had some files it couldn't download, 18.04 errors on building qemu. Found a fix for that so hopefully it will build now, then I shall test the surround tomorrow

mariotaku commented 3 years ago

Would like to try out, but have some difficulties with building the NDK, hopefully fixed now. Ubuntu 16.04 had some files it couldn't download, 18.04 errors on building qemu. Found a fix for that so hopefully it will build now, then I shall test the surround tomorrow

You can grab prebuilt NDK to save some time, plus it can run on almost any distro

ryang3d commented 3 years ago

0.7.9 release NDK doesn't have AAC implemented does it? I couldn't find a decoder combination that works for my setup yet.

EDIT: I clearly don't know what I'm talking about... But I realize what I did there though. Just getting excited for progress I guess XD Will follow up if/when I make time to build moonlight myself

mariotaku commented 3 years ago

0.7.9 pre-built NDK doesn't have AAC implemented does it? I couldn't find a decoder combination that works for my setup yet.

What do you mean by prebuilt NDK and AAC? I assume you are talking about prebuilt moonlight, it's not in prebuilt yet. But if you want to build moonlight on your own, you don't have to build the whole webOS NDK which will take 6+ hours.

royka1 commented 3 years ago

You can grab prebuilt NDK to save some time, plus it can run on almost any distro Ok tnx, did that before but had a lot missing files, so thought I had to built it myself.

Tried the prebuilt before but then had a lot of errors, didn't know I had to do a git submodule update --init --recursive

Finally succeeded to build the ipk, when I choose NDL videodecoder I can't choose surround. So I chose the SMP videodecoder (black screen), and tried the pulse and ndl audio de, but unfortunately only received 2 channels on the receiver. Edit: The receiver receives a 2 channel PCM signal and I've got WebOS version 4.3.0

mariotaku commented 3 years ago

I see, AAC support was added to NDL audio though, so if you only hear 2 channels, that mean all attempts above has failed. I'll remove audio channel option from webOS, as it's not supported.

mariotaku commented 3 years ago

Sorry about that, but I'll have to close this until I got official information from LG.

royka1 commented 3 years ago

@mariotaku That's unfortunate for the time you spent on it, hopefully LG will release info about that. Tnx for trying anyway

ryang3d commented 3 years ago

@mariotaku That's unfortunate for the time you spent on it, hopefully LG will release info about that. Tnx for trying anyway

Agreed, thanks for all the effort! Crossing fingers for future developments...

To clarify the current status though, is surround sound over HDMI eARC working with moonlight, while surround sound over optical is not working? Or is surround sound just not working at all in either scenario?

royka1 commented 3 years ago

@ryang3d Surround sound over eARC should work as that support multichannel pcm. Over ARC/optical it needs to be transcoded first

drsno commented 1 year ago

What is the current status of surround sound? If I read this post, surround sound should work with Pulse Audio over eARC. However, in the Moonlight settings, Audio settings - Sound Channels (Experimental), there is only the option 'Stereo'. And indeed, while the sound output of GeForce Gamestream is 5.1, Moonlight outputs it as stereo.

If this is expected, is there any outlook on progressing this and supporting surround? Moonlight is working perfectly except for this issue.

mariotaku commented 1 year ago

What is the current status of surround sound? If I read this post, surround sound should work with Pulse Audio over eARC. However, in the Moonlight settings, Audio settings - Sound Channels (Experimental), there is only the option 'Stereo'. And indeed, while the sound output of GeForce Gamestream is 5.1, Moonlight outputs it as stereo.

If this is expected, is there any outlook on progressing this and supporting surround? Moonlight is working perfectly except for this issue.

According to our test result, no matter how many channels moonlight produces to the decoder, it will be downmixed to stereo. So I believe it's not possible to continue this feature, unless I have access to surround sound devices and test with a bunch of audio codecs.

marvin-roesch commented 1 year ago

@royka1 Have you confirmed yourself that surround over eARC works? I have a Sony HT-A7000 soundbar attached to my LG G2 and was not able to get surround sound working. I built a custom version to re-enable the 5.1 (and also 7.1, as that's ideally what I want) surround options and use PulseAudio as audio backend.

When I play surround content from the streaming machine, it gets downmixed to stereo by the TV. I was also able to verify with the help of @mariotaku that this is not an issue with moonlight, but instead a more general issue with the TV's support for multichannel (L)PCM. Using the test files at https://www2.iis.fraunhofer.de/AAC/multichannel.html, I found out that the AAC-encoded files work just fine and play as surround since the TV passes through the digital format. The original Wave files they have listed get downmixed just like moonlight. Executing speaker-test -c 6 on the TV via a connected shell has the same effect.

This leads me to believe that multichannel LPCM still isn't supported properly on LG TVs even with eARC. Changing the Digital Sound Output option from "Pass-through" (or "Auto") to "PCM" in the TV settings results in the AAC-encoded files from the Fraunhofer page also being downmixed. This implies that the issue is indeed not with the input data, but rather somewhere in a conversion step between playback by the TV and the connected eARC device.

I'd really love to get surround sound working with moonlight-tv, as it has been working very well for me otherwise.

drsno commented 1 year ago

I really would love to progress this issue as well. I can build and test versions if needed on my LG C1 with eARC connected 5.1 receiver. One thing I found out when testing custom builds is that when I forced to use 5.1 sound on the NDL Audio decoder, the receiver actually received a 5.1 signal. However, all channels were mixed, some were duplicated or missing. The subwoofer got a constant signal, so kept on rumbling. It was an interesting find though that Moonlight+TV were able to output 5.1 sound this way.

marvin-roesch commented 1 year ago

@noudenaa Could you try issuing the speaker-test -c 6 -l 1 command from the Terminal tab in the webOS Dev Manager? I'd be interested to know if that correctly plays surround sound for you or if it mixes things down. That would at least help me to see if it's "just" an issue with my setup where multichannel PCM isn't supported or if it's a more general thing.

drsno commented 1 year ago

With my current settings, that command results in my receiver getting a 2.1 signal. Front-left and front-right are played normally, front center is played over the front-left and front-right, and the back sounds are playing over their corresponding front speakers. LFE doesn't play at all.

marvin-roesch commented 1 year ago

Okay, so it's doing the same thing as for me when I was trying this out. It's interesting that you could get NDL to output 5.1 (even if it wasn't really working). For me, the NDL backend just errors if I attempt that. I'll be experimenting a little more in a bit. Are you maybe on the Moonlight Discord so we can directly write to each other on this to more rapidly test things out? I'm Paleo there.

rudy-lath-vizio commented 11 months ago

Did this ever get resolved?

mariotaku commented 11 months ago

Did this ever get resolved?

Not yet. According to LG's firmware there's a chance that on post-2022 models eARC supports PCM passthrough up to 6 channels. Didn't look into it yet.

francoislg commented 9 months ago

For the record, I have a 2023 LG C3 with a Denon receiver through eARC, set up in full passthrough.

I also built a custom version that unlocks the 5.1 and 7.1, tested all four audio backends, all I can get is Stereo sound.

I also tested speaker-test -c 6 -l 1 and can only hear the 2 front speakers.

Not sure if I can do anything else to help... I'd very much like this to work, this app is the only one to smoothly support 120fps HDR, so 5.1 is the only thing missing to make this the "ultimate" Moonlight experience 😄

RedGuilhas commented 9 months ago

For the record, I have a 2023 LG C3 with a Denon receiver through eARC, set up in full passthrough.

I also built a custom version that unlocks the 5.1 and 7.1, tested all four audio backends, all I can get is Stereo sound.

I also tested speaker-test -c 6 -l 1 and can only hear the 2 front speakers.

Not sure if I can do anything else to help... I'd very much like this to work, this app is the only one to smoothly support 120fps HDR, so 5.1 is the only thing missing to make this the "ultimate" Moonlight experience 😄

Any news on this? I also have an LG C3 and the only thing missing for me is surround sound.

mariotaku commented 9 months ago

@RedGuilhas There's no update from LG in 2023.

pankompot commented 8 months ago

@mariotaku thanks a lot for your work on this port, it works great and I'm super happy with picture performance. As other people mentioned, surround sound is just the only missing thing. If we could help in any way through testing, pushing LG support or anything else, please just shout. Otherwise I'm really looking forward for a development in 2024 :)

rayfilm0815 commented 8 months ago

Me too, all I need is a surround sound so I can ditch those expensive and annoying HDMI cable (via Google Translate)

astarktc commented 6 months ago

Hey everyone, just wanted to share that there is a solution that has been working great for me since I discovered it a few months ago. In my case, I'm running sunshine hosted on windows 11, and all I had to do was configure my sound in windows to use the "Dolby atmos for home theater" option.

If you install the dolby access app from the windows store, the atmos for home theater option is free to use (only the headphones one requires a purchase)

I think this works for the same reason @marvin-roesch & @royka1 were able to play aac encoded surround sound with no issue: the dolby atmos setting encodes the sound output to dolby which my LG passes through to the receiver, therefore ignoring the stereo setting in the moonlight app.

Note that despite the name, you don't actually have to have an atmos system :) you just have to be able to decode the pass through output on your receiver. I actually just installed a new receiver and 4 in-ceiling speakers this last weekend, so I'm excited to test and see if I not only get surround sound from my gamestream, but height effects too :)

Disclaimer: I do have an lg c2 48" connected to my host pc (with an atmos compatible soundbar connected through earc) so I don't know whether or not this setup was a prerequisite that made this solution possible for me. Your mileage may vary, but try it out and let me your results.