OpenAL播放pcm或wav数据流-windows/ios/android(一)

OpenAL播放pcm或wav数据流-windows/ios/android(一)


最近在研究渲染问题,本文采用openal做pcm和wav数据流播放,并非本地文件,demo是windows的,ios通用。网上都是ios的,ios需要引用OpenAl.framework框架,

Android平台需要做openal的jni,android的openal库可以参考

http://blog.csdn.net/matrix_laboratory/article/details/53319735这篇文章,各个平台需要做稍微处理。

下面是代码:

//.h

/** Copyright (c/c++) <2016.11.22> <zwg/>
* Function  
* OpenAL through the buffer queuing mechanism to support the streaming playback of sound. The buffer queue is a buffer associated with a single source contact mechanism.
* when audio playback, continuous rendering of each buffer, as if the buffer is composed of a continuous sound. This can be controlled by some special functions.
* flow is generally the source of the work. In a number of audio buffer by alSourceQueueBuffers () function to queue, and then play the sound source,
* next with property AL_BUFFERS_PROCESSED to query. This property obtains the number of buffers that have been processed,
* allows applications to use the alSourceUnqueueBuffers () function to delete the buffers that have been processed.
* alSourceUnqueueBuffers () function will start from the queue header will be processed in order to remove the buffer. Finally, the rest of the buffer queue in gear.
* Opanal for audio rendering related implementation and definition, etc.
* OpenAL通过缓冲器排队机制支持声音的流式播放。缓冲器排队是多个缓冲器与单一音源相关联的一种机制。
* 当音源播放时,连续对各个缓冲器进行渲染,就好象这些缓冲器组成了一个连续的声音。这可以通过一些特殊函数来控制。
* 流音源的工作一般是这样的。音源里的一批缓冲器通过alSourceQueueBuffers()函数进行排队,然后播放音源,
* 接下来用属性AL_BUFFERS_PROCESSED来查询。该属性得出已经处理好的缓冲器的数量,
* 从而允许应用程序使用alSourceUnqueueBuffers()函数删除那些已经处理好的缓冲器。
* alSourceUnqueueBuffers()函数将从队列头部开始依次将处理好的缓冲器删除。最后,其余的缓冲器在音源上排队。
* OpanAl 用于音频渲染相关实现及定义,等
*/

#ifndef __LVS_OPENAL_INTERFACE_H__
#define __LVS_OPENAL_INTERFACE_H__

#include <stdio.h>
#include <stdlib.h>
#include <string>

//windows
#ifdef WIN32
#include <Windows.h>
//openAl库
#include "alut.h"
#pragma comment(lib,"alut.lib")
#pragma comment(lib,"OpenAL32.lib")
//ios
#elif __APPLE__
#include "alut.h"
//ANDROID平台  
#elif __ANDROID__  
#include "alut.h"
//linux
#else
#include "alut.h"
#endif

//到处宏定义
//windows
#ifdef WIN32
#define LVS_DLLEXPORT __declspec(dllexport)
//ios
#elif __APPLE__
#define LVS_DLLEXPORT
//linux
#else
#define LVS_DLLEXPORT
#endif

using namespace std;

//接口初始化
int lvs_openal_interface_init();
//接口释放
void lvs_openal_interface_uninit();
//接口开始播放
void lvs_openal_interface_playsound();
//接口停止播放
void lvs_openal_interface_stopsound();
//接口设置音量
void lvs_openal_interface_setvolume(float volume);//volume取值范围(0~1)
//接口获取音量
float lvs_openal_interface_getvolu
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值