资源简介
使用webrtc开源库中的算法,将其封装为动态库,用来转换音频原始数据pcm采样率
代码片段和文件信息
#include “resamplerImpl.h“
#include
#include
#include
#include
#include
#include
#include
#include
#define SOC_FILE “audio8kHz.pcm“
#define DEST_FILE “audio11kHz.pcm“
int main()
{
FILE* fpIn = fopen(SOC_FILE “rb“);
if (NULL == fpIn)
{
printf(“%s:[%d] open %s file failed\n“ __FUNCTION__ __LINE__ SOC_FILE);
return -1;
}
FILE* fpOut = fopen(DEST_FILE “wb“);
if (NULL == fpOut)
{
printf(“%s:[%d] open %s file failed\n“ __FUNCTION__ __LINE__ DEST_FILE);
return -1;
}
//webrtc::PushResampler pushResampler;
InitializeIfNeeded(8000 11000 1);
//(const T* src size_t src_length T* dst size_t dst_capacity)
int16_t * pbG711ABuffer = (int16_t *)malloc(90 * sizeof(int16_t));
memset(pbG711ABuffer 0 170);
int16_t* pbPCMTmpBuffer = (int16_t *)malloc(1024 * sizeof(int16_t));
memset(pbPCMTmpBuffer 0 1024);
size_t gBytesRead = 0;
size_t destCount = 0;
while ((gBytesRead = fread(pbG711ABuffer 2 80 fpIn)) > 0)
{
if (gBytesRead < 80) {
break;
}
destCount = Resample(pbG711ABuffer gBytesRead pbPCMTmpBuffer 1024);
fwrite(pbPCMTmpBuffer 2 destCount fpOut);
}
fclose(fpIn);
fclose(fpOut);
return 0;
}
- 上一篇:.net 官方代码规范
- 下一篇:hook COM接口 挂钩
评论
共有 条评论