Changeset 2984 for code/branches/sound/src/orxonox/sound/SoundBase.cc
- Timestamp:
- May 18, 2009, 4:52:26 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/sound/src/orxonox/sound/SoundBase.cc
r2980 r2984 26 26 * 27 27 */ 28 #include <vector> 28 29 #include <AL/alut.h> 29 30 #include <vorbis/vorbisfile.h> … … 71 72 ALenum error = alGetError(); 72 73 if(error == AL_INVALID_VALUE) 73 COUT(2) << " OpenAL: Invalid sound position" << std::endl;74 COUT(2) << "Sound: OpenAL: Invalid sound position" << std::endl; 74 75 75 76 Vector3 vel = this->entity_->getVelocity(); … … 77 78 error = alGetError(); 78 79 if(error == AL_INVALID_VALUE) 79 COUT(2) << " OpenAL: Invalid sound position" << std::endl;80 COUT(2) << "Sound: OpenAL: Invalid sound velocity" << std::endl; 80 81 81 82 Quaternion orient = this->entity_->getOrientation(); … … 84 85 error = alGetError(); 85 86 if(error == AL_INVALID_VALUE) 86 COUT(2) << " OpenAL: Invalid sound position" << std::endl;87 COUT(2) << "Sound: OpenAL: Invalid sound direction" << std::endl; 87 88 } 88 89 } … … 133 134 bool SoundBase::loadFile(std::string filename) { 134 135 filename = Core::getMediaPathString() + "/audio/" + filename; 135 COUT(3) << " OpenAL ALUT: loading file " << filename << std::endl;136 COUT(3) << "Sound: OpenAL ALUT: loading file " << filename << std::endl; 136 137 this->buffer_ = alutCreateBufferFromFile(filename.c_str()); 137 138 if(this->buffer_ == AL_NONE) { 138 COUT(2) << " OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;139 COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl; 139 140 if(filename.find("ogg", 0) != std::string::npos) 140 141 { … … 149 150 alSourcei(this->source_, AL_BUFFER, this->buffer_); 150 151 if(alGetError() != AL_NO_ERROR) { 151 COUT(2) << " OpenAL: Error loading sample file" << std::endl;152 COUT(2) << "Sound: OpenAL: Error loading sample file" << std::endl; 152 153 return false; 153 154 } … … 160 161 return state; 161 162 } 162 163 163 164 ALuint SoundBase::loadOggFile(std::string filename) 164 165 { 165 // just a dummy 166 return AL_NONE; 166 COUT(2) << "Sound: Trying fallback ogg loader"; 167 168 char inbuffer[4096]; 169 std::vector<char> outbuffer; 170 OggVorbis_File vf; 171 int eof = false; 172 int current_section; 173 174 FILE* f = fopen(filename.c_str(), "rb"); 175 176 if(ov_open(f, &vf, NULL, 0) < 0) 177 { 178 COUT(2) << "Sound: libvorbisfile: File seems not to be an Ogg Vorbis bitstream" << std::endl; 179 ov_clear(&vf); 180 return AL_NONE; 181 } 182 183 while(!eof) 184 { 185 long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section); 186 if (ret == 0) 187 { 188 eof = true; 189 } 190 else if (ret < 0) 191 { 192 COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl; 193 ov_clear(&vf); 194 return AL_NONE; 195 } 196 else 197 { 198 outbuffer.insert(outbuffer.end(), inbuffer, inbuffer + sizeof(inbuffer)); 199 } 200 } 201 202 ov_clear(&vf); 203 204 return alutCreateBufferFromFileImage(&outbuffer, outbuffer.size()); 167 205 } 168 206 } // namespace: orxonox
Note: See TracChangeset
for help on using the changeset viewer.