diff options
Diffstat (limited to 'tizen-audio-volume.c')
-rw-r--r-- | tizen-audio-volume.c | 90 |
1 files changed, 52 insertions, 38 deletions
diff --git a/tizen-audio-volume.c b/tizen-audio-volume.c index 9fca5cc..97e445c 100644 --- a/tizen-audio-volume.c +++ b/tizen-audio-volume.c @@ -339,49 +339,63 @@ error: return ret; } -audio_return_t _audio_volume_set_level_radio(audio_hal_t *ah, uint32_t level) +static audio_return_t _audio_volume_set_ratio_radio(audio_hal_t *ah, double ratio) { audio_return_t audio_ret = AUDIO_RET_OK; - int volume = 0; + int new_value = 0; + int prev_value = -1; int mute = -1; + int max_value; + int min_value; AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); /* Applying mute at volume zero */ - if (level == 0) { - if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_MUTE, 0))) - AUDIO_LOG_ERROR("set mixer(%s) failed", MIXER_FMRADIO_MUTE); + if (ratio == 0) { + if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_MUTE, FMRADIO_MUTE_ON))) { + AUDIO_LOG_ERROR("[mute on] set mixer(%s) failed", MIXER_FMRADIO_MUTE); + return AUDIO_ERR_INTERNAL; + } + new_value = 0; + goto set_volume; + } - } else { - if ((audio_ret = _mixer_control_get_value(ah, MIXER_FMRADIO_MUTE, &mute))) { - AUDIO_LOG_ERROR("get mixer(%s) failed", MIXER_FMRADIO_MUTE); + /* Unmute if muted */ + if ((audio_ret = _mixer_control_get_value(ah, MIXER_FMRADIO_MUTE, &mute))) { + AUDIO_LOG_ERROR("[mute get] get mixer(%s) failed", MIXER_FMRADIO_MUTE); + return audio_ret; + } + if (mute == FMRADIO_MUTE_ON) { + if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_MUTE, FMRADIO_MUTE_OFF))) { + AUDIO_LOG_ERROR("[mute off] set mixer(%s) failed", MIXER_FMRADIO_MUTE); return audio_ret; } - if (mute == 0) { - if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_MUTE, 1))) { - AUDIO_LOG_ERROR("set mixer(%s) failed", MIXER_FMRADIO_MUTE); - return audio_ret; - } - } } - if ((_mixer_control_get_value(ah, MIXER_FMRADIO_L_VOLUME, &volume))) - AUDIO_LOG_ERROR("get mixer(%s) failed", MIXER_FMRADIO_L_VOLUME); - else { - if (volume != ah->volume.radio_volume_value_table[level]) { - if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_L_VOLUME, ah->volume.radio_volume_value_table[level]))) { - AUDIO_LOG_ERROR("set mixer(%s) failed", MIXER_FMRADIO_L_VOLUME); - return audio_ret; - } + max_value = ah->volume.radio_volume_value_table[ah->volume.radio_volume_num_of_levels - 1]; + min_value = ah->volume.radio_volume_value_table[0]; + new_value = (int) (ratio * (max_value - min_value) + min_value); + +set_volume: + /* Left volume */ + if ((_mixer_control_get_value(ah, MIXER_FMRADIO_L_VOLUME, &prev_value))) + AUDIO_LOG_ERROR("[volume get] get mixer(%s) failed", MIXER_FMRADIO_L_VOLUME); + if (new_value != prev_value) { + AUDIO_LOG_INFO("[volume set] set mixer(%s), %d", MIXER_FMRADIO_L_VOLUME, new_value); + if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_L_VOLUME, new_value))) { + AUDIO_LOG_ERROR("[volume set] set mixer(%s) failed", MIXER_FMRADIO_L_VOLUME); + return audio_ret; } } - if ((_mixer_control_get_value(ah, MIXER_FMRADIO_R_VOLUME, &volume))) - AUDIO_LOG_ERROR("get mixer(%s) failed", MIXER_FMRADIO_R_VOLUME); - else { - if (volume != ah->volume.radio_volume_value_table[level]) { - if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_R_VOLUME, ah->volume.radio_volume_value_table[level]))) - AUDIO_LOG_ERROR("set mixer(%s) failed", MIXER_FMRADIO_R_VOLUME); + /* Right volume */ + if ((_mixer_control_get_value(ah, MIXER_FMRADIO_R_VOLUME, &prev_value))) + AUDIO_LOG_ERROR("[volume get] get mixer(%s) failed", MIXER_FMRADIO_R_VOLUME); + if (new_value != prev_value) { + AUDIO_LOG_INFO("[volume set] set mixer(%s), %d", MIXER_FMRADIO_R_VOLUME, new_value); + if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_R_VOLUME, new_value))) { + AUDIO_LOG_ERROR("[volume set] set mixer(%s) failed", MIXER_FMRADIO_R_VOLUME); + return audio_ret; } } @@ -395,7 +409,6 @@ audio_return_t _audio_volume_init(audio_hal_t *ah) audio_return_t audio_ret = AUDIO_RET_OK; int init_value[AUDIO_VOLUME_TYPE_MAX] = { 9, 11, 7, 11, 7, 4, 4, 7 }; int* fm_table = NULL; - int number_of_steps = 0; AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); @@ -426,13 +439,13 @@ audio_return_t _audio_volume_init(audio_hal_t *ah) } /* radio volume table */ - __load_radio_volume_table(&fm_table, &number_of_steps); + __load_radio_volume_table(&fm_table, &ah->volume.radio_volume_num_of_levels); if (fm_table) { - AUDIO_LOG_DEBUG("number of steps -> %d", number_of_steps); + AUDIO_LOG_DEBUG("number of levels -> %d", ah->volume.radio_volume_num_of_levels); /*copy from temp structure to main strcture*/ - for (i = 0; i < number_of_steps; i++) { + for (i = 0; i < ah->volume.radio_volume_num_of_levels; i++) ah->volume.radio_volume_value_table[i] = fm_table[i]; - } + free(fm_table); fm_table = NULL; } @@ -529,10 +542,6 @@ audio_return_t audio_set_volume_level(void *audio_handle, audio_volume_info_t *i ah->volume.volume_level[__get_volume_idx_by_string_type(info->type)] = level; AUDIO_LOG_INFO("set [%s] volume_level: %d, direction(%d)", info->type, level, info->direction); - /* set mixer related to H/W volume if needed */ - if ((__get_volume_idx_by_string_type(info->type) == AUDIO_VOLUME_TYPE_MEDIA) && ah->device.is_radio_on) - audio_ret = _audio_volume_set_level_radio(ah, level); - return audio_ret; } @@ -573,5 +582,10 @@ audio_return_t audio_set_volume_ratio(void *audio_handle, audio_stream_info_t *i AUDIO_LOG_INFO("set [%s] volume_ratio: %f, direction(%u), index(%u)", info->role, ratio, info->direction, info->idx); + if (!strncmp(info->role, "radio", strlen(info->role))) { + AUDIO_LOG_INFO("set radio volume according to the ratio[%f]", ratio); + audio_ret = _audio_volume_set_ratio_radio(ah, ratio); + } + return audio_ret; -}
\ No newline at end of file +} |