资源简介
本工程包含了使用各种API(Direct3D,OpenGL,GDI,DirectSound,SDL2)播放多媒体例子。
其中音频输入为PCM采样数据。输出至系统的声卡播放出来。
视频输入为YUV/RGB像素数据。输出至显示器上的一个窗口播放出来。
通过本工程的代码初学者可以快速学习使用这几个API播放视频和音频的技术。
一共包括了如下几个子工程:
simplest_audio_play_directsound: 使用DirectSound播放PCM音频采样数据。
simplest_audio_play_sdl2: 使用SDL2播放PCM音频采样数据。
simplest_video_play_direct3d: 使用Direct3D的Surface播放RGB/YUV视频像素数据。
simplest_video_play_direct3d_texture:使用Direct3D的Texture播放RGB视频像素数据。
simplest_video_play_gdi: 使用GDI播放RGB/YUV视频像素数据。
simplest_video_play_opengl: 使用OpenGL播放RGB/YUV视频像素数据。
simplest_video_play_opengl_texture: 使用OpenGL的Texture播放YUV视频像素数据。
simplest_video_play_sdl2: 使用SDL2播放RGB/YUV视频像素数据。
代码片段和文件信息
/**
* 最简单的DirectSound播放音频的例子(DirectSound播放PCM)
* Simplest Audio Play DirectSound (DirectSound play PCM)
*
* 雷霄骅 Lei Xiaohua
* leixiaohua1020@126.com
* 中国传媒大学/数字电视技术
* Communication University of China / Digital TV Technology
* http://blog.csdn.net/leixiaohua1020
*
* 本程序使用DirectSound播放PCM音频采样数据。
* 是最简单的DirectSound播放音频的教程。
*
* 函数调用步骤如下:
*
* [初始化]
* DirectSoundCreate8():创建一个DirectSound对象。
* SetCooperativeLevel():设置协作权限,不然没有声音。
* IDirectSound8->CreateSoundBuffer():创建一个主缓冲区对象。
* IDirectSoundBuffer->QueryInterface(IID_IDirectSoundBuffer8..):
* 创建一个副缓冲区对象,用来存储要播放的声音数据文件。
* IDirectSoundBuffer8->QueryInterface(IID_IDirectSoundNotify..):
* 创建通知对象,通知应用程序指定播放位置已经达到。
* IDirectSoundNotify8->SetNotificationPositions():设置通知位置。
* IDirectSoundBuffer8->SetCurrentPosition():设置播放的起始点。
* IDirectSoundBuffer8->Play():开始播放。
*
* [循环播放数据]
* IDirectSoundBuffer8->Lock():锁定副缓冲区,准备写入数据。
* fread():读取数据。
* IDirectSoundBuffer8->Unlock():解锁副缓冲区。
* WaitForMultipleobjects():等待“播放位置已经达到”的通知。
*
* This software plays PCM raw audio data using DirectSound.
* It‘s the simplest tutorial about DirectSound.
*
* The process is shown as follows:
*
* [Init]
* DirectSoundCreate8(): Init DirectSound object.
* SetCooperativeLevel(): Must set or we won‘t hear sound.
* IDirectSound8->CreateSoundBuffer(): Create primary sound buffer.
* IDirectSoundBuffer->QueryInterface(IID_IDirectSoundBuffer8..):
* Create secondary sound buffer.
* IDirectSoundBuffer8->QueryInterface(IID_IDirectSoundNotify..):
* Create Notification object.
* IDirectSoundNotify8->SetNotificationPositions():
* Set Notification Positions.
* IDirectSoundBuffer8->SetCurrentPosition(): Set position to start.
* IDirectSoundBuffer8->Play(): Begin to play.
*
* [Loop to play data]
* IDirectSoundBuffer8->Lock(): Lock secondary buffer.
* fread(): get PCM data.
* IDirectSoundBuffer8->Unlock(): UnLock secondary buffer.
* WaitForMultipleobjects(): Wait for Notifications.
*/
#include
#include
#include
#include
#define MAX_AUDIO_BUF 4
#define BUFFERNOTIFYSIZE 192000
int sample_rate=44100; //PCM sample rate
int channels=2; //PCM channel number
int bits_per_sample=16; //bits per sample
BOOL main(int argcchar * argv[])
{
int i;
FILE * fp;
if((fp=fopen(“../NocturneNo2inEflat_44.1k_s16le.pcm““rb“))==NULL){
printf(“cannot open this file\n“);
return -1;
}
IDirectSound8 *m_pDS=0;
IDirectSoundBuffer8 *m_pDSBuffer8=NULL; //used to manage sound buffers.
IDirectSoundBuffer *m_pDSBuffer=NULL;
IDirectSoundNotify8 *m_pDSNotify=0;
DSBPOSITIONNOTIFY m_pDSPosNotify[MAX_AUDIO_BUF];
HANDLE m_event[MAX_AUDIO_BUF];
SetConsoletitle(TEXT(“Simplest Audio Play DirectSound“));//Console title
//Init DirectSound
if(FAILED(DirectSoundCreate8(NULL&m_pDSNULL)))
return FALSE;
if(FAILED(m_pDS->SetCooperativeLevel(FindWindow(NULLTEXT(“Simpl
- 上一篇:VideoEye 0.2 源代码
- 下一篇:最简单的视音频播放 1.1
相关资源
- OpenGL参考手册
- GDI自绘滚动条
- Qt Creator opengl实现四元数鼠标控制轨迹
- OpenGL文档,api大全,可直接查询函数
- opengl轮廓字体源代码
- MFC读三维模型obj文件
- 利用OpenGL写毛笔字算法
- MFC中OpenGL面和体的绘制以及动画效果
- 基于OPENGL的光线跟踪源代码368758
- VC 实现三维旋转(源码)
- 自编用openGL实现3D分形树,分形山
- OpenGL球形贴图自旋程序
- OpenGL导入贴图的Texture类
- VC 使用GDI 矢量绘图软件源代码
- 计算机图形学(openGL)代码
- 用OpenGL开发的机械臂运动仿真程序(
- OpenGL-3D坦克模拟
- 易语言矩阵的旋转源码易语言GDI矩阵
- 易语言认识矩阵源码易语言GDI矩阵源
- 易语言矩阵应用到指定坐标源码易语
- OPENGL实现世界上最小的3D游戏
- VS2012OpenGL配置所需要的全部libdllh文件
- delphi基于gdi+的图片旋转任意角度
- 易语言图像编码、解码器源码易语言
- 易语言GDI三角板源码
- 易语言GDI设置输出前景色源码
-
易语言GDI自绘电梯st
yle源码 - 易语言GDI绘制文字到窗口源码
- 易语言GDI画CPU动态线源码
- 易语言GDI输出文字背景透明源码
评论
共有 条评论