diff options
Diffstat (limited to 'post_proc')
-rw-r--r-- | post_proc/volume_listener.c | 58 |
1 files changed, 16 insertions, 42 deletions
diff --git a/post_proc/volume_listener.c b/post_proc/volume_listener.c index 3367b76..1402ae6 100644 --- a/post_proc/volume_listener.c +++ b/post_proc/volume_listener.c @@ -18,6 +18,7 @@ //#define LOG_NDEBUG 0 #include <stdlib.h> #include <dlfcn.h> +#include <math.h> #include <cutils/list.h> #include <cutils/log.h> @@ -32,7 +33,8 @@ #define VOL_FLAG ( EFFECT_FLAG_TYPE_INSERT | \ EFFECT_FLAG_VOLUME_IND | \ EFFECT_FLAG_DEVICE_IND | \ - EFFECT_FLAG_OFFLOAD_SUPPORTED) + EFFECT_FLAG_OFFLOAD_SUPPORTED | \ + EFFECT_FLAG_NO_PROCESS) #define PRINT_STREAM_TYPE(i) ALOGV("descriptor found and is of stream type %s ",\ i == MUSIC?"MUSIC": \ @@ -228,7 +230,7 @@ static void check_and_set_gain_dep_cal() { // iterate through list and make decision to set new gain dep cal level for speaker device // 1. find all usecase active on speaker - // 2. find average of left and right for each usecase + // 2. find energy sum for each usecase // 3. find the highest of all the active usecase // 4. if new value is different than the current value then load new calibration @@ -242,15 +244,22 @@ static void check_and_set_gain_dep_cal() ALOGV("%s ==> Start ...", __func__); - // select the highest volume on speaker device + float sum_energy = 0.0; + bool sum_energy_used = false; + float temp_vol = 0; + // compute energy sum for the active speaker device (pick loudest of both channels) list_for_each(node, &vol_effect_list) { context = node_to_item(node, struct vol_listener_context_s, effect_list_node); if ((context->state == VOL_LISTENER_STATE_ACTIVE) && - (context->dev_id & AUDIO_DEVICE_OUT_SPEAKER) && - (new_vol < (context->left_vol + context->right_vol) / 2)) { - new_vol = (context->left_vol + context->right_vol) / 2; + (context->dev_id & AUDIO_DEVICE_OUT_SPEAKER)) { + sum_energy_used = true; + temp_vol = fmax(context->left_vol, context->right_vol); + sum_energy += temp_vol * temp_vol; } } + if (sum_energy_used) { + new_vol = fmin(sqrt(sum_energy), 1.0); + } if (new_vol != current_vol) { ALOGV("%s:: Change in decision :: current volume is %f new volume is %f", @@ -332,41 +341,6 @@ static inline int16_t clamp16(int32_t sample) return sample; } -static int vol_effect_process(effect_handle_t self, - audio_buffer_t *in_buffer, - audio_buffer_t *out_buffer) -{ - int status = 0; - ALOGV("%s Called ", __func__); - - vol_listener_context_t *context = (vol_listener_context_t *)self; - pthread_mutex_lock(&vol_listner_init_lock); - - if (context->state != VOL_LISTENER_STATE_ACTIVE) { - ALOGE("%s: state is not active .. return error", __func__); - status = -EINVAL; - goto exit; - } - - // calculation based on channel count 2 - if (in_buffer->raw != out_buffer->raw) { - if (context->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) { - size_t i; - for (i = 0; i < out_buffer->frameCount*2; i++) { - out_buffer->s16[i] = clamp16(out_buffer->s16[i] + in_buffer->s16[i]); - } - } else { - memcpy(out_buffer->raw, in_buffer->raw, out_buffer->frameCount * 2 * sizeof(int16_t)); - } - - } - -exit: - pthread_mutex_unlock(&vol_listner_init_lock); - return status; -} - - static int vol_effect_command(effect_handle_t self, uint32_t cmd_code, uint32_t cmd_size, void *p_cmd_data, uint32_t *reply_size, @@ -818,7 +792,7 @@ static int vol_prc_lib_get_descriptor(const effect_uuid_t *uuid, /* effect_handle_t interface implementation for volume listener effect */ static const struct effect_interface_s effect_interface = { - vol_effect_process, + NULL, vol_effect_command, vol_effect_get_descriptor, NULL, |