rms_api.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef RMS_API_H
  2. #define RMS_API_H
  3. int get_rms_buf(int section, int time, int fs, int switch_1);
  4. void rms_init(void *ptr, int section, int fs, int time, int switch_1, float attackFactor, float releaseFactor, int D_time, float alpha);
  5. int rms(void *ptr, short *in_buf, int len);
  6. typedef struct __spectrum_rms {
  7. int switch_1;
  8. float attackFactor;//平滑因子
  9. float releaseFactor;
  10. float alpha;//最值的平滑因子
  11. int section;
  12. int fs;
  13. short *index;//索引
  14. short *cache;//缓存地址
  15. float *DB;//记录增益
  16. int time;//缓存时间,ms为单位
  17. int T_num;//缓存时间内的点数
  18. int D_time;//跟新db的时间
  19. int counter;//计数器
  20. int *max;//记录最大值
  21. int T;//缓存长度
  22. long long *add;//求和累加
  23. int _T;
  24. int pool[0];
  25. } spec_rms;
  26. #if 0
  27. rms.a库说明:
  28. 该库计算的是经过滤波后的信号的db值,其中包括打开rms计算db和关闭rms计算db两种模式;
  29. 调用说明:
  30. buf_size = get_rms_buf(section, time, fs, switch_1); //获取buf大小:
  31. section:
  32. 段数(可配置),
  33. time: 缓存时间(单位毫秒,整形输入),
  34. fs:
  35. 采样频率,
  36. switch_1:模式开关(1打开rms,0关闭rms),
  37. work_buf = malloc(buf_size); //申请内存
  38. rms_init(work_buf, channel, section, fs, time, switch_1, attackFactor, releaseFactor);
  39. 初始化:
  40. channel:声道数,
  41. attackFactor, releaseFactor:下降因子和上升因子(范围0 - 1,建议attackFactor取较大值)
  42. attackFactor 1 releaseFactor 1不能设置成1, 设置成1永远都是0
  43. attackFactor取大,db值降的慢,releaseFactor取大,db值升的慢
  44. rms(work_buf, in_buf, out_buf, len);//运行
  45. in_buf 输入数据,16bit
  46. out_buf 输出数据,16bit
  47. len 数据长度(其中一段滤波器的点数)
  48. 数据输出为单通道并行输出
  49. #endif
  50. #endif