Showing posts with label KDE. Show all posts
Showing posts with label KDE. Show all posts

Sunday, January 04, 2015

Tips to fix sound server issues on linux (Alsa, Pulseaudio)

Usually everything else works out of the box on linux but the audio. I think analog audio would work just fine but I always use digital audio over SPDIF or HDMI so that could be the reason why I have always some audio problems.

So I list here some common tips that I will not have to google those again in next time. As KDE is mine default desktop environment so there will be some specific tips for just KDE.

TIP 1 - Check that you have all ALSA related packages installed


I have installed these:

dpkg --get-selections | grep 'alsa'
alsa-base                                       install
alsa-oss                                        install
alsa-tools                                      install
alsa-tools-gui                                  install
alsa-utils                                      install
alsamixergui                                    install
alsaplayer-alsa                                 install
alsaplayer-common                               install
alsaplayer-gtk                                  install
cairo-dock-alsamixer-plug-in                    install
gstreamer0.10-alsa:amd64                        install
gstreamer1.0-alsa:amd64                         install
libalsaplayer0                                  install
libsox-fmt-alsa:amd64                           install

TIP 2 - Check your GUI settings 


Try to unmute channels and try to different audio devices. In KDE try to modify mixer and KDE audio settings.


TIP 3 - Disable PulseAudio server


Usually mine problems are solved when I disable pulseaudio or at least I have to do it to get it audio first working with Alsa.

So you don't have to totally remove pulseaudio you can disable it first.

If you need to remove it totally then purge the installation. Sometimes it may uninstall some dependencies that are needed, so be careful when purging it.

Disabling automatic spawning of PulseAudio server

Some users may prefer to manually start the PulseAudio server before running certain programs and then stop the PulseAudio server when they are finished. A simple way to accomplish this is to add or edit following file:
/home/<username>/.config/pulse/client.conf 

and add or uncomment following attribute:
autospawn = no

If you want later undo this just comment that line:

#autospawn = no

or remove the file:

rm /home/<username>/.config/pulse/client.conf

autospawn = no

Now you can manually start the pulseaudio server with

$ pulseaudio --start

and stop it with

$ pulseaudio -k

If you have problems to kill pulseaudio then you can try following commands:

$ pkill -f pulseaudio
$ ps aux | grep pulse


You should now find that KDE audio settings are different for ALSA and PULSEAUDIO. When you stop/kill PULSEAUDIO then KDE's mixer and audio settings should view ALSA settings.


ALSA active (pulseaudio stopped)


PULSEAUDIO active

TIP 4 - Found your working sound cards and devices (ALSA)

Following command can be used to list your cards and devices:

$ aplay -l (list all soundcards and digital audio devices)
$ aplay -L (list device names)

And test audio files can be found in folder:
/usr/share/sounds/alsa/

Aplay can be used to test, if your pcm outputs are working. Be sure to unmute and set volume for master and pcm channels with mixer first. It might be a good idea to set a moderate volume level for not damaging your boxes. For hw:0,0  means hw:<card>,<device>. List of available numbers can be found using the "$ aplay -l" -command. Then let it play the test file. Try all the combinations of cards and devices.

$ aplay -D hw:0,0 Noise.wav

If you receive a cryptic error message about "Channels count non available" then the wav file uses a sample rate different to the hardware. You can add a resampling layer with the 'plug' plugin, e.g.

$ aplay -D plughw:0,0 Noise.wav

Many don't know that you can play files using the devices names too. Using the command "$ aplay -L" it lists devices by names, example:

iec958:CARD=PCH,DEV=0
  HDA Intel PCH, ALC892 Digital
  IEC958 (S/PDIF) Digital Audio Output

To play that device you can use following command:

$ aplay -D iec958:CARD=PCH,DEV=0 Noise.wav


If you receive a cryptic error message about "Channels count non available" then the wav file uses a sample rate different to the hardware. You can add resampling layer with the 'plug' plugin.

 $ aplay -D plughw:CARD=PCH,DEV=0 Noise.wav

