signalstats_wrapper.h_ 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef SIGNALSTATS_WRAPPER_H
  2. #define SIGNALSTATS_WRAPPER_H
  3. #include <vector>
  4. #include <string>
  5. // #include <pybind11/pybind11.h>
  6. // #include <pybind11/numpy.h>
  7. #include <nlohmann/json.hpp>
  8. // 定义导出宏
  9. #ifdef _WIN32
  10. #ifdef BUILDING_DLL
  11. #define EXPORT_API __declspec(dllexport)
  12. #else
  13. #define EXPORT_API __declspec(dllimport)
  14. #endif
  15. #else
  16. #define EXPORT_API __attribute__((visibility("default")))
  17. #endif
  18. // namespace py = pybind11;
  19. namespace signalstats_wrapper
  20. {
  21. /**
  22. * @brief 初始化Python解释器
  23. *
  24. * 初始化嵌入式Python解释器并设置必要的Python路径。
  25. * 必须在调用任何Python相关功能前调用此函数。
  26. */
  27. EXPORT_API void initialize();
  28. /**
  29. * @brief 释放Python解释器
  30. *
  31. * 释放嵌入式Python解释器资源。
  32. * 应在程序结束时调用此函数。
  33. */
  34. EXPORT_API void finalize();
  35. /**
  36. * @brief C++接口封装函数
  37. *
  38. * @param output 输出结果容器
  39. * @param audio_signal 音频信号数据(vector)
  40. * @param audio_samplerate 采样率(Hz)
  41. * @param silence_threshold 静音检测阈值
  42. * @param db_threshold 分贝阈值
  43. * @param cv_threshold 变异系数阈值
  44. * @param window_params 窗函数参数
  45. * @param nperseg 每段样本数
  46. * @param noverlap 重叠样本数
  47. * @param nfft FFT点数
  48. * @param debug 是否输出调试信息
  49. */
  50. EXPORT_API nlohmann::json& detect_signal_wrapper(
  51. nlohmann::json &output,
  52. const std::vector<double> &audio_signal,
  53. double audio_samplerate,
  54. double silence_threshold = 3e-3,
  55. double db_threshold = -70.0,
  56. double cv_threshold = -70.0,
  57. const std::vector<std::string> &window_params = {"tukey", "0.25"},
  58. int nperseg = 256,
  59. int noverlap = 32,
  60. int nfft = 256,
  61. bool debug = false);
  62. }
  63. #endif // SIGNALSTATS_WRAPPER_H