将G711转化为PCM,然后再采用CDL2播放,在VS2010下测试通过,并附带G711音频测试文件
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 25 2014-06-05 19:35 AudioDecode&play—G711播放DEMO_20150806.gitignore
文件 22247936 2015-07-09 16:34 AudioDecode&play—G711播放DEMO_20150806avcodec-56.dll
文件 1380352 2015-06-19 12:41 AudioDecode&play—G711播放DEMO_20150806avdevice-56.dll
文件 2386432 2015-06-19 12:41 AudioDecode&play—G711播放DEMO_20150806avfilter-5.dll
文件 6021632 2015-06-19 12:41 AudioDecode&play—G711播放DEMO_20150806avformat-56.dll
文件 495104 2015-07-09 16:34 AudioDecode&play—G711播放DEMO_20150806avutil-54.dll
文件 1698 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugcl.command.1.tlog
文件 30292 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806DebugCL.read.1.tlog
文件 1130 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806DebugCL.write.1.tlog
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debuglink-cvtres.read.1.tlog
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debuglink-cvtres.write.1.tlog
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debuglink.6016-cvtres.read.1.tlog
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debuglink.6016-cvtres.write.1.tlog
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debuglink.6016.read.1.tlog
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debuglink.6016.write.1.tlog
文件 4140 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debuglink.command.1.tlog
文件 8032 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debuglink.read.1.tlog
文件 2464 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debuglink.write.1.tlog
文件 1070 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugmt.command.1.tlog
文件 970 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugmt.read.1.tlog
文件 776 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugmt.write.1.tlog
文件 1594 2015-08-06 09:25 AudioDecode&play—G711播放DEMO_20150806Debug
c.command.1.tlog
文件 914 2015-08-06 09:25 AudioDecode&play—G711播放DEMO_20150806Debug
c.read.1.tlog
文件 930 2015-08-06 09:25 AudioDecode&play—G711播放DEMO_20150806Debug
c.write.1.tlog
文件 31232 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugsimplest_audio_play_sdl2.exe
文件 658 2015-08-06 08:54 AudioDecode&play—G711播放DEMO_20150806Debugsimplest_audio_play_sdl2.exe.embed.manifest
文件 724 2015-08-06 09:25 AudioDecode&play—G711播放DEMO_20150806Debugsimplest_audio_play_sdl2.exe.embed.manifest.res
文件 616 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugsimplest_audio_play_sdl2.exe.intermediate.manifest
文件 385072 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugsimplest_audio_play_sdl2.ilk
文件 73 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugsimplest_audio_play_sdl2.lastbuildstate
............此处省略205个文件信息
/**
* 最简单的SDL2播放音频的例子(SDL2播放PCM)
* Simplest Audio Play SDL2 (SDL2 play PCM)
*
* 雷霄骅 Lei Xiaohua
* leixiaohua1020@126.com
* 中国传媒大学/数字电视技术
* Communication University of China / Digital TV Technology
* http://blog.csdn.net/leixiaohua1020
*
* 本程序使用SDL2播放PCM音频采样数据。SDL实际上是对底层绘图
* API(Direct3D,OpenGL)的封装,使用起来明显简单于直接调用底层
* API。
*
* 函数调用步骤如下:
*
* [初始化]
* SDL_Init():初始化SDL。
* SDL_OpenAudio():根据参数(存储于SDL_AudioSpec)打开音频设备。
*
* [循环播放数据]
* SDL_PauseAudio():播放音频数据。
* SDL_Delay():延时等待播放完成。
*
* This software plays PCM raw audio data using SDL2.
* SDL is a wrapper of low-level API (DirectSound).
* Use SDL is much easier than directly call these low-level API.
*
* The process is shown as follows:
*
* [Init]
* SDL_Init(): Init SDL.
* SDL_OpenAudio(): Opens the audio device with the desired
* parameters (In SDL_AudioSpec).
*
* [Loop to play data]
* SDL_PauseAudio(): Play Audio.
* SDL_Delay(): Wait for completetion of playback.
*/
#include
#include
#include
#include
extern “C“
{
#include “sdl/SDL.h“
#include
#include
#include
};
#define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */
#define QUANT_MASK (0xf) /* Quantization field mask. */
#define NSEGS (8) /* Number of A-law segments. */
#define SEG_SHIFT (4) /* Left shift for segment number. */
#define SEG_MASK (0x70) /* Segment field mask. */
#define BIAS (0x84) /* Bias for linear code. */
//Buffer:
//|-----------|-------------|
//chunk-------pos---len-----|
static Uint8 *audio_chunk;
static Uint32 audio_len;
static Uint8 *audio_pos;
int ulaw2linear( unsigned char u_val)
{
int t;
/* Complement to obtain normal u-law value. */
u_val = ~u_val;
/*
* Extract and bias the quantization bits. Then
* shift up by the segment number and subtract out the bias.
*/
t = ((u_val & QUANT_MASK) << 3) + BIAS;
t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT;
return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS));
}
int g711utoPCM(const char* g711file const char* pcmfile){
FILE * inpf;
FILE * outf;
inpf = fopen(g711file “rb“);
if( inpf == NULL )
{
printf(“G.711 file cant open
“);
return 1 ;
}
outf = fopen(pcmfile “wb“);
unsigned char* Buf;
Buf = (unsigned char*)calloc(1024 sizeof(char));
int nalLen = 0;
while(!feof(inpf))
{
nalLen =fread(Buf11inpf);
int iLinear = ulaw2linear(Buf[0]);
fwrite(&iLinear12outf);//写到文件
}
if(inpf)
fclose(inpf);
if(outf)
fclose(outf);
printf(“The pcm audio file is end !
“);
return 0;
}
/* Audio Callback
* The audio function callback takes the following parameters:
* stream: A pointer to the audio buffer to be filled
* len: The length (in bytes) of the audio buffer
*
*/
void fill_audio(void *udataUint8 *streamint len){
//SDL 2.0
SDL_mem
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 25 2014-06-05 19:35 AudioDecode&play—G711播放DEMO_20150806.gitignore
文件 22247936 2015-07-09 16:34 AudioDecode&play—G711播放DEMO_20150806avcodec-56.dll
文件 1380352 2015-06-19 12:41 AudioDecode&play—G711播放DEMO_20150806avdevice-56.dll
文件 2386432 2015-06-19 12:41 AudioDecode&play—G711播放DEMO_20150806avfilter-5.dll
文件 6021632 2015-06-19 12:41 AudioDecode&play—G711播放DEMO_20150806avformat-56.dll
文件 495104 2015-07-09 16:34 AudioDecode&play—G711播放DEMO_20150806avutil-54.dll
文件 1698 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugcl.command.1.tlog
文件 30292 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806DebugCL.read.1.tlog
文件 1130 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806DebugCL.write.1.tlog
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugli
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugli
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugli
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugli
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugli
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugli
文件 4140 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugli
文件 8032 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugli
文件 2464 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugli
文件 1070 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugmt.command.1.tlog
文件 970 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugmt.read.1.tlog
文件 776 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugmt.write.1.tlog
文件 1594 2015-08-06 09:25 AudioDecode&play—G711播放DEMO_20150806Debug
c.command.1.tlog
文件 914 2015-08-06 09:25 AudioDecode&play—G711播放DEMO_20150806Debug
c.read.1.tlog
文件 930 2015-08-06 09:25 AudioDecode&play—G711播放DEMO_20150806Debug
c.write.1.tlog
文件 31232 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugsimplest_audio_play_sdl2.exe
文件 658 2015-08-06 08:54 AudioDecode&play—G711播放DEMO_20150806Debugsimplest_audio_play_sdl2.exe.em
文件 724 2015-08-06 09:25 AudioDecode&play—G711播放DEMO_20150806Debugsimplest_audio_play_sdl2.exe.em
文件 616 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugsimplest_audio_play_sdl2.exe.intermediate.manifest
文件 385072 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugsimplest_audio_play_sdl2.ilk
文件 73 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806Debugsimplest_audio_play_sdl2.lastbuildstate
............此处省略205个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)