The "Channels count non available"can be fixed by defining your "ctl" (short for "control") entry in /etc/asound.conf -file. Example:
   
defaults.ctl.card 0
defaults.pcm.card 0
defaults.pcm.device 0

TIP 5 - Audio works in KDE but not in the Firefox etc...


Then you should define default audio card and device. Check tip 6.


TIP 6 - Modify ALSA configs


There could be two config files for ALSA. The system-wide file /etc/asound.conf or the user-specific file ~/.asoundrc.

First you should try to comment out all the lines that you have in those files and try again if you have some audio problems.

If that didn't fixed then I try explain different configuration options shortly.

To set digital out as default

On most soundcards the digital output emits the same sound signal as the analog output. If this is not the case for you then you can set the default playback device by using .asoundrc or /etc/asound.conf. If you want your digital output to be the default you might need to add this:

pcm.!default {
        type hw
        card <the card number you worked out above>
        device <the device number you worked out above>
}
This is the most simple configuration that I try usually first. Just edit the card and device values that worked for you in the aplay sound testing (TIP4).

defaults.ctl.card 1
defaults.pcm.card 1
defaults.pcm.device 7

This way I fixed mine audio problems in one machine:

pcm.!default {

   type plug
   slave {
       pcm "iec958"
   }
}

Here is other config that I have used:

pcm.!default {
  type plug
  slave {
    pcm "hw:1,7"
  }
}
ctl.!default {
  type hw
  card 1
}

Or that can be define also this way:

pcm.!default {
  type hw
  card 1
  device 7
}
ctl.!default {
  type hw
  card 1
  device 7
}
On the pulseaudio side you can always define default audio device as well by editing following config file: /etc/pulse/default.pa (define/edit those in bold text with your device numbers)

#load-module module-alsa-sink device=hw:1,1
#load-module module-alsa-source device=hw:1,1

Usually I have been able to fix my audio problems following these tips. I will define this article again when I next time have some audio problems. At the moment I have 4 Debian or Ubuntu installations and audio worked out of the box only one of those installations. Now I have two systems without pulseaudio. I think I'm not expert in these audio issues but I have always been able to solve those. I think this is the area that needs some attention in linux development. It just shouldn't be this difficult to solve always these issues.

When the audio works then I usually set the on-the-fly AC3 encoding:
http://shellscreen.blogspot.fi/2014/11/6-channel-aac-to-ac3-on-fly-encoding-on.html

Friday, November 21, 2014

Apple Magic Trackpad on KDE







It seems that it's quite easy to get Apple Magic Trackpad work on linux. Besides the trackpad you will need a bluetooth receiver. The most recent laptops come with a built-in Bluetooth but in my case I needed to buy it for my desktop pc.

Bluetooth receiver


I bought ASUS USB-BT400 bluetooth adapter mainly because it just works out of the box on Linux and it is Bluetooth 4.0 / 3.0 / 2.1 / 2.0 compatible.

On first boot I checked following things

That I have touchpad config tool for KDE. It was missing so installed it.

$ sudo apt-get install kde-config-touchpad

That I have all needed bluetooth applications installed.

dpkg --get-selections | grep 'blue'
bluedevil                                       install
bluetooth                                       install
bluez                                           install
libbluedevil2:amd64                             install
libbluetooth3:amd64                             install

That I can see the bluetooth adapter.

$ lsusb | grep 'ASUS'
Bus 003 Device 005: ID 0b05:17cb ASUSTek Computer, Inc.

After those things I powered up the Apple Magic Trackpad and scanned my bluetooth devices (System settings > Bluetooth)

A new bluetooth adapter found the Apple Wireless Trackpad. I paired and connected it. By the way default pin is: 0 0 0 0

Finally I checked the kernel message details of my Apple devices. The red text lines are for Apple Magic Trackpad and black text for Apple Magic Mouse.

