Changeset 6071 for code/branches/sound3/src
- Timestamp:
- Nov 15, 2009, 10:36:45 PM (15 years ago)
- Location:
- code/branches/sound3/src/orxonox
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/sound3/src/orxonox/gamestates/GSMainMenu.cc
r6031 r6071 102 102 if (GameMode::playsSound()) 103 103 { 104 this->ambient_->setLoop (true);105 this->ambient_->setPlayOnLoad(true); 104 this->ambient_->setLooping(true); 105 this->ambient_->play(); // works without source 106 106 } 107 107 … … 136 136 if (GameMode::playsSound()) 137 137 { 138 this->ambient_->setSource(soundPathMain_);138 this->ambient_->setAmbientSource(soundPathMain_); 139 139 } 140 140 } -
code/branches/sound3/src/orxonox/sound/AmbientSound.cc
r6069 r6071 32 32 #include "core/EventIncludes.h" 33 33 #include "core/GameMode.h" 34 #include "core/Resource.h" 34 35 #include "core/XMLPort.h" 35 36 #include "SoundManager.h" 37 #include "MoodManager.h" 36 38 37 39 namespace orxonox … … 56 58 SUPER(AmbientSound, XMLPort, xmlelement, mode); 57 59 XMLPortParamExtern(AmbientSound, BaseSound, this, "volume", setVolume, getVolume, xmlelement, mode); 58 XMLPortParamExtern(AmbientSound, BaseSound, this, "loop", setLoop , getLoop, xmlelement, mode);59 XMLPortParamExtern(AmbientSound, BaseSound, this, "play OnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);60 XMLPortParam Extern(AmbientSound, BaseSound, this, "source", setSource, getSource, xmlelement, mode);60 XMLPortParamExtern(AmbientSound, BaseSound, this, "loop", setLooping, getLooping, xmlelement, mode); 61 XMLPortParamExtern(AmbientSound, BaseSound, this, "play", play, isPlaying, xmlelement, mode); 62 XMLPortParam(AmbientSound, "source", setAmbientSource, getAmbientSource, xmlelement, mode); 61 63 } 62 64 … … 107 109 } 108 110 109 void AmbientSound::set Source(const std::string& source)111 void AmbientSound::setAmbientSource(const std::string& source) 110 112 { 113 this->ambientSource_ = source; 111 114 if (GameMode::playsSound()) 112 115 { 113 std::string filePath = SoundManager::getInstance().getAmbientPath(source); 114 if (!filePath.empty()) 115 { 116 BaseSound::setSource(filePath); 117 return; 118 } 119 COUT(3) << "Sound: " << source << ": Not a valid name! Ambient sound will not change." << std::endl; 116 std::string path = "ambient/" + MoodManager::getInstance().getMood() + "/" + source; 117 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path); 118 if (fileInfo != NULL) 119 this->setSource(path); 120 else 121 COUT(3) << "Sound: " << source << ": Not a valid name! Ambient sound will not change." << std::endl; 120 122 } 121 123 } -
code/branches/sound3/src/orxonox/sound/AmbientSound.h
r6069 r6071 59 59 virtual void pause(); 60 60 61 virtual void setSource(const std::string& source); 61 virtual void setAmbientSource(const std::string& source); 62 const std::string& getAmbientSource() const { return this->ambientSource_; } 62 63 63 64 private: 64 void doPlay(); // Continue playing without re-registering the sound65 void doPlay(); 65 66 void doStop(); 66 67 void doPause(); 68 69 std::string ambientSource_; //!< Analogous to source_, but mood independent 67 70 }; 68 71 } -
code/branches/sound3/src/orxonox/sound/BaseSound.cc
r6070 r6071 29 29 #include "BaseSound.h" 30 30 31 #include <cassert> 31 32 #include <vector> 32 33 #include <AL/alut.h> … … 42 43 : audioSource_(0) 43 44 , audioBuffer_(0) 44 , bPlayOnLoad_(false)45 45 , bLoop_(false) 46 , state_(Stopped) 46 47 { 47 48 RegisterRootObject(BaseSound); 48 49 49 50 if (GameMode::playsSound()) 51 { 50 52 alGenSources(1, &this->audioSource_); 53 assert(this->audioSource_ != 0); 54 } 51 55 } 52 56 … … 54 58 { 55 59 this->setSource(""); 56 if ( this->audioSource_)60 if (GameMode::playsSound()) 57 61 alDeleteSources(1, &this->audioSource_); 58 62 } … … 60 64 void BaseSound::play() 61 65 { 62 if (alIsSource(this->audioSource_)) 63 { 64 if (this->bLoop_) 65 alSourcei(this->audioSource_, AL_LOOPING, AL_TRUE); 66 else 67 alSourcei(this->audioSource_, AL_LOOPING, AL_FALSE); 66 if (!this->isPlaying() && GameMode::showsGraphics()) 67 { 68 this->state_ = Playing; 68 69 alSourcePlay(this->audioSource_); 69 70 70 71 if (alGetError() != AL_NO_ERROR) 71 {72 72 COUT(2) << "Sound: OpenAL: Error playing sound " << this->audioSource_ << std::endl; 73 }74 73 } 75 74 } … … 77 76 void BaseSound::stop() 78 77 { 79 if (alIsSource(this->audioSource_)) 78 this->state_ = Stopped; 79 if (GameMode::playsSound()) 80 80 alSourceStop(this->audioSource_); 81 81 } … … 83 83 void BaseSound::pause() 84 84 { 85 if (alIsSource(this->audioSource_)) 85 if (this->isStopped()) 86 return; 87 this->state_ = Paused; 88 if (GameMode::playsSound()) 86 89 alSourcePause(this->audioSource_); 87 }88 89 bool BaseSound::isPlaying()90 {91 if (alIsSource(this->audioSource_))92 return getSourceState() == AL_PLAYING;93 return false;94 }95 96 bool BaseSound::isPaused()97 {98 if (alIsSource(this->audioSource_))99 return getSourceState() == AL_PAUSED;100 return false;101 }102 103 bool BaseSound::isStopped()104 {105 if (alIsSource(this->audioSource_))106 return getSourceState() == AL_INITIAL || getSourceState() == AL_STOPPED;107 return true;108 90 } 109 91 … … 121 103 } 122 104 105 void BaseSound::setLooping(bool val) 106 { 107 this->bLoop_ = val; 108 if (GameMode::playsSound()) 109 alSourcei(this->audioSource_, AL_LOOPING, (val ? AL_TRUE : AL_FALSE)); 110 } 111 123 112 void BaseSound::setSource(const std::string& source) 124 113 { … … 128 117 return; 129 118 } 130 131 if ( alIsSource(this->audioBuffer_))132 { 133 this->stop();119 120 if (this->audioBuffer_ != 0 && alIsBuffer(this->audioBuffer_)) 121 { 122 alSourceStop(this->audioSource_); 134 123 // Unload old sound first 135 124 alSourcei(this->audioSource_, AL_BUFFER, 0); … … 183 172 184 173 alSource3f(this->audioSource_, AL_POSITION, 0, 0, 0); 185 186 this->setVolume(this->volume_); 187 188 if (this->bPlayOnLoad_) 189 this->play(); 190 } 191 192 ALint BaseSound::getSourceState() 193 { 194 ALint state; 195 alGetSourcei(this->audioSource_, AL_SOURCE_STATE, &state); 196 return state; 174 alSourcef (this->audioSource_, AL_GAIN, this->volume_); 175 alSourcei (this->audioSource_, AL_LOOPING, (this->bLoop_ ? AL_TRUE : AL_FALSE)); 176 if (this->isPlaying() || this->isPaused()) 177 alSourcePlay(this->audioSource_); 178 if (this->isPaused()) 179 alSourcePause(this->audioSource_); 180 181 if (alGetError() != AL_NO_ERROR) 182 COUT(2) << "Sound: OpenAL: Error playing sound " << this->audioSource_ << std::endl; 197 183 } 198 184 -
code/branches/sound3/src/orxonox/sound/BaseSound.h
r6069 r6071 53 53 virtual void pause(); 54 54 55 bool isPlaying() ;56 bool isPaused() ;57 bool isStopped() ;55 bool isPlaying() { return this->state_ = Playing; } 56 bool isPaused() { return this->state_ = Paused; } 57 bool isStopped() { return this->state_ = Stopped; } 58 58 59 59 virtual void setSource(const std::string& source); … … 63 63 float getVolume() const { return this->volume_; } 64 64 65 bool getPlayOnLoad() const { return this->bPlayOnLoad_; } 66 void setPlayOnLoad(bool val) { this->bPlayOnLoad_ = val; } 67 68 bool getLoop() const { return this->bLoop_; } 69 void setLoop(bool val) { this->bLoop_ = val; } 65 bool getLooping() const { return this->bLoop_; } 66 void setLooping(bool val); 70 67 71 68 //ALuint getALAudioSource(void); … … 73 70 protected: 74 71 ALuint loadOggFile(); 75 ALint getSourceState();76 72 77 73 ALuint audioSource_; … … 79 75 80 76 private: 77 enum State 78 { 79 Stopped, 80 Playing, 81 Paused 82 }; 83 81 84 std::string source_; 82 85 float volume_; 83 bool bPlayOnLoad_;84 86 bool bLoop_; 87 State state_; 85 88 DataStreamPtr dataStream_; 86 89 }; -
code/branches/sound3/src/orxonox/sound/SoundManager.cc
r6069 r6071 40 40 #include "core/GameMode.h" 41 41 #include "core/ScopedSingletonManager.h" 42 #include "core/Resource.h"43 42 #include "core/ConfigValueIncludes.h" 44 43 #include "BaseSound.h" 45 #include "MoodManager.h"46 44 #include "AmbientSound.h" 47 45 … … 223 221 } 224 222 225 //! Get the current mood and return the full path string to the requested sound.226 std::string SoundManager::getAmbientPath(const std::string& source)227 {228 std::string path = "ambient/" + MoodManager::getInstance().getMood() + "/" + source;229 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path);230 if (fileInfo == NULL)231 {232 return "";233 }234 return path;235 }236 237 223 void SoundManager::fadeIn(AmbientSound* sound) 238 224 { -
code/branches/sound3/src/orxonox/sound/SoundManager.h
r6069 r6071 60 60 void unregisterAmbientSound(AmbientSound* oldAmbient); 61 61 void pauseAmbientSound(AmbientSound* ambient); 62 std::string getAmbientPath(const std::string& source);63 62 64 63 private: -
code/branches/sound3/src/orxonox/sound/WorldSound.cc
r6069 r6071 54 54 SUPER(WorldSound, XMLPort, xmlelement, mode); 55 55 XMLPortParamExtern(WorldSound, BaseSound, this, "volume", setVolume, getVolume, xmlelement, mode); 56 XMLPortParamExtern(WorldSound, BaseSound, this, "loop", setLoop , getLoop, xmlelement, mode);57 XMLPortParamExtern(WorldSound, BaseSound, this, "play OnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);56 XMLPortParamExtern(WorldSound, BaseSound, this, "loop", setLooping, getLooping, xmlelement, mode); 57 XMLPortParamExtern(WorldSound, BaseSound, this, "play", play, isPlaying, xmlelement, mode); 58 58 XMLPortParamExtern(WorldSound, BaseSound, this, "source", setSource, getSource, xmlelement, mode); 59 59 }
Note: See TracChangeset
for help on using the changeset viewer.