Skip to content

Commit

Permalink
ALSA: allow driver to increase number of channels, fixes playback of 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FernetMenta committed Dec 14, 2013
1 parent 3f46335 commit 705e102
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp
Expand Up @@ -99,7 +99,7 @@ CAESinkALSA::~CAESinkALSA()
Deinitialize();
}

inline CAEChannelInfo CAESinkALSA::GetChannelLayout(AEAudioFormat format, unsigned int maxChannels)
inline CAEChannelInfo CAESinkALSA::GetChannelLayout(AEAudioFormat format, unsigned int minChannels, unsigned int maxChannels)
{
enum AEChannel* channelMap = ALSAChannelMap;
unsigned int count = 0;
Expand Down Expand Up @@ -131,16 +131,22 @@ inline CAEChannelInfo CAESinkALSA::GetChannelLayout(AEAudioFormat format, unsign
channelMap = ALSAChannelMap71Wide;
}
for (unsigned int c = 0; c < 8; ++c)
{
for (unsigned int i = 0; i < format.m_channelLayout.Count(); ++i)
{
if (format.m_channelLayout[i] == channelMap[c])
{
count = c + 1;
break;
}
}
}
count = std::max(count, minChannels);
}

CAEChannelInfo info;
for (unsigned int i = 0; i < count && i < maxChannels+1; ++i)
count = std::min(count, maxChannels);
for (unsigned int i = 0; i < count; ++i)
info += channelMap[i];

CLog::Log(LOGDEBUG, "CAESinkALSA::GetChannelLayout - Input Channel Count: %d Output Channel Count: %d", format.m_channelLayout.Count(), count);
Expand Down Expand Up @@ -171,7 +177,7 @@ void CAESinkALSA::GetAESParams(AEAudioFormat format, std::string& params)

bool CAESinkALSA::Initialize(AEAudioFormat &format, std::string &device)
{
CAEChannelInfo channelLayout = GetChannelLayout(format, 8);
CAEChannelInfo channelLayout = GetChannelLayout(format, 2, 8);
m_initDevice = device;
m_initFormat = format;
ALSAConfig inconfig, outconfig;
Expand Down Expand Up @@ -246,7 +252,7 @@ bool CAESinkALSA::Initialize(AEAudioFormat &format, std::string &device)
return false;
}
// adjust format to the configuration we got
format.m_channelLayout = GetChannelLayout(format, outconfig.channels);
format.m_channelLayout = GetChannelLayout(format, outconfig.channels, outconfig.channels);
format.m_sampleRate = outconfig.sampleRate;
format.m_frames = outconfig.periodSize;
format.m_frameSize = outconfig.frameSize;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/cores/AudioEngine/Sinks/AESinkALSA.h
Expand Up @@ -52,7 +52,7 @@ class CAESinkALSA : public IAESink

static void EnumerateDevicesEx(AEDeviceInfoList &list, bool force = false);
private:
CAEChannelInfo GetChannelLayout(AEAudioFormat format, unsigned int maxChannels);
CAEChannelInfo GetChannelLayout(AEAudioFormat format, unsigned int minChannels, unsigned int maxChannels);
void GetAESParams(const AEAudioFormat format, std::string& params);
void HandleError(const char* name, int err);

Expand Down

0 comments on commit 705e102

Please sign in to comment.