$ dmesg | grep 'magic'
[   37.587869] magicmouse 0005:05AC:030D.0009: unknown main item tag 0x0
[   37.588008] magicmouse 0005:05AC:030D.0009: input,hidraw6: BLUETOOTH HID v3.06 Mouse [Apple Magic Mouse] on 5c:f3:70:63:97:a1
[157856.306955] magicmouse 0005:05AC:030E.000A: unknown main item tag 0x0
[157856.307157] magicmouse 0005:05AC:030E.000A: input,hidraw7: BLUETOOTH HID v1.60 Mouse [Apple Wireless Trackpad] on 5c:f3:70:63:97:a1

Once your trackpad has been paired, the "hid_magicmouse" module should automatically load. Both Apple Magic Mouse and Trackpad uses the same "hid_magicmouse" driver. To verify that it is loaded you can check it in terminal:

$ lsmod | grep 'magic'
hid_magicmouse         12679  0
hid                   102264  6 hidp,hid_generic,usbhid,hid_logitech_dj,hid_magicmouse
If it is not loaded you can load id this way:

$ sudo modprobe hid_magicmouse

Synaptic driver solution


So my Apple Magic Trackpad semi-worked right out of the box on Debian Testing (Jessie). I use KDE as default desktop environment.

What worked out of the box?

  • Mouse movements (horizontal speed was slower than vertical - can be fixed)
  • One finger click (Mouse left button)
  • Two fingers click (Mouse right button)
  • Two fingers gestures (scrolling top/down/left/right)
  • Three fingers click (Paste)
It uses "synaptic" driver out of the box and you can configure following things using the Synaptiks GUI:
(KDE: System settings > Input devices > Touchpad)

  • Hot corner areas (example for scrolling)
  • Tap clicking 
Horizontal scroll fix and other fine-tuning

To fix that slow horizontal scrolling I created following file:

/etc/X11/xorg.conf.d/60-apple-magic-trackpad.conf

And here is my configuration for that file:

# Configuration for fine-tuning only the Apple Magic Trackpad.
Section "InputClass"
    Identifier "Apple Magic Trackpad"
    Driver "synaptics"

    # Match only the Apple Magic Trackpad
    MatchUSBID "05ac:030e"
    MatchIsTouchpad "on"

    # Set resolution tweaks for better response
    Option "VertResolution" "75"
    Option "HorizResolution" "75"

    # Set a timeout for multi finger click so accidental double-clicks don't
    # happen when right clicking and other gestures
    Option "EmulateMidButtonTime" "100"

    # Increase sensitivity
    Option "MinSpeed" "0.50"
    Option "MaxSpeed" "1.00"
    Option "AccelFactor" "0.1"

    # Scrolling
    Option "VertScrollDelta" "100"
    Option "HorizScrollDelta" "100"
EndSection

Those settings were fine on my pc. I have Monitor (4K) and TV (1080p) connected to my pc. Those settings could be different if you don't have that big monitor or multi-monitor system.

Note: Every time you edit that file you will need to restart the X server, I restarted the PC just in case.

The final tuning I did using the Synaptiks GUI for touchpads
(KDE: System settings > Input devices > Touchpad)



MTRACK driver solution


Previous solution wasn't perfect so I did some googling and I found out that I need to install mtrack driver for 4 fingers gestures.

$ sudo apt-get install xserver-xorg-input-mtrack

After driver installation I configured the X server to use that driver. I opened again following configuration file:
/etc/X11/xorg.conf.d/60-apple-magic-trackpad.conf

And I edited it as below:

# Configuration for fine-tuning only the Apple Magic Trackpad.
Section "InputClass"
    Identifier "Apple Magic Trackpad"
    Driver "mtrack"

    # Match only the Apple Magic Trackpad
    MatchUSBID "05ac:030e"
    MatchIsTouchpad "on"

    # Set resolution tweaks for better response

