The no sound problem is because pulseaudio is configured to output to a dummy sound device.
We need to configure it to output to our sound card.
So you need to get your sound card number and device number. Mine for example is hw:0,7
This looks a little complicated but its not. Only two lines in moonlight.sh need changed to fix the sound.
To find your numbers SSH into LibreELEC and do:
# aplay -l
This will return a list of sound devices.
Here is one of mine.
card 0: HDMI [HDA Intel HDMI], device 7: HDMI 1 [HDMI 1]
To test if this the right device substitute the CARD number and DEVICE number into this command.
# aplay -D plughw:CARD,DEVICE /usr/share/kodi/addons/http://resource.uisounds.kodi/resources/notify.wav
Test each one of your sound devices in turn until you hear output from your speakers.
When you find the correct sound device you will use the CARD and DEVICE numbers below.
Now its time to edit moonlight.sh using nano or something like WinSCP.
# nano /storage/.kodi/addons/script.moonlight/bin/moonlight.sh
scroll to the bottom of moonlight.sh and find this section of the script.
modprobe snd_bcm2835 :
echo $MOONLIGHT_ARG >> $ADDON_LOG_FILE
/bin/sh -c "${ADDON_DIR}/bin/moonlight ${MOONLIGHT_ARG} > ${ADDON_LOG_FILE} 2>&1"
rmmod snd_bcm2835 :
Change it to read like this.
INDEX=$(pactl load-module module-alsa-sink device=hw:CARD,DEVICE channels=2)
echo $MOONLIGHT_ARG >> $ADDON_LOG_FILE
/bin/sh -c "${ADDON_DIR}/bin/moonlight ${MOONLIGHT_ARG} > ${ADDON_LOG_FILE} 2>&1"
pactl unload-module $INDEX
Be sure to replace CARD and DEVICE with the numbers you found above. And set the number of channels. For 5.1 channels=6
Also, in moonlight's settings, disable "Force video acceleration", and reboot after making any changes to the settings.
Sadly its buggy with some games. In the Witcher 3 for instance some sounds play on the host pc.
Works great for Doom and Assassins Creed though.