aem_adapter_audio.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #include "aem_adapter_audio.h"
  2. #include "aem_log.h"
  3. #include "aem_app_err_if.h"
  4. #include "tts_manager.h"
  5. #include "audio_system.h"
  6. #include "audio_policy.h"
  7. #include "volume_manager.h"
  8. #include "bt_manager.h"
  9. #include "aem_video_service.h"
  10. const uint8_t *tts_file_name[AEM_RINGTONE_MAX] =
  11. {
  12. "callring.act",
  13. "welcome.act",
  14. "poweroff.act",
  15. };
  16. int aem_tts_play(uint8_t *name)
  17. {
  18. #if CONFIG_VIDEO_PLAYER
  19. if (aem_is_video_running() == true)
  20. {
  21. return -1;
  22. }
  23. #endif
  24. if (NULL == name)
  25. return AEM_ERR_NULL;
  26. return tts_manager_play(name, PLAY_IMMEDIATELY);
  27. }
  28. int aem_tts_stop(void)
  29. {
  30. int ret = AEM_OK;
  31. // aem_set_audio_system_mute(AEM_AUDIO_RINGTONE, 0);
  32. ret = tts_manager_stop(NULL);
  33. tts_manager_wait_finished(true);
  34. // aem_set_audio_system_mute(AEM_AUDIO_RINGTONE, 1);
  35. return ret;
  36. }
  37. void aem_tts_event_cb_register(aem_audio_event_cb event_cb)
  38. {
  39. tts_event_nodify lisener = (tts_event_nodify)event_cb;
  40. tts_manager_add_event_lisener(lisener);
  41. }
  42. #ifdef CONFIG_BT_AVRCP
  43. static int aem_bt_transmit_sync_vol_to_remote(int volume)
  44. {
  45. int max_volume = audio_policy_get_volume_level();
  46. uint8_t avrcp_vol; /* percentage */
  47. if (!bt_manager_trs_get_connected_dev_num())
  48. {
  49. return -ENODEV;
  50. }
  51. if (volume <= 0)
  52. {
  53. avrcp_vol = 0;
  54. }
  55. else if (volume >= max_volume)
  56. {
  57. avrcp_vol = 127;
  58. }
  59. else
  60. {
  61. avrcp_vol = (uint8_t)(volume * 127 / max_volume);
  62. }
  63. SYS_LOG_INF("volume %d -> remote %d\n", volume, avrcp_vol);
  64. return bt_manager_avrcp_set_absolute_volume(BTSRV_DEVICE_PLAYER, &avrcp_vol, 1);
  65. }
  66. #endif
  67. int aem_set_system_volume(aem_volume_type_e type, int volume)
  68. {
  69. int vol = volume % (aem_get_system_max_volume() + 1);
  70. audio_stream_type_e stream_type = AUDIO_STREAM_TTS;
  71. switch (type)
  72. {
  73. case AEM_AUDIO_CALL:
  74. stream_type = AUDIO_STREAM_VOICE;
  75. break;
  76. case AEM_AUDIO_RINGTONE:
  77. stream_type = AUDIO_STREAM_TTS;
  78. break;
  79. case AEM_AUDIO_LOCAL_MUSIC:
  80. stream_type = AUDIO_STREAM_LOCAL_MUSIC;
  81. #ifdef CONFIG_BT_AVRCP
  82. aem_bt_transmit_sync_vol_to_remote(vol);
  83. #endif
  84. break;
  85. case AEM_AUDIO_BT_MUSIC:
  86. stream_type = AUDIO_STREAM_MUSIC;
  87. break;
  88. default:
  89. break;
  90. }
  91. return system_volume_set(stream_type, volume, false);
  92. }
  93. int aem_get_system_volume(aem_volume_type_e type)
  94. {
  95. audio_stream_type_e stream_type = AUDIO_STREAM_TTS;
  96. switch (type)
  97. {
  98. case AEM_AUDIO_CALL:
  99. stream_type = AUDIO_STREAM_VOICE;
  100. break;
  101. case AEM_AUDIO_RINGTONE:
  102. stream_type = AUDIO_STREAM_TTS;
  103. break;
  104. case AEM_AUDIO_LOCAL_MUSIC:
  105. stream_type = AUDIO_STREAM_LOCAL_MUSIC;
  106. break;
  107. case AEM_AUDIO_BT_MUSIC:
  108. stream_type = AUDIO_STREAM_MUSIC;
  109. break;
  110. default:
  111. break;
  112. }
  113. return system_volume_get(stream_type);
  114. }
  115. int aem_get_system_min_volume(void)
  116. {
  117. return audio_system_get_min_volume();
  118. }
  119. int aem_get_system_max_volume(void)
  120. {
  121. return audio_system_get_max_volume();
  122. }
  123. int aem_get_system_microphone_muted(void)
  124. {
  125. return audio_system_get_microphone_muted();
  126. }
  127. void aem_set_system_microphone_muted(int value)
  128. {
  129. audio_system_mute_microphone(value);
  130. }
  131. int aem_get_audio_system_mute(aem_volume_type_e type)
  132. {
  133. audio_stream_type_e stream_type = AUDIO_STREAM_TTS;
  134. switch (type)
  135. {
  136. case AEM_AUDIO_CALL:
  137. stream_type = AUDIO_STREAM_VOICE;
  138. break;
  139. case AEM_AUDIO_RINGTONE:
  140. stream_type = AUDIO_STREAM_TTS;
  141. break;
  142. case AEM_AUDIO_LOCAL_MUSIC:
  143. stream_type = AUDIO_STREAM_LOCAL_MUSIC;
  144. break;
  145. case AEM_AUDIO_BT_MUSIC:
  146. stream_type = AUDIO_STREAM_MUSIC;
  147. break;
  148. default:
  149. break;
  150. }
  151. return audio_system_get_stream_mute(stream_type);
  152. }
  153. void aem_set_audio_system_mute(aem_volume_type_e type, int mute)
  154. {
  155. audio_stream_type_e stream_type = AUDIO_STREAM_TTS;
  156. switch (type)
  157. {
  158. case AEM_AUDIO_CALL:
  159. stream_type = AUDIO_STREAM_VOICE;
  160. break;
  161. case AEM_AUDIO_RINGTONE:
  162. stream_type = AUDIO_STREAM_TTS;
  163. break;
  164. case AEM_AUDIO_LOCAL_MUSIC:
  165. stream_type = AUDIO_STREAM_LOCAL_MUSIC;
  166. break;
  167. case AEM_AUDIO_BT_MUSIC:
  168. stream_type = AUDIO_STREAM_MUSIC;
  169. break;
  170. default:
  171. break;
  172. }
  173. audio_system_set_stream_mute(stream_type, mute);
  174. }
  175. void aem_audio_system_set_stream_volume(aem_volume_type_e type, int volume)
  176. {
  177. audio_stream_type_e stream_type = AUDIO_STREAM_TTS;
  178. switch (type)
  179. {
  180. case AEM_AUDIO_CALL:
  181. stream_type = AUDIO_STREAM_VOICE;
  182. break;
  183. case AEM_AUDIO_RINGTONE:
  184. stream_type = AUDIO_STREAM_TTS;
  185. break;
  186. case AEM_AUDIO_LOCAL_MUSIC:
  187. stream_type = AUDIO_STREAM_LOCAL_MUSIC;
  188. break;
  189. case AEM_AUDIO_BT_MUSIC:
  190. stream_type = AUDIO_STREAM_MUSIC;
  191. break;
  192. default:
  193. break;
  194. }
  195. audio_system_set_stream_volume(stream_type, volume);
  196. }