All commands are to be run as the osmc user!
You have to change the device-names to your system!
sudo apt-get install pulseaudio
reboot
(This installs pulseaudio v10 as of 1March 2020. See below how to install PA v13. Recommended if you feel comfortable)
Debugtip (“No PulseAudio daemon runni…”)
Fix pacmd “No PulseAudio daemon running, or not running as session daemon” error by locating the runtime folder in /home/osmc/.config/pulse/.....-runtime/
And set the proper PULSE_RUNTIME_PATH environment variableexport PULSE_RUNTIME_PATH="/home/osmc/.config/pulse/ad878236c70e4d039bd7de40dbff260a-runtime/"
If this doesn’t work. Verify that pulse is actually run:
ps aux | grep pulse
If it isn’t, try starting pulseaudio in verbose mode to figure out the problem:
pulseaudio -vvvvv
Good luck…!
pacmd should now work.
List output sources:
pacmd list-sinks
List input sources:
pacmd list-sources
Note that iec958 / SPDIF is not listed as a possible input!. But first, we shall:
Set Hifiberry as default sink (audio output)
sudo nano /etc/pulse/default.pa
Add at the end:
set-default-sink alsa_output.platform-soc_sound.analog-stereo
Restart OSMC/Kodi to reinit:
sudo systemctl restart mediacenter
To test; just use Kodi. Make sure Kodi’s Audio output device is set to “ALSA Playback/recording through the PulseAudio sound server”. Alternatively, wget a sound-file from Voices and Vocal Sound Effects and play it with:
aplay hi-1.wav
ENABLE iec958-stereo (SPDIF-INPUT) profile
source: PulseAudio/Troubleshooting - ArchWiki
Source 2: Recording S/PDIF (SPDIF) under Linux - LinuxMusicians
Edit March 2020:
For my CM106-compatible USB set; I had to configure my CM106 to go into SPDIF-mode.
amixer -c Device scontrols # See available controls
amixer -c Device get 'PCM Capture Source' # Get current and availble settings for 'PCM Capture Source'
amixer -c Device set 'PCM Capture Source' 'IEC958 In' # Set it to IEC958 In (aka spdif)
alsactl store # permanently store alsamixer configuration
After, configure pulseaudio to use iec958:
pacmd list-cards | less
Look for card-name. We want to enable the input:iec958-stereo profile
sudo nano /etc/pulse/default.pa
add line:
set-card-profile alsa_card.usb-0d8c_USB_Sound_Device-00 input:iec958-stereo
(or set-card-profile alsa_card.usb-0d8c_USB_Sound_Device-00 input:analog-stereo for mic-in)
I also had to change the chosen port for analog input. pacmd list-sinks
is your friend:
set-source-port alsa_input.usb-0d8c_USB_Sound_Device-00.analog-stereo iec958-stereo-input
Then restart OSMC/Kodi to reinitialize pulseaudio:
sudo systemctl restart mediacenter
Forward the source to the sink
module-loopback options: Modules – PulseAudio
load-module module-loopback source_dont_move="true" latency_msec=40 max_latency_msec=300 fast_adjust_threshold_msec=100 source=alsa_input.usb-0d8c_USB_Sound_Device-00.iec958-stereo
Finally…
restart kodi again. It should work
sudo systemctl restart mediacenter
tl,dr; my /etc/pulse/default looks like:
set-default-sink alsa_output.platform-soc_sound.stereo-fallback
set-card-profile alsa_card.usb-0d8c_USB_Sound_Device-00 input:iec958-stereo
set-default-source alsa_input.usb-0d8c_USB_Sound_Device-00.iec958-stereo
# max_latency_msec=1000 fast_adjust_threshold_msec=100
load-module module-loopback source_dont_move="true" latency_msec=40 max_latency_msec=300 fast_adjust_threshold_msec=100 source=alsa_input.usb-0d8c_USB_Sound_Device-00.iec958-stereo
If you experience audio crackling. This may be due to timing issues, also read this: https://kodi.wiki/view/PulseAudio
Fix audio crackling
This fixed it for me:
sudo nano /etc/pulse/daemon.conf
Add the line, at the end:
resample-method = speex-float-5
I’m not sure why it needs to resample though. Just make sure that pacmd list-sources | grep "sample spec"
and pacmd list-sinks | grep "sample spec"
show the same values and that it matches with what Kodi outputs… And all should be fine without resampling AFAIK…
Second crackling fix
Ok, so that actually didn’t fix audio crackling. It just made it less worse.
I now also tried setting the volume of the sink lower;
pactl set-sink-volume 0 95%
(remember, pactl list sinks
is your friend)
I also forced Kodi to output on 44100hZ -only-, to prevent remixing.
Anyway, it seems i am not the only one with audio crackling/stuttering and pulseaudio… -sigh-
And now I’ve also tried editting /etc/pulse/daemon.conf and setting realtime-scheduling = no
Fix audio crackling II
I have changed the latency_msec=1 option to latency_msec=200 for module-loopback after i saw that pulseaudio was running into constant buffer underruns (pulseaudio -vvvvvv
). That fixed about 99% of the crackling.
The remaining crackling appears to be resolved by setting the default-sample-rate to 48000. Additionally, I made sure that osmc can run processes with a nice level of -11
.
I have modified /etc/pulse/daemon.conf
to enable the following settings:
default-sample-format = s24le
high-priority = yes
nice-level = -11
exit-idle-time = -1
flat-volumes = yes
;default-sample-rate = 44100
default-sample-rate = 48000
;alternate-sample-rate = 44100
;resample-method = speex-fixed-10
resample-method = speex-float-10
default-fragments = 3
default-fragment-size-msec = 7
avoid-resampling = yes
Additionally, I modified /etc/security/limits.d/osmc.conf
to allow osmc to set its nice level to -11;
* - nice -1
osmc - nice -11
Make sure to reboot the PC after making these changes; a restart of the mediacenter service will not suffice.
Volume-fix
My TV doesn’t let me control audio volume anymore, and kodi doesn’t control the volume either for some reason… Which is kinda annoying. Im still searching for a fix for this one. (found it, scroll below for IR)
Oh, my install still uses PulseAudio 10, but PA11 has a feature I want to try out; Option to avoid resampling more often)
No working SPDIF-IN
March 2020. Got it working. If you’re experience a lot of audio lag, make sure everything is running at 48000hZ. Lastly, make sure you’re running PA13 or build it from scratch, as it has a lot of nice improvements.
If you’re building PA13 on your ARM device, run the bootstrapsh, and afterwards again run configure:
CFLAGS="-g -O0 -fomit-frame-pointer" ./configure --enable-force-preopen --enable-bluez5