media_effect_param.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2020, Actions Semi Co., Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #define SYS_LOG_DOMAIN "media"
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <sdfs.h>
  10. #include <audio_system.h>
  11. #include <media_effect_param.h>
  12. #define BTCALL_EFX_PATTERN "alcfg.bin"
  13. #define LINEIN_EFX_PATTERN "linein.efx"
  14. #define MUSIC_DRC_EFX_PATTERN "alcfg.bin"
  15. #define MUSIC_NO_DRC_EFX_PATTERN "alcfg.bin"
  16. static const void *btcall_effect_user_addr;
  17. static const void *linein_effect_user_addr;
  18. static const void *music_effect_user_addr;
  19. int medie_effect_set_user_param(uint8_t stream_type, uint8_t effect_type, const void *vaddr, int size)
  20. {
  21. const void **user_addr = NULL;
  22. int expected_size = 0;
  23. switch (stream_type) {
  24. case AUDIO_STREAM_VOICE:
  25. user_addr = &btcall_effect_user_addr;
  26. expected_size = sizeof(asqt_para_bin_t);
  27. break;
  28. case AUDIO_STREAM_LINEIN:
  29. user_addr = &linein_effect_user_addr;
  30. expected_size = sizeof(aset_para_bin_t);
  31. break;
  32. default:
  33. user_addr = &music_effect_user_addr;
  34. expected_size = sizeof(aset_para_bin_t);
  35. break;
  36. }
  37. printk("%s %d user_addr %p ,expected_size %dvaddr:%p size:%d\n",__FUNCTION__,__LINE__,user_addr,expected_size, vaddr, size);
  38. *user_addr = vaddr;
  39. return 0;
  40. }
  41. static const void *_media_effect_load(const char *efx_pattern, int *expected_size, uint8_t stream_type)
  42. {
  43. char efx_name[16];
  44. void *vaddr = NULL;
  45. int size = 0;
  46. strncpy(efx_name, efx_pattern, sizeof(efx_name));
  47. sd_fmap(efx_name, &vaddr, &size);
  48. if (!vaddr || !size) {
  49. SYS_LOG_ERR("not found");
  50. return NULL;
  51. }
  52. *expected_size = size;
  53. SYS_LOG_INF("%s", efx_name);
  54. return vaddr;
  55. }
  56. const void *media_effect_get_param(uint8_t stream_type, uint8_t effect_type, int *effect_size)
  57. {
  58. const void *user_addr = NULL;
  59. const char *efx_pattern = NULL;
  60. int expected_size = 0;
  61. switch (stream_type) {
  62. case AUDIO_STREAM_TTS: /* not use effect file */
  63. return NULL;
  64. case AUDIO_STREAM_VOICE:
  65. user_addr = btcall_effect_user_addr;
  66. efx_pattern = BTCALL_EFX_PATTERN;
  67. expected_size = sizeof(asqt_para_bin_t);
  68. break;
  69. case AUDIO_STREAM_LINEIN:
  70. user_addr = linein_effect_user_addr;
  71. efx_pattern = LINEIN_EFX_PATTERN;
  72. expected_size = sizeof(aset_para_bin_t);
  73. break;
  74. case AUDIO_STREAM_TWS:
  75. user_addr = music_effect_user_addr;
  76. efx_pattern = MUSIC_NO_DRC_EFX_PATTERN;
  77. expected_size = sizeof(aset_para_bin_t);
  78. break;
  79. default:
  80. user_addr = music_effect_user_addr;
  81. #ifdef CONFIG_MUSIC_DRC_EFFECT
  82. efx_pattern = MUSIC_DRC_EFX_PATTERN;
  83. #else
  84. efx_pattern = MUSIC_NO_DRC_EFX_PATTERN;
  85. #endif
  86. expected_size = sizeof(aset_para_bin_t);
  87. break;
  88. }
  89. if (!user_addr)
  90. user_addr = _media_effect_load(efx_pattern, &expected_size, stream_type);
  91. if (user_addr && effect_size)
  92. *effect_size = expected_size;
  93. return user_addr;
  94. }