{"id":367,"date":"2013-04-13T15:58:30","date_gmt":"2013-04-13T22:58:30","guid":{"rendered":"http:\/\/10.43.101.63:24469\/?p=367"},"modified":"2017-02-21T00:57:29","modified_gmt":"2017-02-21T08:57:29","slug":"lossless-hd-audio-over-hdmi-with-pulseaudio-under-linux","status":"publish","type":"post","link":"https:\/\/aarontc.com\/archive\/2013\/04\/lossless-hd-audio-over-hdmi-with-pulseaudio-under-linux\/","title":{"rendered":"Lossless HD Audio over HDMI with PulseAudio under Linux"},"content":{"rendered":"
Today I finally managed to get lossless HD audio working from my Linux media PC over HDMI! I’ll probably update this post as time goes, but for now it’s a quick recipe of what I did:<\/p>\n
Video cards present HDMI audio interfaces in an interesting way. There appears to be one audio device per digital display connector on the GPU (yes, you really can transport audio over a DVI connector!). For some reason, sending audio to any of the output devices on the GPU will work – although you only get two channels unless you select the correct device! I suspect this is related to buffer sharing amongst the output devices, but I digress…<\/p>\n
To find the correct output device, run a few iterations of <\/p>\n
speaker-test -c8 -twav -D[hdmi:CARD=NVidia,DEV=3]<\/pre>\nreplacing the part in square brackets with an available output as shown by <\/p>\n
aplay -L<\/pre>\n<\/p>\nHere’s a sample of what the aplay output looks like on my system:<\/p>\n
\nmedia@ro ~ $ aplay -L\r\nnull\r\n Discard all samples (playback) or generate zero samples (capture)\r\npulse\r\n PulseAudio Sound Server\r\nsysdefault:CARD=PCH\r\n HDA Intel PCH, ALC892 Analog\r\n Default Audio Device\r\nfront:CARD=PCH,DEV=0\r\n HDA Intel PCH, ALC892 Analog\r\n Front speakers\r\nsurround40:CARD=PCH,DEV=0\r\n HDA Intel PCH, ALC892 Analog\r\n 4.0 Surround output to Front and Rear speakers\r\nsurround41:CARD=PCH,DEV=0\r\n HDA Intel PCH, ALC892 Analog\r\n 4.1 Surround output to Front, Rear and Subwoofer speakers\r\nsurround50:CARD=PCH,DEV=0\r\n HDA Intel PCH, ALC892 Analog\r\n 5.0 Surround output to Front, Center and Rear speakers\r\nsurround51:CARD=PCH,DEV=0\r\n HDA Intel PCH, ALC892 Analog\r\n 5.1 Surround output to Front, Center, Rear and Subwoofer speakers\r\nsurround71:CARD=PCH,DEV=0\r\n HDA Intel PCH, ALC892 Analog\r\n 7.1 Surround output to Front, Center, Side, Rear and Woofer speakers\r\niec958:CARD=PCH,DEV=0\r\n HDA Intel PCH, ALC892 Digital\r\n IEC958 (S\/PDIF) Digital Audio Output\r\nsysdefault:CARD=pcsp\r\n pcsp, pcsp\r\n Default Audio Device\r\nfront:CARD=pcsp,DEV=0\r\n pcsp, pcsp\r\n Front speakers\r\nhdmi:CARD=NVidia,DEV=0\r\n HDA NVidia, HDMI 0\r\n HDMI Audio Output\r\nhdmi:CARD=NVidia,DEV=1\r\n HDA NVidia, HDMI 1\r\n HDMI Audio Output\r\nhdmi:CARD=NVidia,DEV=2\r\n HDA NVidia, HDMI 2\r\n HDMI Audio Output\r\nhdmi:CARD=NVidia,DEV=3\r\n HDA NVidia, HDMI 3\r\n HDMI Audio Output\r\n<\/pre>\n<\/blockquote>\nTurns out the correct device on my system is hdmi:CARD=NVidia,DEV=3<\/em>. Piece of cake! The hard part is over, right? It is if you’re a PulseAudio guru… which I’m not. After wading around some forums and delving into man pages for a few hours, here’s what I found solved the issue:<\/p>\n
Add this line to \/etc\/pulse\/default.pa<\/strong> to create the new sink:<\/p>\n
load-module module-alsa-sink device=hw:2,7 rate=192000 channels=8 tsched=0 sink_properties=device.description=HDMI sink_name=HDMI channel_map=front-left,front-right,rear-left,rear-right,front-center,lfe,side-left,side-right<\/pre>\nAlso, you’ll want to comment out the lines that automatically load other modules. Find the lines below and insert a pound sign to disable them:<\/p>\n
#load-module module-udev-detect\r\n#load-module module-detect<\/pre>\n<\/p>\nNow that the sink is created, configure output settings and sample rates for any PulseAudio instances!<\/p>\n
Configure PulseAudio Defaults<\/h2>\n
Edit the file \/etc\/pulse\/daemon.conf<\/strong> and add a block like this to the end:<\/p>\n
default-sample-channels = 8\r\ndefault-sample-rate = 192000\r\nenable-remixing = no\r\nenable-lfe-remixing = no\r\nflat-volumes = no\r\nresample-method = src-sinc-best-quality<\/pre>\n<\/p>\nA little explanation is in order – here’s what those parameters do:<\/p>\n
\n
- default-sample-channels<\/em> – Informs PulseAudio clients that they should prefer 8 channel streams. The default is 2, which is rather bland when you’ve got 6 to spare!<\/li>\n
- default-sample-rate<\/em> – Informs PulseAudio clients that they should prefer 192,000kHz sample rate, which sounds spectacular. (Sometimes considered “studio quality”!) Be aware that a lot of audio equipment won’t support this sample rate. If yours doesn’t, try 96000 or 48000 instead.<\/li>\n
- enable-remixing<\/em> – Disables (or enables) up- and down-mixing of source streams. This means that a 2-channel stream would be up-mixed to 7.1 channels, or a 32-channel stream would be down-mixed to 8 channels. I disable this because there is too much bass when a 2-channel signal is duplicated to 7 channels. You should test it both ways to see which you prefer. (I’m hoping a future version of PulseAudio will give more control over this functionality, I’d really like to up-mix post-processed signals with the low end removed to avoid this problem!)<\/li>\n
- enable-lfe-remixing<\/em> – Basically the same as enable-remixing<\/em> but PulseAudio will pull the low end of all played channels and route it to the lfe channel. Essentially useless on any system that has crossover functionality in the DSP. (Of course, this might be useful for analog outputs but who does that anymore?)<\/li>\n
- flat-volumes<\/em> – Causes PulseAudio to adjust the output volume for a particular sink to the highest of all the sources on that sink. I disable this because it’s frustrating for the output volume to change when I don’t expect it.<\/li>\n
- resample-method<\/em> – Selects what method PulseAudio will use to resample sources on playback. The default is probably okay, but I prefer to use the highest quality option for my home theatre application. You can see what methods are available by running pulseaudio –dump-resample-methods<\/strong>.<\/li>\n<\/ul>\n
Enjoy!<\/h2>\n
Now that PulseAudio is configured, you can test the setup by running <\/p>\n
speaker-test -c8 -twav<\/pre>\nAssuming everything is in order, sit back and enjoy! Any application using PulseAudio for output will understand that 8 channels are available and should output properly.<\/p>\n","protected":false},"excerpt":{"rendered":"
Today I finally managed to get lossless HD audio working from my Linux media PC over HDMI! I’ll probably update this post as time goes, but for now it’s a quick recipe of what I did: Configure a PulseAudio ALSA sink to use the HDMI output Video cards present HDMI audio interfaces in an interesting […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[5,4],"tags":[44,39,46,43,56,45,42,41],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6PV8H-5V","jetpack-related-posts":[{"id":335,"url":"https:\/\/aarontc.com\/archive\/2012\/04\/checking-software-raid-arrays-under-linux\/","url_meta":{"origin":367,"position":0},"title":"Checking software RAID arrays under Linux","author":"Aaron","date":"April 30, 2012","format":false,"excerpt":"Mostly as a reminder to myself... it's important to have a cron job that verifies your RAID array integrity on a regular basis. (Once a week is what most hardware RAID controllers seem to use.) This is accomplished with a command such as: echo check > \/sys\/block\/md0\/md\/sync_action Replace md0 with\u2026","rel":"","context":"In "Linux"","block_context":{"text":"Linux","link":"https:\/\/aarontc.com\/archive\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":315,"url":"https:\/\/aarontc.com\/archive\/2011\/12\/linux-is-not-windows\/","url_meta":{"origin":367,"position":1},"title":"Linux is Not Windows","author":"Aaron","date":"December 18, 2011","format":false,"excerpt":"Yesterday, Mark pointed me at the following article, which I feel is quite relevant to most Linux versus Windows debates that go on these days. In particular, the analogies of cars versus motorbikes, and paid support (no community) versus free support (community), seem to do a fantastic job of explaining\u2026","rel":"","context":"In "Linux"","block_context":{"text":"Linux","link":"https:\/\/aarontc.com\/archive\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":17,"url":"https:\/\/aarontc.com\/archive\/2010\/04\/recovering-from-a-multiple-disk-failure-with-linux-software-raid5\/","url_meta":{"origin":367,"position":2},"title":"Recovering from a multiple-disk failure with Linux software RAID5","author":"Aaron","date":"April 28, 2010","format":false,"excerpt":"The scenario is this: I have a system with several external USB hard drives that are part of a RAID5 array. (It's a work in progress, I'm simply out of SATA controllers right now.) The problem is that sometimes (about once per month) two or more of the drives will\u2026","rel":"","context":"In "Linux"","block_context":{"text":"Linux","link":"https:\/\/aarontc.com\/archive\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":233,"url":"https:\/\/aarontc.com\/archive\/2010\/09\/mark-shuttleworth-%c2%bb-blog-archive-%c2%bb-reflections-on-ubuntu-canonical-and-the-march-to-free-software-adoption\/","url_meta":{"origin":367,"position":3},"title":"Mark Shuttleworth \u00bb Blog Archive \u00bb Reflections on Ubuntu, Canonical and the march to free software adoption","author":"Aaron","date":"September 15, 2010","format":false,"excerpt":"Interesting commentary on recent criticism that Ubuntu has received for not contributing to the Linux kernel: Mark Shuttleworth \u00bb Blog Archive \u00bb Reflections on Ubuntu, Canonical and the march to free software adoption.","rel":"","context":"In "Linux"","block_context":{"text":"Linux","link":"https:\/\/aarontc.com\/archive\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":329,"url":"https:\/\/aarontc.com\/archive\/2012\/03\/cool-open-source-games\/","url_meta":{"origin":367,"position":4},"title":"Cool Open Source Games","author":"Aaron","date":"March 15, 2012","format":false,"excerpt":"I was made aware of this article by Chris Haverkate, and I think it deems sharing: Cool Open Source Games You Should Contribute To","rel":"","context":"In "Linux"","block_context":{"text":"Linux","link":"https:\/\/aarontc.com\/archive\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":333,"url":"https:\/\/aarontc.com\/archive\/2012\/03\/14-ways-to-contribute-to-open-source-without-being-a-programming-genius-or-a-rock-star\/","url_meta":{"origin":367,"position":5},"title":"14 Ways to Contribute to Open Source without Being a Programming Genius or a Rock Star","author":"Aaron","date":"March 15, 2012","format":false,"excerpt":"Another useful link I think is worth sharing. If you feel like contributing to Open Source but aren't sure how, this is a great article for getting started: 14 Ways to Contribute to Open Source without Being a Programming Genius or a Rock Star.","rel":"","context":"In "Linux"","block_context":{"text":"Linux","link":"https:\/\/aarontc.com\/archive\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/posts\/367"}],"collection":[{"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/comments?post=367"}],"version-history":[{"count":10,"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/posts\/367\/revisions"}],"predecessor-version":[{"id":608,"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/posts\/367\/revisions\/608"}],"wp:attachment":[{"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/media?parent=367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/categories?post=367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/tags?post=367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}