[LINUX] LPCM over HDMI audio resampling questions?
#1
Question 
There is a really good news for Nvidia 8200, 8300, 9300, 9400 integrated motherboard users:

Nvidia started to implement the lossless 8 channel linear pcm over hdmi hd sound for their hardware. There is already a simple patch which applies to Alsa 1.0.20.

With the patched file currently 16bit, 48khz 8channel lossless sound is available, except the channel mapping is wrong and mixed up. With a little modification to the patch i was able to get full 192khz/24bit 6 channel, full hd lossless sound over hdmi cable. To use this feature you need to have an AV receiver with the minimum hdmi 1.0 standard input.

Here is the patch:
http://www.spinics.net/lists/alsa-devel/msg24325.html

Here is me emailing with Nvidia developer about the issues:
http://www.spinics.net/lists/alsa-devel/msg24437.html

I think with this option we are getting closer to get dolby tru-hd and dts master audio movie tracks, along with listening music with 24/96 multichannel format. All we need to have is ffmpeg guys implementing the decode of the new audio standards (maybe they already did, i am not sure) and xbmc to output the decoded high def lpcm without downsample.

By the time i think we can still get a great use of the increased bit/sample and sampling rate. I think xbmc's smoothvideo feature could benefit from this as i think resampling of 48khz audio to 48khz has a lot more quality loss than resampling it to eg. 192khz/24bits.

@Bobo1on1: How is libsamplerate work now in xbmc ? Is it possible to make the resampling to a higher quality sound format ?

How is it with hd audio formats in xbmc. Is it always downsampled to 48khz when i play a movie or an audio file ?


The implementation nvidia made is very cool becasue with it hw:0,3 device shows as a multichannel "analog" device. So it can be used as regular analog hda codec.

If someone wants to try this feature. Here is what i did:
(Note that this process could screw up your installation and make Ubuntu package management wrong with Alsa packages. Also the patch are being developed and changed regulary which would need some maintaining)

This only works for Ubuntu Jaunty and Alsa 1.0.20

Install Alsa 1.0.20 with the famous universal Alsa Upgrade script.

Code:
http://ubuntuforums.org/showthread.php?p=6589810#post6589810

run the script with:

Code:
sudo ./AlsaUpgrade-1.0.x-rev-1.17.sh

Get the patched patch_nvhdmi.c file here:

Code:
http://git.alsa-project.org/?p=alsa-kernel.git;a=blob_plain;f=sound/pci/hda/patch_nvhdmi.c;h=f5792e2eea82dd412dd18f7aca3b6f328027444b

Don't be fooled with the name as it is already patched to enable 8ch lpcm.

Copy the patch_nvhdmi.c file to Alsa source directory downloaded previously by the upgrade script.

Code:
cp ./patch_nvhdmi.c /usr/src/Alsa-1.0.20/alsa-driver-1.0.20/sound/pci/hda/patch_nvhdmi.c

Now compile the kernel modules:

Code:
cd /usr/src/Alsa-1.0.20/alsa-driver-1.0.20/
sudo make clean
sudo make

Copy only the Nvidia kernel module to the overwriting the Ubuntu 1.0.20 kernel module.

Code:
sudo cp pci/hda/snd-hda-codec-nvhdmi.ko /lib/modules/2.6.28-11-generic/kernel/sound/pci/hda/snd-hda-codec-nvhdmi.ko
sudo reboot

After reboot you can test the feature with

Code:
speaker-test -Dhdmi -c6

magically it will start sending multichannel lpcm to your av receiver over hdmi. Note that it is only working if X is loaded. At least you have to start an Xterminal, because the alsa module is not working without the nvidia display kernel module.

I think from now we only need a good .asoundrc file to map the correct channels to the correct place and we can play any type of multichannel format without a bunch of analog cables attached to the receiver. Even multichannel aac tracks or flac tracks are possible this way, without the loss of quality.

Anyone can make the .asoundrc files ? I was thinking of making virtual surround51, surround40 etc devices with correct channel mapping.

Have fun, AlanSmile
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#2
You're suffering a common misconception here. Up sampling does NOT improve quality one bit. If anything it's just a potential point to introduce artifacts. The only legitimate reason to up sample audio is if your hardware doesn't support the lower sample rate (or I suppose to slow the audio down slightly for a/v sync, if you're ok with that sort of thing).

It's good that nvidia is finally getting 8ch LPCM going (this by no means implies lossless, not sure where you picked that up). Maybe we can finally shut the folks with 6+ch ogg, flac, etc up. Smile
Reply
#3
althekiller Wrote:You're suffering a common misconception here. Up sampling does NOT improve quality one bit. If anything it's just a potential point to introduce artifacts. The only legitimate reason to up sample audio is if your hardware doesn't support the lower sample rate (or I suppose to slow the audio down slightly for a/v sync, if you're ok with that sort of thing).

