资源简介
将G711转化为PCM,然后再采用CDL2播放,在VS2010下测试通过,并附带G711音频测试文件
代码片段和文件信息
/**
* 最简单的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\n“);
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 ! \n“);
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_20150806\avcodec-56.dll
文件 1380352 2015-06-19 12:41 AudioDecode&play—G711播放DEMO_20150806\avdevice-56.dll
文件 2386432 2015-06-19 12:41 AudioDecode&play—G711播放DEMO_20150806\avfilter-5.dll
文件 6021632 2015-06-19 12:41 AudioDecode&play—G711播放DEMO_20150806\avformat-56.dll
文件 495104 2015-07-09 16:34 AudioDecode&play—G711播放DEMO_20150806\avutil-54.dll
文件 1698 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\cl.command.1.tlog
文件 30292 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\CL.read.1.tlog
文件 1130 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\CL.write.1.tlog
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\li
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\li
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\li
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\li
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\li
文件 2 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\li
文件 4140 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\li
文件 8032 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\li
文件 2464 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\li
文件 1070 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\mt.command.1.tlog
文件 970 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\mt.read.1.tlog
文件 776 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\mt.write.1.tlog
文件 1594 2015-08-06 09:25 AudioDecode&play—G711播放DEMO_20150806\Debug\rc.command.1.tlog
文件 914 2015-08-06 09:25 AudioDecode&play—G711播放DEMO_20150806\Debug\rc.read.1.tlog
文件 930 2015-08-06 09:25 AudioDecode&play—G711播放DEMO_20150806\Debug\rc.write.1.tlog
文件 31232 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\simplest_audio_play_sdl2.exe
文件 658 2015-08-06 08:54 AudioDecode&play—G711播放DEMO_20150806\Debug\simplest_audio_play_sdl2.exe.em
文件 724 2015-08-06 09:25 AudioDecode&play—G711播放DEMO_20150806\Debug\simplest_audio_play_sdl2.exe.em
文件 616 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\simplest_audio_play_sdl2.exe.intermediate.manifest
文件 385072 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\simplest_audio_play_sdl2.ilk
文件 73 2015-08-06 09:36 AudioDecode&play—G711播放DEMO_20150806\Debug\simplest_audio_play_sdl2.lastbuildstate
............此处省略205个文件信息
- 上一篇:最经典的开源车牌识别代码 OPENCV
- 下一篇:为我们的世界建模
相关资源
- ios 音频转码
- 我测试用的pcm文件
- pcm音频测试文件
- 音频PCMSample
- pcm音频重采样
- g721 g711 g729 g723 g722 音频编码解码及分
- G711.alaw文件
- 基于Labview的调制解调2ASK2DPSK2FSK2PSKA
- 测试用的pcm音频数据
- --测试专用pcm音频文件以及pcm播放工具
- 通信原理课程设计 脉冲编码调制PCM系
- ADPCM语音压缩编码的分析与仿真
- speex音频转pcm和aac
- G711编码原理ppt
- 利用windows api采集麦克风音频并播放
- Qt播放PCM音频裸流文件
- 使用AudioRecord进行录音 获取录音字节
- pcm文件 16K采样率
- PCM仿真均匀量化、非均匀量化及A律
- PCM编译码.zip
- PCMan-FTP+溢出脚本
- 音频文件包含 pcm、wav、amr、m4a 共4个
- 将wav格式转换为PCM格式
- Qt之实现录音播放及rawpcm转wav格式
- PCM相互转换WAV
- verilog实现的PCM模块
- QT实现wav音频文件读写
- G711播放器
- pcm-g711a-采集器-播放器
- 一个DPCM的源代码
评论
共有 条评论