Changeset 1784 for code/trunk/src/audio/AudioManager.cc
- Timestamp:
- Sep 15, 2008, 10:54:25 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/audio/AudioManager.cc
r1747 r1784 30 30 31 31 #include <cstdlib> 32 33 32 #include <AL/alut.h> 34 33 34 #include "util/Debug.h" 35 35 #include "AudioBuffer.h" 36 36 #include "AudioSource.h" 37 37 #include "AudioStream.h" 38 #include "util/Error.h"39 #include "util/Debug.h"40 38 41 39 namespace audio 42 40 { 43 44 45 ambientPath = "audio/ambient";41 AudioManager::AudioManager() 42 { 43 ambientPath = "audio/ambient"; 46 44 47 alutInit(NULL, 0); 45 alutInit(NULL, 0); 46 } 48 47 48 AudioManager::~AudioManager() 49 { 50 for (unsigned int i=0;i<bgSounds.size();i++) 51 { 52 bgSounds[i]->release(); 53 } 54 alutExit(); 55 } 49 56 50 } 57 void AudioManager::ambientStart() 58 { 59 // currentBgSound = 0; 60 if (bgSounds.size() > 0) 61 { 62 currentBgSound = rand() % bgSounds.size(); 63 if(!bgSounds[currentBgSound]->playback()) 64 { 65 COUT(2) << "AudioManager: Ogg refused to play." << std::endl; 66 } 67 else 68 { 69 COUT(3) << "Info: Started playing background sound" << std::endl; 70 } 71 } 72 } 51 73 52 AudioManager::~AudioManager() 53 { 54 for (unsigned int i=0;i<bgSounds.size();i++) 55 { 56 bgSounds[i]->release(); 57 } 58 alutExit(); 59 } 74 void AudioManager::ambientStop() 75 { 76 COUT(3) << "Info: Stopped playing background sound" << std::endl; 77 } 60 78 61 void AudioManager::ambientStart() 62 { 63 // currentBgSound = 0; 64 if (bgSounds.size() > 0) 65 { 66 currentBgSound = rand() % bgSounds.size(); 67 if(!bgSounds[currentBgSound]->playback()) 68 { 69 orxonox::Error("Ogg refused to play."); 70 } 71 else 72 { 73 COUT(3) << "Info: Started playing background sound" << std::endl; 74 } 75 } 76 } 79 void AudioManager::ambientAdd(std::string file) 80 { 81 std::string path = ambientPath + "/" + file + ".ogg"; 82 AudioStream* tmp = new AudioStream(path); 83 tmp->open(); 84 if (tmp->isLoaded()) 85 { 86 bgSounds.push_back(tmp); 87 COUT(3) << "Info: Added background sound " << file << std::endl; 88 } 89 } 77 90 78 void AudioManager::ambientStop() 79 { 80 COUT(3) << "Info: Stopped playing background sound" << std::endl; 81 } 91 void AudioManager::tick(float dt) 92 { 93 if (bgSounds.size() > 0) 94 { 95 if (bgSounds[currentBgSound]->isLoaded()) 96 { 97 bool playing = bgSounds[currentBgSound]->update(); 98 if (!bgSounds[currentBgSound]->playing() && playing) 99 { 100 if (!bgSounds[currentBgSound]->playback()) 101 COUT(2) << "AudioManager: Ogg abruptly stopped." << std::endl; 102 else 103 COUT(2) << "AudioManager: Ogg stream was interrupted." << std::endl; 82 104 83 void AudioManager::ambientAdd(std::string file) 84 { 85 std::string path = ambientPath + "/" + file + ".ogg"; 86 AudioStream* tmp = new AudioStream(path); 87 tmp->open(); 88 if (tmp->isLoaded()) 89 { 90 bgSounds.push_back(tmp); 91 COUT(3) << "Info: Added background sound " << file << std::endl; 92 } 93 } 105 } 106 if (!playing) 107 { 108 // if (currentBgSound < bgSounds.size()-1) 109 // { 110 // currentBgSound++; 111 // } 112 // else 113 // { 114 // currentBgSound=0; 115 // } 116 // switch to next sound in list/array 117 currentBgSound = ++currentBgSound % bgSounds.size(); 94 118 95 void AudioManager::tick(float dt) 96 { 97 if (bgSounds.size() > 0) 98 { 99 if (bgSounds[currentBgSound]->isLoaded()) 100 { 101 bool playing = bgSounds[currentBgSound]->update(); 102 if(!bgSounds[currentBgSound]->playing() && playing) 103 { 104 if(!bgSounds[currentBgSound]->playback()) 105 orxonox::Error("Ogg abruptly stopped."); 106 else 107 orxonox::Error("Ogg stream was interrupted."); 119 if (!bgSounds[currentBgSound]->isLoaded()) 120 { 121 bgSounds[currentBgSound]->release(); 122 bgSounds[currentBgSound]->open(); 123 } 124 bgSounds[currentBgSound]->playback(); 125 COUT(3) << "Info: Playing next background sound" << std::endl; 126 } 127 } 128 } 129 } 108 130 109 } 110 if (!playing) 111 { 112 // if (currentBgSound < bgSounds.size()-1) 113 // { 114 // currentBgSound++; 115 // } 116 // else 117 // { 118 // currentBgSound=0; 119 // } 120 // switch to next sound in list/array 121 currentBgSound = ++currentBgSound % bgSounds.size(); 131 void AudioManager::setPos(std::vector<float> newPosition) 132 { 122 133 123 if (!bgSounds[currentBgSound]->isLoaded()) 124 { 125 bgSounds[currentBgSound]->release(); 126 bgSounds[currentBgSound]->open(); 127 } 128 bgSounds[currentBgSound]->playback(); 129 COUT(3) << "Info: Playing next background sound" << std::endl; 130 } 131 } 132 } 133 } 134 } 134 135 135 void AudioManager::setPos(std::vector<float> newPosition)136 136 void AudioManager::setSpeed(std::vector<float> newSpeed) 137 { 137 138 138 139 } 139 140 140 void AudioManager::setSpeed(std::vector<float> newSpeed)141 141 void AudioManager::setOri(std::vector<float> at, std::vector<float> up) 142 { 142 143 143 } 144 145 void AudioManager::setOri(std::vector<float> at, std::vector<float> up) 146 { 147 148 } 144 } 149 145 }
Note: See TracChangeset
for help on using the changeset viewer.