Sunday, April 27, 2008

Pulse audio and SPDIF output in Kubuntu (Hardy Heron 8.04)

8 comments

Preface

Here I will explain how I got my Realteck ALC888 SPDIF digital output working with pulseaudio in Kubuntu Hardy Heron (8.04).

Background (rant so skip if you are in a hurry)

I have a MSI board with integrated Realtek ALC888 Audio card that came with analog outputs only. Fortunately these boards usually come with a SPDIF header where you can connect a SPDIF bracket to get a digital output. These brackets are difficult to get and in my case I had to call the main board dealer (calling customer support) and they sold me one for about USD/30.00. Another alternative I considered was to buy a cheap sound card with SPDIF outputs for about the same amount like the ENVY24HTS-PCI or the CMI8768-8CHPCI but the idea of wasting the ALC888 was daunting.

I needed the SPDIF ouput because my ALLA VIBRAR 5.1ch Headphones have only SPDIF (Coax and Fiber) inputs.

After trying a lot, and I mean a LOT!, alsa was not working well with my Headphones, anything I played througth the digial output would be accompanied by all kinds of artifacts (cracks, skips, pauses) coming out from the headphones.

So I decided to try the recent pulseaudio and once I got my audio working I never looked back at alsa again.

For some reason pulseaudio did not came as default with any of the beta, rc and final installations of Hardy Heron (Kubuntu 8.04 KDE4) so here is how I managed to get Pulseaudio working for me.

Pulse Audio in Kubuntu (Hardy Heron 8.04)

First we install the necessary packages:



sudo aptitude install pulseaudio libao-pulse pulseaudio-module-hal \

  pulseaudio-module-x11 pulseaudio-utils libsdl1.2debian-pulseaudio



and then create a .asoundrc configuration file to tell all ALSA applications to use pulse.

pcm.!default {

    type plug

    slave {

         pcm "spdif"

     }

}






This configuration file will set pulseaudio as the default sound server and in this particular case it will also set the digital (SPDIF) output as default. If you prefer the analog outputs simply remove the type plug and slave sections.

The above configuration works and I get sound on the SPDIF output but I also have a stereo jack in the front panel of the PC that was getting wasted. So after some research I got the following asoundrc configuration file:


pcm.!default {

    type pulse

    type plug

     slave {

         #pcm "spdif"

         pcm multi

     }

     ttable.0.0 1.0

     ttable.1.1 1.0

     ttable.0.2 1.0

     ttable.1.3 1.0

}



clt.!default {

   type pulse

}



pcm.stereo {

  type pulse

  type plug

  slave {

  pcm multi

  }

  ttable.0.0 1.0

  ttable.1.1 1.0

  ttable.0.2 1.0

  ttable.1.3 1.0

  }

 

 ctl.stereo {

  type pulse

  card 0

  }





pcm.multi {

  type multi

  slaves.a.pcm "analog-hw"

  slaves.a.channels 2

  slaves.b.pcm "digital-hw"

  slaves.b.channels 2

  bindings.0.slave a

  bindings.0.channel 0

  bindings.1.slave a

  bindings.1.channel 1

  bindings.2.slave b

  bindings.2.channel 0

  bindings.3.slave b

  bindings.3.channel 1

  }

 

 ctl.multi {

  type hw

  card 0

  }



I really do not understand this file so don't ask. This configuration file also allows output from the front stereo jack so I can have both the 5.1ch headphones on SPDIF and an additional stereo headphone working simultaneously.

Starting the server
Let us start the pulseaudio server so we can test some applications:


1 pulseaudio –system=1 –high-priority=1 -D



The recomended way to start the pulseaudio system is per user/session so instead of editing the /etc/default/pulseaudio file I simply create a pulsestart.sh script and put it in our KDE Autostart dir (i.e. $HOME/.kde4/Autostart).


1 !#/bin/bash

2 pulseaudio –system=1 –high-priority=1 -D



This way everytime I start KDE the pulseaudio server gets started too. Now with the server running we need to tell our applications to use it instead of directly accessing alsa.

Pulse audio with Amarok in Kubuntu (Hardy Heron 8.04)
This one is the easiest as it has a configuration panel that allows you to choose the output plugin. See screenshot:


Pulse audio with MPlayer in Kubuntu (Hardy Heron 8.04)

MPlayer in Kubuntu Hardy Heron comes by default with pulseaudio support and in fact uses it as default. If it is not default then you can also force mplayer to use pulse audio with the -ao pulse switch. One way to check if mplayer is really using pulseaudio is to run mplayer from command line and look for a line that looks like AO: [pulse] 48000Hz 2ch s16le (2 bytes per sample). If instead you see alsa or anything else between the square brackets then something is wrong with your installation.

