Changeset 338
- Timestamp:
- Nov 28, 2007, 6:17:23 PM (17 years ago)
- Location:
- code/branches/audio/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/audio/src/audio/Ambient.cc
r335 r338 1 1 #include <iostream> 2 #include <string> 2 3 #include "Ambient.h" 3 #include "../../include/AL/al.h"4 #include "../../include/AL/alc.h"5 #include "../../include/AL/alut.h"6 4 7 5 namespace audio 8 6 { 9 Ambient::Ambient( )7 Ambient::Ambient(std::string audioFile) 10 8 { 11 SourcePos[0]=0; 12 SourcePos[1]=0; 13 SourcePos[2]=0; 14 15 SourceVel[0]=0; 16 SourceVel[1]=0; 17 SourceVel[2]=0; 18 19 ListenerPos[0]=0; 20 ListenerPos[1]=0; 21 ListenerPos[2]=0; 22 23 ListenerVel[0]=0; 24 ListenerVel[1]=0; 25 ListenerVel[2]=0; 26 27 ListenerOri[0]=0; 28 ListenerOri[1]=0; 29 ListenerOri[2]=-1; 30 ListenerOri[3]=0; 31 ListenerOri[4]=1; 32 ListenerOri[5]=0; 33 34 35 // Initialize OpenAL and clear the error bit. 36 37 alutInit(NULL, 0); 38 alGetError(); 39 40 // Load the wav data. 41 42 if(LoadALData() == AL_FALSE) 43 { 44 printf("Error loading sound data."); 9 a = new AudioObject(audioFile); 10 } 11 12 Ambient::~Ambient() 13 { 45 14 46 15 } 47 48 SetListenerValues();49 50 // Setup an exit procedure.51 52 //atexit(KillALData);53 54 std::cout << "Play sone ambient background sound";55 }56 16 57 ALboolean Ambient::LoadALData()58 {59 ALenum format;60 ALsizei size;61 ALvoid* data;62 ALsizei freq;63 ALboolean loop;64 65 66 alGenBuffers(1, &Buffer);67 68 if(alGetError() != AL_NO_ERROR)69 return AL_FALSE;70 71 alutLoadWAVFile((ALbyte*)"wavdata/pirate.wav", &format, &data, &size, &freq, &loop);72 alBufferData(Buffer, format, data, size, freq);73 alutUnloadWAV(format, data, size, freq);74 75 alGenSources(1, &Source);76 77 if(alGetError() != AL_NO_ERROR)78 return AL_FALSE;79 80 alSourcei (Source, AL_BUFFER, Buffer );81 alSourcef (Source, AL_PITCH, 1.0 );82 alSourcef (Source, AL_GAIN, 1.0 );83 alSourcefv(Source, AL_POSITION, SourcePos);84 alSourcefv(Source, AL_VELOCITY, SourceVel);85 alSourcei (Source, AL_LOOPING, loop );86 87 if(alGetError() == AL_NO_ERROR)88 return AL_TRUE;89 90 91 return AL_FALSE;92 }93 94 void Ambient::SetListenerValues()95 {96 alListenerfv(AL_POSITION, ListenerPos);97 alListenerfv(AL_VELOCITY, ListenerVel);98 alListenerfv(AL_ORIENTATION, ListenerOri);99 }100 101 void Ambient::KillALData()102 {103 alDeleteBuffers(1, &Buffer);104 alDeleteSources(1, &Source);105 alutExit();106 }107 108 17 void Ambient::play() 109 18 { 110 alSourcePlay(Source); 111 19 a->play(); 112 20 } 113 21 } -
code/branches/audio/src/audio/Ambient.h
r334 r338 7 7 #include "../../include/AL/alut.h" 8 8 9 #include "AudioObject.h" 9 10 10 11 namespace audio … … 13 14 { 14 15 public: 15 Ambient(); 16 Ambient(std::string audioFile); 17 ~Ambient(); 16 18 void play(); 17 19 private: 18 ALboolean LoadALData(); 19 void SetListenerValues(); 20 void KillALData(); 21 22 ALuint Buffer; 23 ALuint Source; 24 ALfloat SourcePos[3]; 25 ALfloat SourceVel[3]; 26 ALfloat ListenerPos[3]; 27 ALfloat ListenerVel[3]; 28 ALfloat ListenerOri[6]; 20 AudioObject* a; 29 21 }; 30 31 32 33 34 35 22 } 36 23 -
code/branches/audio/src/audio/CMakeLists.txt
r334 r338 1 1 PROJECT(Orxonox) 2 2 3 SET(SRC_FILES Ambient.cc) 4 SET(INC_FILES Ambient.h) 3 SET(SRC_FILES 4 Ambient.cc 5 AudioObject.cc 6 ) 7 SET(INC_FILES 8 Ambient.h 9 AudioObject.h 10 ) 5 11 6 12 -
code/branches/audio/src/orxonox/orxonox.cc
r334 r338 191 191 void createScene(void) 192 192 { 193 audio::Ambient* bgsound = new audio::Ambient();194 193 audio::Ambient* bgsound = new audio::Ambient("wavdata/pirate.wav"); 194 bgsound->play(); 195 195 196 196 string levelFile = "sp_level_moonstation.oxw";
Note: See TracChangeset
for help on using the changeset viewer.