spectrum_eq.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef SPECTRUM_API_H
  2. #define SPECTRUM_API_H
  3. #include "media/spectrum/coeff_calculate_api.h"
  4. #include "media/spectrum/rms_api.h"
  5. #include "application/audio_eq.h"
  6. #include "media/audio_stream.h"
  7. typedef struct _spectrum_open_parm {
  8. u32 sr;
  9. u32 channel: 4;
  10. u32 section: 6;
  11. u32 rms_en: 1;
  12. u32 time_ms: 4;
  13. u32 d_time: 16; //50ms~500ms
  14. float alpha;//(0~1)
  15. float attackFactor;
  16. float releaseFactor;
  17. int *freq_center;
  18. int *quality_factor;
  19. void *priv;
  20. int (*output)(void *priv, float *db, u32 len);//user define
  21. } spectrum_open_parm;
  22. typedef struct _spectrum_hdl {
  23. void *rms_hdl;//算db值
  24. int *coeff; //存放系数的地址
  25. struct audio_eq *eq[10];
  26. u32 data_len;
  27. s16 *data;//输出数据地址
  28. spectrum_open_parm parm;
  29. struct audio_stream_entry entry; // 音频流入口
  30. } spectrum_hdl;
  31. spectrum_hdl *audio_spectrum_open(spectrum_open_parm *parm);
  32. int audio_spectrum_close(spectrum_hdl *hdl);
  33. #if 0
  34. //例子
  35. /*----------------------------------------------------------------------------*/
  36. /**@brief 频响输出回调
  37. @param data:db值存放的首地址,连续存放 len 个 float型的db值
  38. @return len
  39. @note
  40. */
  41. /*----------------------------------------------------------------------------*/
  42. int spectrum_output(void *priv, float *data, u32 len)
  43. {
  44. u8 db_num = len;
  45. float *tar_data = data;
  46. for (int i = 0; i < db_num; i++) {
  47. //输出10个 浮点db值
  48. /* printf("tar_data db 0x%x\n", *(int *)&tar_data[i]); */
  49. //printf("tar_data db %d.%d\n", (int )tar_data[i],(int)((int)(tar_data[i]*100)%100));
  50. }
  51. return len;
  52. }
  53. static u32 freq[] = {31, 62, 125, 250, 500, 1000, 2000, 4000, 8000, 16000};
  54. static u32 quality[] = {
  55. (int)(0.7f * (1 << 24)), (int)(0.7f * (1 << 24)),
  56. (int)(0.7f * (1 << 24)), (int)(0.7f * (1 << 24)),
  57. (int)(0.7f * (1 << 24)), (int)(0.7f * (1 << 24)),
  58. (int)(0.7f * (1 << 24)), (int)(0.7f * (1 << 24)),
  59. (int)(0.7f * (1 << 24)), (int)(0.7f * (1 << 24))
  60. };
  61. /*----------------------------------------------------------------------------*/
  62. /**@brief 打开频响统计
  63. @param sr:采样率
  64. @return hdl:句柄
  65. @note
  66. */
  67. /*----------------------------------------------------------------------------*/
  68. spectrum_hdl *spectrum_open_demo(u32 sr)
  69. {
  70. #if TCFG_EQ_ENABLE
  71. spectrum_hdl *hdl = NULL;
  72. spectrum_open_parm parm = {0};
  73. parm.sr = sr;
  74. parm.channel = 1;
  75. parm.section = EQ_SECTION_MAX;
  76. parm.rms_en = 1;
  77. parm.time_ms = 5;
  78. parm.attackFactor = 0.9;
  79. parm.releaseFactor = 0.9;
  80. parm.freq_center = freq;
  81. parm.quality_factor = quality;
  82. parm.d_time = 100;
  83. parm.alpha = 0.9;
  84. parm.priv = NULL;
  85. parm.output = spectrum_output;
  86. hdl = audio_spectrum_open(&parm);
  87. return hdl;
  88. #else
  89. return NULL;
  90. #endif
  91. }
  92. #endif
  93. #endif