Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3890 in orxonox.OLD for orxonox/branches


Ignore:
Timestamp:
Apr 19, 2005, 2:20:01 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/sound_engine: loading unloading should work

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  
    2020#include "sound_engine.h"
    2121#include <SDL_mixer.h>
     22#include "compiler.h"
    2223
    2324using namespace std;
    2425
     26
     27/*----------------
     28  SOUND AND MUSIC
     29  ---------------*/
     30
     31Sound::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
     55Sound::~Sound()
     56{
     57
     58}
     59
     60SoundEffect::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
     77SoundEffect::~SoundEffect(void)
     78{
     79  // deleting the effects-chunk
     80  Mix_FreeChunk(this->effect);
     81}
     82
     83Music::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
     101Music::~Music()
     102{
     103  Mix_FreeMusic(this->music);
     104}
     105
     106/*----------------------
     107 STARTING AND UNLOADING
     108  ----------------------*/
    25109/**
    26110   \brief standard constructor
     
    31115
    32116   // preInit
    33    this->isInit = false;
    34117   this->frequency = SOUND_DEFAULT_FREQUENCY;
    35118   this->format = MIX_DEFAULT_FORMAT;
     
    65148  this->disableSound();
    66149}
     150
     151bool SoundEngine::isInit = false;
     152bool SoundEngine::enabled = false;
     153
    67154
    68155
     
    94181            PRINTF(1)("Mix_OpenAudio: %s\n", Mix_GetError());
    95182        }
    96  
    97 
    98183    }
    99184}
     
    143228    }
    144229}
     230
     231
     232/*-------------
     233  FUNCTIONALITY
     234  -------------*/
     235
     236/**
     237   \param numberOfChannels sets the number of Channels to use.
     238*/
     239void 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  
    2929#define SOUND_DEFAULT_BUFIZE 16384
    3030
     31// an enumerator of the different Sound Types.
     32typedef 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
    3139// FORWARD DEFINITION
     40
     41class 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
     50class 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
     58class 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};
    3265
    3366//! The Main Sound Engine
     
    3871  virtual ~SoundEngine(void);
    3972
     73
     74  void setNumberOfChannels(unsigned int numberOfChannels);
     75
     76
     77  static bool isInit;
     78  static bool enabled;
    4079 private:
    4180  SoundEngine(void);
    4281  static SoundEngine* singletonRef;
    4382
    44  
    45  
    4683  void enableSound(void);
    4784  void disableSound(void);
     
    5188  // settings
    5289  int volume;
     90  unsigned int numberOfChannels;
    5391
    5492  // audio specifications
     
    5997  int buffers;
    6098
    61   bool isInit;
     99
     100
    62101};
    63102
Note: See TracChangeset for help on using the changeset viewer.