signalstats.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 静音检测阈值
  36. * @param db_threshold 分贝阈值
  37. * @param cv_threshold 变异系数阈值
  38. * @param window_params 窗函数参数
  39. * @param nperseg 每段样本数
  40. * @param noverlap 重叠样本数
  41. * @param nfft FFT点数
  42. * @param debug 是否输出调试信息
  43. * @return nlohmann::json& 输出结果容器
  44. */
  45. EXPORT_API nlohmann::json& detect_signal(
  46. nlohmann::json &output,
  47. const std::vector<double> &audio_signal,
  48. double audio_samplerate,
  49. double silence_threshold = 3e-3,
  50. double db_threshold = -70.0,
  51. double cv_threshold = -70.0,
  52. const std::vector<std::string> &window_params = {"tukey", "0.25"},
  53. int nperseg = 256,
  54. int noverlap = 32,
  55. int nfft = 256,
  56. bool debug = false);
  57. }
  58. #endif // SIGNALSTATS_H