# Tap
Option "TapButton1"                "1"
Option "TapButton2"                  "3"
Option "TapButton3"                 "8"
Option "TapButton4"                 "9"
# Click
Option "ClickFinger1"               "1"
Option "ClickFinger2"                "3"
Option "ClickFinger3"                 "2"
# Two finger swipe
Option "ScrollDistance"            "15"
Option "ScrollUpButton"            "4"
Option "ScrollDownButton"        "5"
Option "ScrollLeftButton"        "6"
Option "ScrollRightButton"        "7"
# Three finger swipe
Option "SwipeDistance"            "180"
Option "SwipeUpButton"            "34"
Option "SwipeDownButton"        "35"
Option "SwipeLeftButton"        "8"
Option "SwipeRightButton"        "9"
# Four finger swipe
Option "Swipe4Distance"            "200"
Option "Swipe4UpButton"            "20"
Option "Swipe4DownButton"        "21"
Option "Swipe4LeftButton"        "23"
Option "Swipe4RightButton"        "22"
# Scaling
Option "ScaleDistance"            "40"
Option "ScaleUpButton"            "12"
Option "ScaleDownButton"        "13"
# Rotate
Option "RotateDistance"            "40"
Option "RotateLeftButton"        "14"
Option "RotateRightButton"        "14"

Option "TapDragEnable"            "true"
Option "TapDragTime"            "350"
Option "TapDragWait"            "40"
Option "TapDragDist"            "200"

Option          "Sensitivity" "0.85"
Option      "FingerHigh" "5"
Option      "FingerLow" "5"
Option          "IgnoreThumb" "true"
Option          "IgnorePalm" "true"

#    Option          "ButtonMoveEmulate" "false"
Option      "ButtonIntegrated" "true"

EndSection
Here is listed all configuration options for Mtrack:
https://github.com/BlueDragonX/xf86-input-mtrack

Those red text numbers in the configuration file are mouse button numbers. A common mouse have by default max 9 buttons and this is the layout for those 9 buttons:
1 = Left click
2 = Middle click
3 = Right click
4 = Scroll top
5 = Scroll down
6 = Scroll left
7 = Scroll right
8 = Back
9 = Forward

The rest button numbers in configuration file is just make it up by myself so there is not any big logic behind on that numbering.

Note: Remember restart the X server or PC after you have modified that 60-apple-magic-trackpad.conf -file.

With that configuration trackpad movents, gestures and clicks got through as mouse buttons. I tested that using the XEV input detection tool.

$ xev

I did those gestures on the trackpad and I sametime checked the log on Konsole. Example 3 fingers swipe left I got following info on ZEV:

ButtonPress event, serial 40, synthetic NO, window 0x7000001,
    root 0xc9, subw 0x0, time 1002624673, (103,137), root:(103,278),
    state 0x10, button 8, same_screen YES

As you can see it was registered as click on mouse button 8.

Then I installed following packages to bind trackpad gestures to various actions.

$ sudo apt-get install xautomation 
$ sudo apt-get install xbindkeys

The final step was bind gestures and clicks to the actions

So I created configuration file for xbindkeys to the home folder

$ xbindkeys -d > ~/.xbindkeysrc

Then I added following rows to that configuration file. Basically I linked my keyboard shortcuts to the mouse buttons that are created by trackpad gestures:

# Minimize toggle - Swipe 4 fingers up - Key: Meta + F8
"xte 'keydown Super_L' 'key F8' 'keyup Super_L'"
  b:20

# View all windows - Swipe 4 fingers down - Key: Meta + F8
"xte 'keydown Control_L' 'key F8' 'keyup Control_L'"
  b:21

# Move current window to TV - Swipe 4 fingers right : Meta+b
"xte 'keydown Super_L' 'key b' 'keyup Super_L'"
  b:22

# Move current window back to the monitor - Swipe 4 fingers left : Meta+v
"xte 'keydown Super_L' 'key v' 'keyup Super_L'"
  b:23

