From 813e6f31c8006190615cbf8ab031db2362bcf553 Mon Sep 17 00:00:00 2001
From: Alex Deryskyba <alex@codesnake.com>
Date: Fri, 19 Sep 2014 01:55:12 +0300
Subject: [PATCH] [aml] Change the sample rates that are supported by ALSA but
 unsupported by HDMI to the closest supported value

---
 xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp b/xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp
index 6bf2c53..32ab888 100644
--- a/xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp
+++ b/xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp
@@ -673,6 +673,26 @@ bool CAESinkALSA::InitializeHW(const ALSAConfig &inconfig, ALSAConfig &outconfig
   snd_pcm_hw_params_set_access(m_pcm, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
 
   unsigned int sampleRate   = inconfig.sampleRate;
+#ifdef HAS_LIBAMCODEC
+  // Change the sample rates that are supported by ALSA but unsupported by HDMI to the closest supported value
+  switch (sampleRate)
+  {
+  case 5512:
+  case 8000:
+  case 11025:
+  case 16000:
+  case 22050:
+    sampleRate = 44100;
+    break;
+  case 64000:
+    sampleRate = 88200;
+    break;
+  case 384000:
+    sampleRate = 192000;
+    break;
+  }
+#endif
+
   snd_pcm_hw_params_set_rate_near    (m_pcm, hw_params, &sampleRate, NULL);
 
   unsigned int channelCount = inconfig.channels;
