summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Yves Avenard <jyavenard@mythtv.org>2011-03-02 13:01:43 (GMT)
committer Jean-Yves Avenard <jyavenard@mythtv.org>2011-03-02 13:01:43 (GMT)
commita79e8179a940c4fae0b952e57c09a277ab2fddc9 (patch)
tree33b8402f28d40ad8f35b9b70cf7035d0fb02acea
parent6b7ea3149b3a6b61461b12ac0d1a9bac5ebed408 (diff)
Fix 7.1 channel order in CoreAudio (mac).
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!).
-rw-r--r--mythtv/libs/libmyth/audio/audiooutputca.cpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/mythtv/libs/libmyth/audio/audiooutputca.cpp b/mythtv/libs/libmyth/audio/audiooutputca.cpp
index d6b924e..a48c31e 100644
--- a/mythtv/libs/libmyth/audio/audiooutputca.cpp
+++ b/mythtv/libs/libmyth/audio/audiooutputca.cpp
@@ -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>
@@ -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
@@ -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);
}
@@ -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)
@@ -357,6 +395,12 @@ bool AudioOutputCA::RenderAudio(unsigned char *aubuf,
memset(aubuf + written_size, 0, 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());