It's good that nvidia is finally getting 8ch LPCM going (this by no means implies lossless, not sure where you picked that up). Maybe we can finally shut the folks with 6+ch ogg, flac, etc up. Smile

Yes Althekiller you are right about upsampling itself does not improve quality, but...
if you HAVE to resample something, like xbmc does with audio if sync to video option is on, than the quality could be a lot better if you resample the lower bitrate material to a higher bitrate format in one step. It is analog what we do with video with high quality upscaling, or this is the reason why mp3 encoders resample 44khz CD material to 48khz while dealing with the sound.

So i am perfectly sure that it makes sense to make the resampling of the audio speed to a higher bitrate format. This is more true on those cases where the speed of the audio playback only has to be changed a few %, like when we upspeed 24fps movie to 25fps. This case we have to stretch the 48khz data grid by 4% to the same grid. If we have this grid more dense (192khz) than we can reproduce the original sound quality better sped up 4%.

this is my oppinion. The real question is that can libsamplerate support this method ?
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#4
Libsamplerate can do it just fine, but upsampling is not implemented right now.
Reply
#5
bobo1on1 Wrote:Libsamplerate can do it just fine, but upsampling is not implemented right now.

@bobo1on1

Thanks for the info. So as it is implemented now, it is resampling everything to 16/48khz or to the same format as the movie is in ?

I think in the future it would be a good idea that if the soundcard supports higher bitrate than the movie sound track's format than xbmc should upsample the sound before resamples it to the needed speed.

I think higher bitrate and bit formats are already an option to every intel hda codec users in analog mode and it will be more users to have this as this new feature is finished to the Nvidia MCP78 and MCP7A chipstes (which ION is also using). Also i read that on Intel G45 chipsets HD LPCM sound is already working for months.

Thanks for the great work Bobo1on1,

Alan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#6
It just resamples to the same rate, this might be changed in the future to allow upsampling, but it doesn't have a very high priority at the moment.
Reply
#7
Thank's for the info !
Keep up the great work ! You made xbmc so much better with smoothvideo !

Alan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#8
well, I just read something about Dolby TruHD and DTS Master Audio and got wet... is that actually related to that stuff, and will it be possible?
OpenElec Standalone --> Asus Chromebox 'Panther' --> Onkyo TX-NR709 --> Sony 55" X85C Android TV (also with Kodi!)
Asus Chromebox EZ Script
Kodi on Sony Bravia Android TVs
Reply
#9
I'm interested in getting 6 channel LPCM over analog (my receiver doesn't have HDMI). Is this possible in XBMC?
Reply
#10
snoxbox Wrote:I'm interested in getting 6 channel LPCM over analog (my receiver doesn't have HDMI). Is this possible in XBMC?

it's not possible period, since LPCM is a digital format. You either output LPCM over HDMI or SPDIF, or you output analog.

I assume you mean is it possible for XBMC to output a file with a 6-ch LPCM (or FLAC) audio track via analog, and the answer is yes
Reply
#11
snoxbox Wrote:I'm interested in getting 6 channel LPCM over analog (my receiver doesn't have HDMI). Is this possible in XBMC?

You can get 6 (or eight) channel audio via analog connection as well. If you have for example Intel HDA codec on your board, all you need to do is connect 3 jack to 2rca cables from the computer to your av receiver. Your av receiver needs to have six channel discrete analog input supported. You can even use HD formats as HDA Codec supports up to 24/192khz.

The difference is just the way we transport audio. In case of lpcm over HDMI we have a completely quality lossless connection, in case of lpcm converted to analog and connected to the receiver, we could have a little quality loss depending on your cable quality, sound card quality, receiver quality etc.

Theortically if you use 6 channel analog connection with 24bits / 192khz sample format, with a HD quality sound track you can still have a lot better audio quality than if you use 16bits/48khz spdif connection with lossy codecs like ac3 or dts. And you can also have multichannel audio in case of other formats than ac3 and dts for example: WMA, FLAC, AAC multichannel formats which you can NOT achieve with normal spdif of 2 channel analog connection.

And YES it is possible in XBMC. If your audio card supports it, you have to set analog output in Audio Hardware settings and uncheck the downsample to 2 channels option.
You can verify if your card is capable of 6 channel discrete output by the following. Open up a terminal and:

aplay -L

This lists the available virtual sound devices. If you see surround51 than you are good to go.
You can also try:

speaker-test -Ddefault -c6

This tests is your cables are plugged in the right places sounding all channels after each other.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#12
alanwww1 Wrote:And YES it is possible in XBMC. If your audio card supports it, you have to set analog output in Audio Hardware settings and uncheck the downsample to 2 channels option.

