1 / 17

GAM532 DPS932 – Week 9

GAM532 DPS932 – Week 9. 2D Audio. Audio Section Introduction. Game Engines. Graphics Engine. Audio Engine. Input Engine. Direct 3D (Direct X). OpenGL. Xaudio2 (Direct X). OpenAL. Raw Input(Windows). Sound Engine Purpose. Load Sound File. Prepare Sound Data. Process Sound Data.

kellsie
Download Presentation

GAM532 DPS932 – Week 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GAM532DPS932 – Week 9 2D Audio

  2. Audio Section Introduction

  3. Game Engines Graphics Engine Audio Engine Input Engine Direct 3D (Direct X) OpenGL Xaudio2 (Direct X) OpenAL Raw Input(Windows)

  4. Sound Engine Purpose Load Sound File Prepare Sound Data Process Sound Data Output Sound

  5. Emperor Engine Architecture XA2 Object XA2 API iEngine Engine Controller Manager Model 1 or 1 1 m 1 m 1 m 1 AL 1.1 Object AL 1.1 API 1 XA2 Device AL 1.1Device iController iModel 1 or 1 AL 1.1 API XA2 API

  6. Interface Base ClassRM = Resource ManagerBM = Base ManagerIM = Iterative Manager Singleton Audio Engine Components Emitter <AS> Contains (m = many) XA/AL API Wrapper Either or (only one) RM Mesh <RS> XA2Device AL 1.1 Device SoundManager <AS> AudioController <AS> m Listener <AS> Engine <AS> BM ListenerManager<AS> m IM EmitterManager<AS> m Sound <AS>

  7. Initializing Audio Systems #include <XAudio2.h> #pragma comment (lib, "XAudio2.lib") //Create Audio Engine XAudio2Create(&engine); //Create Output Object engine->CreateMasteringVoice(&master); //Start engine engine->StartEngine(); #include <AL/al.h> #include <AL/alc.h> //Create Audio Engine engine = alcOpenDevice(0); //Create Context Object context = alcCreateContext(engine, 0); //Bind context (prepares system) alcMakeContextCurrent(context);

  8. Controlling & Destroying Audio Systems //Set Master Volume master->SetVolume(volume); //Destroy the engine engine->StopEngine(); engine->Release(); //Set Master Volume alListenerf(AL_GAIN, volume); //Destroy the engine alcMakecontextCurrent(0); alcDestroyContext(context); alcCloseDevice(engine);

  9. Sounds, Emitters, Listeners Active Emitter Objects Hardware Output Sound Objects Listener Objects

  10. Sound Object Holds the Data of a sound file Data 8723 6498 7213 6498 7162 3948 7629 3874 6982 3764 9827 3649 8723 6498 7235 Size 60 Format WAVE Only one copy of any sound file should exist, otherwise you’re wasting memory!

  11. Emitter Objects Object that plays sounds Controls play state and volumes Can be played as 2D or 3D 2D Sound 3D Sound Left - Right 100% 100% Left - Right 92% 45%

  12. Initializing an Emitter //Create the source and buffer objects alGenBuffers(1, &buffer); alGenSources(1, &source); float pos[] = {0,0,0}; //Give source default values alSourcei(source, AL_BUFFER, buffer); alSourcef(source, AL_PITCH, 1.0f); alSourcef(source, AL_GAIN, 1.0f); alSourcefv(source, AL_POSITION, pos); alSourcefv(source, AL_VELOCITY, pos); alSourcei(source, AL_LOOPING, AL_FALSE); //Create the source object CreateSourceVoice(&source, (WAVEFORMATEX*)&format); //Fill the buffer object buffer.pAudioData = data; buffer.AudioBytes = size; //Prepare the source for playing by the emitter source->SubmitSourceBuffer(&buffer);

  13. Controlling an Emitter //Play the prepared sound buffer source->Start(); //Set the volume of the emitter source->SetVolume(volume); //Stop playing current sound source->Stop(); //Clear out prepared buffers source->FlushSourceBuffers(); //Check if the sound is playing XAUDIO2_VOICE_STATE vs; source->GetState(&vs); if(vs.BuffersQueued!=0) ... //if buffers queued is 0, the sound has stopped //Play the prepared sound buffer alSourcePlay(source); //Set the volume of the emitter alSourcef(source, AL_GAIN, volume); //Stop playing current sound alSourceStop(source); //Pause playing current sound alSourcePause(source); //Check if the sound is playing ALenum state; alGetSourcei(source, AL_SOURCE_STATE, &state); if(state == AL_PLAYING) … //if state is AL_PLAYING, then the sound is playing

  14. Looping sound //Will loop the whole sound forever buffer.LoopBegin= 0; buffer.LoopLength= buffer.PlayLength; buffer.LoopCount= XAUDIO2_LOOP_INFINITE; //Stops the sound from looping buffer.LoopBegin= 0; buffer.LoopLength= 0; buffer.LoopCount= 0; //Will loop the whole sound forever alSourcei(source, AL_LOOPING, true); //Stops the sound from looping alSourcei(source, AL_LOOPING, false);

  15. Destroying Emitter //Clears out the buffers source->FlushSourceBuffers(); //Destroys the emitter source->DestroyVoice(); //Clears our the buffers alDeleteBuffers(1, &buffer); //Destroy the emitter alDeleteSources(1, &source);

  16. Sounds, Emitters, Listeners Active Emitter Objects Hardware Output Sound Objects Listener Objects

  17. To Do • Continue work on your enhancement • Work on OpenGL labs • Schedule meeting with me

More Related