Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3887 in orxonox.OLD for orxonox/branches/sound_engine/src/lib


Ignore:
Timestamp:
Apr 19, 2005, 12:28:55 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: added some classes to handle Audio

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  
    1010
    1111   ### File Specific:
    12    main-programmer: ...
     12   main-programmer: Benjamin Grauer
    1313   co-programmer: ...
     14   
     15   Some code was taken from Simon's first implementation of the SoundEngine.
    1416*/
    1517
    16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
     18#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND
    1719
    18 #include "proto_singleton.h"
     20#include "sound_engine.h"
    1921
    2022using namespace std;
    21 
    2223
    2324/**
    2425   \brief standard constructor
    2526*/
    26 ProtoSingleton::ProtoSingleton ()
     27SoundEngine::SoundEngine ()
    2728{
    28    this->setClassName ("ProtoSingleton");
    29 
     29   this->setClassName ("SoundEngine");
     30   this->isInit = false;
     31   this->enableSound();
    3032}
    3133
    32 /**
    33    \brief the singleton reference to this class
    34 */
    35 ProtoSingleton* ProtoSingleton::singletonRef = NULL;
     34//! brief the singleton reference to this class
     35SoundEngine* SoundEngine::singletonRef = NULL;
    3636
    3737/**
    3838   \returns a Pointer to this Class
    3939*/
    40 ProtoSingleton* ProtoSingleton::getInstance(void)
     40SoundEngine* SoundEngine::getInstance(void)
    4141{
    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;
    4545}
    4646
     
    4949
    5050*/
    51 ProtoSingleton::~ProtoSingleton ()
     51SoundEngine::~SoundEngine ()
    5252{
    53   ProtoSingleton::singletonRef = NULL;
     53  SoundEngine::singletonRef = NULL;
     54 
     55  this->disableSound();
     56}
    5457
     58
     59/**
     60   \brief enables the SDL_mixer library
     61*/
     62void 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;
    5571}
     72
     73/**
     74   \brief disabled SDL_mixer
     75*/
     76void 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*/
     90bool 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  
    11/*!
    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.
    619*/
    720
    8 #ifndef _PROTO_SINGLETON_H
    9 #define _PROTO_SINGLETON_H
     21#ifndef _SOUND_ENGINE_H
     22#define _SOUND_ENGINE_H
    1023
    1124#include "base_object.h"
     25#include <SDL_mixer.h>
    1226
    13 // FORWARD DEFINITION \\
     27// FORWARD DEFINITION
    1428
    15 //! A default singleton class.
    16 class ProtoSingleton : public BaseObject {
     29//! The Main Sound Engine
     30class SoundEngine : public BaseObject {
    1731
    1832 public:
    19   static ProtoSingleton* getInstance(void);
    20   virtual ~ProtoSingleton(void);
     33  static SoundEngine* getInstance(void);
     34  virtual ~SoundEngine(void);
    2135
    2236 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;
    2547};
    2648
    27 #endif /* _PROTO_SINGLETON_H */
     49
     50#endif /* _SOUND_ENGINE_H */
Note: See TracChangeset for help on using the changeset viewer.