Changeset 430
- Timestamp:
- Dec 5, 2007, 11:47:05 PM (17 years ago)
- Location:
- code/branches/FICN
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/audio/AudioManager.cc
r423 r430 1 1 #include "AudioManager.h" 2 3 2 4 3 5 namespace audio … … 5 7 AudioManager::AudioManager() 6 8 { 9 ambientPath = "audio/ambient"; 10 7 11 alutInit(NULL, 0); 8 9 bgSound.open("ambient1");12 13 10 14 11 15 12 16 13 bgSound.display();14 15 if(!bgSound.playback())16 {17 orxonox::Error("Ogg refused to play.");18 }19 17 } 20 18 21 19 AudioManager::~AudioManager() 22 20 { 23 bgSound.release(); 21 for (unsigned int i=0;i<=bgSounds.size();i++) 22 { 23 bgSounds[i].release(); 24 } 24 25 alutExit(); 26 } 27 28 void AudioManager::ambientStart() 29 { 30 currentBgSound = 0; 31 if (bgSounds.size() > 0) 32 { 33 if(!bgSounds[currentBgSound].playback()) 34 { 35 orxonox::Error("Ogg refused to play."); 36 } 37 else 38 { 39 std::cout << "Started playing background sound"<<std::endl; 40 } 41 } 42 43 } 44 45 void AudioManager::ambientStop() 46 { 47 std::cout << "Stopped playing background sound"<<std::endl; 48 } 49 50 void AudioManager::ambientAdd(std::string file) 51 { 52 std::string path = ambientPath + "/" + file + ".ogg"; 53 AudioStream tmp(path); 54 tmp.open(); 55 if (tmp.isLoaded()) 56 { 57 bgSounds.push_back(tmp); 58 std::cout << "Added background sound "<<file<<std::endl; 59 } 25 60 } 26 61 27 62 void AudioManager::update() 28 63 { 29 30 if (bgSound.isLoaded()) 64 if (bgSounds.size() > 0) 31 65 { 32 bgSound.update(); 33 if(!bgSound.playing()) 34 { 35 if(!bgSound.playback()) 36 orxonox::Error("Ogg abruptly stopped."); 37 else 38 orxonox::Error("Ogg stream was interrupted."); 39 } 66 if (bgSounds[currentBgSound].isLoaded()) 67 { 68 bool playing = bgSounds[currentBgSound].update(); 69 if(!bgSounds[currentBgSound].playing() && playing) 70 { 71 if(!bgSounds[currentBgSound].playback()) 72 orxonox::Error("Ogg abruptly stopped."); 73 else 74 orxonox::Error("Ogg stream was interrupted."); 75 76 } 77 if (!playing) 78 { 79 if (currentBgSound < bgSounds.size()-1) 80 { 81 currentBgSound++; 82 } 83 else 84 { 85 currentBgSound=0; 86 } 87 if (!bgSounds[currentBgSound].isLoaded()) 88 { 89 bgSounds[currentBgSound].release(); 90 bgSounds[currentBgSound].open(); 91 } 92 bgSounds[currentBgSound].playback(); 93 std::cout << "Playing next background sound "<<std::endl; 94 } 95 } 40 96 } 41 97 } -
code/branches/FICN/src/audio/AudioManager.h
r419 r430 37 37 void update(); 38 38 39 void ambientAdd(std::string file); 40 void ambientStart(); 41 void ambientStop(); 42 39 43 private: 40 44 41 // Backgroundsound 42 AudioStream bgSound; 45 // Background sound 46 std::vector<AudioStream> bgSounds; 47 int currentBgSound; 48 49 50 51 std::string ambientPath; 43 52 44 53 // Vector containing all audio files -
code/branches/FICN/src/audio/AudioStream.cc
r424 r430 4 4 namespace audio 5 5 { 6 void AudioStream::open(std::string path) 6 AudioStream::AudioStream(std::string path) 7 { 8 this->path = path; 9 loaded = false; 10 } 11 12 void AudioStream::open() 7 13 { 8 14 int result; 9 loaded = false; 10 11 12 path = "audio/ambient/" + path + ".ogg"; 15 13 16 14 17 if(!(oggFile = fopen(path.c_str(), "rb"))) … … 53 56 void AudioStream::release() 54 57 { 55 if (loaded) 56 { 58 57 59 alSourceStop(source); 58 60 empty(); … … 64 66 ov_clear(&oggStream); 65 67 loaded = false; 66 }68 67 69 } 68 70 … … 155 157 } 156 158 159 if (active==false) 160 { 161 loaded = false; 162 } 157 163 return active; 158 164 } -
code/branches/FICN/src/audio/AudioStream.h
r423 r430 7 7 { 8 8 #define BUFFER_SIZE (4096 * 4) 9 #define STREAM_FILES_DIR "audio/ambient"10 9 11 10 class AudioStream 12 11 { 13 12 public: 14 15 void open( std::string path);13 AudioStream(std::string path); 14 void open(); 16 15 void release(); 17 16 void display(); … … 30 29 private: 31 30 31 std::string path; 32 32 33 FILE* oggFile; 33 34 OggVorbis_File oggStream; -
code/branches/FICN/src/orxonox/orxonox.cc
r427 r430 287 287 auMan = new audio::AudioManager(); 288 288 289 auMan->ambientAdd("a1"); 290 auMan->ambientAdd("a2"); 291 auMan->ambientAdd("a3"); 292 //auMan->ambientAdd("ambient1"); 293 auMan->ambientStart(); 289 294 290 295 string levelFile = "sp_level_moonstation.oxw";
Note: See TracChangeset
for help on using the changeset viewer.