Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2854 in orxonox.OLD for orxonox/branches/sound/src/sound_control.cc


Ignore:
Timestamp:
Nov 14, 2004, 4:44:31 PM (20 years ago)
Author:
simon
Message:

/branches/sound: finally a running version. To test, you can switch the parameters in the test class sound_test. A .ogg file named music.ogg from the directory . is played. The test class is really ugly, I know.

File:
1 edited

Legend:

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

    r2838 r2854  
    1515
    1616#include "sound_control.h"
    17 #include <string.h>
    18 #include "SDL_mixer.h"
    1917
    2018using namespace std;
    2119
    2220// global variables
    23 
    24 SoundControl* SoundControl::instance = 0; // singleton reference
    25 int volume = SDL_MIX_MAXVOLUME; // volume
    26 int done = 0; //
     21SoundControl* SoundControl::instance = NULL; // singleton reference
     22int volume = SDL_MIX_MAXVOLUME;
     23int done = 0;
    2724int track_number = 1;
    28 Mix_Music* music = NULL;
     25static Mix_Music* music = NULL;
     26int audio_rate = MIX_DEFAULT_FREQUENCY, audio_channels = MIX_DEFAULT_CHANNELS, audio_buffers = 16384, bits = 0;
     27Uint16 audio_format = MIX_DEFAULT_FORMAT;
     28
    2929
    3030/**
     
    3535*/
    3636SoundControl::SoundControl () {
    37  
    38   //setup parameters
    39   int audio_rate = MIX_DEFAULT_FREQUENCY, audio_channels = MIX_DEFAULT_CHANNELS, audio_buffers = 8192, bits = 0;
    40   Uint16 audio_format = MIX_DEFAULT_FORMAT;
    41 
    42   //initializing sound and calling Mix_OpenAudio
     37
     38  /*
     39  initializing sound and calling Mix_OpenAudio
    4340  if(SDL_Init(SDL_INIT_AUDIO)<0){
    44     printf("SDL_Init: \n");
    45     exit(1);
     41    printf("SDL_Init: INIT_AUDIO error.\n");
    4642  }
     43  */
    4744 
    4845  if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)){
    49     printf("Mix_OpenAudio: \n");
    50     exit(1);
     46    printf("Mix_OpenAudio: Failed to open audio!\n");
    5147  }
    5248 
     
    5652
    5753/**
    58     \brief Destructor for the singleton instance
     54    \brief Default destructor
    5955*/
    6056SoundControl::~SoundControl () {
    61   delete instance;
    62   instance = 0;
    6357}
    6458
     
    6761*/
    6862SoundControl* SoundControl::getInstance() {
    69   if (instance == 0) {
     63  if (instance == NULL) {
    7064    instance = new SoundControl;
    7165  }
     
    7468
    7569void SoundControl::deleteInstance() {
    76   ~SoundControl();
     70  delete instance;
     71  instance = NULL;
    7772}
    7873
     
    186181*/
    187182void SoundControl::pauseMusic () {
    188   Mix_PauseMusic()
     183  Mix_PauseMusic();
    189184}
    190185
     
    194189*/
    195190void SoundControl::resumeMusic () {
    196   Mix_ResumeMusic()
     191  Mix_ResumeMusic();
    197192}
    198193
     
    200195    \brief Selects the track of all orxonox tracks
    201196*/
    202 void SoundControl::trackSelect () {
     197void SoundControl::trackSelect() {
    203198  switch (track_number) {
    204199  case 1:
     
    219214    music = Mix_LoadMUS("luke_grey_orxonox3.ogg");
    220215    if(Mix_PlayMusic(music, 1) == -1){
    221     printf("Mix_PlayMusic: %s\n",Mix_GetError());
    222   }
    223   Mix_HookMusicFinished(musicDone);   
    224   break;
     216      printf("Mix_PlayMusic: %s\n",Mix_GetError());
     217    }
     218    Mix_HookMusicFinished(musicDone);   
     219    break;
    225220  case 4:
    226221    music = Mix_LoadMUS("luke_grey_and_aquarius_orxonox.ogg");
     
    239234  case 6:
    240235    music = Mix_LoadMUS("nomenes_funkadudu.ogg");
    241   if(Mix_PlayMusic(music, 1) == -1){
    242     printf("Mix_PlayMusic: %s\n",Mix_GetError());
    243   }
    244   Mix_HookMusicFinished(musicDone);   
    245 break;
     236    if(Mix_PlayMusic(music, 1) == -1){
     237      printf("Mix_PlayMusic: %s\n",Mix_GetError());
     238    }
     239    Mix_HookMusicFinished(musicDone);
     240    break;
    246241  }
    247242}
     
    251246    \brief Hooked by playOgg at end of .ogg playback
    252247*/
    253 void SoundControl::musicDone () {
    254   track_number++;
     248void SoundControl::musicDone() {
    255249  Mix_HaltMusic();
    256250  Mix_FreeMusic(music);
Note: See TracChangeset for help on using the changeset viewer.