Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2838 in orxonox.OLD for orxonox/branches/sound


Ignore:
Timestamp:
Nov 12, 2004, 2:41:26 PM (20 years ago)
Author:
simon
Message:

branches/sound: instance can now be freed via static deleteInstance()

Location:
orxonox/branches/sound/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/sound/src/sound_control.cc

    r2815 r2838  
    2020using namespace std;
    2121
     22// global variables
     23
     24SoundControl* SoundControl::instance = 0; // singleton reference
     25int volume = SDL_MIX_MAXVOLUME; // volume
     26int done = 0; //
     27int track_number = 1;
     28Mix_Music* music = NULL;
    2229
    2330/**
     
    3239  int audio_rate = MIX_DEFAULT_FREQUENCY, audio_channels = MIX_DEFAULT_CHANNELS, audio_buffers = 8192, bits = 0;
    3340  Uint16 audio_format = MIX_DEFAULT_FORMAT;
    34   Mix_Music* music = NULL;
    35  
     41
    3642  //initializing sound and calling Mix_OpenAudio
    3743  if(SDL_Init(SDL_INIT_AUDIO)<0){
     
    5359*/
    5460SoundControl::~SoundControl () {
    55   instance = NULL;
     61  delete instance;
     62  instance = 0;
    5663}
    5764
     
    5966   \brief Returns a reference to the singleton
    6067*/
    61 SoundControl* SoundControl::getObject(){
    62   static SoundControl instance;
    63   return &instance;
    64 }
    65 
     68SoundControl* SoundControl::getInstance() {
     69  if (instance == 0) {
     70    instance = new SoundControl;
     71  }
     72  return instance;
     73}
     74
     75void SoundControl::deleteInstance() {
     76  ~SoundControl();
     77}
    6678
    6779/**
     
    7486  bits=audio_format&0xFF;
    7587  printf("Opened audio at %d Hz %d bit %s, %d bytes audio buffer\n", audio_rate, bits, audio_channels > 1 ? "stereo" : "mono", audio_buffers );
    76  
    77   int volume = SDL_MIX_MAXVOLUME;
    7888  Mix_VolumeMusic(volume);
    79   int track_number = 1;
    80   int done = 0;
    8189}
    8290
     
    194202void SoundControl::trackSelect () {
    195203  switch (track_number) {
    196   case 1: 
     204  case 1:
    197205    music = Mix_LoadMUS("luke_grey_orxonox1.ogg");
     206    if(Mix_PlayMusic(music, 1) == -1){
     207      printf("Mix_PlayMusic: %s\n",Mix_GetError());
     208    }
     209    Mix_HookMusicFinished(musicDone);
    198210    break;
    199211  case 2:
    200     music = Mix_LoadMUS("luke_grey_orxonox2.ogg");
     212    music = Mix_LoadMUS("luke_grey_orxonox2.ogg");
     213    if(Mix_PlayMusic(music, 1) == -1){
     214      printf("Mix_PlayMusic: %s\n",Mix_GetError());
     215    }
     216    Mix_HookMusicFinished(musicDone);
    201217    break;
    202218  case 3:
    203219    music = Mix_LoadMUS("luke_grey_orxonox3.ogg");
    204     break;
     220    if(Mix_PlayMusic(music, 1) == -1){
     221    printf("Mix_PlayMusic: %s\n",Mix_GetError());
     222  }
     223  Mix_HookMusicFinished(musicDone);   
     224  break;
    205225  case 4:
    206226    music = Mix_LoadMUS("luke_grey_and_aquarius_orxonox.ogg");
     227    if(Mix_PlayMusic(music, 1) == -1){
     228      printf("Mix_PlayMusic: %s\n",Mix_GetError());
     229    }
     230    Mix_HookMusicFinished(musicDone);   
    207231    break;
    208232  case 5:
    209233    music = Mix_LoadMUS("nomenes_orxonox.ogg");
     234    if(Mix_PlayMusic(music, 1) == -1){
     235      printf("Mix_PlayMusic: %s\n",Mix_GetError());
     236    }
     237    Mix_HookMusicFinished(musicDone);   
    210238    break;
    211239  case 6:
    212240    music = Mix_LoadMUS("nomenes_funkadudu.ogg");
    213     break;
     241  if(Mix_PlayMusic(music, 1) == -1){
     242    printf("Mix_PlayMusic: %s\n",Mix_GetError());
     243  }
     244  Mix_HookMusicFinished(musicDone);   
     245break;
    214246  }
    215247}
  • orxonox/branches/sound/src/sound_control.h

    r2815 r2838  
    77
    88 public:
    9   SoundControl* getObject();
     9  static SoundControl* getInstance();
     10  static void deleteInstance();
    1011  void setNumberOfChannels(int number_of channels);
    1112  int playMod(char* filename);
     
    2122  void trackSelect();
    2223
     24protected:
     25  void initialise();
     26  SoundControl();
     27  ~SoundControl();
     28
    2329private:
    24   void initialise();
    25   //SoundControl singleton object must be made via getObject()
    26   SoundControl();
    27   ~SoundControl()
     30  static SoundControl* instance;
     31
    2832}
    2933
  • orxonox/branches/sound/src/sound_test.cc

    r2815 r2838  
    2121using namespace std;
    2222
     23SoundControl* test;
    2324
    2425SoundTest::SoundTest () {
    25  
     26  test = SoundControl::getInstance();
    2627}
    2728
     
    4142  sound.~SoundControl();
    4243}
    43  
  • orxonox/branches/sound/src/sound_test.h

    r2815 r2838  
    1111  SoundTest ();
    1212  ~SoundTest ();
    13 
     13  void main (void);
    1414};
    1515
Note: See TracChangeset for help on using the changeset viewer.