介绍了openal的基本用法
alListenerfv(AL_VELOCITY,listenerVel); alListenerfv(AL_ORIENTATION,listenerOri);
12,接下来就是播放声音了,很简单:alSourcePlay(sourceIndex);
如果你有多个源,可以调用多次,这样就可以在同一时刻听到不同声音。
比如我现在还有一个sourceTwoIndex源,关联了一个bufferTwoIndex,那么可以接着调用
alSourcePlay(sourceTwoIndex);
这样就有两个声音在播放了。
13,注意在你播放声音的时候,不要马上退出程序,如果你刚让程序播放,就退出,就基本听不到声音了,openal不会耐心等声音播放完毕再友好的退出!所以加上下面的代码:
while (choose != 'q')
{ } choose = getchar(); switch(choose) { case'w': } sourcePos[0] -= sourceVel[0]; sourcePos[1] -= sourceVel[1]; sourcePos[2] -= sourceVel[2]; alSourcefv(sourceIndex,AL_POSITION,sourcePos); if (alGetError() != AL_NO_ERROR) { } alSourcei(sourceIndex, AL_SOURCE_RELATIVE, AL_FALSE); break; sourcePos[0] += sourceVel[0]; sourcePos[1] += sourceVel[1]; sourcePos[2] += sourceVel[2]; alSourcefv(sourceIndex,AL_POSITION,sourcePos); if (alGetError() != AL_NO_ERROR) { } alSourcei(sourceIndex, AL_SOURCE_RELATIVE, AL_FALSE); break; // 出错 exit(0); // 出错 exit(0); case's':
就可以通过按键控制程序的继续运行,按下’w’,声音源位置就会离我们越来越近,因为他的位置z变小了。 按’s’相反效果。
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库OpenAl笔记(4)在线全文阅读。
相关推荐: