在音頻的採集編碼發送端,用 std::ifstream 將採集到的原始數據、前處理後的pcm數據或編碼後的RTP數據包替換掉,就可以指定音頻的輸入源,在特定的輸入源之下衡量音頻傳輸/處理的效果。
假如要替換pcm原始音頻數據
////////////////////////////////////////////////////////
#include <fstream>
// 類成員中加入, xxx爲一次讀取的長度
char data[xxx];
std::ifstream in;
// 構造函數中加入
in.open("/sdcard/test.pcm", std::ios::binary);
// 析構函數中加入
in.close();
// 音頻採集位置中加入
if(!in.eof())
{
in.read(data, sizeof(data));
}
else
{
// 先clear(),之後seekg()
in.clear();
in.seekg(0, std::ios::beg);
}
////////////////////////////////////////////////////////
#include <cstdio>
static char* data = (char*)malloc(xxx);
static FILE* file = fopen("/sdcard/test.pcm", "rb");
if(xxx != fread(data, 1, xxx, file)
{
fseek(file, 0, SEEK_SET);
return;
}