GlobalInfo.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "GlobalInfo.h"
  2. #include <QCoreApplication>
  3. #include <QDir>
  4. GlobalInfo::~GlobalInfo()
  5. {
  6. }
  7. /* 初始化全局信息 */
  8. void GlobalInfo::initGlobalInfo()
  9. {
  10. /* 初始化文件夹 */
  11. initDirectories();
  12. /* 初始化数据 */
  13. initData();
  14. }
  15. /* 初始化文件夹 */
  16. void GlobalInfo::initDirectories()
  17. {
  18. /* 拼接文件夹路径 */
  19. QString appDataPath = QCoreApplication::applicationDirPath();
  20. m_wavPath = appDataPath + "/" + m_dirWav;
  21. m_longWavPath = appDataPath + "/" + m_dirLongWav;
  22. m_alarmWavPath = appDataPath + "/" + m_dirAlarm;
  23. m_configPath = appDataPath + "/" + m_dirConfig;
  24. /* 判断相关文件夹是否存在 */
  25. QDir dirWav(m_wavPath);
  26. if (!dirWav.exists()) {
  27. dirWav.mkpath(m_wavPath); // 创建wav文件夹
  28. }
  29. QDir dirLongWav(m_longWavPath);
  30. if (!dirLongWav.exists()) {
  31. dirLongWav.mkpath(m_longWavPath); // 创建录音长文件文件夹
  32. }
  33. QDir dirAlarmWav(m_alarmWavPath);
  34. if (!dirAlarmWav.exists()) {
  35. dirAlarmWav.mkpath(m_alarmWavPath); // 创建报警文件夹
  36. }
  37. /* 清空wav文件夹中的内容 */
  38. dirWav.setFilter(QDir::Files | QDir::NoDotAndDotDot);
  39. QFileInfoList fileList = dirWav.entryInfoList();
  40. for (const QFileInfo &fileInfo : fileList)
  41. {
  42. QFile::remove(fileInfo.filePath()); // 删除文件
  43. }
  44. }
  45. /* 初始化默认数据 */
  46. void GlobalInfo::initData()
  47. {
  48. m_sampleRate = 48000; /* 采样率 */
  49. m_numChannels = 2; /* 声道数 */
  50. m_bitsPerSample = 16; /* 每个采样点的位数 */
  51. m_oneSecondCount = m_sampleRate * m_numChannels * 2; /* 48khz * 2字节/采样点 * 2声道 */
  52. m_wavQueueElementCount = 60; /* 环形队列元素数目,默认是1分钟数据 */
  53. m_wavFileDuration = 60; /* 默认是1分钟数据 */
  54. /* 初始化环形队列元素数目 */
  55. m_wavQueueElementCount = 60; /* 默认是1分钟数据 */
  56. m_pcmErrorPercent = 10; /* 音频不对称百分比 */
  57. m_pcmLessPercent = 0; /* 音频少于百分比,默认不开放这个功能 */
  58. }