青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 505  文章 - 1034  trackbacks - 0
<2008年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910


子曾經(jīng)曰過:編程無他,唯手熟爾!

常用鏈接

留言簿(94)

隨筆分類(649)

隨筆檔案(505)

相冊(cè)

BCB

Crytek

  • crymod
  • Crytek's Offical Modding Portal

Game Industry

OGRE

other

Programmers

Qt

WOW Stuff

搜索

  •  

積分與排名

  • 積分 - 925234
  • 排名 - 14

最新隨筆

最新評(píng)論

閱讀排行榜

評(píng)論排行榜

http://www.gamedev.net/reference/articles/article1958.asp

Programming 3D Sound With OpenAL in Windows
by Dan Ricart

As the capabilities of sound cards and sound APIs have increased over the years, 3D sound has played an increasingly important role in games. Creating an immersive experience for the gamer goes beyond nice looking graphics. Done correctly, ambient sound and music can take games to a whole new level. To achieve this effect, different sound programming APIs have been developed such as Microsoft's DirectSound and DirectSound3D, Aureal's A3D and Creative Labs EAX. More recently, Loki Entertainment and Creative Labs have developed OpenAL. They have done this in an effort to create a more standard, cross-platform API to allow developers to add sound to any title. This article explains the basics of OpenAL and how to get started adding 3D sound to your project.

OpenAL is basically an audio library that contains functions for playing back sounds and music in a game environment. It allows a programmer to load whatever sounds they like and control certain characteristics such as position, velocity, direction and angles for cones that determine how the sound is traveling. All sounds are positioned relative to the listener which represents the current place in the game universe where the user is. The closer the listener gets to a sound, the louder it gets. OpenAL can also be used for the playback of music. OpenAL can make use of streaming to continuously play music back in the background. OpenAL also supports the use of DirectSound3D and EAX in Windows. There are functions contained in the library that allow the use of these APIs without much extra programming.

The main advantage of OpenAL over DirectSound and EAX is that OpenAL is designed to be a cross platform API. It is possible to download Windows, Mac and Linux binaries of it so it can be used on many Operating Systems. DirectSound and DirectSound3D were designed only for Windows and EAX is basically an extension of DirectSound3D. For those wishing to create an application for multiple Operating Systems, OpenAL might be the way to go. This tutorial is designed to show you how to get basic functionality out of OpenAL in Windows. The code shown here is from the demo application that you can download which contains the complete example. OpenGL is used for the rendering so the demo shows some similarities between OpenGL and OpenAL.

Getting Started

The first thing to do is to obtain the OpenAL SDK. This can be obtained from Creative Labs developer site at developer.creative.com. Once the SDK is set up you can begin using its functions. You will first need to initialize OpenAL at the start of your game or application. For my application I am going to use the basic method of setting it up for DirectSound3D but it is also possible to make use of EAX by checking for its availability. The initialization code looks like this:

ALCcontext? * Context;
ALCdevice?
*
Device;

Device?
= ?alcOpenDevice((ALubyte * ) " DirectSound3D "
);
if ?(Device? ==
?NULL)
{
??exit(
- 1
);
}

// Create?context(s)

Context = alcCreateContext(Device,NULL);

// Set?active?context

alcMakeContextCurrent(Context);

// ?Clear?Error?Code

alGetError();

Loading Sounds

Once OpenAL has been initialized you can start filling buffers with sounds. The first step is to fill a buffer with sound using the alutLoadWAVFile function. Once you have filled the buffer you need to attach it to a source. This source can then be used to play back the sound. The code for loading a sound looks like this:

char * ?alBuffer;? // data?for?the?buffer
ALenum?alFormatBuffer;? // for?the?buffer?format
ALsizei?alFreqBuffer;? // for?the?frequency?of?the?buffer
long ?alBufferLen;? // the?bit?depth
ALboolean?alLoop;? // looped
unsigned? int ?alSource;? // buffer?source
unsigned? int ?alSampleSet;

// load?the?wave?file

alutLoadWAVFile( " test.wav " , & alFormatBuffer,?( void ? ** )? & alBuffer,(unsigned? int ? * ) & alBufferLen,? & alFreqBuffer,? & loop);