Great. But is it possible with TrueHD etc.? From what I understand, I'll be better off decoding TrueHD on my htpc, and sending 6 channel audio over analog to my receiver, than if I downsample to DTS or whatever and send it via optical (obviously depending on the quality of the components used). I'd like to know if XBMC can decode TrueHD, or if I'm better off encoding all my Blu-Rays with 6 channel FLAC (which apparently works 'accidentally' in the win builds, according to another thread, not sure about linux).

Just trying to figure out the best possible sound I can get from a blu-ray rip, not using HDMI.


Edit: By the way, it's not that I'm too lazy to try it. I'm waiting for those damn Zotac ION boards to come out here so I can build my htpc. Currently stuck on an xbox. And I'm in the process of converting all my blu-rays now, so I'm trying to work out what to do with the audio streams.
Reply
#13
It is for sure that you need to decode TruHD audio on the PC. At least for now, because there is no hardware capable (allowed) to directly stream these formats over hdmi. But you have 8channel lpcm which now we can use to send the decoded stream directly to the AV receiver without any quality loss.

xbmc can decode whatever ffmpeg can so theoretically it can decode dolby truhd streams, but it is a bit confusing what i read, because it might be that it can only decode it if it is demuxed from the ac3 core.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#14
ffmpeg (should) decode mlp/truehd just fine.
Reply
#15
Okay,

So I have been playing around with this LPCM patch from NVIDIA. As Alan said the channel mapping is a bit mixed up at the moment. I have found a little hack to get around this for the moment. According to the asound.conf file found in /usr/share/xbmc/system/ the correct channel mapping for 5.1 in Linux is:
Channel 0: FL
Channel 1: FR
Channel 2: BL
Channel 3: BR
Channel 4: Center
Channel 5: LFE

After applying this patch and running
Code:
speaker-test -Dhdmi -c6
speaker-test reports that it is sending sound to:
Code:
0 - Front Left
4 - Center
1 - Front Right
3 - Rear Right
2 - Rear Left
5 - LFE

That looks like it should line up with the Linux mapping standard but what it outputs doesn't match up. It actually sounds like this:
Screen output-----------Actual Output through Denon AV Receiver
0 - Front Left -------------------> 0 - Front Left (correct)
4 - Center ----------------------> 2 - Back Left (incorrect)
1 - Front Right ------------------> 1 - Front Right (correct)
3 - Rear Right -------------------> 5 - LFE (incorrect)
2 - Rear Left --------------------> 4 - Center (incorrect)
5 - LFE -------------------------> 3 - Back Right (incorrect)

or in a more simple way to look at it:

0 -> 0
1 -> 1
2 -> 4
3 -> 5
4 -> 2
5 -> 3

Well if you look at the asound.conf file that XBMC uses again (/usr/share/xbmc/system/) you will notice a similar mapping in the ttable under pcm_win51:
Code:
pcm.xbmc_win51 {
  @args.0 SLAVE
  @args.SLAVE {
    type string
    default "default"
  }
  type route
  slave {
    pcm $SLAVE
    channels 6
  }
  ttable {
   [color=red] 0.0= 1
    1.1= 1
    2.4= 1
    3.5= 1
    4.2= 1
    5.3= 1[/color]
  }
}

When I saw this I decided to change the ttable to:
Code:
pcm.xbmc_win51 {
  @args.0 SLAVE
  @args.SLAVE {
    type string
    default "default"
  }
  type route
  slave {
    pcm $SLAVE
    channels 6
  }
  ttable {
    0.0= 1
    1.1= 1
    2.2= 1
    3.3= 1
    4.4= 1
    5.5= 1
  }
}
As to directly map the channels instead of redirecting them. After doing this speaker-test still doesn't work but 5.1 FLAC files in XBMC do! I haven't tested a direct TrueHD stream yet but all of the Blu-Ray/HD-DVD mkv's I've created with TrueHD or Uncompressed tracks re-encoded to FLAC sound great. My 3:10 Yuma MKV that has a 7.1 FLAC track works as well and even shows up as 7.1 on my Denon receiver. My FLAC tracks sound great.
The only problem that I have run into so far was playing back an BluRay MKV I made from a Dave Matthew's Concert. The FLAC track is sampled @ 96kHz (since the TrueHD track is as well) and when I select the FLAC track the video and audio play in slow motion and my receiver reports that it is receiving a 48kHz signal. I'm guessing it has something to do with XBMC resampling the audio to 48kHz from 96kHz Huh
Anyway, try modifying your asound.conf to look like mine and let me know how it goes for you.
Reply

Logout Mark Read Team Forum Stats Members Help
[LINUX] LPCM over HDMI audio resampling questions?0