Pulse audio with SDL applications in Kubuntu (Hardy Heron 8.04)

Most games in Linux (i.e. Urban Terror) use SDL audio so we must ensure all SDL applications use the pulseaudio server. When you install the pulseaudio packages this should be done automatically but one bug was preventing the dependency manager to install the needed package: libsdl1.2debian-pulseaudio with:

sudo aptitude install libsdl1.2debian-pulseaudio

Installing this package will enable SDL applications to use the pulseaudio server. We can check this by running a game like Urban Terror and looking at the console. We should see something like:

------ Initializing Sound ------
Initializing SDL audio driver...
SDL audio driver is "pulse".
SDL_AudioSpec:
Format: AUDIO_S16LSB
Freq: 22050
Samples: 1024
Channels: 2
Starting SDL audio callback...
SDL audio initialized.

Pay attention to the SDL audio driver and see what it says. If it says alsa or anything different from pulse then you are not using pulse audio.

Pulse audio with Flash player in Kubuntu (Hardy Heron 8.04)

This one is a little more complicated as we need to install an experimental library but not that complicated and it worked flawlessly in Konqueror and Firefox. Simply follow the next steps:


1 sudo aptitude install  build-essential automake1.9 autoconf libtool libesd0-dev libpulse-dev libssl-dev

2 git-clone http://git.0pointer.de/repos/libflashsupport.git/ libflashsupport

3 cd libflashsupport

4 ./bootstrap.sh

5 make

6 sudo make install



What we are doing here is installing some dependencies, downloading the source code of the library from a Git repository, compiling, installing and that is it. Now we have pulse audio support in flash.

The only way I can test that flash is really using the pulseaudio server is to play a flash video and at the same time play music in amarok. If flash is using pulseaudio then you should be able to hear both the flash audio and amarok music simultaneously. If flash is not using pulse audio then the flash video will have no sound or amarok will not play any audio.

Pulse audio with AC3/DTS pass thru in Kubuntu (Hardy Heron 8.04)
Ok so not everything is perfect and pulseaudio does not solves all my desires. The whole idea of the digital ouput (SPDIF) is to be able to send raw AC3 sound to my headphones receivers. This offers the best quality since these headphones have a hardware AC3 decoder so I can get full 5.1 channel surround sound out of them. The problem is that pulseaudio is not able to pass thru the AC3/DTS streams to the SPDIF output.

The solution is to use alsa in this case with the mplayer hwac3 switch like:

mplayer -ac hwac3

that works perfect and there is no need to stop the pulseaudio server. The only inconvenient is that you cannot use any other sound application while the AC3 audio is playing. This is because during the time the AC3 audio is playing alsa is taking control of the sound card and all other applications that rely now in pulseaudio cannot get access to the card.

In my case is not really that big of a problem because when I am seeing a DVD I do not want to hear any other sounds from my PC like knotify.


References
http://pulseaudio.org/wiki/PerfectSetup
http://forums.debian.net/viewtopic.php?t=12497
http://ubuntuforums.org/showthread.php?t=714712

[get this widget]

Thursday, April 17, 2008

Plotting SVN history??

0 comments

Found a blog post by Samuel Jansen were he plots his subversion repository history so out of curiosity I plotted mine too...

actually nothing interesting, steady development almost linear and as you can see but it made me notice that I am almost near my 1000 mark!! when I reach it then I will have an excuse to celebrate and give a nice "1000 SVN passed mark present".

[get this widget]

Sunday, April 13, 2008

Linux Cafe in Akihabara

1 comments

Have been in Akihabara (Electric Town) several times but never saw this shop before:





If you read the details below the logo you will see this shop is been there since 2001!! and I never saw it... I must go check my eyes. Anyway if you are an Open Source person walking around Akihabara you may well pass a get yourself a nice cup of open source coffee.



[get this widget]

Wednesday, April 09, 2008

Simple Mail Server (Kubuntu)

0 comments

If you need a small personal mail server to send log reports and system alarms from your Kubuntu machines to a local and/or external mail address then you may use Exim4 that is the default mail server (MTA) that comes with (K)Ubuntu.

To install is very easy:



1 sudo aptitude install exim4 exim4-base



and to configure simply run:


1 sudo dpkg-reconfigure exim4-config



