signalstats.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef SIGNALSTATS_H
  2. #define SIGNALSTATS_H
  3. #include <nlohmann/json.hpp>
  4. // 定义导出宏
  5. #ifdef _WIN32
  6. #ifdef BUILDING_DLL
  7. #define EXPORT_API __declspec(dllexport)
  8. #else
  9. #define EXPORT_API __declspec(dllimport)
  10. #endif
  11. #else
  12. #define EXPORT_API __attribute__((visibility("default")))
  13. #endif
  14. namespace signalstats
  15. {
  16. /**
  17. * @brief 初始化
  18. * 必须在使用前调用此函数。
  19. *
  20. * @param debug 是否输出调试信息
  21. */
  22. EXPORT_API void initialize(bool debug=false);
  23. /**
  24. * @brief 释放资源
  25. *
  26. * 应在程序结束时调用此函数。
  27. */
  28. EXPORT_API void finalize();
  29. /**
  30. * @brief 信号检测
  31. *
  32. * @param output 输出结果容器
  33. * @param audio_signal 音频信号数据(vector)
  34. * @param audio_samplerate 采样率(Hz)
  35. * @param silence_threshold 信号强度之静音检测阈值(默认-60.0),范围(-100,0],单位dBFS(相对于满量程的分贝)
  36. * @param db_threshold 能量强度之噪声分贝阈值(默认-70.0),范围[-100,0],单位dB
  37. * @param cv_threshold 能量强度之变异系数阈值(默认-70.0),范围[-100,0],单位dB
  38. * @param window_params 窗函数参数,窗函数类型和参数(默认("tukey", 0.25)),alpha (0.0,1.0)
  39. * @param nperseg 每段样本数(默认256),正整数
  40. * @param noverlap 重叠样本数(默认32),正整数
  41. * @param nfft FFT点数(默认256),正整数
  42. * @return nlohmann::json& 输出结果容器
  43. */
  44. EXPORT_API nlohmann::json& detect_signal(
  45. nlohmann::json &output,
  46. const std::vector<double> &audio_signal,
  47. double audio_samplerate,
  48. double silence_threshold = -60.0,
  49. double db_threshold = -70.0,
  50. double cv_threshold = -70.0,
  51. const std::vector<std::string> &window_params = {"tukey", "0.25"},
  52. int nperseg = 256,
  53. int noverlap = 32,
  54. int nfft = 256);
  55. }
  56. #endif // SIGNALSTATS_H