Changeset 5899 for code/branches/core5/src/orxonox
- Timestamp:
- Oct 7, 2009, 11:19:19 AM (15 years ago)
- Location:
- code/branches/core5/src/orxonox
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/src/orxonox/gamestates/GSMainMenu.cc
r5896 r5899 63 63 // Load sound 64 64 this->ambient_ = new AmbientSound(0); 65 this->ambient_->setSou ndFile("ambient/mainmenu.wav");65 this->ambient_->setSource("ambient/mainmenu.wav"); 66 66 } 67 67 } -
code/branches/core5/src/orxonox/sound/AmbientSound.cc
r5896 r5899 49 49 { 50 50 SUPER(AmbientSound, XMLPort, xmlelement, mode); 51 XMLPortParamExtern(AmbientSound, BaseSound, this, "sou ndFile", setSoundFile, getSoundFile, xmlelement, mode);51 XMLPortParamExtern(AmbientSound, BaseSound, this, "source", setSource, getSource, xmlelement, mode); 52 52 XMLPortParamExtern(AmbientSound, BaseSound, this, "loop", setLoop, getLoop, xmlelement, mode); 53 53 XMLPortParamExtern(AmbientSound, BaseSound, this, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode); -
code/branches/core5/src/orxonox/sound/BaseSound.cc
r5896 r5899 40 40 { 41 41 BaseSound::BaseSound() 42 : source_(0)43 , buffer_(0)42 : audioSource_(0) 43 , audioBuffer_(0) 44 44 , bPlayOnLoad_(false) 45 45 , bLoop_(false) … … 50 50 BaseSound::~BaseSound() 51 51 { 52 this->setSou ndFile("");52 this->setSource(""); 53 53 } 54 54 55 55 void BaseSound::play() 56 56 { 57 if (alIsSource(this-> source_))57 if (alIsSource(this->audioSource_)) 58 58 { 59 59 if (this->bLoop_) 60 alSourcei(this-> source_, AL_LOOPING, AL_TRUE);60 alSourcei(this->audioSource_, AL_LOOPING, AL_TRUE); 61 61 else 62 alSourcei(this-> source_, AL_LOOPING, AL_FALSE);63 alSourcePlay(this-> source_);62 alSourcei(this->audioSource_, AL_LOOPING, AL_FALSE); 63 alSourcePlay(this->audioSource_); 64 64 65 65 if (alGetError() != AL_NO_ERROR) 66 66 { 67 COUT(2) << "Sound: OpenAL: Error playin sound " << this-> source_ << std::endl;67 COUT(2) << "Sound: OpenAL: Error playin sound " << this->audioSource_ << std::endl; 68 68 } 69 69 } … … 72 72 void BaseSound::stop() 73 73 { 74 if (alIsSource(this-> source_))75 alSourceStop(this-> source_);74 if (alIsSource(this->audioSource_)) 75 alSourceStop(this->audioSource_); 76 76 } 77 77 78 78 void BaseSound::pause() 79 79 { 80 if (alIsSource(this-> source_))81 alSourcePause(this-> source_);80 if (alIsSource(this->audioSource_)) 81 alSourcePause(this->audioSource_); 82 82 } 83 83 84 84 bool BaseSound::isPlaying() 85 85 { 86 if (alIsSource(this-> source_))86 if (alIsSource(this->audioSource_)) 87 87 return getSourceState() == AL_PLAYING; 88 88 return false; … … 91 91 bool BaseSound::isPaused() 92 92 { 93 if (alIsSource(this-> source_))93 if (alIsSource(this->audioSource_)) 94 94 return getSourceState() == AL_PAUSED; 95 95 return true; … … 98 98 bool BaseSound::isStopped() 99 99 { 100 if (alIsSource(this-> source_))100 if (alIsSource(this->audioSource_)) 101 101 return getSourceState() == AL_INITIAL || getSourceState() == AL_STOPPED; 102 102 return true; … … 109 109 } 110 110 111 void BaseSound::setSou ndFile(const std::string& soundFile)112 { 113 this->sou ndFile_ = soundFile;111 void BaseSound::setSource(const std::string& source) 112 { 113 this->source_ = source; 114 114 if (!GameMode::playsSound()) 115 115 return; 116 116 117 if (sou ndFile.empty() && alIsSource(this->source_))117 if (source.empty() && alIsSource(this->audioSource_)) 118 118 { 119 119 // Unload sound 120 alSourcei(this-> source_, AL_BUFFER, 0);121 alDeleteSources(1, &this-> source_);122 alDeleteBuffers(1, &this-> buffer_);123 return; 124 } 125 126 COUT(3) << "Sound: OpenAL ALUT: loading file " << sou ndFile << std::endl;120 alSourcei(this->audioSource_, AL_BUFFER, 0); 121 alDeleteSources(1, &this->audioSource_); 122 alDeleteBuffers(1, &this->audioBuffer_); 123 return; 124 } 125 126 COUT(3) << "Sound: OpenAL ALUT: loading file " << source << std::endl; 127 127 // Get DataStream from the resources 128 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(sou ndFile);128 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(source); 129 129 if (fileInfo == NULL) 130 130 { 131 COUT(2) << "Warning: Sound file '" << sou ndFile << "' not found" << std::endl;132 return; 133 } 134 DataStreamPtr stream = Resource::open(sou ndFile);131 COUT(2) << "Warning: Sound file '" << source << "' not found" << std::endl; 132 return; 133 } 134 DataStreamPtr stream = Resource::open(source); 135 135 // Read everything into a temporary buffer 136 136 char* buffer = new char[fileInfo->size]; 137 137 stream->read(buffer, fileInfo->size); 138 138 139 this-> buffer_ = alutCreateBufferFromFileImage(buffer, fileInfo->size);139 this->audioBuffer_ = alutCreateBufferFromFileImage(buffer, fileInfo->size); 140 140 delete[] buffer; 141 141 142 if (this-> buffer_ == AL_NONE)142 if (this->audioBuffer_ == AL_NONE) 143 143 { 144 144 COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl; … … 147 147 //{ 148 148 // COUT(2) << "Sound: Trying fallback ogg loader" << std::endl; 149 // this-> buffer_ = loadOggFile(filename);149 // this->audioBuffer_ = loadOggFile(filename); 150 150 //} 151 151 152 //if (this-> buffer_ == AL_NONE)152 //if (this->audioBuffer_ == AL_NONE) 153 153 //{ 154 154 // COUT(2) << "Sound: fallback ogg loader failed: " << alutGetErrorString(alutGetError()) << std::endl; … … 157 157 } 158 158 159 alGenSources(1, &this-> source_);160 alSourcei(this-> source_, AL_BUFFER, this->buffer_);159 alGenSources(1, &this->audioSource_); 160 alSourcei(this->audioSource_, AL_BUFFER, this->audioBuffer_); 161 161 if (alGetError() != AL_NO_ERROR) 162 162 { 163 COUT(2) << "Sound: OpenAL: Error loading sample file: " << sou ndFile << std::endl;164 return; 165 } 166 167 alSource3f(this-> source_, AL_POSITION, 0, 0, 0);163 COUT(2) << "Sound: OpenAL: Error loading sample file: " << source << std::endl; 164 return; 165 } 166 167 alSource3f(this->audioSource_, AL_POSITION, 0, 0, 0); 168 168 169 169 if (this->bPlayOnLoad_) … … 174 174 { 175 175 ALint state; 176 alGetSourcei(this-> source_, AL_SOURCE_STATE, &state);176 alGetSourcei(this->audioSource_, AL_SOURCE_STATE, &state); 177 177 return state; 178 178 } -
code/branches/core5/src/orxonox/sound/BaseSound.h
r5896 r5899 55 55 bool isStopped(); 56 56 57 void setSou ndFile(const std::string& soundFile);58 const std::string& getSou ndFile() { return this->soundFile_; }57 void setSource(const std::string& source); 58 const std::string& getSource() { return this->source_; } 59 59 60 60 bool getPlayOnLoad() { return this->bPlayOnLoad_; } … … 65 65 66 66 protected: 67 //ALuint loadOggFile(const std::string& filename);67 ALuint loadOggFile(const std::string& filename); 68 68 ALint getSourceState(); 69 69 70 ALuint source_;71 ALuint buffer_;70 ALuint audioSource_; 71 ALuint audioBuffer_; 72 72 73 73 private: 74 std::string sou ndFile_;74 std::string source_; 75 75 bool bPlayOnLoad_; 76 76 bool bLoop_; -
code/branches/core5/src/orxonox/sound/WorldSound.cc
r5897 r5899 52 52 { 53 53 SUPER(WorldSound, XMLPort, xmlelement, mode); 54 XMLPortParamExtern(WorldSound, BaseSound, this, "sou ndFile", setSoundFile, getSoundFile, xmlelement, mode);54 XMLPortParamExtern(WorldSound, BaseSound, this, "source", setSource, getSource, xmlelement, mode); 55 55 XMLPortParamExtern(WorldSound, BaseSound, this, "loop", setLoop, getLoop, xmlelement, mode); 56 56 XMLPortParamExtern(WorldSound, BaseSound, this, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode); … … 65 65 void WorldSound::tick(float dt) 66 66 { 67 if (alIsSource(this-> source_))67 if (alIsSource(this->audioSource_)) 68 68 { 69 69 const Vector3& pos = this->getWorldPosition(); 70 alSource3f(this-> source_, AL_POSITION, pos.x, pos.y, pos.z);70 alSource3f(this->audioSource_, AL_POSITION, pos.x, pos.y, pos.z); 71 71 ALenum error = alGetError(); 72 72 if (error == AL_INVALID_VALUE) … … 74 74 75 75 const Vector3& vel = this->getVelocity(); 76 alSource3f(this-> source_, AL_VELOCITY, vel.x, vel.y, vel.z);76 alSource3f(this->audioSource_, AL_VELOCITY, vel.x, vel.y, vel.z); 77 77 error = alGetError(); 78 78 if (error == AL_INVALID_VALUE) … … 81 81 const Quaternion& orient = this->getWorldOrientation(); 82 82 Vector3 at = orient.zAxis(); 83 alSource3f(this-> source_, AL_DIRECTION, at.x, at.y, at.z);83 alSource3f(this->audioSource_, AL_DIRECTION, at.x, at.y, at.z); 84 84 error = alGetError(); 85 85 if (error == AL_INVALID_VALUE)
Note: See TracChangeset
for help on using the changeset viewer.