直接上代码
#include "RtAudio.h"
#include "../libaac/faac.h"
#include "../libaac/faaccfg.h"
#include <memory>
#include <thread>
#include <mutex>
#include <queue>
#include <conio.h>
using namespace std;
const unsigned long uiSampleteRate = 44100;
const unsigned int uiChannels = 2;
const int uiBitRate = 96000;
unsigned long ulSamplesInputSize = 0;
vector<char> vHeader;
vector<char> vBytesCache;
mutex g_i_mutex;
BOOL bStop = false;
shared_ptr<unsigned char> frame = nullptr;
faacEncHandle pFaacHandle;
unsigned long ulMaxOutputSize = 0;
shared_ptr<unsigned char> pOutputBuffer = nullptr;
shared_ptr<RtAudio> pGrabEngine = make_shared<RtAudio>();//语音类
FILE* fp_out = nullptr;
FILE* fp_out1 = nullptr;
float getFrameDuration()
{
float frameDuration = (float)ulSamplesInputSize * 1000.00 / (float)uiSampleteRate / uiChannels;
cout <<"AAC frame duration=" << frameDuration << "sample_rate=%d" << uiSampleteRate << endl;
return frameDuration;
//(float)getFrameSize() * 1000.00 / ((float)m_samplerate * 16.0 / 8.0 * 2.0);
}
void onDataCaptured(char *data, int size)
{
lock_guard<mutex> lock(g_i_mutex);
for (int i = 0; i < size; ++i)
{
vBytesCache.push_back(data[i]);
}
}
void stopCapture(