summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/hardware/audio.h24
-rw-r--r--include/hardware/audio_amplifier.h142
-rw-r--r--include/hardware/gralloc.h17
-rw-r--r--include/hardware/hwcomposer_defs.h4
-rw-r--r--include/hardware/lights.h20
-rw-r--r--include/hardware/nfc.h1
-rw-r--r--include/hardware/power.h26
-rw-r--r--modules/audio/Android.mk13
-rw-r--r--modules/audio/audio_amplifier.c146
-rw-r--r--modules/audio_remote_submix/audio_hw.cpp55
10 files changed, 429 insertions, 19 deletions
diff --git a/include/hardware/audio.h b/include/hardware/audio.h
index ca7b18b..a562554 100644
--- a/include/hardware/audio.h
+++ b/include/hardware/audio.h
@@ -28,6 +28,9 @@
#include <hardware/hardware.h>
#include <system/audio.h>
#include <hardware/audio_effect.h>
+#ifdef AUDIO_LISTEN_ENABLED
+#include <listen_types.h>
+#endif
__BEGIN_DECLS
@@ -652,6 +655,27 @@ struct audio_hw_device {
int (*set_audio_port_config)(struct audio_hw_device *dev,
const struct audio_port_config *config);
+#ifdef AUDIO_LISTEN_ENABLED
+ /** This method opens the listen session and returns a handle */
+ int (*open_listen_session)(struct audio_hw_device *dev,
+ struct listen_open_params*,
+ struct listen_session** handle);
+
+ /** This method closes the listen session */
+ int (*close_listen_session)(struct audio_hw_device *dev,
+ struct listen_session* handle);
+
+ /** This method sets the mad observer callback */
+ int (*set_mad_observer)(struct audio_hw_device *dev,
+ listen_callback_t cb_func);
+
+ /* This method is used for setting listen hal specfic parameters.
+ * If multiple paramets are set in one call and setting any one of them
+ * fails it will return failure.
+ */
+ int (*listen_set_parameters)(struct audio_hw_device *dev,
+ const char *kv_pairs);
+#endif
};
typedef struct audio_hw_device audio_hw_device_t;
diff --git a/include/hardware/audio_amplifier.h b/include/hardware/audio_amplifier.h
new file mode 100644
index 0000000..4305094
--- /dev/null
+++ b/include/hardware/audio_amplifier.h
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2015, The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CM_AUDIO_AMPLIFIER_INTERFACE_H
+#define CM_AUDIO_AMPLIFIER_INTERFACE_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <hardware/audio.h>
+#include <hardware/hardware.h>
+
+#include <system/audio.h>
+
+__BEGIN_DECLS
+
+#define AMPLIFIER_HARDWARE_MODULE_ID "audio_amplifier"
+
+#define AMPLIFIER_HARDWARE_INTERFACE "audio_amplifier_hw_if"
+
+#define AMPLIFIER_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
+
+#define AMPLIFIER_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
+#define AMPLIFIER_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
+#define AMPLIFIER_DEVICE_API_VERSION_CURRENT AMPLIFIER_DEVICE_API_VERSION_2_0
+
+typedef struct amplifier_device {
+ /**
+ * Common methods of the amplifier device. This *must* be the first member
+ * of amplifier_device as users of this structure will cast a hw_device_t
+ * to amplifier_device pointer in contexts where it's known
+ * the hw_device_t references a amplifier_device.
+ */
+ struct hw_device_t common;
+
+ /**
+ * Notify amplifier device of current input devices
+ *
+ * This function should handle only input devices.
+ */
+ int (*set_input_devices)(struct amplifier_device *device, uint32_t devices);
+
+ /**
+ * Notify amplifier device of current output devices
+ *
+ * This function should handle only output devices.
+ */
+ int (*set_output_devices)(struct amplifier_device *device, uint32_t devices);
+
+ /**
+ * Notify amplifier device of output device enable/disable
+ *
+ * This function should handle only output devices.
+ */
+ int (*enable_output_devices)(struct amplifier_device *device,
+ uint32_t devices, bool enable);
+
+ /**
+ * Notify amplifier device of input device enable/disable
+ *
+ * This function should handle only input devices.
+ */
+ int (*enable_input_devices)(struct amplifier_device *device,
+ uint32_t devices, bool enable);
+
+ /**
+ * Notify amplifier device about current audio mode
+ */
+ int (*set_mode)(struct amplifier_device *device, audio_mode_t mode);
+
+ /**
+ * Notify amplifier device that an output stream has started
+ */
+ int (*output_stream_start)(struct amplifier_device *device,
+ struct audio_stream_out *stream, bool offload);
+
+ /**
+ * Notify amplifier device that an input stream has started
+ */
+ int (*input_stream_start)(struct amplifier_device *device,
+ struct audio_stream_in *stream);
+
+ /**
+ * Notify amplifier device that an output stream has stopped
+ */
+ int (*output_stream_standby)(struct amplifier_device *device,
+ struct audio_stream_out *stream);
+
+ /**
+ * Notify amplifier device that an input stream has stopped
+ */
+ int (*input_stream_standby)(struct amplifier_device *device,
+ struct audio_stream_in *stream);
+
+ /**
+ * set/get output audio device parameters.
+ */
+ int (*set_parameters)(struct amplifier_device *device,
+ struct str_parms *parms);
+} amplifier_device_t;
+
+typedef struct amplifier_module {
+ /**
+ * Common methods of the amplifier module. This *must* be the first member
+ * of amplifier_module as users of this structure will cast a hw_module_t
+ * to amplifier_module pointer in contexts where it's known
+ * the hw_module_t references a amplifier_module.
+ */
+ struct hw_module_t common;
+} amplifier_module_t;
+
+/** convenience API for opening and closing a supported device */
+
+static inline int amplifier_device_open(const struct hw_module_t *module,
+ struct amplifier_device **device)
+{
+ return module->methods->open(module, AMPLIFIER_HARDWARE_INTERFACE,
+ (struct hw_device_t **) device);
+}
+
+static inline int amplifier_device_close(struct amplifier_device *device)
+{
+ return device->common.close(&device->common);
+}
+
+__END_DECLS
+
+#endif // CM_AUDIO_AMPLIFIER_INTERFACE_H
diff --git a/include/hardware/gralloc.h b/include/hardware/gralloc.h
index ef86f90..07ac029 100644
--- a/include/hardware/gralloc.h
+++ b/include/hardware/gralloc.h
@@ -143,6 +143,19 @@ enum {
GRALLOC_USAGE_PRIVATE_2 = 0x40000000,
GRALLOC_USAGE_PRIVATE_3 = 0x80000000,
GRALLOC_USAGE_PRIVATE_MASK = 0xF0000000,
+
+#ifdef EXYNOS4_ENHANCEMENTS
+ /* SAMSUNG */
+ GRALLOC_USAGE_PRIVATE_NONECACHE = 0x00800000,
+
+ GRALLOC_USAGE_HW_FIMC1 = 0x01000000,
+ GRALLOC_USAGE_HW_ION = 0x02000000,
+ GRALLOC_USAGE_YUV_ADDR = 0x04000000,
+ GRALLOC_USAGE_CAMERA = 0x08000000,
+
+ /* SEC Private usage , for Overlay path at HWC */
+ GRALLOC_USAGE_HWC_HWOVERLAY = 0x20000000,
+#endif
};
/*****************************************************************************/
@@ -237,6 +250,10 @@ typedef struct gralloc_module_t {
int (*unlock)(struct gralloc_module_t const* module,
buffer_handle_t handle);
+#ifdef EXYNOS4_ENHANCEMENTS
+ int (*getphys) (struct gralloc_module_t const* module,
+ buffer_handle_t handle, void** paddr);
+#endif
/* reserved for future use */
int (*perform)(struct gralloc_module_t const* module,
diff --git a/include/hardware/hwcomposer_defs.h b/include/hardware/hwcomposer_defs.h
index 0131bc5..9c7d790 100644
--- a/include/hardware/hwcomposer_defs.h
+++ b/include/hardware/hwcomposer_defs.h
@@ -192,6 +192,10 @@ enum {
*/
HWC_DISPLAY_DPI_X = 4,
HWC_DISPLAY_DPI_Y = 5,
+
+ /* Indicates which of the vendor-defined color transforms is provided by
+ * this configuration. */
+ HWC_DISPLAY_COLOR_TRANSFORM = 6,
};
/* Allowed events for hwc_methods::eventControl() */
diff --git a/include/hardware/lights.h b/include/hardware/lights.h
index 2cf5519..777c915 100644
--- a/include/hardware/lights.h
+++ b/include/hardware/lights.h
@@ -51,6 +51,12 @@ __BEGIN_DECLS
#define LIGHT_ID_BLUETOOTH "bluetooth"
#define LIGHT_ID_WIFI "wifi"
+/*
+ * Additional hardware-specific lights
+ */
+#define LIGHT_ID_CAPS "caps"
+#define LIGHT_ID_FUNC "func"
+
/* ************************************************************************
* Flash modes for the flashMode field of light_state_t.
*/
@@ -82,6 +88,11 @@ __BEGIN_DECLS
#define BRIGHTNESS_MODE_SENSOR 1
/**
+ * Light mode allows multiple LEDs
+ */
+#define LIGHT_MODE_MULTIPLE_LEDS 0x01
+
+/**
* The parameters that can be set for a given light.
*
* Not all lights must support all parameters. If you
@@ -101,6 +112,9 @@ struct light_state_t {
*
* The high byte should be ignored. Callers will set it to 0xff (which
* would correspond to 255 alpha).
+ *
+ * CyanogenMod: The high byte value can be implemented to control the LEDs
+ * Brightness from the Lights settings. The value goes from 0x01 to 0xFF.
*/
unsigned int color;
@@ -116,6 +130,12 @@ struct light_state_t {
* Currently the values are BRIGHTNESS_MODE_USER and BRIGHTNESS_MODE_SENSOR.
*/
int brightnessMode;
+
+ /**
+ * Define the LEDs modes (multiple, ...).
+ * See the LIGHTS_MODE_* mask constants.
+ */
+ unsigned int ledsModes;
};
struct light_device_t {
diff --git a/include/hardware/nfc.h b/include/hardware/nfc.h
index 58d33d9..6002e34 100644
--- a/include/hardware/nfc.h
+++ b/include/hardware/nfc.h
@@ -54,6 +54,7 @@ __BEGIN_DECLS
*/
#define NFC_NCI_HARDWARE_MODULE_ID "nfc_nci"
#define NFC_NCI_BCM2079X_HARDWARE_MODULE_ID "nfc_nci.bcm2079x"
+#define NFC_NCI_NXP_PN54X_HARDWARE_MODULE_ID "nfc_nci.pn54x"
#define NFC_NCI_CONTROLLER "nci"
/*
diff --git a/include/hardware/power.h b/include/hardware/power.h
index 084cba8..c266d8b 100644
--- a/include/hardware/power.h
+++ b/include/hardware/power.h
@@ -47,11 +47,18 @@ typedef enum {
POWER_HINT_VIDEO_ENCODE = 0x00000003,
POWER_HINT_VIDEO_DECODE = 0x00000004,
POWER_HINT_LOW_POWER = 0x00000005,
- POWER_HINT_CAM_PREVIEW = 0x00000006
+ POWER_HINT_CAM_PREVIEW = 0x00000006,
+
+ POWER_HINT_CPU_BOOST = 0x00000010,
+ POWER_HINT_LAUNCH_BOOST = 0x00000011,
+ POWER_HINT_AUDIO = 0x00000020,
+ POWER_HINT_SET_PROFILE = 0x00000030
+
} power_hint_t;
typedef enum {
- POWER_FEATURE_DOUBLE_TAP_TO_WAKE = 0x00000001
+ POWER_FEATURE_DOUBLE_TAP_TO_WAKE = 0x00000001,
+ POWER_FEATURE_SUPPORTED_PROFILES = 0x00001000
} feature_t;
/**
@@ -117,7 +124,8 @@ typedef struct power_module {
* User is interacting with the device, for example, touchscreen
* events are incoming. CPU and GPU load may be expected soon,
* and it may be appropriate to raise speeds of CPU, memory bus,
- * etc. The data parameter is unused.
+ * etc. The data parameter is the estimated length of the interaction
+ * in milliseconds, or 0 if unknown.
*
* POWER_HINT_LOW_POWER
*
@@ -126,6 +134,12 @@ typedef struct power_module {
* parameter is non-zero when low power mode is activated, and zero
* when deactivated.
*
+ * POWER_HINT_CPU_BOOST
+ *
+ * An operation is happening where it would be ideal for the CPU to
+ * be boosted for a specific duration. The data parameter is an
+ * integer value of the boost duration in microseconds.
+ *
* A particular platform may choose to ignore any hint.
*
* availability: version 0.2
@@ -148,6 +162,12 @@ typedef struct power_module {
*/
void (*setFeature)(struct power_module *module, feature_t feature, int state);
+ /*
+ * (*getFeature) is called to get the current value of a particular
+ * feature or capability from the hardware or PowerHAL
+ */
+ int (*getFeature)(struct power_module *module, feature_t feature);
+
} power_module_t;
diff --git a/modules/audio/Android.mk b/modules/audio/Android.mk
index ef4b8f5..8dfda57 100644
--- a/modules/audio/Android.mk
+++ b/modules/audio/Android.mk
@@ -60,3 +60,16 @@ LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := -Wno-unused-parameter
include $(BUILD_SHARED_LIBRARY)
+
+# The stub audio amplifier HAL module that can be used as a skeleton for
+# new implementations.
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := audio_amplifier.default
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_SRC_FILES := audio_amplifier.c
+LOCAL_SHARED_LIBRARIES := liblog libcutils
+LOCAL_MODULE_TAGS := optional
+LOCAL_CFLAGS := -Wno-unused-parameter
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/audio/audio_amplifier.c b/modules/audio/audio_amplifier.c
new file mode 100644
index 0000000..9b92356
--- /dev/null
+++ b/modules/audio/audio_amplifier.c
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2015 The CyanogenMod Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "amplifier_default"
+//#define LOG_NDEBUG 0
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <sys/types.h>
+
+#include <cutils/log.h>
+#include <cutils/str_parms.h>
+
+#include <hardware/audio_amplifier.h>
+#include <hardware/hardware.h>
+
+static int amp_set_input_devices(amplifier_device_t *device, uint32_t devices)
+{
+ return 0;
+}
+
+static int amp_set_output_devices(amplifier_device_t *device, uint32_t devices)
+{
+ return 0;
+}
+
+static int amp_enable_output_devices(amplifier_device_t *device,
+ uint32_t devices, bool enable)
+{
+ return 0;
+}
+
+static int amp_enable_input_devices(amplifier_device_t *device,
+ uint32_t devices, bool enable)
+{
+ return 0;
+}
+
+static int amp_set_mode(amplifier_device_t *device, audio_mode_t mode)
+{
+ return 0;
+}
+
+static int amp_output_stream_start(amplifier_device_t *device,
+ struct audio_stream_out *stream, bool offload)
+{
+ return 0;
+}
+
+static int amp_input_stream_start(amplifier_device_t *device,
+ struct audio_stream_in *stream)
+{
+ return 0;
+}
+
+static int amp_output_stream_standby(amplifier_device_t *device,
+ struct audio_stream_out *stream)
+{
+ return 0;
+}
+
+static int amp_input_stream_standby(amplifier_device_t *device,
+ struct audio_stream_in *stream)
+{
+ return 0;
+}
+
+static int amp_set_parameters(struct amplifier_device *device,
+ struct str_parms *parms)
+{
+ return 0;
+}
+
+static int amp_dev_close(hw_device_t *device)
+{
+ if (device)
+ free(device);
+
+ return 0;
+}
+
+static int amp_module_open(const hw_module_t *module, const char *name,
+ hw_device_t **device)
+{
+ if (strcmp(name, AMPLIFIER_HARDWARE_INTERFACE)) {
+ ALOGE("%s:%d: %s does not match amplifier hardware interface name\n",
+ __func__, __LINE__, name);
+ return -ENODEV;
+ }
+
+ amplifier_device_t *amp_dev = calloc(1, sizeof(amplifier_device_t));
+ if (!amp_dev) {
+ ALOGE("%s:%d: Unable to allocate memory for amplifier device\n",
+ __func__, __LINE__);
+ return -ENOMEM;
+ }
+
+ amp_dev->common.tag = HARDWARE_DEVICE_TAG;
+ amp_dev->common.module = (hw_module_t *) module;
+ amp_dev->common.version = HARDWARE_DEVICE_API_VERSION(1, 0);
+ amp_dev->common.close = amp_dev_close;
+
+ amp_dev->set_input_devices = amp_set_input_devices;
+ amp_dev->set_output_devices = amp_set_output_devices;
+ amp_dev->enable_output_devices = amp_enable_output_devices;
+ amp_dev->enable_input_devices = amp_enable_input_devices;
+ amp_dev->set_mode = amp_set_mode;
+ amp_dev->output_stream_start = amp_output_stream_start;
+ amp_dev->input_stream_start = amp_input_stream_start;
+ amp_dev->output_stream_standby = amp_output_stream_standby;
+ amp_dev->input_stream_standby = amp_input_stream_standby;
+ amp_dev->set_parameters = amp_set_parameters;
+
+ *device = (hw_device_t *) amp_dev;
+
+ return 0;
+}
+
+static struct hw_module_methods_t hal_module_methods = {
+ .open = amp_module_open,
+};
+
+amplifier_module_t HAL_MODULE_INFO_SYM = {
+ .common = {
+ .tag = HARDWARE_MODULE_TAG,
+ .module_api_version = AMPLIFIER_MODULE_API_VERSION_0_1,
+ .hal_api_version = HARDWARE_HAL_API_VERSION,
+ .id = AMPLIFIER_HARDWARE_MODULE_ID,
+ .name = "Default audio amplifier HAL",
+ .author = "The CyanogenMod Open Source Project",
+ .methods = &hal_module_methods,
+ },
+};
diff --git a/modules/audio_remote_submix/audio_hw.cpp b/modules/audio_remote_submix/audio_hw.cpp
index 20c0fab..58bc4a2 100644
--- a/modules/audio_remote_submix/audio_hw.cpp
+++ b/modules/audio_remote_submix/audio_hw.cpp
@@ -159,11 +159,11 @@ typedef struct route_config {
// destroyed if both and input and output streams are destroyed.
struct submix_stream_out *output;
struct submix_stream_in *input;
-#if ENABLE_RESAMPLING
- // Buffer used as temporary storage for resampled data prior to returning data to the output
+#if (ENABLE_RESAMPLING || ENABLE_CHANNEL_CONVERSION)
+ // Buffer used as temporary storage for audio data prior to returning data to the output
// stream.
- int16_t resampler_buffer[DEFAULT_PIPE_SIZE_IN_FRAMES];
-#endif // ENABLE_RESAMPLING
+ int16_t processor_buffer[DEFAULT_PIPE_SIZE_IN_FRAMES];
+#endif
} route_config_t;
struct submix_audio_device {
@@ -473,8 +473,8 @@ static void submix_audio_device_release_pipe_l(struct submix_audio_device * cons
rsxadev->routes[route_idx].rsxSource = 0;
}
memset(rsxadev->routes[route_idx].address, 0, AUDIO_DEVICE_MAX_ADDRESS_LEN);
-#ifdef ENABLE_RESAMPLING
- memset(rsxadev->routes[route_idx].resampler_buffer, 0,
+#if (ENABLE_RESAMPLING || ENABLE_CHANNEL_CONVERSION)
+ memset(rsxadev->routes[route_idx].processor_buffer, 0,
sizeof(int16_t) * DEFAULT_PIPE_SIZE_IN_FRAMES);
#endif
}
@@ -1133,13 +1133,14 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
}
#endif // ENABLE_CHANNEL_CONVERSION
+#if (ENABLE_RESAMPLING || ENABLE_CHANNEL_CONVERSION)
+ const size_t processor_buffer_size_frames =
+ sizeof(rsxadev->routes[in->route_handle].processor_buffer) / frame_size;
+#endif
#if ENABLE_RESAMPLING
const uint32_t input_sample_rate = in_get_sample_rate(&stream->common);
const uint32_t output_sample_rate =
rsxadev->routes[in->route_handle].config.output_sample_rate;
- const size_t resampler_buffer_size_frames =
- sizeof(rsxadev->routes[in->route_handle].resampler_buffer) /
- sizeof(rsxadev->routes[in->route_handle].resampler_buffer[0]);
float resampler_ratio = 1.0f;
// Determine whether resampling is required.
if (input_sample_rate != output_sample_rate) {
@@ -1156,16 +1157,18 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
while ((remaining_frames > 0) && (attempts < MAX_READ_ATTEMPTS)) {
ssize_t frames_read = -1977;
size_t read_frames = remaining_frames;
-#if ENABLE_RESAMPLING
+#if (ENABLE_RESAMPLING || ENABLE_CHANNEL_CONVERSION)
char* const saved_buff = buff;
+#endif
+#if ENABLE_RESAMPLING
if (resampler_ratio != 1.0f) {
// Calculate the number of frames from the pipe that need to be read to generate
// the data for the input stream read.
const size_t frames_required_for_resampler = (size_t)(
(float)read_frames * (float)resampler_ratio);
- read_frames = min(frames_required_for_resampler, resampler_buffer_size_frames);
+ read_frames = min(frames_required_for_resampler, processor_buffer_size_frames);
// Read into the resampler buffer.
- buff = (char*)rsxadev->routes[in->route_handle].resampler_buffer;
+ buff = (char*)rsxadev->routes[in->route_handle].processor_buffer;
}
#endif // ENABLE_RESAMPLING
#if ENABLE_CHANNEL_CONVERSION
@@ -1173,6 +1176,13 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
// Need to read half the requested frames since the converted output
// data will take twice the space (mono->stereo).
read_frames /= 2;
+ } else if (output_channels == 2 && input_channels == 1) {
+ // If the resampler is active, we already swapped for the processor_buffer
+ if (resampler_ratio == 1.0f) {
+ buff = (char*)rsxadev->routes[in->route_handle].processor_buffer;
+ }
+
+ read_frames = min(read_frames, processor_buffer_size_frames/2);
}
#endif // ENABLE_CHANNEL_CONVERSION
@@ -1191,11 +1201,17 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
if (output_channels == 2 && input_channels == 1) {
// Offset into the output stream data in samples.
ssize_t output_stream_offset = 0;
+ // If resampler is active, continue writing to the temporary buffer
+ int16_t *mixed_buffer =
+ (resampler_ratio == 1.0f) ? (int16_t*)saved_buff : (int16_t*)buff;
for (ssize_t input_stream_frame = 0; input_stream_frame < frames_read;
input_stream_frame++, output_stream_offset += 2) {
// Average the content from both channels.
- data[input_stream_frame] = ((int32_t)data[output_stream_offset] +
- (int32_t)data[output_stream_offset + 1]) / 2;
+ mixed_buffer[input_stream_frame] = ((int32_t)data[output_stream_offset] +
+ (int32_t)data[output_stream_offset + 1]) / 2;
+ }
+ if (resampler_ratio == 1.0f) {
+ buff = saved_buff;
}
} else if (output_channels == 1 && input_channels == 2) {
// Offset into the input stream data in samples.
@@ -1219,13 +1235,20 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
// sampled at a different rate this will result in very nasty aliasing.
const float output_stream_frames = (float)frames_read;
size_t input_stream_frame = 0;
+ size_t input_buf_offset = 0, output_buf_offset = 0;
for (float output_stream_frame = 0.0f;
output_stream_frame < output_stream_frames &&
input_stream_frame < remaining_frames;
output_stream_frame += resampler_ratio, input_stream_frame++) {
- resampled_buffer[input_stream_frame] = data[(size_t)output_stream_frame];
+ input_buf_offset = input_stream_frame * input_channels;
+ output_buf_offset = (size_t)output_stream_frame * input_channels;
+ resampled_buffer[input_buf_offset] = data[output_buf_offset];
+ if (input_channels == 2) {
+ // copy second channel in the frame
+ resampled_buffer[input_buf_offset + 1] = data[output_buf_offset + 1];
+ }
}
- ALOG_ASSERT(input_stream_frame <= (ssize_t)resampler_buffer_size_frames);
+ ALOG_ASSERT(input_stream_frame <= (ssize_t)processor_buffer_size_frames);
SUBMIX_ALOGV("in_read(): resampler produced %zd frames", input_stream_frame);
frames_read = input_stream_frame;
buff = saved_buff;