Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

orxonox/branches/sound_engine: loading unloading should work

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.