Changeset 3887 in orxonox.OLD for orxonox/branches/sound_engine/src/lib/sound
- Timestamp:
- Apr 19, 2005, 12:28:55 AM (20 years ago)
- Location:
- orxonox/branches/sound_engine/src/lib/sound
- Files:
-
- 1 added
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/sound_engine/src/lib/sound/sound_engine.cc
r3884 r3887 10 10 11 11 ### File Specific: 12 main-programmer: ...12 main-programmer: Benjamin Grauer 13 13 co-programmer: ... 14 15 Some code was taken from Simon's first implementation of the SoundEngine. 14 16 */ 15 17 16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY 18 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND 17 19 18 #include " proto_singleton.h"20 #include "sound_engine.h" 19 21 20 22 using namespace std; 21 22 23 23 24 /** 24 25 \brief standard constructor 25 26 */ 26 ProtoSingleton::ProtoSingleton()27 SoundEngine::SoundEngine () 27 28 { 28 this->setClassName ("ProtoSingleton"); 29 29 this->setClassName ("SoundEngine"); 30 this->isInit = false; 31 this->enableSound(); 30 32 } 31 33 32 /** 33 \brief the singleton reference to this class 34 */ 35 ProtoSingleton* ProtoSingleton::singletonRef = NULL; 34 //! brief the singleton reference to this class 35 SoundEngine* SoundEngine::singletonRef = NULL; 36 36 37 37 /** 38 38 \returns a Pointer to this Class 39 39 */ 40 ProtoSingleton* ProtoSingleton::getInstance(void)40 SoundEngine* SoundEngine::getInstance(void) 41 41 { 42 if (! ProtoSingleton::singletonRef)43 ProtoSingleton::singletonRef = new ProtoSingleton();44 return ProtoSingleton::singletonRef;42 if (!SoundEngine::singletonRef) 43 SoundEngine::singletonRef = new SoundEngine(); 44 return SoundEngine::singletonRef; 45 45 } 46 46 … … 49 49 50 50 */ 51 ProtoSingleton::~ProtoSingleton()51 SoundEngine::~SoundEngine () 52 52 { 53 ProtoSingleton::singletonRef = NULL; 53 SoundEngine::singletonRef = NULL; 54 55 this->disableSound(); 56 } 54 57 58 59 /** 60 \brief enables the SDL_mixer library 61 */ 62 void SoundEngine::enableSound(void) 63 { 64 if (!this->isInit) 65 if (SDL_Init(SDL_INIT_AUDIO)) 66 { 67 PRINTF(1)("SDL-sound could not be initialized\n"); 68 return; 69 } 70 this->isInit = true; 55 71 } 72 73 /** 74 \brief disabled SDL_mixer 75 */ 76 void SoundEngine::disableSound(void) 77 { 78 if (this->isInit) 79 { 80 SDL_QuitSubSystem(SDL_INIT_AUDIO); 81 } 82 else 83 PRINTF(4)("SDL_mixer was not initialized.\n"); 84 } 85 86 /** 87 \brief checks if the compiled version and the local version of SDL_mixer match. 88 \returns true if match, false otherwise 89 */ 90 bool SoundEngine::checkVersion(void) 91 { 92 SDL_version compile_version; 93 SDL_version link_version; 94 MIX_VERSION(&compile_version); 95 link_version = *Mix_Linked_Version(); 96 97 if (compile_version.major == link_version.major && 98 compile_version.minor == link_version.minor && 99 compile_version.patch == link_version.patch) 100 { 101 return true; 102 } 103 else 104 { 105 PRINTF(2)("compiled with SDL_mixer version: %d.%d.%d\n", 106 compile_version.major, 107 compile_version.minor, 108 compile_version.patch); 109 110 PRINTF(2)("running with SDL_mixer version: %d.%d.%d\n", 111 link_version.major, 112 link_version.minor, 113 link_version.patch); 114 return false; 115 } 116 } -
orxonox/branches/sound_engine/src/lib/sound/sound_engine.h
r3884 r3887 1 1 /*! 2 \file proto_singleton.h 3 \brief Definition of the proto class template, used quickly start work 4 5 a simple file to copy and create a singleton-class from 2 \file sound_engine.h 3 \brief Definition of the SoundEngine 4 5 !!AVOID!!: 6 SDL_OpenAudio 7 Use Mix_OpenAudio instead. 8 SDL_CloseAudio 9 Use Mix_CloseAudio instead. 10 SDL_PauseAudio 11 Use Mix_Pause(-1) and Mix_PauseMusic instead, to pause. 12 Use Mix_Resume(-1) and Mix_ResumeMusic instead, to unpause. 13 SDL_LockAudio 14 This is just not needed since SDL_mixer handles this for you. 15 Using it may cause problems as well. 16 SDL_UnlockAudio 17 This is just not needed since SDL_mixer handles this for you. 18 Using it may cause problems as well. 6 19 */ 7 20 8 #ifndef _ PROTO_SINGLETON_H9 #define _ PROTO_SINGLETON_H21 #ifndef _SOUND_ENGINE_H 22 #define _SOUND_ENGINE_H 10 23 11 24 #include "base_object.h" 25 #include <SDL_mixer.h> 12 26 13 // FORWARD DEFINITION \\27 // FORWARD DEFINITION 14 28 15 //! A default singleton class.16 class ProtoSingleton: public BaseObject {29 //! The Main Sound Engine 30 class SoundEngine : public BaseObject { 17 31 18 32 public: 19 static ProtoSingleton* getInstance(void);20 virtual ~ ProtoSingleton(void);33 static SoundEngine* getInstance(void); 34 virtual ~SoundEngine(void); 21 35 22 36 private: 23 ProtoSingleton(void); 24 static ProtoSingleton* singletonRef; 37 SoundEngine(void); 38 static SoundEngine* singletonRef; 39 40 41 42 void enableSound(void); 43 void disableSound(void); 44 static bool checkVersion(void); 45 46 bool isInit; 25 47 }; 26 48 27 #endif /* _PROTO_SINGLETON_H */ 49 50 #endif /* _SOUND_ENGINE_H */
Note: See TracChangeset
for help on using the changeset viewer.