webrtc PCM 音频 相关函数
来源:互联网 发布:手机淘宝一元秒杀 编辑:程序博客网 时间:2024/06/07 18:20
webrtc PCM resample
在webrtc中,对应的音频resample文件是:
"webrtc\common_audio\resampler\include\resampler.h"
目前,在这个文件中,仅仅可以对PCM的采样率进行改变,不可以改变声道数;
但是左右声道的提取,也比较简单,可以自己实现,可以看我之前的文章;
如果需要更加强大和方便的音频resample可以直接用FFmpeg,但是为了最小限度的改变webrtc,所以还是用webrtc中提供的相关库;
#include "webrtc\common_audio\resampler\include\resampler.h"
int file_size(char* filename)
{
FILE *fp = fopen(filename, "r");
if (!fp) return -1;
fseek(fp, 0L, SEEK_END);
int size = ftell(fp);
fclose(fp);
return size;
}
void Ctmfc_webrtc_videoDlg::OnBnClickedButton3()
{
// TODO: Add your control notification handler code here
char * pstrFile = "E:\\webrtc_Audio_Remote_BytesPerSample_2,__channels_2,__SampleRate_48000 - test.pcm";
int lengthIn = file_size(pstrFile);
size_t outLen = 0;
uint8_t * samplesIn = new uint8_t[lengthIn];
uint8_t * samplesOut = new uint8_t[lengthIn];
FILE * f = fopen(pstrFile, "r+b");
fread(samplesIn, 1, lengthIn, f);
fclose(f);
webrtc::Resampler pcmResampler( 48000, 8000, 2 );
// Resample samplesIn to samplesOut.
int Res = pcmResampler.Push((int16_t*)samplesIn, lengthIn/2, (int16_t* )samplesOut, lengthIn/2, outLen); // NOLINT: to avoid changing APIs
FILE * fAudio = fopen( "E:\\webrtc_Audio_resample.pcm", "w+b");
fwrite((uint8_t *)samplesOut, 1, outLen*2, fAudio);
fclose(fAudio);
}
简单封装为一个函数:
uint8_t * resampe( uint8_t * samplesIn, int lengthIn, int nSampleRate, int nChannel, size_t & outLen)
{
webrtc::Resampler pcmResampler(nSampleRate, /*nTargetAudioSample*/8000, nChannel);
uint8_t * samplesOut = new uint8_t[lengthIn];
outLen = 0;
// // Resample samplesIn to samplesOut.
int Res = pcmResampler.Push((int16_t*)samplesIn, lengthIn / 2, (int16_t*)samplesOut, lengthIn / 2, outLen);
Res = 0;
outLen = outLen * 2;
if (outLen>0)
{
return samplesOut;
}
return NULL;
}
这里要注意的是,修改采样率后,音质可能出现噪音;
关于左右声道的算法可以用: class AudioFrameOperations
相关目录:webrtc58\src\webrtc\audio\utility\audio_frame_operations.h
- webrtc PCM 音频 相关函数
- webrtc音频相关
- PCM1------PCM音频采样数据处理函数
- PCM2------PCM音频采样数据处理函数
- PCM音频
- PCM音频
- PCM音频
- 关于PCM音频数据的相关转换算法
- 关于PCM音频数据的相关转换算法
- WebRTC音频
- 音频PCM编码说明
- 嵌入式 PCM音频一
- 嵌入式 pcm音频二
- 嵌入式 pcm音频三
- PCM音频数据格式介绍
- PCM音频采样数据处理
- 多媒体音频PCM数据
- 音频PCM知识整理
- explicit关键字
- typedef 与 define的区别
- 读取手机联系人信息
- easyui中combobox设置默认选中项的方法
- SSM三大框架
- webrtc PCM 音频 相关函数
- addEventListenter和attachEvent事件兼容代码
- 游戏人工智能之状态驱动智能体(二)
- BZOJ4012: [HNOI2015]开店 重链剖分 可持久化线段树
- linux文件权限的设置
- 解决okhttp报java.lang.IllegalStateException: closed,java.lang.IllegalStateException: closed
- 英语听力
- 整数排序II
- 关于在windows下启动zookeeper报错,闪退问题