and in the first dialog (image below) select "internet site". For all next options I used the defaults that would allow local users and services to send emails locally and to remote addresses (i.e. gmail accounts).


Now to test the new server you can send a simple email to your Gmail account:


1 mail -s test mygmail@gmail.com

2 test mail

3 .

4 Cc:



The "-s" switch is the mail subject. After the command simply type whatever you want in the mail body. To finish the email press followed by a dot "." and then again. After this you will be prompted with "Cc:" so press and then check your Gmail account. You should have received an email with the message and subject you used above.

Now say you want to receive LogWatch reports or any other mail directed to root in your Gmail account. Then you can simply create an alias in the "/etc/aliases" file like:


1 # Added by installer for initial user

2 root:   mygmail@gmail.com



then rebuild the aliases database


1 sudo newaliases



If you require more complex mail configurations you may check my previous posts about Sendmail and Postfix setup in (K)Ubuntu here.

[get this widget]

Friday, April 04, 2008

Get latest ffmpeg (svn) in FreeBSD-7.0

0 comments

If you want to compile the latest ffmpeg from subversion with some external libraries support like x264, faac, Theora and Vorbis in the latest FreeBSD release (7.0) then follow this simple steps:

If you do not have the ports tree installed (i.e. /usr/ports is empty or non existent) then you can use portsnap to download and update it (these commands must be done as root):



1 pkg_add -r portsnap

2 mkdir /usr/ports

3 portsnap fetch

4 portsnap extract

5 portsnap update



Install some ports to enable more funcionality in ffmpeg (these commands also must be done as root):


 1 # faac support

 2 cd /usr/ports/audio/faac

 3 make install clean

 4

 5 # vorbis support

 6 cd /usr/ports/audio/vorbis-tools

 7 make install clean

 8

 9 # x264 support

10 cd /usr/ports/multimedia/x264

11 make install clean

12

13 # theora support

14 cd /usr/ports/multimedia/libtheora

15 make install clean

16

17 # ffplay support

18 cd /usr/ports/deve/sdl12

19 make install clean



Checkout ffmpeg from subversion, configure, compile and install (only the last command needs root priviledges);


 1 # checkout ffmpeg from subversion

 2 svn co svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg

 3 cd ffmpeg

 4

 5 # export library and include paths

 6 # so configure can find the external

 7 # libraries (i.e. x264)

 8 export LIBRARY_PATH=/usr/local/lib

 9 export CPATH=/usr/local/include

10

11 # run configure with desired options

12 ./configure --enable-gpl --enable-pthreads \

13  --enable-shared --enable-swscale  \

14  --enable-libx264 --enable-libfaac \

15  --enable-libtheora --enable-libvorbis \

16  --enable-encoder=g726 --enable-encoder=ljpeg \

17  --enable-encoder=mjpeg

18

19 # compile using GNU Make (gmake), not BSD Make

20 gmake

21

22 # install

23 su root -c 'gmake install'



If you want to enable other external codec libraries supported by ffmpeg make sure to install their respective ports (if available) and then run the configure script with the desired libraries enabled. You can see a list of supported codec libraries with ".configure --help".

Note that this instructions were tested with revision 12684 of ffmpeg subverion but ffmpeg is a very active project and this instructions are not guarantee to work with the latest subversion revision.

[get this widget]

Thursday, April 03, 2008

Japanese Input in KDE 4.0.3 (Anthy)

2 comments

So you want to try the newest and greatest KDE 4.0.3 release but you can't because you need to be able to write other languages other than English like in my case Japanese, Chinese and/or Korean??

After googling I found here that there is a scim input method that allows input of these languages in KDE4 and also fixes some problems with proprietary software like Skype, Adobe Reader, etc.

This input method is called scim-bridge and can be easily installed in Kubuntu with the command:


sudo aptitude install scim-bridge-agent scim-bridge-client-qt4 scim-bridge-client-qt scim-bridge-client-gtk

Then to enable scim-bridge as your input method you can use im-switch:

im-switch -s scim-bridge

or if you do not have im-switch then you can do it manually with:

sudo ln -sf /etc/alternatives/xinput-all_ALL /etc/X11/xinit/xinput.d/scim-bridge


Seems that scim-bridge is now the default input method in Ubuntu/Kubuntu but not sure, see resources below to get more detailed explanation on how to setup SCIM in Ubuntu.

https://help.ubuntu.com/community/SCIM
https://help.ubuntu.com/community/SCIM/Kubuntu
https://wiki.ubuntu.com/InputMethods/SCIM/Setup

[get this widget]