aboutsummaryrefslogtreecommitdiffstats
path: root/include/system
diff options
context:
space:
mode:
authorJean-Michel Trivi <jmtrivi@google.com>2012-03-02 16:41:35 -0800
committerJean-Michel Trivi <jmtrivi@google.com>2012-03-05 13:59:09 -0800
commit4ab051ab4613f2622dc3f3f0f57bb34d8a40a6a9 (patch)
treefd367b96130dce02d58c665f23927502211f77e0 /include/system
parent0afee8b668d1ff5bae4294108d5e21abfae28d12 (diff)
downloadsystem_core-4ab051ab4613f2622dc3f3f0f57bb34d8a40a6a9.tar.gz
system_core-4ab051ab4613f2622dc3f3f0f57bb34d8a40a6a9.tar.bz2
system_core-4ab051ab4613f2622dc3f3f0f57bb34d8a40a6a9.zip
Add function to derive a channel mask from a channel count
Change-Id: I22523ded9cd8e5283a285a9db21d819bbbc1b6c3
Diffstat (limited to 'include/system')
-rw-r--r--include/system/audio.h36
1 files changed, 35 insertions, 1 deletions
diff --git a/include/system/audio.h b/include/system/audio.h
index 0f19101b..09803196 100644
--- a/include/system/audio.h
+++ b/include/system/audio.h
@@ -250,7 +250,9 @@ typedef enum {
AUDIO_CHANNEL_IN_Z_AXIS |
AUDIO_CHANNEL_IN_VOICE_UPLINK |
AUDIO_CHANNEL_IN_VOICE_DNLINK),
-} audio_channels_t;
+};
+
+typedef uint32_t audio_channel_mask_t;
typedef enum {
AUDIO_MODE_INVALID = -2,
@@ -382,6 +384,38 @@ static inline bool audio_is_output_channel(uint32_t channel)
return false;
}
+/* Derive a channel mask from a channel count.
+ * This is to be used when the content channel mask is unknown. The 1, 2, 4, 5, 6, 7 and 8 channel
+ * cases are mapped to the standard game/home-theater layouts, but note that 4 is mapped to quad,
+ * and not stereo + FC + mono surround. A channel count of 3 is arbitrarily mapped to stereo + FC
+ * for continuity with stereo.
+ * Returns the matching channel mask, or 0 if the number of channels exceeds that of the
+ * configurations for which a default channel mask is defined.
+ */
+static inline audio_channel_mask_t audio_channel_mask_from_count(uint32_t channel_count)
+{
+ switch(channel_count) {
+ case 1:
+ return AUDIO_CHANNEL_OUT_MONO;
+ case 2:
+ return AUDIO_CHANNEL_OUT_STEREO;
+ case 3:
+ return (AUDIO_CHANNEL_OUT_STEREO | AUDIO_CHANNEL_OUT_FRONT_CENTER);
+ case 4: // 4.0
+ return AUDIO_CHANNEL_OUT_QUAD;
+ case 5: // 5.0
+ return (AUDIO_CHANNEL_OUT_QUAD | AUDIO_CHANNEL_OUT_FRONT_CENTER);
+ case 6: // 5.1
+ return AUDIO_CHANNEL_OUT_5POINT1;
+ case 7: // 6.1
+ return (AUDIO_CHANNEL_OUT_5POINT1 | AUDIO_CHANNEL_OUT_BACK_CENTER);
+ case 8:
+ return AUDIO_CHANNEL_OUT_7POINT1;
+ default:
+ return 0;
+ }
+}
+
static inline bool audio_is_valid_format(audio_format_t format)
{
switch (format & AUDIO_FORMAT_MAIN_MASK) {