Changeset 5904 for code/branches
- Timestamp:
- Oct 8, 2009, 12:00:21 AM (15 years ago)
- Location:
- code/branches/core5/src/orxonox/sound
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/src/orxonox/sound/BaseSound.cc
r5899 r5904 132 132 return; 133 133 } 134 DataStreamPtr stream= Resource::open(source);134 dataStream_ = Resource::open(source); 135 135 // Read everything into a temporary buffer 136 136 char* buffer = new char[fileInfo->size]; 137 stream->read(buffer, fileInfo->size); 137 dataStream_->read(buffer, fileInfo->size); 138 dataStream_->seek(0); 138 139 139 140 this->audioBuffer_ = alutCreateBufferFromFileImage(buffer, fileInfo->size); … … 143 144 { 144 145 COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl; 145 return; 146 //if (filename.find("ogg", 0) != std::string::npos) 147 //{ 148 // COUT(2) << "Sound: Trying fallback ogg loader" << std::endl; 149 // this->audioBuffer_ = loadOggFile(filename); 150 //} 151 152 //if (this->audioBuffer_ == AL_NONE) 153 //{ 154 // COUT(2) << "Sound: fallback ogg loader failed: " << alutGetErrorString(alutGetError()) << std::endl; 155 // return; 156 //} 146 if (source.find("ogg", 0) != std::string::npos) 147 { 148 COUT(2) << "Sound: Trying fallback ogg loader" << std::endl; 149 this->audioBuffer_ = loadOggFile(); 150 } 151 152 if (this->audioBuffer_ == AL_NONE) 153 { 154 COUT(2) << "Sound: fallback ogg loader failed: " << alutGetErrorString(alutGetError()) << std::endl; 155 return; 156 } 157 157 } 158 158 … … 178 178 } 179 179 180 #if 0 // Not yet supported because of missing resource implementation 181 ALuint BaseSound::loadOggFile(const std::string& filename) 180 size_t readVorbis(void* ptr, size_t size, size_t nmemb, void* datasource) 181 { 182 return static_cast<Ogre::DataStream*>(datasource)->read(ptr, size * nmemb); 183 } 184 185 int seekVorbis(void* datasource, ogg_int64_t offset, int whence) 186 { 187 Ogre::DataStream* stream = static_cast<Ogre::DataStream*>(datasource); 188 int offset_beg = offset; 189 if (whence == SEEK_CUR) 190 offset_beg = stream->tell() + offset; 191 else if (whence == SEEK_END) 192 offset_beg = stream->size() + offset; 193 else if (whence != SEEK_SET) 194 return -1; 195 stream->seek(offset_beg); 196 return 0; 197 } 198 199 long tellVorbis(void* datasource) 200 { 201 return static_cast<long>(static_cast<Ogre::DataStream*>(datasource)->tell()); 202 } 203 204 ALuint BaseSound::loadOggFile() 182 205 { 183 206 char inbuffer[4096]; … … 190 213 ALenum format; 191 214 192 FILE* f = fopen(filename.c_str(), "rb"); 193 194 if (ov_open(f, &vf, NULL, 0) < 0) 215 // Open file with custom streaming 216 ov_callbacks vorbisCallbacks; 217 vorbisCallbacks.read_func = &readVorbis; 218 vorbisCallbacks.seek_func = &seekVorbis; 219 vorbisCallbacks.tell_func = &tellVorbis; 220 vorbisCallbacks.close_func = NULL; 221 222 int ret = ov_open_callbacks(dataStream_.get(), &vf, NULL, 0, vorbisCallbacks); 223 if (ret < 0) 195 224 { 196 225 COUT(2) << "Sound: libvorbisfile: File does not seem to be an Ogg Vorbis bitstream" << std::endl; … … 230 259 return buffer; 231 260 } 232 #endif233 261 234 262 } // namespace: orxonox -
code/branches/core5/src/orxonox/sound/BaseSound.h
r5899 r5904 32 32 33 33 #include <string> 34 #include <OgreSharedPtr.h> 35 #include <OgreDataStream.h> 34 36 #include "core/OrxonoxClass.h" 35 37 … … 65 67 66 68 protected: 67 ALuint loadOggFile( const std::string& filename);69 ALuint loadOggFile(); 68 70 ALint getSourceState(); 69 71 … … 75 77 bool bPlayOnLoad_; 76 78 bool bLoop_; 79 DataStreamPtr dataStream_; 77 80 }; 78 81 }
Note: See TracChangeset
for help on using the changeset viewer.