123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #ifndef _CALULATEAUDIO_H_
- #define _CALULATEAUDIO_H_
- #include <string>
- #include "GlobalVariable.h"
- #include "ChannelParam.h"
- #include "RingQueueManualMutex.hpp"
- struct OneSecondData;
- /**
- * @brief 音频数据数量信息
- *
- */
- struct StAudioNum
- {
- StAudioNum();
- StAudioNum(const StAudioNum& obj) { *this = obj; }
- SoundCardRoadInfo_t roadInfo; /* 通道ID */
- int nTotal; /* 总数据包数 */
- int nLDataNum; // 音频数据正数个数
- int nLUnDataNum; // 音频数据负数个数
- int nRDataNum; // 音频数据正数个数
- int nRUnDataNum; // 音频数据负数个数
- /* 判断条件 */
- int pcmErrorPercent = 0; // 音频不对称百分比
- int pcmLessPercent = 0; // 音频少于百分比
- // std::string strRoadName; // 通道名称
- StAudioNum& operator=(const StAudioNum& obj);
- bool AudioIsError(int nDataNum, int nUnDataNum, bool bLeft);
- // 有问题的音频
- bool IsErrorAudio();
- };
- /**
- * @brief 计算DB和反相的类
- *
- */
- class CAudio2ChanCorrelator
- {
- public:
- CAudio2ChanCorrelator();
- virtual ~CAudio2ChanCorrelator();
- public:
- // correlate data contained in A & B buffers
- int CorrelateChunks(const short * ptrBufferA, const short * ptrBufferB, int nBufferLength,
- short* pMaxA, short* pMaxB,
- short* pRMSA, short* pRMSB,
- StAudioNum &audioInfo);
- int CorrelateChunks(const short * ptrBufferA, const short * ptrBufferB, int nBufferLength,
- short* pMaxA, short* pMaxB,
- short* pRMSA, short* pRMSB,
- short* pLRAvg);
- // returns current correlation value (between -100 to 100)
- int GetCorrelationLevel(void);
- private:
- int m_nDisplayCutOffLevel; // levels below this value will not be processed
- bool m_bSignA; // phase of A sample
- float m_fCorrelationSum; // holds the summation of the correlation process
- int m_nCorrelationValue; // current correlation value
- float m_fDampingFactor; // value between 0 and 1
- };
- /*--------------------------------------------------------------------------
- * 全局函数定义
- *--------------------------------------------------------------------------*/
- /* 计算DB的全局函数 */
- int calculateDB(short val);
- /*--------------------------------------------------------------------------
- * 计算音量的静音、过载、反相等功能的类
- *--------------------------------------------------------------------------*/
- /**
- * @brief 封装一层音量计算需要的函数,方便计算
- *
- */
- class CaculateDBData
- {
- public:
- CaculateDBData();
- ~CaculateDBData();
- /* 是否有数据 */
- bool isEmpty() const { return ringQueue.isEmpty(); }
- /* 设置偏移值 */
- void setOffset(long offset);
- /* 计算静音 */
- bool calculateSilent(const StVolumeParam& param, const int avgDBSeconds, int& startPos, int& endPos);
- /* 计算过载 */
- bool calculateOverload(const StVolumeParam& param, const int avgDBSeconds, int& startPos, int& endPos, bool isLastOverload);
- /* 计算反相 */
- bool calculatePhase(const StVolumeParam& param, const int avgDBSeconds, int& startPos, int& endPos, bool isLastReversed);
- /* 判断平均音量是否低于设置的值 */
- bool isAvgDBLessThan(const long minDBLongTime, const long minDB);
- /* 计算正弦波是否是噪音,正弦波几秒直接判断为噪音 */
- bool isSinDB(const int sinSeconds, const int calSeconds, int& leftDB, int& rightDB);
- RingQueueManualMutex<OneSecondData*> ringQueue;
- private:
- /* 偏移值,数据只访问最新的数据,所以这个是向前偏移 */
- int m_offset = 0;
- };
- #endif // _CALULATEAUDIO_H_
|