# New Tab - FF - Swipe 3 fingers up : Control+t
#"xte 'keydown Control_L' 'key t' 'keyup Control_L'"
# b:34
 
# Close Tab - FF - Swipe 3 fingers down : Control+w
#"xte 'keydown Control_L' 'key w' 'keyup Control_L'"
# b:35

The last two Firefox actions I disabled because I sometimes launched accidentally those gesture actions.

KDE keyboard shortcut actions I configured using the following GUI:
(KDE: System settings > Shortcuts and Gestures)


In the screenshot above you can see META+V and META+B shortcuts are linked to move window to other screen. In xbindkey configuration those shortcuts are linked to 4 finger swipes by monitor locations (left / right). Nice gesture to move active MPV-videoplayer window to TV!

Short video demonstration about 4 fingers swipe up and down




In the video:
  • 4 fingers swipe up minimize / maximize all windows (toggle)
  • 4 fingers swipe down presents all windows visible (toggle)

Final thoughs


I think synaptics  driver offers much better feel for my trackpad but I cannot activate gestures for 3 and 4 fingers. Let's hope that it will get some new features in near future.

Mtrack driver seems to be working just fine but I still need to fine configure those pressure, distance and other settings to improve more my trackpad experience.

In Debian it seems to be almost impossible to try those other options like Touchegg. If you have some tips how to configure this Apple Magic Trackpad some other-way in Debian, please comment below.

Friday, November 14, 2014

SOLVED! Debian mount USB stick always as root and you cannot write it as normal user (Known Debian Jessie USB installation issue)

I just installed Debian Jessie KDE edition ISO and I got problem to save the files to USB memory stick.

Then I checked the the permissions of the USB stick and it was root:root.

I finally fixed it by commenting out following line on /etc/fstab-file:

#/dev/sdf1 /media/usb0 auto rw,user,noauto 0 0

Now it works just great at least in KDE.


The reason for the issue is that if you install Debian from a USB drive, the installer adds sdX1 to fstab and whenever you plug it in the system will mount it as root.

So you should always remember to uncomment that line from fstab after installing from USB.

Tuesday, November 11, 2014

Download subtitles via Dolphin

Introduction to Subliminal

Subliminal is perfect subtitle downloader that comes with an easy CLI (command-line interface) that can be integrated to the Dolphin as service menu.

Subliminal uses multiple providers like:
  •     Addic7ed
  •     OpenSubtitles
  •     Podnapisi
  •     TheSubDB
  •     TvSubtitles
Subliminal web page


Debian installation

sudo apt-get instal python-pip
sudo pip install subliminal


Download a movie

After installation you should test the Sublimal for your movies. If you don't have any movies you can download Sintel.

Sintel the movie (open source)


Download Sintel the movie
More open source movies


Test Subliminal


Use terminal and download subtitle to the movie using following command:

subliminal -l en Name_Of_The_Movie_file.mkv
It should download the subtitle to the same directory. The "-l" sets the subtitle language to be "en" (English) in the example above.

How to use Subliminal.... run this command in terminal:

subliminal --help

KDE Dolphin right click service menu for Sublimal


As root make a new file:

/usr/share/kde4/services/subliminal.desktop

Content of the file:

[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KonqPopupMenu/Plugin
MimeType=video/*
Actions=DownloadSub

[Desktop Action DownloadSub]
Type=Application
Name=Subliminal subtitle search
Exec=subliminal -m 0 -l en fi --addic7ed-username <username> --addic7ed-password <password> -- %U
Icon=video

The bold text in the example is the search command, you can edit it the way you like. Mine search command finds both English "en" and Finnish "fi" subtitles.

Register to the "addic7ed" and change the <username> and <password> placeholders if you like to use that provider or just remove the option .

When you have saved the file then check that Dolphin is closed. Then open Dolphin, go to the folder that contains some movie files, right click the movie file and select: Actions > Subliminal subtitle search

That's all! It should work now!