|
@@ -1,11 +1,13 @@
|
|
#include "NoiseDetectThread.h"
|
|
#include "NoiseDetectThread.h"
|
|
|
|
|
|
|
|
+#include <random>
|
|
|
|
|
|
#include "CreateWAVThread.h"
|
|
#include "CreateWAVThread.h"
|
|
#include "ThreadManager.h"
|
|
#include "ThreadManager.h"
|
|
#include "commonDefine.h"
|
|
#include "commonDefine.h"
|
|
#include "GlobalInfo.h"
|
|
#include "GlobalInfo.h"
|
|
#include "signalstats_wrapper.h"
|
|
#include "signalstats_wrapper.h"
|
|
|
|
+#include "spdlog.h"
|
|
|
|
|
|
|
|
|
|
NoiseDetectThread::NoiseDetectThread(CalculateThreadInfo_t& threadInfo)
|
|
NoiseDetectThread::NoiseDetectThread(CalculateThreadInfo_t& threadInfo)
|
|
@@ -86,18 +88,35 @@ bool NoiseDetectThread::initData()
|
|
auto sampleRate = GInfo.sampleRate();
|
|
auto sampleRate = GInfo.sampleRate();
|
|
m_sample_rate = static_cast<double>(sampleRate);
|
|
m_sample_rate = static_cast<double>(sampleRate);
|
|
|
|
|
|
|
|
+ /* 初始化噪音检测功能 */
|
|
|
|
+ signalstats_wrapper::initialize();
|
|
|
|
+
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
/* 清理数据 */
|
|
/* 清理数据 */
|
|
void NoiseDetectThread::clearData()
|
|
void NoiseDetectThread::clearData()
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+ /* 释放资源 */
|
|
|
|
+ signalstats_wrapper::finalize();
|
|
}
|
|
}
|
|
|
|
|
|
/* 调用动态库检测噪音 */
|
|
/* 调用动态库检测噪音 */
|
|
bool NoiseDetectThread::detectNoise()
|
|
bool NoiseDetectThread::detectNoise()
|
|
{
|
|
{
|
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "{} 开始调用动态库计算噪音", m_logBase);
|
|
|
|
+ SPDLOG_LOGGER_INFO(m_logger, "{} 左声道数据大小: {}, 右声道数据大小: {}",
|
|
|
|
+ m_logBase, m_leftRightData.vecLeftData.size(), m_leftRightData.vecRightData.size());
|
|
|
|
+
|
|
|
|
+ // std::vector<double> audio_signal(48000);
|
|
|
|
+ // std::random_device rd;
|
|
|
|
+ // std::mt19937 gen(rd());
|
|
|
|
+ // std::normal_distribution<> dist(0.0, 1.0);
|
|
|
|
+
|
|
|
|
+ // for (auto& sample : audio_signal) {
|
|
|
|
+ // sample = dist(gen);
|
|
|
|
+ // }
|
|
|
|
+
|
|
auto startTime = std::chrono::steady_clock::now();
|
|
auto startTime = std::chrono::steady_clock::now();
|
|
bool isNoiseLeft = false; /* 是否检测到左声道噪音 */
|
|
bool isNoiseLeft = false; /* 是否检测到左声道噪音 */
|
|
bool isNoiseRight = false; /* 是否检测到右声道噪音 */
|
|
bool isNoiseRight = false; /* 是否检测到右声道噪音 */
|
|
@@ -108,6 +127,7 @@ bool NoiseDetectThread::detectNoise()
|
|
auto ret = signalstats_wrapper::detect_signal_wrapper(
|
|
auto ret = signalstats_wrapper::detect_signal_wrapper(
|
|
jsonOutput, /* 返回结果,和jsonResult是一样的 */
|
|
jsonOutput, /* 返回结果,和jsonResult是一样的 */
|
|
m_leftRightData.vecLeftData, /* 左声道数据 */
|
|
m_leftRightData.vecLeftData, /* 左声道数据 */
|
|
|
|
+ // audio_signal, /* 测试数据 */
|
|
m_sample_rate, /* 采样率(HZ) */
|
|
m_sample_rate, /* 采样率(HZ) */
|
|
m_silence_threshold, /* 静音阈值 */
|
|
m_silence_threshold, /* 静音阈值 */
|
|
m_db_threshold, /* 分贝阈值 */
|
|
m_db_threshold, /* 分贝阈值 */
|
|
@@ -116,15 +136,21 @@ bool NoiseDetectThread::detectNoise()
|
|
m_nperseg, /* 每段样本数 */
|
|
m_nperseg, /* 每段样本数 */
|
|
m_noverlap, /* 重叠样本数 */
|
|
m_noverlap, /* 重叠样本数 */
|
|
m_nfft, /* FFT点数 */
|
|
m_nfft, /* FFT点数 */
|
|
- false /* 是否输出调试信息, true表示输出调试信息, false表示不输出调试信息 */
|
|
|
|
|
|
+ true /* 是否输出调试信息, true表示输出调试信息, false表示不输出调试信息 */
|
|
);
|
|
);
|
|
isNoiseLeft = jsonOutput["noise"].is_null() ? false : jsonOutput["noise"].get<bool>();
|
|
isNoiseLeft = jsonOutput["noise"].is_null() ? false : jsonOutput["noise"].get<bool>();
|
|
|
|
|
|
|
|
+ std::chrono::duration<double> duration = std::chrono::steady_clock::now() - startTime;
|
|
|
|
+ std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
|
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "{} 计算左声道噪音耗时: {}ms", m_logBase, ms.count());
|
|
|
|
+ startTime = std::chrono::steady_clock::now(); /* 重置开始时间 */
|
|
|
|
+
|
|
/*-------------------------- 再检测右声道 --------------------------*/
|
|
/*-------------------------- 再检测右声道 --------------------------*/
|
|
jsonOutput.clear(); /* 清空输出结果 */
|
|
jsonOutput.clear(); /* 清空输出结果 */
|
|
signalstats_wrapper::detect_signal_wrapper(
|
|
signalstats_wrapper::detect_signal_wrapper(
|
|
jsonOutput, /* 返回结果,和jsonResult是一样的 */
|
|
jsonOutput, /* 返回结果,和jsonResult是一样的 */
|
|
m_leftRightData.vecRightData, /* 右声道数据 */
|
|
m_leftRightData.vecRightData, /* 右声道数据 */
|
|
|
|
+ // audio_signal, /* 测试数据 */
|
|
m_sample_rate, /* 采样率(HZ) */
|
|
m_sample_rate, /* 采样率(HZ) */
|
|
m_silence_threshold, /* 静音阈值 */
|
|
m_silence_threshold, /* 静音阈值 */
|
|
m_db_threshold, /* 分贝阈值 */
|
|
m_db_threshold, /* 分贝阈值 */
|
|
@@ -146,9 +172,9 @@ bool NoiseDetectThread::detectNoise()
|
|
|
|
|
|
std::chrono::duration<double> duration = std::chrono::steady_clock::now() - startTime;
|
|
std::chrono::duration<double> duration = std::chrono::steady_clock::now() - startTime;
|
|
std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
|
|
std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
|
|
- SPDLOG_LOGGER_DEBUG(m_logger, "{} 调用动态库检测噪音耗时: {}ms", m_logBase, ms.count());
|
|
|
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "{} 计算右声道噪音耗时: {}ms", m_logBase, ms.count());
|
|
|
|
|
|
- SPDLOG_LOGGER_DEBUG(m_logger, "{} 左声道噪音检测结果: {}, 右声道噪音检测结果: {}", m_logBase, isNoiseLeft, isNoiseRight);
|
|
|
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "{} 左声道噪音检测结果: {}, 右声道噪音检测结果: {}", m_logBase, isNoiseLeft, isNoiseRight);
|
|
|
|
|
|
/* -------------------------- 和以往的结果对比 --------------------------*/
|
|
/* -------------------------- 和以往的结果对比 --------------------------*/
|
|
m_isNoiseLast = m_isNoise.load(); /* 上一次的噪音检测结果 */
|
|
m_isNoiseLast = m_isNoise.load(); /* 上一次的噪音检测结果 */
|