summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorPaul McLean <pmclean@google.com>2014-07-18 19:27:07 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-07-17 21:15:46 +0000
commit845e78993bde8a14749a5d6b90753249582c6b83 (patch)
treeb674639be403dc47aef2d07dd9d74fc902b07216 /modules
parent8df2feb00d3510c16d98a0675a7df361d3851728 (diff)
parentc2201159bbdfd58ed54e505061825df3ab9f1ef0 (diff)
downloadhardware_libhardware-845e78993bde8a14749a5d6b90753249582c6b83.zip
hardware_libhardware-845e78993bde8a14749a5d6b90753249582c6b83.tar.gz
hardware_libhardware-845e78993bde8a14749a5d6b90753249582c6b83.tar.bz2
Merge "Move channel expansion/contraction functions to audio_utils/channels.h/.c" into lmp-dev
Diffstat (limited to 'modules')
-rw-r--r--modules/usbaudio/Android.mk5
-rw-r--r--modules/usbaudio/audio_hw.c259
2 files changed, 5 insertions, 259 deletions
diff --git a/modules/usbaudio/Android.mk b/modules/usbaudio/Android.mk
index 2af7897..89c498b 100644
--- a/modules/usbaudio/Android.mk
+++ b/modules/usbaudio/Android.mk
@@ -21,8 +21,9 @@ LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := \
audio_hw.c
LOCAL_C_INCLUDES += \
- external/tinyalsa/include
-LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa
+ external/tinyalsa/include \
+ $(call include-path-for, audio-utils)
+LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa libaudioutils
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := -Wno-unused-parameter
diff --git a/modules/usbaudio/audio_hw.c b/modules/usbaudio/audio_hw.c
index 8fbd528..05f0d2b 100644
--- a/modules/usbaudio/audio_hw.c
+++ b/modules/usbaudio/audio_hw.c
@@ -37,6 +37,8 @@
#include <tinyalsa/asoundlib.h>
+#include <audio_utils/channels.h>
+
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
/* This is the default configuration to hand to The Framework on the initial
@@ -225,263 +227,6 @@ static size_t convert_32_to_16(const int32_t * in_buff, size_t num_in_samples, s
}
/*
- * Convert a buffer of N-channel, interleaved PCM16 samples to M-channel PCM16 channels
- * (where N < M).
- * in_buff points to the buffer of PCM16 samples
- * in_buff_channels Specifies the number of channels in the input buffer.
- * out_buff points to the buffer to receive converted PCM16 samples.
- * out_buff_channels Specifies the number of channels in the output buffer.
- * num_in_bytes size of input buffer in BYTES
- * returns
- * the number of BYTES of output data.
- * NOTE
- * channels > N are filled with silence.
- * This conversion is safe to do in-place (in_buff == out_buff)
- * We are doing this since we *always* present to The Framework as STEREO device, but need to
- * support 4-channel devices.
- * TODO Move this to a utilities module.
- */
-static size_t expand_channels_16(const int16_t* in_buff, int in_buff_chans,
- int16_t* out_buff, int out_buff_chans,
- size_t num_in_bytes)
-{
- /*
- * Move from back to front so that the conversion can be done in-place
- * i.e. in_buff == out_buff
- * NOTE: num_in_samples * out_buff_channels must be an even multiple of in_buff_chans
- */
- size_t num_in_samples = num_in_bytes / sizeof(int16_t);
-
- size_t num_out_samples = (num_in_samples * out_buff_chans) / in_buff_chans;
-
- short* dst_ptr = out_buff + num_out_samples - 1;
- size_t src_index;
- const short* src_ptr = in_buff + num_in_samples - 1;
- int num_zero_chans = out_buff_chans - in_buff_chans;
- for (src_index = 0; src_index < num_in_samples; src_index += in_buff_chans) {
- int dst_offset;
- for (dst_offset = 0; dst_offset < num_zero_chans; dst_offset++) {
- *dst_ptr-- = 0;
- }
- for (; dst_offset < out_buff_chans; dst_offset++) {
- *dst_ptr-- = *src_ptr--;
- }
- }
-
- /* return number of *bytes* generated */
- return num_out_samples * sizeof(int16_t);
-}
-
-/*
- * Convert a buffer of N-channel, interleaved PCM16 samples to M-channel PCM16 channels
- * (where N > M).
- * in_buff points to the buffer of PCM16 samples
- * in_buff_channels Specifies the number of channels in the input buffer.
- * out_buff points to the buffer to receive converted PCM16 samples.
- * out_buff_channels Specifies the number of channels in the output buffer.
- * num_in_bytes size of input buffer in BYTES
- * returns
- * the number of BYTES of output data.
- * NOTE
- * channels > N are thrown away.
- * This conversion is safe to do in-place (in_buff == out_buff)
- * We are doing this since we *always* present to The Framework as STEREO device, but need to
- * support 4-channel devices.
- * TODO Move this to a utilities module.
- */
-static size_t contract_channels_16(const int16_t* in_buff, size_t in_buff_chans,
- int16_t* out_buff, size_t out_buff_chans,
- size_t num_in_bytes)
-{
- /*
- * Move from front to back so that the conversion can be done in-place
- * i.e. in_buff == out_buff
- * NOTE: num_in_samples * out_buff_channels must be an even multiple of in_buff_chans
- */
- size_t num_in_samples = num_in_bytes / sizeof(int16_t);
-
- size_t num_out_samples = (num_in_samples * out_buff_chans) / in_buff_chans;
-
- size_t num_skip_samples = in_buff_chans - out_buff_chans;
-
- int16_t* dst_ptr = out_buff;
- const int16_t* src_ptr = in_buff;
- size_t src_index;
- for (src_index = 0; src_index < num_in_samples; src_index += in_buff_chans) {
- size_t dst_offset;
- for (dst_offset = 0; dst_offset < out_buff_chans; dst_offset++) {
- *dst_ptr++ = *src_ptr++;
- }
- src_ptr += num_skip_samples;
- }
-
- /* return number of *bytes* generated */
- return num_out_samples * sizeof(int16_t);
-}
-
-/*
- * Convert a buffer of N-channel, interleaved PCM32 samples to M-channel PCM32 channels
- * (where N < M).
- * in_buff points to the buffer of PCM32 samples
- * in_buff_channels Specifies the number of channels in the input buffer.
- * out_buff points to the buffer to receive converted PCM32 samples.
- * out_buff_channels Specifies the number of channels in the output buffer.
- * num_in_bytes size of input buffer in BYTES
- * returns
- * the number of BYTES of output data.
- * NOTE
- * channels > N are filled with silence.
- * This conversion is safe to do in-place (in_buff == out_buff)
- * We are doing this since we *always* present to The Framework as STEREO device, but need to
- * support 4-channel devices.
- * TODO Move this to a utilities module.
- */
-static size_t expand_channels_32(const int32_t* in_buff, size_t in_buff_chans,
- int32_t* out_buff, size_t out_buff_chans,
- size_t num_in_bytes)
-{
- /*
- * Move from back to front so that the conversion can be done in-place
- * i.e. in_buff == out_buff
- * NOTE: num_in_samples * out_buff_channels must be an even multiple of in_buff_chans
- */
- size_t num_in_samples = num_in_bytes / sizeof(int32_t);
-
- size_t num_out_samples = (num_in_samples * out_buff_chans) / in_buff_chans;
-
- int32_t* dst_ptr = out_buff + num_out_samples - 1;
- const int32_t* src_ptr = in_buff + num_in_samples - 1;
- size_t num_zero_chans = out_buff_chans - in_buff_chans;
- size_t src_index;
- for (src_index = 0; src_index < num_in_samples; src_index += in_buff_chans) {
- size_t dst_offset;
- for (dst_offset = 0; dst_offset < num_zero_chans; dst_offset++) {
- *dst_ptr-- = 0;
- }
- for (; dst_offset < out_buff_chans; dst_offset++) {
- *dst_ptr-- = *src_ptr--;
- }
- }
-
- /* return number of *bytes* generated */
- return num_out_samples * sizeof(int32_t);
-}
-
-/*
- * Convert a buffer of N-channel, interleaved PCM32 samples to M-channel PCM16 channels
- * (where N > M).
- * in_buff points to the buffer of PCM32 samples
- * in_buff_channels Specifies the number of channels in the input buffer.
- * out_buff points to the buffer to receive converted PCM16 samples.
- * out_buff_channels Specifies the number of channels in the output buffer.
- * num_in_bytes size of input buffer in BYTES
- * returns
- * the number of BYTES of output data.
- * NOTE
- * channels > N are thrown away.
- * This conversion is safe to do in-place (in_buff == out_buff)
- * We are doing this since we *always* present to The Framework as STEREO device, but need to
- * support 4-channel devices.
- * TODO Move this to a utilities module.
- */
-static size_t contract_channels_32(const int32_t* in_buff, size_t in_buff_chans,
- int32_t* out_buff, size_t out_buff_chans,
- size_t num_in_bytes)
-{
- /*
- * Move from front to back so that the conversion can be done in-place
- * i.e. in_buff == out_buff
- * NOTE: num_in_samples * out_buff_channels must be an even multiple of in_buff_chans
- */
- size_t num_in_samples = num_in_bytes / sizeof(int32_t);
-
- size_t num_out_samples = (num_in_samples * out_buff_chans) / in_buff_chans;
-
- size_t num_skip_samples = in_buff_chans - out_buff_chans;
-
- int32_t* dst_ptr = out_buff;
- const int32_t* src_ptr = in_buff;
- size_t src_index;
- for (src_index = 0; src_index < num_in_samples; src_index += in_buff_chans) {
- size_t dst_offset;
- for (dst_offset = 0; dst_offset < out_buff_chans; dst_offset++) {
- *dst_ptr++ = *src_ptr++;
- }
- src_ptr += num_skip_samples;
- }
-
- /* return number of *bytes* generated */
- return num_out_samples * sizeof(int32_t);
-}
-
-static size_t contract_channels(const void* in_buff, size_t in_buff_chans,
- void* out_buff, size_t out_buff_chans,
- unsigned sample_size_in_bytes, size_t num_in_bytes)
-{
- switch (sample_size_in_bytes) {
- case 2:
- return contract_channels_16((const int16_t*)in_buff, in_buff_chans,
- (int16_t*)out_buff, out_buff_chans,
- num_in_bytes);
-
- /* TODO - do this conversion when we have a device to test it with */
- case 3:
- ALOGE("24-bit channel contraction not supported.");
- return 0;
-
- case 4:
- return contract_channels_32((const int32_t*)in_buff, in_buff_chans,
- (int32_t*)out_buff, out_buff_chans,
- num_in_bytes);
-
- default:
- return 0;
- }
-}
-
-static size_t expand_channels(const void* in_buff, size_t in_buff_chans,
- void* out_buff, size_t out_buff_chans,
- unsigned sample_size_in_bytes, size_t num_in_bytes)
-{
- switch (sample_size_in_bytes) {
- case 2:
- return expand_channels_16((const int16_t*)in_buff, in_buff_chans,
- (int16_t*)out_buff, out_buff_chans,
- num_in_bytes);
-
- /* TODO - do this conversion when we have a device to test it with */
- case 3:
- ALOGE("24-bit channel expansion not supported.");
- return 0;
-
- case 4:
- return expand_channels_32((const int32_t*)in_buff, in_buff_chans,
- (int32_t*)out_buff, out_buff_chans,
- num_in_bytes);
-
- default:
- return 0;
- }
-}
-
-static size_t adjust_channels(const void* in_buff, size_t in_buff_chans,
- void* out_buff, size_t out_buff_chans,
- unsigned sample_size_in_bytes, size_t num_in_bytes)
-{
- if (out_buff_chans > in_buff_chans) {
- return expand_channels(in_buff, in_buff_chans, out_buff, out_buff_chans,
- sample_size_in_bytes, num_in_bytes);
- } else if (out_buff_chans < in_buff_chans) {
- return contract_channels(in_buff, in_buff_chans, out_buff, out_buff_chans,
- sample_size_in_bytes, num_in_bytes);
- } else if (in_buff != out_buff) {
- memcpy(out_buff, in_buff, num_in_bytes);
- }
-
- return num_in_bytes;
-}
-
-/*
* ALSA Utilities
*/
/*TODO This table and the function that uses it should be moved to a utilities module (probably) */