Changeset 6332 for code/branches/presentation2/src/orxonox/sound
- Timestamp:
- Dec 13, 2009, 12:11:40 AM (15 years ago)
- Location:
- code/branches/presentation2/src/orxonox/sound
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc
r6270 r6332 33 33 #include <vorbis/vorbisfile.h> 34 34 35 #include "util/Clock.h" 36 #include "core/Game.h" 35 37 #include "util/Exception.h" 36 38 #include "util/StringUtils.h" … … 40 42 namespace orxonox 41 43 { 42 SoundBuffer::SoundBuffer(const std::string& filename )44 SoundBuffer::SoundBuffer(const std::string& filename, std::list<shared_ptr<SoundBuffer> >::iterator poolIterator) 43 45 : filename_(filename) 44 46 , audioBuffer_(AL_NONE) 47 , poolIterator_(poolIterator) 45 48 { 46 49 if (this->filename_.empty()) … … 60 63 if (getLowercase(extension) == "ogg") 61 64 { 65 int before = Game::getInstance().getGameClock().getRealMicroseconds(); 62 66 // Try ogg loader 63 67 this->loadOgg(fileInfo, dataStream); 68 int after = Game::getInstance().getGameClock().getRealMicroseconds(); 69 COUT(0) << filename << ": " << (after - before) << std::endl; 64 70 } 65 71 else … … 80 86 ALint size; 81 87 alGetBufferi(this->audioBuffer_, AL_SIZE, &size); 82 if (!alGetError()) 83 return size; 84 else 85 return 0; 88 return alGetError() ? 0 : size; 86 89 } 87 90 … … 108 111 { 109 112 Ogre::DataStream* stream = static_cast<Ogre::DataStream*>(datasource); 110 int offset_beg = offset; 111 if (whence == SEEK_CUR) 112 offset_beg = stream->tell() + offset; 113 else if (whence == SEEK_END) 114 offset_beg = stream->size() + offset; 115 else if (whence != SEEK_SET) 113 switch (whence) 114 { 115 case SEEK_SET: 116 stream->seek(offset); 117 break; 118 case SEEK_CUR: 119 stream->skip(offset); 120 break; 121 case SEEK_END: 122 stream->seek(stream->size() + offset); 123 break; 124 default: 116 125 return -1; 117 stream->seek(offset_beg);126 } 118 127 return 0; 119 128 } -
code/branches/presentation2/src/orxonox/sound/SoundBuffer.h
r6270 r6332 42 42 { 43 43 friend class SoundManager; 44 // Make sure nobody deletes an instance (using smart pointers) 45 template <class T> 46 friend void boost::checked_delete(T*); 44 47 45 48 public: 46 SoundBuffer(const std::string& filename);47 ~SoundBuffer();48 49 49 inline ALuint getBuffer() 50 50 { return this->audioBuffer_; } … … 55 55 { return this->filename_; } 56 56 57 void setPooling(bool val)58 { this->bPooling_ = true; }59 bool getPooling() const60 { return this->bPooling_; }61 62 57 private: 58 SoundBuffer(const std::string& filename, std::list<shared_ptr<SoundBuffer> >::iterator poolIterator); 59 ~SoundBuffer(); 63 60 void loadStandard(const shared_ptr<ResourceInfo>& fileInfo, DataStreamPtr dataStream); 64 61 void loadOgg(const shared_ptr<ResourceInfo>& fileInfo, DataStreamPtr dataStream); … … 67 64 ALuint audioBuffer_; 68 65 std::list<shared_ptr<SoundBuffer> >::iterator poolIterator_; 69 bool bPooling_;70 66 }; 71 67 } -
code/branches/presentation2/src/orxonox/sound/SoundManager.cc
r6322 r6332 60 60 Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit); 61 61 62 /* 62 63 // Get list of available sound devices and display them 63 /*const char* devices = alcGetString(NULL, ALC_DEVICE_SPECIFIER);64 const char* devices = alcGetString(NULL, ALC_DEVICE_SPECIFIER); 64 65 char* device = new char[strlen(devices)+1]; 65 66 strcpy(device, devices); 66 67 std::string renderDevice; 67 //SetConfigValue(renderDevice, std::string(device)).description("Sound device used for rendering");68 SetConfigValue(renderDevice, std::string(device)).description("Sound device used for rendering"); 68 69 COUT(4) << "Sound: Available devices: "; 69 70 while (true) … … 79 80 // Open the selected device 80 81 COUT(3) << "Sound: Opening device \"" << renderDevice << "\"" << std::endl; 81 this->device_ = alcOpenDevice(renderDevice.c_str());*/ 82 this->device_ = alcOpenDevice(renderDevice.c_str()); 83 */ 82 84 this->device_ = alcOpenDevice(NULL); 83 85 if (this->device_ == NULL) … … 573 575 try 574 576 { 575 buffer.reset(new SoundBuffer(filename)); 576 buffer->poolIterator_ = this->effectsPool_.end(); 577 buffer.reset(new SoundBuffer(filename, this->effectsPool_.end())); 577 578 } 578 579 catch (...) -
code/branches/presentation2/src/orxonox/sound/SoundManager.h
r6322 r6332 92 92 void unregisterAmbientSound(AmbientSound* oldAmbient); 93 93 void pauseAmbientSound(AmbientSound* ambient); 94 94 95 95 void setVolume(float vol, SoundType::Value type); 96 96 float getVolume(SoundType::Value type); // tolua_export 97 97 98 98 void toggleMute(SoundType::Value type); // tolua_export 99 99 bool getMute(SoundType::Value type); // tolua_export … … 117 117 void checkAmbientVolumeValidity(void); 118 118 void checkEffectsVolumeValidity(void); 119 119 120 120 float checkVolumeRange(float vol); 121 121 122 122 void updateVolume(SoundType::Value type); 123 123 124 124 void setVolumeInternal(float vol, SoundType::Value type); 125 125 float getVolumeInternal(SoundType::Value type); … … 128 128 ALCdevice* device_; 129 129 ALCcontext* context_; 130 130 131 131 typedef std::list<std::pair<AmbientSound*, bool> > AmbientList; 132 132 AmbientList ambientSounds_; 133 133 134 134 float crossFadeStep_; //!< Absolute change per second (0.1 means 10% of the nominal volume) for cross fading 135 135 std::list<AmbientSound*> fadeInList_; 136 136 std::list<AmbientSound*> fadeOutList_; 137 137 138 138 float soundVolume_; 139 139 float ambientVolume_; … … 150 150 unsigned int maxSources_; 151 151 std::vector<ALuint> soundSources_; 152 152 153 153 static SoundManager* singletonPtr_s; 154 154 }; // tolua_export
Note: See TracChangeset
for help on using the changeset viewer.