FaceAccess/Record/main.h

107 lines
2.3 KiB
C
Raw Normal View History

2024-09-04 17:57:23 +08:00
#ifndef __MAIN_H__
#define __MAIN_H__
#include "RkAudio.h"
#include <fstream>
#include <memory>
2024-09-04 20:17:15 +08:00
class SpeexDsp;
2024-09-05 12:24:05 +08:00
class WebRtcAecm;
2024-09-06 09:45:44 +08:00
enum Dsp {
Vqe,
Speex,
AecMobile,
Aec3,
};
2024-09-06 16:35:51 +08:00
constexpr auto DumpPath = "/sdcard/data";
2024-09-04 17:57:23 +08:00
class Task {
public:
virtual void run() = 0;
2024-09-06 09:45:44 +08:00
virtual ~Task() {
}
2024-09-04 17:57:23 +08:00
};
class RecorderTask : public Task {
public:
void run() final;
private:
std::shared_ptr<RkAudio::Input> m_input;
std::shared_ptr<std::ofstream> m_ofs;
};
class PlayerTask : public Task {
public:
2024-09-04 20:17:15 +08:00
void setChannels(int channels);
2024-09-04 17:57:23 +08:00
void setPath(const std::string &path);
void run() final;
protected:
void play();
private:
2024-09-04 20:17:15 +08:00
int m_channels = 2;
2024-09-04 17:57:23 +08:00
std::string m_path;
2024-09-04 20:17:15 +08:00
std::vector<char> m_buffer;
2024-09-04 17:57:23 +08:00
std::shared_ptr<std::ifstream> m_ifs;
std::shared_ptr<RkAudio::Output> m_output;
};
2024-09-06 09:45:44 +08:00
class EchoRecordPrivate;
2024-09-04 17:57:23 +08:00
class EchoRecordTask : public Task {
public:
2024-09-06 09:45:44 +08:00
EchoRecordTask();
~EchoRecordTask();
void setDsp(Dsp dsp);
2024-09-06 16:35:51 +08:00
void setDumpEnabled(bool enabled);
2024-09-04 17:57:23 +08:00
void setChannels(int channels);
void run() final;
private:
int m_channels = 2;
2024-09-06 09:45:44 +08:00
Dsp m_dsp = Vqe;
2024-09-04 17:57:23 +08:00
std::shared_ptr<RkAudio::Output> m_output;
std::shared_ptr<RkAudio::Input> m_input;
2024-09-04 20:17:15 +08:00
std::shared_ptr<SpeexDsp> m_speex;
2024-09-05 12:24:05 +08:00
std::shared_ptr<WebRtcAecm> m_webRtcAecm;
std::vector<uint8_t> m_outBuffer;
std::vector<uint8_t> m_nearendBuffer;
std::vector<uint8_t> m_farendBuffer;
2024-09-06 09:45:44 +08:00
EchoRecordPrivate *m_d = nullptr;
2024-09-06 16:35:51 +08:00
std::shared_ptr<std::ofstream> m_outOfs;
std::shared_ptr<std::ofstream> m_micOfs;
};
class ProcessFileTaskPrivate;
class ProcessFileTask : public Task {
public:
ProcessFileTask();
~ProcessFileTask();
void setDsp(Dsp dsp);
void run() final;
protected:
void process();
private:
ProcessFileTaskPrivate *m_d = nullptr;
Dsp m_dsp = Speex;
std::shared_ptr<SpeexDsp> m_speex;
std::shared_ptr<WebRtcAecm> m_webRtcAecm;
std::shared_ptr<std::ifstream> m_speakerIfs;
std::shared_ptr<std::ifstream> m_micIfs;
std::shared_ptr<std::ofstream> m_ofs;
2024-09-06 23:06:54 +08:00
std::shared_ptr<std::ofstream> m_nsOfs; // 降噪后的文件
2024-09-06 16:35:51 +08:00
std::string m_outFilename;
std::chrono::system_clock::time_point m_begin;
2024-09-04 17:57:23 +08:00
};
2024-09-06 09:45:44 +08:00
Dsp dspFromString(const std::string &dsp);
std::string dspToString(Dsp dsp);
2024-09-04 17:57:23 +08:00
#endif // __MAIN_H__