/* * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved. * Description: audio hal customized source file. * Author: Hisilicon * Create: 2020-05-11 * Notes: NA * History: 2020-05-11 yinyingcai for CodingStyle */ #define LOG_TAG "audio_hal_custom" #define LOG_NDEBUG 0 #include "audio_custom.h" #include #include #include #include "audio_hw.h" struct custom_device { int reserved; }; #define EXTDEV_PATCHSRC_VOL_STEP 6 #define AO_PORT_VOL_MIN (-81) // use to Convert index to DB #define INTEGER_DENOMINATOR 2 #define DECIMAL_MULTIPLIER 500 #define AEF_VOLUME_COMPENSATE 0 #define MAX_VOLUME_INDEX 100 static void init_nano(void) { ALOGD("nano_init not support"); } int custom_init(struct audio_device *adev) { int ret; struct custom_device *custom_dev; custom_dev = malloc(sizeof(struct custom_device)); if (custom_dev == NULL) { return -ENOMEM; } ret = memset_s(custom_dev, sizeof(struct custom_device), 0, sizeof(struct custom_device)); if (ret != EOK) { ALOGD("memset_s custom_dev failed(0x%x)", ret); } adev->custom_private_data = custom_dev; init_nano(); return 0; } void custom_deinit(struct audio_device *adev) { if (adev->custom_private_data != NULL) { free(adev->custom_private_data); adev->custom_private_data = NULL; } } void custom_open_nano(struct audio_config *config __unused, struct audio_stream_in **streamin __unused) { ALOGD("%s not support", __func__); } void custom_close_nano(struct audio_stream_in *stream __unused) { ALOGD("%s not support", __func__); } void custom_adev_set_parameters(struct audio_device *dev __unused, struct str_parms *parms __unused) { ALOGD("%s called", __func__); } void custom_adev_get_parameters(const struct audio_device *dev __unused, struct str_parms *query __unused, struct str_parms *result __unused) { ALOGD("%s called", __func__); } bool custom_in_implement_needed(audio_devices_t devices __unused, audio_input_flags_t flags __unused, audio_source_t source __unused) { ALOGD("%s called", __func__); return false; } int custom_open_input_stream(audio_devices_t devices __unused, const struct audio_config *config __unused, audio_input_flags_t flags __unused, audio_source_t source __unused, struct stream_in *in __unused) { ALOGD("%s called", __func__); return 0; } void custom_close_input_stream(struct stream_in *in __unused) { ALOGD("%s called", __func__); } bool custom_out_implement_needed(audio_devices_t devices __unused, audio_output_flags_t flags __unused, struct audio_config *config __unused, const char *address __unused) { ALOGD("%s called", __func__); return false; } int custom_open_output_stream(audio_devices_t devices __unused, audio_output_flags_t flags __unused, struct audio_config *config __unused, const char *address __unused, struct stream_out *out __unused) { ALOGD("%s called", __func__); return 0; } void custom_close_output_stream(struct stream_out *out __unused) { ALOGD("%s called", __func__); } // used in tv product void custom_calc_extdev_patchsrc_volume(int32_t index, int *integer_gain, int *decimal_gain) { double precision_vol = 0.0; int32_t volume[EXTDEV_PATCHSRC_VOL_STEP] = { 0, 10, 25, 50, 75, 100}; /* volume curve index */ double volume_gain[EXTDEV_PATCHSRC_VOL_STEP] = { -54.000, -38.000, -30.125, -16.375, -6.125, 0}; /* index's gain in db */ ALOGD("%s called", __func__); if (integer_gain == NULL || decimal_gain == NULL) { return; } if (index < volume[EXTDEV_PATCHSRC_VOL_STEP - 1] && index >= volume[0]) { for (int i = 0; i < EXTDEV_PATCHSRC_VOL_STEP - 1; i++) { if (index >= volume[i] && index < volume[i + 1]) { precision_vol = (volume_gain[i + 1] - volume_gain[i]) / (volume[i + 1] - volume[i]) * (index - volume[i]) + volume_gain[i]; break; } } } else { if (index < volume[0]) { precision_vol = volume_gain[0]; } else { precision_vol = volume_gain[EXTDEV_PATCHSRC_VOL_STEP - 1]; } } precision_vol = precision_vol + (double)AEF_VOLUME_COMPENSATE; *integer_gain = (int32_t)precision_vol; *decimal_gain = (int32_t)((precision_vol - (double)(*integer_gain)) * 1000); /* one int is 1000 decimal */ *decimal_gain -= (*decimal_gain) % 125; /* 125 is the accuracy */ } // used in stb product void custom_calc_ao_port_volume(int32_t index, int *integer_gain, int *decimal_gain) { ALOGD("%s called", __func__); int32_t index_cur = index; if (integer_gain == NULL || decimal_gain == NULL) { return; } if (index_cur > MAX_VOLUME_INDEX) { index_cur = MAX_VOLUME_INDEX; } index_cur = index_cur + AO_PORT_VOL_MIN; *integer_gain = index_cur / INTEGER_DENOMINATOR; *decimal_gain = DECIMAL_MULTIPLIER * (index_cur % INTEGER_DENOMINATOR); }