Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2815 in orxonox.OLD for orxonox/branches/sound/src


Ignore:
Timestamp:
Nov 11, 2004, 6:16:00 PM (20 years ago)
Author:
simon
Message:

branches/sound: made SoundControl singleton. Must be built via getObject()

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

Legend:

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

    r2793 r2815  
    2424    \brief standard constructor
    2525   
    26     This constructor builds a SoundControl Object, which waits for callers
    27     calling its functions to output sound. All sound output is handles by this 
    28     object, which must only be constructed once.
     26    This constructor builds a SoundControl Object, which waits for callers.
     27    All sound output is handled by this singleton object.
    2928*/
    3029SoundControl::SoundControl () {
     
    4039    exit(1);
    4140  }
    42 
     41 
    4342  if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)){
    4443    printf("Mix_OpenAudio: \n");
    4544    exit(1);
    4645  }
    47 
    48   postConstruction();
    49 }
    50 
    51 SoundControl::SoundControl (int audio_rate audiorate, Uint16 audio_format audioformat, int audio_channels audiochannels, int audio_buffers audiobuffers) {
    52  
    53   //setup parameters
    54   int audio_rate = audiorate, audio_channels = audiochannels, audio_buffers = audiobuffers, bits = 0;
    55   Uint16 audio_format = audioformat;
    56   Mix_Music* music = NULL;
    57  
    58   //initializing sound and calling Mix_OpenAudio
    59   if(SDL_Init(SDL_INIT_AUDIO)<0){
    60     printf("SDL_Init: \n");
    61     exit(1);
    62   }
    63 
    64   if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)){
    65     printf("Mix_OpenAudio: \n");
    66     exit(1);
    67   }
    68 
    69   postConstruction();
    70 }
    71 
    72 
    73 /**
    74     \brief standard destructor
     46 
     47  initialise();
     48}
     49
     50
     51/**
     52    \brief Destructor for the singleton instance
    7553*/
    7654SoundControl::~SoundControl () {
    77   SoundControl* SoundControl::singleton = NULL;
    78 }
    79 
    80 SoundControl* SoundControl::singleton = NULL;
     55  instance = NULL;
     56}
     57
     58/**
     59   \brief Returns a reference to the singleton
     60*/
     61SoundControl* SoundControl::getObject(){
     62  static SoundControl instance;
     63  return &instance;
     64}
    8165
    8266
     
    8468    \brief Is called by SoundControl object to initiate all values
    8569*/
    86 void SoundControl::postConstruction () {
     70void SoundControl::initialise() {
    8771 
    8872  // Print some info
     
    9983
    10084/**
    101     \brief Sets the number of output Channels
     85    \brief Sets the number of output Channels (should not be used)
    10286*/
    10387void SoundControl::setNumberOfChannels (int number_of_channels) {
     
    220204    break;
    221205  case 4:
    222     music = Mix_LoadMUS("luke_grey_and aquarius_orxonox.ogg");
     206    music = Mix_LoadMUS("luke_grey_and_aquarius_orxonox.ogg");
    223207    break;
    224208  case 5:
    225209    music = Mix_LoadMUS("nomenes_orxonox.ogg");
    226210    break;
     211  case 6:
     212    music = Mix_LoadMUS("nomenes_funkadudu.ogg");
     213    break;
    227214  }
    228215}
  • orxonox/branches/sound/src/sound_control.h

    r2793 r2815  
    77
    88 public:
    9   SoundControl ();
    10   ~SoundControl ();
     9  SoundControl* getObject();
    1110  void setNumberOfChannels(int number_of channels);
    1211  int playMod(char* filename);
     
    2322
    2423private:
    25   void postConstruction();
    26   SoundControl* singleton;
    27 
     24  void initialise();
     25  //SoundControl singleton object must be made via getObject()
     26  SoundControl();
     27  ~SoundControl()
    2828}
    2929
  • orxonox/branches/sound/src/sound_test.cc

    r2793 r2815  
    3232
    3333
    34 void main (void){
     34void main (void) {
    3535  SDL_Surface *screen;
    3636  SDL_Init(SDL_INIT_VIDEO);
  • orxonox/branches/sound/src/sound_test.h

    r2793 r2815  
    11
    2 #ifndef PROTO_CLASS_H
    3 #define PROTO_CLASS_H
     2#ifndef SOUND_TEST_H
     3#define SOUND_TEST_H
    44
    55#include "data_tank.h"
    66
    77
    8 class ProtoClass {
     8class SoundTest {
    99
    1010 public:
    11   ProtoClass ();
    12   ~ProtoClass ();
     11  SoundTest ();
     12  ~SoundTest ();
    1313
    1414};
Note: See TracChangeset for help on using the changeset viewer.