// create?1?source

alGenSources( 1 ,? & alSource);

// create?1?buffer

alGenBuffers( 1 ,? & alSampleSet);

// put?the?data?into?our?sampleset?buffer

alBufferData(alSampleSet,?alFormatBuffer,?alBuffer,?alBufferLen,?alFreqBuffer);

// assign?the?buffer?to?this?source

alSourcei(alSource,?AL_BUFFER,?alSampleSet);

// release?the?data

alutUnloadWAV(alFormatBuffer,?alBuffer,?alBufferLen,?alFreqBuffer);

The first step here was to load the file "test.wav". The data is read in and stored in alBuffer. Next a source and a buffer are created. Then the buffer is filled with data from alBuffer. Next the buffer is assigned to the source and the wave data is released.

Setting Source Properties

Once you have a sound source set up you will need to set some of its properties. To do this you use the alSource command. This function works similar to functions in OpenGL where different versions of the function exist such as alSourcei, alSourcef, alSource3f, and so on. The properties you are setting determine which function you use. Setting something like pitch for example just needs one floating point parameter so alSourcef is used. The first parameter passed to the function is that of the source you are modifying. The second parameter corresponds to what property you are changing. The rest of the parameters are the actual settings for this property. Here is an example of setting position and velocity for a sound source:

// set?source?position
alSource3f(alSource,AL_POSITION,?xposition,?yposition,?zposition);

// set?source?velocity

alSource3f(alSource,AL_VELOCITY,?xvelocity,?yvelocity,?zvelocity);

Here alSource is our sound source and AL_POSITION and AL_VELOCITY signal that we want to change the position and velocity parameters. The rest correspond to floating point numbers with preset values.

Using a Listener

The use of a listener in 3D sound is important so that you have a reference point from which to hear sounds. The closer a listener is to a sound source's position, the louder the sound will get provided there are no obstacles. OpenAL already has a listener object set up so all you need to do is modify its properties as needed. The most important properties of the listener are the position and orientation of the listener. These properties are generally updated once for every loop in a game. The position indicates where the listener currently is while the orientation is where the listener is facing. For example, if a listener is facing west and a sound is coming from the north, the sound will appear to come from the right. However if the user orientation changes and turns to face the north, the sound will now appear to come from straight ahead.

Modifying a listener's properties works similarly to the way you change a sound source's properties. The function alListener is used and has variations depending on the property you are modifying. For example, to set the listener position you can call alListener3f and specify 3 separate floating point numbers or you could call alListenerfv and pass an array of floating point numbers. The parameters for the position are simply the x, y and z values for the listener in the game world. The orientation property however takes 6 parameters. The first 3 are for the vector that corresponds to what the user of listener is currently looking at. The next 3 are for the vector leading straight up from where the listener is facing. Here is an example of setting the listener position and orientation:

float ?listenerx,?listenery,?listenerz;
float ?vec[ 6
];

listenerx
= 10.0f
;
listenery
= 0.0f
;
listenerz
= 5.0f
;

vec[
0 ]? = ?fvecx;? // forward?vector?x?value

vec[ 1 ]? = ?fvecy;? // forward?vector?y?value
vec[ 2 ]? = ?fvecz;? // forward?vector?z?value
vec[ 3 ]? = ?uvecx;? // up?vector?x?value
vec[ 4 ]? = ?uvecy;? // up?vector?y?value
vec[ 5 ]? = ?uvecz;? // up?vector?z?value

// set?current?listener?position

alListener3f(AL_POSITION,?listenerx,?listenery,?listenerz);

// set?current?listener?orientation

alListenerfv(AL_ORIENTATION,?vec);

In the first function call, 3 separate floating point numbers were passed for the x, y and z of the listener's position. For the second call, an array called vec is passed. This array is comprised of the six values for the two vectors dealing with the listener's orientation.

Playing Sounds

Once your sounds are loaded and you have set your listener properties you can then play your sounds. To do this you call the function alSourcePlay. This function takes a single parameter which is the source you want to play. To stop a sound you call the function alSourceStop which also takes the name of the source you want to stop. If you want your sound effect to loop such as if you have a sound of running water, you can set the looping property of the sound to true before playing the sound. Here is some sample code:

