Tuning Ubuntu Studio for HTPC

credit: https://wiki.linuxaudio.org/wiki/system_configuration#installing_a_real-time_kernel

  • Checking /etc/fstab mounting drive should using noatime. 
  • Ubuntu Studio already set vm.wappiness = 10. But if you have more than 4 GB ram you could run HTPC linux without swap.
  • add user to audio group. Use $USER return current user or just type username.

sudo useradd -G audio $USER

  • limits.conf/audio.conf. It is advisable to set up your /etc/security/limits.conf file properly, for example:

@audio – rtprio 90 # maximum realtime priority
@audio – memlock unlimited # maximum locked-in-memory address space (KB)

  •  Using realtimeConfigQuickScan script for checking system

You need to install git first

sudo apt install git

Install script and run script

git clone git://github.com/raboof/realtimeconfigquickscan.git
cd realtimeconfigquickscan
perl ./realTimeConfigQuickScan.pl

  • If script warn about CPU governer and said CPU are not run in performance mode. As some might found that cpufreq don’t have driver for their CPU. Just disable CPU energy saving and Turbo mode in Bios would be more easy solution. you could install cpufrequtils and run cpufreq-info to check if driver is available or not. You could check CPU speed by using command

more /proc/cpuinfo | grep MHz

After setting change, every cores in CPU should run at same speed whether load are high or low.

  • In Ubuntu there’re no out of the box realtime kernel, we have to built it ourselves. If you just using Linux for HTPC and didn’t record video or audio, you don’t need realtime kernel. To install necessary packages run

sudo apt-get install kernel-package fakeroot build-essential libssl-dev

mkdir -p ~/tmp/linux-rt
cd ~/tmp/linux-rt
wget -c https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.11.8.tar.xz
wget -c https://www.kernel.org/pub/linux/kernel/projects/rt/4.11/patch-4.11.8-rt4.patch.xz

Extract the kernel sources and patch them with the RT patchset:

tar xJvf linux-4.11.8.tar.xz
cd linux-4.11.8
xzcat ../patch-4.11.8-rt4.patch.xz | patch -p1

 

cp /boot/config-`uname -r` .config

This will copy the config of the kernel you’re currently using. You might want to consider using a config of a kernel already optimized for audio work, like the Ubuntu -lowlatency kernel config. The next step is to create a new config with full preemption enabled from the copied config:

make oldconfig

make -j `nproc` LOCALVERSION= deb-pkg

P.S.

I don’t recommend booting neither realtime or lowlatency kernel for audio playback. When playback with ALSA mode in deadbeef and audacious, I found that its sound a little widen, and less dynamic compare to generic kernel. And I cannot hear differences between realtime and lowlatency kernel. Unless, you could hear differences between generic and lowlatency, there are no need for compiling realtime kernel, imo.

Details of my system are Ubuntu Studio 16.04 LTS, kernel version 4.11.8, and ESI Juli@ + External DAC

 

Reset TV Box/Tablet Bios (Intel)

BIOS of Intel Atom Tablet or TV Box are poorly design. You can soft brick if config BIOS incorrectly. Assuming that you are not disable USB port. You could connect USB keyboard to device and enter BIOS. Although it wouldn’t show anything on screen. This is how you might able to un-brick your device. In my case, I soft bricked my Chinese made Intel X5-z8300 TV Box.

  1. Hit “Del” repeatedly about 5-10 sec to enter BIOS. Wait for another 5-10 sec before proceed
  2. Press “F3” then “Enter” (Load Optimized Defaults)
  3. Press “F4” then “Enter” (Save & Exit)

Hope It could help you, too.

TEARING WHEN PLAYBACK VIDEO OR SCROLLING WEBPAGE (Intel Graphics)

Create file
/usr/share/X11/xorg.conf.d/20-intel.conf

or

/etc/X11/xorg.conf.d/20-intel.conf

Check folder first whether which one existed for *buntu mostly /usr/share/X11/xorg.conf.d/

Section "Device"
	Identifier "Intel Graphics"
	Driver "Intel"
		Option "AccelMethod" "sna"
		Option "TearFree" "true"
		Option "DRI" "3"
		Option "TripleBuffer" "true"
		Option "MigrationHeuristic" "greedy"
		Option "Tiling" "true"
EndSection

or

Section "Device"
	Identifier "Intel Graphics"
	Driver "Intel"
		Option "AccelMethod" "uxa"
		Option "DRI" "2"
		Option "TripleBuffer" "true"
		Option "MigrationHeuristic" "greedy"
		Option "Tiling" "true"
EndSection

for Skylake

Section "Device"
	Identifier "Intel Graphics"
	Driver "intel"
		Option "DRI" "false"
EndSection

 

Note

  1. SNA acceleration is default, change to UXA only you encounter pixelated graphics, corrupt text, etc.
  2. “TearFree” doesn’t work with UXA acceleration
  3. by default DRI is 3 change to 2 if you’re using virtual desktops and switching between desktops cause artifacts


References

https://wiki.archlinux.org/index.php/intel_graphics

https://www.x.org/archive/X11R7.5/doc/man/man4/intel.4.html

 

Force KODI to use ALSA

Force load PulseAudio and ALSA at the same time. Buggy, if you set Kodi Audio output to same device as default desktop audio output. In my case, work like charm as my default desktop audio route to HDMI while Kodi using another device.

create file /usr/share/applications/kodi-alsa.desktop and paste this into the file

 

[Desktop Entry]
Version=1.0
Name=Kodi-ALSA
GenericName=Media Center
Comment=Forced Kodi to run on ALSA instead of PulseAudio
Exec=/usr/share/applications/kodi-alsa.sh
TryExec=/usr/share/applications/kodi-alsa.sh
Icon=kodi
Terminal=false
Type=Application
Categories=AudioVideo;Video;Player;TV;

Actions=Fullscreen;Standalone;

Path=
StartupNotify=false

Create file /usr/share/applications/kodi-alsa.sh and paste this into file

#! /bin/bash

# this makes kodi start with ALSA instead of FUCKING pulse audio

# disable pulse audio
pasuspender

# start kodi with ALSA
AE_SINK=ALSA kodi

Set permission so kodi-alsa.sh could be executed.

credit : https://gist.github.com/bmaeser/1918514429e4855d5188

Config PulseAudio

To disable PulseAudio (affect every user)

in /etc/pulse/client.conf

change this line from

; autospawn = yes

to

autospawn = no

To set sample format, check sample spec first by

pacmd list-sinks

Screenshot at 2017-03-02 22:39:29.png

in /etc/pulse/daemon.conf

resample-method = speex-float-5

default-sample-format = float32ne
default-sample-rate = 88200
alternate-sample-rate = 96000
default-sample-channels = 2
default-channel-map = front-left,front-right

Credit:http://kodi.wiki/view/PulseAudio

SSD & Ram Drive Tweak

As my PC has 16GB ram and SSD. I decided to tweak it like this.

In /etc/fstab, for SSD drive I replace “errors=remount-ro” with “errors=remount-ro,noatime,commit=60”

and add these lines to move system tmp and log to Ramdrive

#Create Ram Disk for cache#Create Ram Disk for cache
tmpfs /var/log tmpfs defaults,noatime,size=10M 0 0
tmpfs /tmp tmpfs defaults,noatime,mode=1777,size=20% 0 0
tmpfs /home/<<your username>>/.cache tmpfs defaults,noatime,mode=1777,size=20% 0 0
tmpfs /home/<<your username>>/.thumbnails tmpfs defaults,noatime,mode=1777,size=10% 0 0