Add channel count functions for audio masks
audio_channel_count_from_in_mask
audio_channel_count_from_out_mask
Change-Id: Ic519f2c3f85d14acb9526cc8812360fcbd15346d
Signed-off-by: Andy Hung <hunga@google.com>
diff --git a/include/system/audio.h b/include/system/audio.h
index 1b7d81a..2bc35c6 100644
--- a/include/system/audio.h
+++ b/include/system/audio.h
@@ -590,6 +590,22 @@
return false;
}
+/* Returns the number of channels from an input channel mask,
+ * used in the context of audio input or recording.
+ */
+static inline uint32_t audio_channel_count_from_in_mask(audio_channel_mask_t channel)
+{
+ return popcount(channel & AUDIO_CHANNEL_IN_ALL);
+}
+
+/* Returns the number of channels from an output channel mask,
+ * used in the context of audio output or playback.
+ */
+static inline uint32_t audio_channel_count_from_out_mask(audio_channel_mask_t channel)
+{
+ return popcount(channel & AUDIO_CHANNEL_OUT_ALL);
+}
+
/* Derive an output 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,