// tell?the?sound?to?loop?continuously
alSourcei(alSource,AL_LOOPING,AL_TRUE);

// play?the?sound

alSourcePlay(alSource);
To stop the sound:
alSourceStop(alSource);

Cleaning Up

Once you are finished with your program you need to free up your sources and buffers and shut down OpenAL. The commands are relatively simple. Here is how to delete your sources and buffers:

//delete?our?source
alDeleteSources(1,&alSource);

//delete?our?buffer

alDeleteBuffers(1,&alSampleSet);
Here the first parameter for each is the number of buffers or sources to be deleted and the second is the buffer or source to be deleted. The last step is to close out OpenAL itself. This is done as follows:
//Get?active?context
Context=alcGetCurrentContext();

//Get?device?for?active?context

Device=alcGetContextsDevice(Context);

//Disable?context

alcMakeContextCurrent(NULL);

//Release?context(s)

alcDestroyContext(Context);

//Close?device

alcCloseDevice(Device);

That's about it for playing basic sounds in OpenAL. The basic steps are to first initialize OpenAL, then load in whatever sounds you need, set the properties of the sounds and listener and then play the sounds. There is a lot more you can do with OpenAL but this was just written to describe some of the basics. The source code that comes along with this demonstrates the use of all of this in an OpenGL demo. In the demo, you control the listener and its position is set to your current position every loop. If you have any questions or comments, e-mail me at ricart3@tcnj.edu.

Download the source code for this article here.

