Skip to content

Commit

Permalink
Fix 7.1 channel order in CoreAudio (mac).
Browse files Browse the repository at this point in the history
To activate 7.1 audio (using either HDMI or DisplayPort); make sure to first launch the Audio MIDI Setup in /Application/Utilities and configure HDMI audio as 8 channels-24 bits (the default is just stereo). It is recommended to disable DTS and AC3 passthrough as it would reset the hdmi audio in two channels mode, which would break future multi-channels playback.
Note that for the time being, E-AC3, TrueHD and DTS-HD MA bitstreaming do NOT work under MacOS. That's until Apple provide the required 192kHz digital sampling rate (the hardware supports it!).

[backport SHA:a79e8179a940c4fae0b952e57c09a277ab2fddc9]
  • Loading branch information
jyavenard committed May 13, 2011
1 parent b736aea commit bea2f62
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion mythtv/libs/libmyth/audiooutputca.cpp
Expand Up @@ -17,7 +17,7 @@
* $Id$
*
* = AUTHORS
* Jeremiah Morris, Andrew Kimpton, Nigel Pearson
* Jeremiah Morris, Andrew Kimpton, Nigel Pearson, Jean-Yves Avenard
*****************************************************************************/

#include <CoreServices/CoreServices.h>
Expand All @@ -31,6 +31,10 @@ using namespace std;
#include "config.h"
#include "SoundTouch.h"

#define LOC QString("CoreAudio: ")
#define LOC_WARN QString("CoreAudio, Warning: ")
#define LOC_ERR QString("CoreAudio, Error: ")

#define CHANNELS_MIN 1
#define CHANNELS_MAX 8

Expand Down Expand Up @@ -266,11 +270,16 @@ AudioOutputSettings* AudioOutputCA::GetOutputSettings(bool /*digital*/)
else
{
for (int i = CHANNELS_MIN; i <= CHANNELS_MAX; i++)
{
if (channels[i])
{
Debug(QString("Support %1 channels").arg(i));
// In case 8 channels are supported but not 6, fake 6
if (i == 8 && !channels[6])
settings->AddSupportedChannels(6);
settings->AddSupportedChannels(i);
}
}
free(channels);
}

Expand Down Expand Up @@ -333,6 +342,35 @@ void AudioOutputCA::CloseDevice()
d->CloseSPDIF();
}

template <class AudioDataType>
static inline void _ReorderSmpteToCA(AudioDataType *buf, uint frames)
{
AudioDataType tmpLS, tmpRS, tmpRLs, tmpRRs, *buf2;
for (uint i = 0; i < frames; i++)
{
buf = buf2 = buf + 4;
tmpRLs = *buf++;
tmpRRs = *buf++;
tmpLS = *buf++;
tmpRS = *buf++;

*buf2++ = tmpLS;
*buf2++ = tmpRS;
*buf2++ = tmpRLs;
*buf2++ = tmpRRs;
}
}

static inline void ReorderSmpteToCA(void *buf, uint frames, AudioFormat format)
{
switch(AudioOutputSettings::FormatToBits(format))
{
case 8: _ReorderSmpteToCA((uchar *)buf, frames); break;
case 16: _ReorderSmpteToCA((short *)buf, frames); break;
default: _ReorderSmpteToCA((int *)buf, frames); break;
}
}

/** Object-oriented part of callback */
bool AudioOutputCA::RenderAudio(unsigned char *aubuf,
int size, unsigned long long timestamp)
Expand All @@ -357,6 +395,12 @@ bool AudioOutputCA::RenderAudio(unsigned char *aubuf,
bzero(aubuf + written_size, size - written_size);
}

//Audio received is in SMPTE channel order, reorder to CA unless passthru
if (!passthru && channels == 8)
{
ReorderSmpteToCA(aubuf, size / output_bytes_per_frame, output_format);
}

/* update audiotime (bufferedBytes is read by GetBufferedOnSoundcard) */
UInt64 nanos = AudioConvertHostTimeToNanos(
timestamp - AudioGetCurrentHostTime());
Expand Down

0 comments on commit bea2f62

Please sign in to comment.