#include "aem_adapter_audio.h" #include "aem_log.h" #include "aem_app_err_if.h" #include "tts_manager.h" #include "audio_system.h" #include "audio_policy.h" #include "volume_manager.h" #include "bt_manager.h" #include "aem_video_service.h" const uint8_t *tts_file_name[AEM_RINGTONE_MAX] = { "callring.act", "welcome.act", "poweroff.act", }; int aem_tts_play(uint8_t *name) { #if CONFIG_VIDEO_PLAYER if (aem_is_video_running() == true) { return -1; } #endif if (NULL == name) return AEM_ERR_NULL; return tts_manager_play(name, PLAY_IMMEDIATELY); } int aem_tts_stop(void) { int ret = AEM_OK; // aem_set_audio_system_mute(AEM_AUDIO_RINGTONE, 0); ret = tts_manager_stop(NULL); tts_manager_wait_finished(true); // aem_set_audio_system_mute(AEM_AUDIO_RINGTONE, 1); return ret; } void aem_tts_event_cb_register(aem_audio_event_cb event_cb) { tts_event_nodify lisener = (tts_event_nodify)event_cb; tts_manager_add_event_lisener(lisener); } #ifdef CONFIG_BT_AVRCP static int aem_bt_transmit_sync_vol_to_remote(int volume) { int max_volume = audio_policy_get_volume_level(); uint8_t avrcp_vol; /* percentage */ if (!bt_manager_trs_get_connected_dev_num()) { return -ENODEV; } if (volume <= 0) { avrcp_vol = 0; } else if (volume >= max_volume) { avrcp_vol = 127; } else { avrcp_vol = (uint8_t)(volume * 127 / max_volume); } SYS_LOG_INF("volume %d -> remote %d\n", volume, avrcp_vol); return bt_manager_avrcp_set_absolute_volume(BTSRV_DEVICE_PLAYER, &avrcp_vol, 1); } #endif int aem_set_system_volume(aem_volume_type_e type, int volume) { int vol = volume % (aem_get_system_max_volume() + 1); audio_stream_type_e stream_type = AUDIO_STREAM_TTS; switch (type) { case AEM_AUDIO_CALL: stream_type = AUDIO_STREAM_VOICE; break; case AEM_AUDIO_RINGTONE: stream_type = AUDIO_STREAM_TTS; break; case AEM_AUDIO_LOCAL_MUSIC: stream_type = AUDIO_STREAM_LOCAL_MUSIC; #ifdef CONFIG_BT_AVRCP aem_bt_transmit_sync_vol_to_remote(vol); #endif break; case AEM_AUDIO_BT_MUSIC: stream_type = AUDIO_STREAM_MUSIC; break; default: break; } return system_volume_set(stream_type, volume, false); } int aem_get_system_volume(aem_volume_type_e type) { audio_stream_type_e stream_type = AUDIO_STREAM_TTS; switch (type) { case AEM_AUDIO_CALL: stream_type = AUDIO_STREAM_VOICE; break; case AEM_AUDIO_RINGTONE: stream_type = AUDIO_STREAM_TTS; break; case AEM_AUDIO_LOCAL_MUSIC: stream_type = AUDIO_STREAM_LOCAL_MUSIC; break; case AEM_AUDIO_BT_MUSIC: stream_type = AUDIO_STREAM_MUSIC; break; default: break; } return system_volume_get(stream_type); } int aem_get_system_min_volume(void) { return audio_system_get_min_volume(); } int aem_get_system_max_volume(void) { return audio_system_get_max_volume(); } int aem_get_system_microphone_muted(void) { return audio_system_get_microphone_muted(); } void aem_set_system_microphone_muted(int value) { audio_system_mute_microphone(value); } int aem_get_audio_system_mute(aem_volume_type_e type) { audio_stream_type_e stream_type = AUDIO_STREAM_TTS; switch (type) { case AEM_AUDIO_CALL: stream_type = AUDIO_STREAM_VOICE; break; case AEM_AUDIO_RINGTONE: stream_type = AUDIO_STREAM_TTS; break; case AEM_AUDIO_LOCAL_MUSIC: stream_type = AUDIO_STREAM_LOCAL_MUSIC; break; case AEM_AUDIO_BT_MUSIC: stream_type = AUDIO_STREAM_MUSIC; break; default: break; } return audio_system_get_stream_mute(stream_type); } void aem_set_audio_system_mute(aem_volume_type_e type, int mute) { audio_stream_type_e stream_type = AUDIO_STREAM_TTS; switch (type) { case AEM_AUDIO_CALL: stream_type = AUDIO_STREAM_VOICE; break; case AEM_AUDIO_RINGTONE: stream_type = AUDIO_STREAM_TTS; break; case AEM_AUDIO_LOCAL_MUSIC: stream_type = AUDIO_STREAM_LOCAL_MUSIC; break; case AEM_AUDIO_BT_MUSIC: stream_type = AUDIO_STREAM_MUSIC; break; default: break; } audio_system_set_stream_mute(stream_type, mute); } void aem_audio_system_set_stream_volume(aem_volume_type_e type, int volume) { audio_stream_type_e stream_type = AUDIO_STREAM_TTS; switch (type) { case AEM_AUDIO_CALL: stream_type = AUDIO_STREAM_VOICE; break; case AEM_AUDIO_RINGTONE: stream_type = AUDIO_STREAM_TTS; break; case AEM_AUDIO_LOCAL_MUSIC: stream_type = AUDIO_STREAM_LOCAL_MUSIC; break; case AEM_AUDIO_BT_MUSIC: stream_type = AUDIO_STREAM_MUSIC; break; default: break; } audio_system_set_stream_volume(stream_type, volume); }