123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #include "c1.h"
- #include "AudioRecord.h"
- #include <chrono>
- #include <thread>
- #include "spdlog/spdlog.h"
- #include "RingQueueManualMutex.hpp"
- AudioLeftRightData::AudioLeftRightData(int totalSize)
- {
- // if (totalSize == 0)
- // {
- // SPDLOG_ERROR("AudioLeftRightData::AudioLeftRightData totalSize is 0");
- // return;
- // }
- this->totalSize = totalSize;
- vecLeftData.reserve(totalSize);
- vecRightData.reserve(totalSize);
- startTime = QDateTime();
- endTime = QDateTime();
- numMSecond = 0;
- }
- AudioLeftRightData::~AudioLeftRightData()
- {
-
- }
- AudioLeftRightData::AudioLeftRightData(const AudioLeftRightData& obj)
- {
- *this = obj; // 使用赋值运算符进行深拷贝
- }
- AudioLeftRightData& AudioLeftRightData::operator=(const AudioLeftRightData &obj)
- {
- if (this == &obj)
- {
- return *this; // 防止自赋值
- }
- // 释放原有资源
- vecLeftData.clear();
- vecRightData.clear();
- // 复制数据
- totalSize = obj.totalSize;
- vecLeftData = obj.vecLeftData;
- vecRightData = obj.vecRightData;
- // 复制时间戳
- startTime = obj.startTime;
- endTime = obj.endTime;
- numMSecond = obj.numMSecond;
- return *this;
- }
- void c1::test1()
- {
- RingQueueManualMutex<AudioLeftRightData*> listData(10);
- SPDLOG_INFO("开始添加 listData 数据");
- for(int i = 0; i < 10; ++i)
- {
- AudioLeftRightData* data = new AudioLeftRightData(48000);
- for(int j = 0; j < 48000; ++j)
- {
- data->vecLeftData.push_back(0.5); // 模拟数据
- data->vecRightData.push_back(0.5); // 模拟数据
- }
- listData.push(data);
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
- }
- SPDLOG_INFO("添加 listData 数据完成, 当前数据大小: {}", listData.QueueSize());
- std::this_thread::sleep_for(std::chrono::milliseconds(10000));
- /* 开始释放数据 */
- SPDLOG_INFO("开始释放 listData 数据");
- while (!listData.isEmpty())
- {
- AudioLeftRightData* data = listData.front_pop();
- if(data != nullptr)
- {
- delete data;
- data = nullptr;
- }
- }
- SPDLOG_INFO("释放 listData 数据完成");
- std::this_thread::sleep_for(std::chrono::milliseconds(5000));
- SPDLOG_INFO("结束 test1");
- }
|