29 lines
948 B
C++
29 lines
948 B
C++
|
#include "BoostLog.h"
|
||
|
#include "DateTime.h"
|
||
|
#include "main.h"
|
||
|
#include <filesystem>
|
||
|
#include <sstream>
|
||
|
|
||
|
void RecorderTask::run() {
|
||
|
constexpr auto path = "/sdcard/data";
|
||
|
if (!std::filesystem::exists(path)) {
|
||
|
std::filesystem::create_directory(path);
|
||
|
}
|
||
|
std::ostringstream oss;
|
||
|
oss << path << "/" << DateTime::currentDateTime().toString("%Y%m%d%H%M%S") << ".pcm";
|
||
|
auto filePath = oss.str();
|
||
|
m_ofs = std::make_shared<std::ofstream>(filePath, std::ofstream::binary);
|
||
|
|
||
|
RkAudio::Format format;
|
||
|
format.channels = 2;
|
||
|
format.period = 64;
|
||
|
m_input = std::make_shared<RkAudio::Input>();
|
||
|
m_input->setDataCallback(
|
||
|
[this](const RkAudio::Frame &frame) { m_ofs->write(reinterpret_cast<const char *>(frame.data), frame.byteSize); });
|
||
|
|
||
|
if (m_input->open(format, false)) {
|
||
|
LOG(info) << "open record succeed, path: " << filePath;
|
||
|
} else {
|
||
|
LOG(info) << "open record failed.";
|
||
|
}
|
||
|
}
|