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-05-13 02:34:40 (GMT)
commit8dd67eb80e2d8d79de1ec675dd2b535da45e0ff1 (patch)
treefe41f628b12a28aa9488770fcb0a7521b5b2e632
parent8119784308f9d56875a050a2d4b6e9d600d3fce3 (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!). [backport SHA:a79e8179a940c4fae0b952e57c09a277ab2fddc9]
-rw-r--r--mythtv/libs/libmyth/audiooutputca.cpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/mythtv/libs/libmyth/audiooutputca.cpp b/mythtv/libs/libmyth/audiooutputca.cpp
index 904b94c..a548af6 100644
--- a/mythtv/libs/libmyth/audiooutputca.cpp
+++ b/mythtv/libs/libmyth/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()
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,
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());