- Timestamp:
- Apr 19, 2005, 2:20:01 AM (20 years ago)
- Location:
- orxonox/branches/sound_engine/src/lib/sound
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/sound_engine/src/lib/sound/sound_engine.cc
r3889 r3890 20 20 #include "sound_engine.h" 21 21 #include <SDL_mixer.h> 22 #include "compiler.h" 22 23 23 24 using namespace std; 24 25 26 27 /*---------------- 28 SOUND AND MUSIC 29 ---------------*/ 30 31 Sound::Sound(const char* fileName, SOUND_TYPE soundType) 32 { 33 // checking if the sound-format is known 34 if (soundType == SOUND_NONE) 35 { 36 if (likely(!strncmp(fileName+(strlen(fileName)-4), ".wav", 4)) || 37 unlikely(!strncmp(fileName+(strlen(fileName)-4), ".voc", 4)) || 38 unlikely(!strncmp(fileName+(strlen(fileName)-5), ".aiff", 5)) || 39 unlikely(!strncmp(fileName+(strlen(fileName)-5), ".riff", 5))) 40 this->soundType = SOUND_WAV; 41 else if (likely(!strncmp(fileName+(strlen(fileName)-4), ".ogg", 4))) 42 this->soundType = SOUND_OGG; 43 else if (likely(!strncmp(fileName+(strlen(fileName)-4), ".mp3", 4))) 44 this->soundType = SOUND_MP3; 45 else if (unlikely(!strncmp(fileName+(strlen(fileName)-4), ".mod", 4)) || 46 unlikely(!strncmp(fileName+(strlen(fileName)-4), ".s3m", 4)) || 47 unlikely(!strncmp(fileName+(strlen(fileName)-3), ".it", 3)) || 48 unlikely(!strncmp(fileName+(strlen(fileName)-3), ".xm", 3))) 49 this->soundType = SOUND_MOD; 50 else if (likely(!strncmp(fileName+(strlen(fileName)-4), ".mid", 4))) 51 this->soundType = SOUND_MID; 52 } 53 } 54 55 Sound::~Sound() 56 { 57 58 } 59 60 SoundEffect::SoundEffect(const char* fileName, SOUND_TYPE soundType) : Sound(fileName, soundType) 61 { 62 // checking how to load 63 this->effect = NULL; 64 if (likely(SoundEngine::isInit)) 65 { 66 if (this->soundType == SOUND_WAV || 67 this->soundType == SOUND_MOD || 68 this->soundType == SOUND_OGG) 69 this->effect = Mix_LoadWAV(fileName); 70 else 71 PRINTF(2)("%s cannot be loaded as SoundEffect. Wrong Type\n", fileName); 72 } 73 else 74 PRINTF(2)("SoundEngine not yet started. not loading SoundEffect %s\n", fileName); 75 } 76 77 SoundEffect::~SoundEffect(void) 78 { 79 // deleting the effects-chunk 80 Mix_FreeChunk(this->effect); 81 } 82 83 Music::Music(const char* fileName, SOUND_TYPE soundType) : Sound(fileName, soundType) 84 { 85 this->music = NULL; 86 if (likely(SoundEngine::isInit)) 87 { 88 if (this->soundType == SOUND_WAV || 89 this->soundType == SOUND_MOD || 90 this->soundType == SOUND_OGG || 91 this->soundType == SOUND_MP3 || 92 this->soundType == SOUND_MID ) 93 this->music = Mix_LoadMUS(fileName); 94 else 95 PRINTF(2)("%s cannot be loaded as Music. Wrong Type\n", fileName); 96 } 97 else 98 PRINTF(2)("SoundEngine not yet started. not loading Music %s\n", fileName); 99 } 100 101 Music::~Music() 102 { 103 Mix_FreeMusic(this->music); 104 } 105 106 /*---------------------- 107 STARTING AND UNLOADING 108 ----------------------*/ 25 109 /** 26 110 \brief standard constructor … … 31 115 32 116 // preInit 33 this->isInit = false;34 117 this->frequency = SOUND_DEFAULT_FREQUENCY; 35 118 this->format = MIX_DEFAULT_FORMAT; … … 65 148 this->disableSound(); 66 149 } 150 151 bool SoundEngine::isInit = false; 152 bool SoundEngine::enabled = false; 153 67 154 68 155 … … 94 181 PRINTF(1)("Mix_OpenAudio: %s\n", Mix_GetError()); 95 182 } 96 97 98 183 } 99 184 } … … 143 228 } 144 229 } 230 231 232 /*------------- 233 FUNCTIONALITY 234 -------------*/ 235 236 /** 237 \param numberOfChannels sets the number of Channels to use. 238 */ 239 void SoundEngine::setNumberOfChannels(unsigned int numberOfChannels) 240 { 241 this->numberOfChannels = numberOfChannels; 242 Mix_AllocateChannels(numberOfChannels); 243 } -
orxonox/branches/sound_engine/src/lib/sound/sound_engine.h
r3889 r3890 29 29 #define SOUND_DEFAULT_BUFIZE 16384 30 30 31 // an enumerator of the different Sound Types. 32 typedef enum SOUND_TYPE {SOUND_NONE, 33 SOUND_WAV, /* .wav */ 34 SOUND_MOD, /* .mod .s3m .it .xm */ 35 SOUND_MID, /* mid */ 36 SOUND_OGG, 37 SOUND_MP3}; 38 31 39 // FORWARD DEFINITION 40 41 class Sound { 42 public: 43 Sound(const char* fileName, SOUND_TYPE soundType); 44 virtual ~Sound(void); 45 protected: 46 SOUND_TYPE soundType; 47 int channel; 48 }; 49 50 class SoundEffect : public Sound { 51 public: 52 SoundEffect(const char* fileName, SOUND_TYPE soundType = SOUND_NONE); 53 virtual ~SoundEffect(void); 54 private: 55 Mix_Chunk* effect; 56 }; 57 58 class Music :public Sound { 59 public: 60 Music(const char* fileName, SOUND_TYPE soundType = SOUND_NONE); 61 virtual ~Music(void); 62 private: 63 Mix_Music* music; 64 }; 32 65 33 66 //! The Main Sound Engine … … 38 71 virtual ~SoundEngine(void); 39 72 73 74 void setNumberOfChannels(unsigned int numberOfChannels); 75 76 77 static bool isInit; 78 static bool enabled; 40 79 private: 41 80 SoundEngine(void); 42 81 static SoundEngine* singletonRef; 43 82 44 45 46 83 void enableSound(void); 47 84 void disableSound(void); … … 51 88 // settings 52 89 int volume; 90 unsigned int numberOfChannels; 53 91 54 92 // audio specifications … … 59 97 int buffers; 60 98 61 bool isInit; 99 100 62 101 }; 63 102
Note: See TracChangeset
for help on using the changeset viewer.