2009-10-17, 21:23
PART 1 SETTING UP ALSA
INTRODUCTION
Note: The part of guide with native alsa setup is mostly for dedicated htpc users who don't use Ubuntu as an everyday desktop (like XbmcBuntu or minimal setup).
With the Pulseaudio setup guide which i add later will be suitable for ubuntu normal desktop setup.
Requirements:
- You need to have Nvidia hdmi audio integrated codec on your motherboard. Like the IONs or 9300 9400 integrated motherboard chipsets.
- You need Ubuntu Jaunty (or Karmic)
- You need the Nvidia drivers 185 series. IMPORTANT: the 190 series driver breaks lpcm hdmi output totally or partially
- At last both not least, you must have a HDMI 1.1 compatibe HDMI AV receiver (Like Onkyo TX-SR605 what i have) connected with hdmi cable
- I will try to update this guide to work with the newest Nvidia graphic cards G210, GT220
- UPDATE 19.10.2009 I got somewhere supporting these cards, just check my Post #30
Update 21.10.2009
Xbmc developers are currently working on a brand new sound rendering system called "master audio". Tha branch has not been updated for a while but it will be continued and might reach mainline in the far future. That could be a solution which utilize the good things in Alsa and also Pulseaudio. That will change the game for sure, but until than this is what we have.
Why HDMI audio over the good old well working SPDIF.
SPDIF connection, either optical or coaxial is bandwidth limited. This means you can only achieve 2 channel UNCOMPRESSED lpcm audio up to (96khz, 24bits in the best case) or with AC3 or DTS LOSSY codecs you can have 5.1 multichannel audio with 48khz, 16bits. So at the best case you can only have Lossy multichannel and only in limited bitrates.
HDMI connection can handle 7.1 multichannel UNCOMPRESSED audio up to 192khhz, 24bits or can bitstream DTS-HD, DOLBY TRUEHD LOSSLESS formats to your AV receiver, if it supports those formats.
There is a great detailed explanation about formats here:
http://www.highdefdigest.com/news/show/1064
So why do i need HDMI over SPDIF now ?
It is true that the available HD multichannel material is limited yet. Mostly to Blu-ray movies and HD DVD-Audio or SACD music.
But there are also the codecs which can not be bitstreamed over SPDIF nor HDMI. These are Apple's multichannel AAC used by .MOV formats, or multichannel HD or SD FLAC music or video sound, WMA HD or SD multichannel material etc. The only way you can enjoy these formats is to decode them to uncompressed LPCM and send them over HDMI.
So there are already a lot of reasons why you want HDMI over SPDIF. And i haven't spoken about the fact that this way you only need one cable for all your 8 channel audio and the FULL HD quality Video signal. If you already using hdmi connection with your audio than this is a must for you as current alsa drivers only support 48khz/16bits with horrible quality CD playback.
What this guide can provide:
- 7.1 multichannel LPCM connection up to 192khz/24bits on nvidia hardware.
- DTS, AC3 bitstreaming over HDMI
- working navigation sounds
- playback of sound on it's original bitrate UNTOUCHED without any upmixing/downmixing to achieve the best possible quality with native ALSA configuration or
- high quality mixing with operation-system sounds on HD bitrates up to 192khz/24bits with pulseaudio configuration (Maybe i add this part a little later)
Just a note that if you use pulseaudio or even with alsa dmix module or default alsa device, your sound is always up/downsampled to a certain bitrate. This could cause serious quality drops even if alsa converts the sound to the same bitrate.
Here are some test results where you can see that only a decent sample rate converter can get close to the original sound. Those SRC-s use a lot of CPU time. The best is to have the native sound untouched, unmixed, unmodified.
You can view further results with a whole bunch of sampler types here:
http://src.infinitewave.ca/
What's not working and what are some side effects.
- DTS-HS, DOLBY-TRUEHD bitstreaming is not working due to hardware and software limitations.
- We will have to update alsa and compile a custom kernel module (this will change in the future as the patches will be applied in the newer kernels, but only at the best case in Ubuntu 10.04) what means that every time you let ubuntu update your working kernel, you will need to make a little additional work to get things up and working again, or you just don't let ubuntu update the kernel.
- In any case you can easily revert the modifications to get back your original setup.
I was in contact with an Nvidia developer We Ni and a great Alsa developer Takashi Iwai to help them testing things out. I should thank them all this great stuff, letting the drivers be ready for HD audio. All credits go to them.
The patched file what we will use (patch_nvhdmi.c) finally went into the kernel tree in the past days so with the next Alsa release and possibly next kernel releases will already include the most important parts.
http://git.alsa-project.org/?p=alsa-kern...4b;hb=HEAD
LET'S DO IT:
We will use the famous Ubuntu Alsa upgrade script which i modified to patch the source to enable all bitrates and channel configurations.
Ths script updates your system to the latest packages. To make things safer i suggest doing this step before running the script to see if everything went ok.
Note that updating your system could install a new kernel over your existing one. In this case your custom kernel modules have to be recompiled. For example if your nvidia driver was not installed from ppa, you will have to recompile the nvidia kernel module with the driver installer, or the better use nvidia ppa for installing the dkms auto update module and you wont'have any problems with updates anymore.
https://launchpad.net/~nvidia-vdpau/+archive/ppa
So let's update
Ater reboot and everything back to normal let's get a needed package which we use (dos2unix) so that we will be able to use bash scripts downloaded from pastebin.com
We will add the current user to the audio group. That is sometimes needed.
Let's get my modified Alsa upgrade script, make it executable, clean from carriage returns:
I have put two more run options to the script
-p patches the downloaded source
-dpi downloads, applies patch, compiles, installs everything in one step
Now we are going to do everything in one step, but alternatively you can run the sript with -d than -p than -i options to make it in 3 steps.
Press "1" when prompted !
Take a break now as this can last for 10-15 minutes. You can follow the process as it is described by the script's text output.
We can clean the unnecessary files now, except from the alsa-driver source. We will need that later if we want to make a kernel upgrade. After it is finished just reboot:
Now it is time for you to decide if you go the native ALSA way or you go in the PULSEAUDIO way.
ALSA pros:
- Native untouched crystal clear sound whatever format the sound has it goes directly to receiver
- no time delay in playback
ALSA cons:
- No software mixing: this is bad if you use Ubntu as a desktop with other apps running, or if you want xbmc music played with crossfade support
PULSEAUDIO pros:
- Software mixing possible with other apps, system sounds
- xbmc crossfade support
- The sounds are played all in a certain bitrate no matter what soundformat you play. This means you don't hear "clicks" from your receiver changing formats all the time.
PULSEAUDIO cons:
- The sounds are played all in a certain bitrate no matter what soundformat you play, this means it alway down/upmixes sounds which depending on the resampler we use, could result a bit of quality drop.
- There is a slight delay in navigation sounds
INTRODUCTION
Note: The part of guide with native alsa setup is mostly for dedicated htpc users who don't use Ubuntu as an everyday desktop (like XbmcBuntu or minimal setup).
With the Pulseaudio setup guide which i add later will be suitable for ubuntu normal desktop setup.
Requirements:
- You need to have Nvidia hdmi audio integrated codec on your motherboard. Like the IONs or 9300 9400 integrated motherboard chipsets.
- You need Ubuntu Jaunty (or Karmic)
- You need the Nvidia drivers 185 series. IMPORTANT: the 190 series driver breaks lpcm hdmi output totally or partially
- At last both not least, you must have a HDMI 1.1 compatibe HDMI AV receiver (Like Onkyo TX-SR605 what i have) connected with hdmi cable
- I will try to update this guide to work with the newest Nvidia graphic cards G210, GT220
- UPDATE 19.10.2009 I got somewhere supporting these cards, just check my Post #30
Update 21.10.2009
Xbmc developers are currently working on a brand new sound rendering system called "master audio". Tha branch has not been updated for a while but it will be continued and might reach mainline in the far future. That could be a solution which utilize the good things in Alsa and also Pulseaudio. That will change the game for sure, but until than this is what we have.
Why HDMI audio over the good old well working SPDIF.
SPDIF connection, either optical or coaxial is bandwidth limited. This means you can only achieve 2 channel UNCOMPRESSED lpcm audio up to (96khz, 24bits in the best case) or with AC3 or DTS LOSSY codecs you can have 5.1 multichannel audio with 48khz, 16bits. So at the best case you can only have Lossy multichannel and only in limited bitrates.
HDMI connection can handle 7.1 multichannel UNCOMPRESSED audio up to 192khhz, 24bits or can bitstream DTS-HD, DOLBY TRUEHD LOSSLESS formats to your AV receiver, if it supports those formats.
There is a great detailed explanation about formats here:
http://www.highdefdigest.com/news/show/1064
So why do i need HDMI over SPDIF now ?
It is true that the available HD multichannel material is limited yet. Mostly to Blu-ray movies and HD DVD-Audio or SACD music.
But there are also the codecs which can not be bitstreamed over SPDIF nor HDMI. These are Apple's multichannel AAC used by .MOV formats, or multichannel HD or SD FLAC music or video sound, WMA HD or SD multichannel material etc. The only way you can enjoy these formats is to decode them to uncompressed LPCM and send them over HDMI.
So there are already a lot of reasons why you want HDMI over SPDIF. And i haven't spoken about the fact that this way you only need one cable for all your 8 channel audio and the FULL HD quality Video signal. If you already using hdmi connection with your audio than this is a must for you as current alsa drivers only support 48khz/16bits with horrible quality CD playback.
What this guide can provide:
- 7.1 multichannel LPCM connection up to 192khz/24bits on nvidia hardware.
- DTS, AC3 bitstreaming over HDMI
- working navigation sounds
- playback of sound on it's original bitrate UNTOUCHED without any upmixing/downmixing to achieve the best possible quality with native ALSA configuration or
- high quality mixing with operation-system sounds on HD bitrates up to 192khz/24bits with pulseaudio configuration (Maybe i add this part a little later)
Just a note that if you use pulseaudio or even with alsa dmix module or default alsa device, your sound is always up/downsampled to a certain bitrate. This could cause serious quality drops even if alsa converts the sound to the same bitrate.
Here are some test results where you can see that only a decent sample rate converter can get close to the original sound. Those SRC-s use a lot of CPU time. The best is to have the native sound untouched, unmixed, unmodified.
You can view further results with a whole bunch of sampler types here:
http://src.infinitewave.ca/
What's not working and what are some side effects.
- DTS-HS, DOLBY-TRUEHD bitstreaming is not working due to hardware and software limitations.
- We will have to update alsa and compile a custom kernel module (this will change in the future as the patches will be applied in the newer kernels, but only at the best case in Ubuntu 10.04) what means that every time you let ubuntu update your working kernel, you will need to make a little additional work to get things up and working again, or you just don't let ubuntu update the kernel.
- In any case you can easily revert the modifications to get back your original setup.
I was in contact with an Nvidia developer We Ni and a great Alsa developer Takashi Iwai to help them testing things out. I should thank them all this great stuff, letting the drivers be ready for HD audio. All credits go to them.
The patched file what we will use (patch_nvhdmi.c) finally went into the kernel tree in the past days so with the next Alsa release and possibly next kernel releases will already include the most important parts.
http://git.alsa-project.org/?p=alsa-kern...4b;hb=HEAD
LET'S DO IT:
We will use the famous Ubuntu Alsa upgrade script which i modified to patch the source to enable all bitrates and channel configurations.
Ths script updates your system to the latest packages. To make things safer i suggest doing this step before running the script to see if everything went ok.
Note that updating your system could install a new kernel over your existing one. In this case your custom kernel modules have to be recompiled. For example if your nvidia driver was not installed from ppa, you will have to recompile the nvidia kernel module with the driver installer, or the better use nvidia ppa for installing the dkms auto update module and you wont'have any problems with updates anymore.
https://launchpad.net/~nvidia-vdpau/+archive/ppa
So let's update
Code:
sudo apt-get update && sudo apt-get upgrade -y
sudo reboot
Ater reboot and everything back to normal let's get a needed package which we use (dos2unix) so that we will be able to use bash scripts downloaded from pastebin.com
Code:
sudo apt-get install tofrodos
We will add the current user to the audio group. That is sometimes needed.
Code:
sudo adduser `who | awk '{print $1}'` audio
Let's get my modified Alsa upgrade script, make it executable, clean from carriage returns:
Code:
cd ~
wget http://pastebin.com/pastebin.php?dl=f29c37574 -O Alsa_upgrade-1.0.21_hd.sh
sudo chmod a+x Alsa_upgrade-1.0.21_hd.sh
dos2unix Alsa_upgrade-1.0.21_hd.sh
I have put two more run options to the script
-p patches the downloaded source
-dpi downloads, applies patch, compiles, installs everything in one step
Now we are going to do everything in one step, but alternatively you can run the sript with -d than -p than -i options to make it in 3 steps.
Code:
sudo ./Alsa_upgrade-1.0.21_hd.sh -dpi
Press "1" when prompted !
Take a break now as this can last for 10-15 minutes. You can follow the process as it is described by the script's text output.
We can clean the unnecessary files now, except from the alsa-driver source. We will need that later if we want to make a kernel upgrade. After it is finished just reboot:
Code:
cd /usr/src/Alsa*
sudo rm -rf alsa-l* alsa-p* alsa-u* alsa-f* alsa-t* alsa-o*
sudo reboot
Now it is time for you to decide if you go the native ALSA way or you go in the PULSEAUDIO way.
ALSA pros:
- Native untouched crystal clear sound whatever format the sound has it goes directly to receiver
- no time delay in playback
ALSA cons:
- No software mixing: this is bad if you use Ubntu as a desktop with other apps running, or if you want xbmc music played with crossfade support
PULSEAUDIO pros:
- Software mixing possible with other apps, system sounds
- xbmc crossfade support
- The sounds are played all in a certain bitrate no matter what soundformat you play. This means you don't hear "clicks" from your receiver changing formats all the time.
PULSEAUDIO cons:
- The sounds are played all in a certain bitrate no matter what soundformat you play, this means it alway down/upmixes sounds which depending on the resampler we use, could result a bit of quality drop.
- There is a slight delay in navigation sounds