add code.

This commit is contained in:
amass 2024-09-07 21:51:11 +08:00
parent 7a2dbca39e
commit 28db31167c
4 changed files with 20 additions and 7 deletions

View File

@ -1,5 +1,4 @@
#include "IoContext.h"
// #include "RKAP_3A.h"
#include "SpeexDsp.h"
#include "WebRtcAecm.h"
#include "api/audio/echo_canceller3_config.h"
@ -52,15 +51,24 @@ void ProcessFileTask::setDsp(Dsp dsp) {
}
}
// ./build/Record/Record --file --dsp=aecm
// ./Record --file --dsp=aecm
void ProcessFileTask::run() {
m_speakerIfs = std::make_shared<std::ifstream>("/sdcard/speaker_16k.pcm", std::ifstream::binary);
m_micIfs = std::make_shared<std::ifstream>("/sdcard/micin_16k.pcm", std::ifstream::binary);
#ifdef __RV1109__
constexpr auto MicFile = "/sdcard/micin_16k.pcm";
constexpr auto SpeakerFile = "/sdcard/speaker_16k.pcm";
#else
constexpr auto MicFile = "resources/micin_16k.pcm";
constexpr auto SpeakerFile = "resources/speaker_16k.pcm";
#endif
m_speakerIfs = std::make_shared<std::ifstream>(SpeakerFile, std::ifstream::binary);
m_micIfs = std::make_shared<std::ifstream>(MicFile, std::ifstream::binary);
std::ostringstream oss;
oss << DumpPath << "/out_" << dspToString(m_dsp) << "_16k.pcm";
oss << DumpPath << "/out_" << dspToString(m_dsp) << "_16k.wav";
m_outFilename = oss.str();
m_ofs = std::make_shared<std::ofstream>(m_outFilename, std::ofstream::binary);
m_ofs = std::make_shared<WavWriter<int16_t>>(m_outFilename, 1, 16000);
oss.str("");
oss << DumpPath << "/ns_" << dspToString(m_dsp) << "_16k.pcm";
@ -130,6 +138,6 @@ void ProcessFileTask::process() {
} else {
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - m_begin);
LOG(info) << "process file finished, out: " << m_outFilename << ", elapsed: " << elapsed;
std::exit(0);
ioConext->stop();
}
}

View File

@ -4,6 +4,7 @@
#include "RkAudio.h"
#include <fstream>
#include <memory>
#include "WavWriter.h"
class SpeexDsp;
class WebRtcAecm;
@ -15,7 +16,11 @@ enum Dsp {
Aec3,
};
#ifdef __RV1109__
constexpr auto DumpPath = "/sdcard/data";
#else
constexpr auto DumpPath = "./build/data";
#endif
class Task {
public:
@ -95,7 +100,7 @@ private:
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;
std::shared_ptr<WavWriter<int16_t>> m_ofs;
std::shared_ptr<std::ofstream> m_nsOfs; // 降噪后的文件
std::string m_outFilename;
std::chrono::system_clock::time_point m_begin;

BIN
resources/micin_16k.pcm Normal file

Binary file not shown.

BIN
resources/speaker_16k.pcm Normal file

Binary file not shown.