posted on 2006-11-20 00:01 七星重劍 閱讀(1361) 評(píng)論(0)  編輯 收藏 引用 所屬分類: Game Music & Sound
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            性色av一区二区怡红| 在线观看欧美精品| 乱人伦精品视频在线观看| 中文在线资源观看视频网站免费不卡| 欧美一区二视频| 9i看片成人免费高清| 国产一区二区三区自拍| 欧美日韩免费观看中文| 麻豆国产精品va在线观看不卡| 亚洲视频国产视频| 亚洲精品一区二区三区在线观看| 久久亚洲综合| 欧美一区亚洲一区| 亚洲午夜电影网| 亚洲美女诱惑| 亚洲区免费影片| 伊人精品久久久久7777| 国产美女精品在线| 国产精品爱久久久久久久| 免费视频亚洲| 久久久久久噜噜噜久久久精品| 亚洲性感激情| 亚洲图片激情小说| 亚洲精选久久| 91久久国产综合久久91精品网站| 美日韩丰满少妇在线观看| 久久久久久久精| 久久福利影视| 久久成人免费网| 午夜欧美不卡精品aaaaa| 一区二区欧美日韩| 99在线精品视频| 亚洲美女精品成人在线视频| 亚洲人www| 亚洲精选在线| 99精品国产在热久久| 一区二区av| 亚洲午夜激情| 亚洲女人小视频在线观看| 亚洲综合色丁香婷婷六月图片| 亚洲一区尤物| 性做久久久久久| 欧美中文字幕| 麻豆成人小视频| 欧美成人中文字幕| 欧美成人免费观看| 亚洲欧洲精品一区二区| 亚洲理伦电影| 一区二区三区四区蜜桃| 亚洲性色视频| 欧美一区在线直播| 久久精彩视频| 免费视频亚洲| 欧美色一级片| 国产欧美韩日| 精品成人在线| 亚洲精品国产拍免费91在线| 夜夜狂射影院欧美极品| 亚洲尤物在线| 久久久另类综合| 亚洲高清视频在线| 一区二区日韩伦理片| 欧美一区亚洲二区| 欧美承认网站| 国产精品理论片在线观看| 国产综合久久久久影院| 亚洲激情中文1区| 亚洲欧美日韩成人高清在线一区| 久久国产欧美日韩精品| 欧美激情1区2区| 一区二区三区高清在线| 午夜久久美女| 欧美电影免费| 国产网站欧美日韩免费精品在线观看| 亚洲成色www久久网站| 一本色道88久久加勒比精品| 欧美一区二视频在线免费观看| 免费欧美在线视频| 夜夜嗨av一区二区三区中文字幕 | 欧美日韩国产bt| 国产欧美短视频| 91久久久久久国产精品| 亚洲午夜女主播在线直播| 老司机午夜精品| 99在线精品免费视频九九视| 欧美一区久久| 欧美日韩亚洲一区| 国内自拍亚洲| 亚洲女人天堂av| 亚洲国产精品va在线观看黑人| 亚洲欧美精品| 欧美日韩一区二区三区四区在线观看| 国产一区二区欧美日韩| 亚洲色无码播放| 亚洲第一黄网| 欧美一区二区在线看| 欧美巨乳在线观看| 亚洲国产精品久久久久秋霞蜜臀| 欧美亚洲在线播放| 亚洲六月丁香色婷婷综合久久| 久久激情视频| 国产欧美欧美| 亚洲一区三区视频在线观看 | 亚洲国产人成综合网站| 欧美在线观看你懂的| av成人免费| 女生裸体视频一区二区三区| 国产一区二区高清视频| 亚洲一级特黄| 亚洲免费观看在线观看| 免费观看一区| 亚洲丰满在线| 久久亚洲不卡| 久久成人亚洲| 国产区精品视频| 亚洲欧美综合v| 一区二区三区视频观看| 欧美日韩爆操| 日韩亚洲综合在线| 亚洲高清三级视频| 免费欧美日韩| 亚洲日本乱码在线观看| 另类激情亚洲| 久久九九国产精品| 极品尤物av久久免费看| 久久蜜桃资源一区二区老牛| 亚洲欧美日韩精品久久奇米色影视| 欧美四级剧情无删版影片| av成人老司机| 夜色激情一区二区| 欧美三级电影大全| 亚洲一区二区三区四区五区黄| 亚洲美女网站| 欧美日韩在线播| 亚洲在线视频网站| 亚洲影音先锋| 国产一区二区三区在线观看免费视频 | 一本一本久久a久久精品综合麻豆| 欧美国产精品人人做人人爱| 亚洲欧洲精品一区二区三区 | 亚洲免费精品| 国产精品男人爽免费视频1| 亚洲综合激情| 亚洲综合日韩中文字幕v在线| 国产九九精品| 久久综合国产精品台湾中文娱乐网| 久久精品99无色码中文字幕 | 久久久久综合网| 亚洲区免费影片| 亚洲每日更新| 国产女优一区| 免播放器亚洲一区| 欧美精品v日韩精品v韩国精品v | 欧美涩涩视频| 欧美在现视频| 美日韩免费视频| 一区二区不卡在线视频 午夜欧美不卡'| 亚洲日本中文字幕免费在线不卡| 欧美日韩大片一区二区三区| 亚洲一区日本| 久久精品在线| 一区二区欧美亚洲| 午夜免费在线观看精品视频| 狠狠入ady亚洲精品| 亚洲国产成人av在线| 国产精品久久二区| 每日更新成人在线视频| 欧美精品少妇一区二区三区| 亚洲欧美成aⅴ人在线观看| 久久精品国产一区二区三区| 99视频+国产日韩欧美| 亚洲欧美日韩成人| 亚洲欧洲日本mm| 亚洲欧美激情一区二区| 亚洲丰满少妇videoshd| 亚洲图片在线| 亚洲成色www久久网站| avtt综合网| 亚洲第一天堂无码专区| 一本大道久久a久久精二百| 在线观看国产欧美| 亚洲一本大道在线| 亚洲精品久久久久久久久久久久久| 中文国产成人精品| 最新成人在线| 欧美一级理论性理论a| 亚洲免费观看视频| 久久精品夜色噜噜亚洲aⅴ| 亚洲永久免费观看| 美女主播视频一区| 欧美一级片在线播放| 欧美日本乱大交xxxxx| 久久夜色精品亚洲噜噜国产mv| 欧美日韩精品三区| 欧美a级大片| 国产视频一区二区三区在线观看| 亚洲高清在线观看| 加勒比av一区二区| 午夜国产精品影院在线观看| 亚洲天堂久久|