#include "audio_gain.h" #include #include #include #include static inline int16_t float_to_short(float f) { static const float scale = 1 << 15; return roundf(fmaxf(fminf(f * scale, scale - 1.f), -scale)); } static inline float short_to_float(int16_t ival) { static const float scale = 1. / (float)(1UL << 15); return ival * scale; } void audio_gain_process(int16_t *src, size_t count, int mute, float db_level) { float db_gain; float value; size_t i; if (src == NULL) { ALOGE("audio_gain_process fail, src is NULL"); return; } db_gain = powf(10, db_level / 20.0f); /* 10 ,20.0 are used to cauculate db */ if (mute != 0) { db_gain = 0.0f; } for (i = 0; i < count; i++) { value = short_to_float(src[i]) * db_gain; src[i] = float_to_short(value); } }