Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Nov 24, 2004, 5:39:05 PM (20 years ago)
Author:
simon
Message:

/branches/sound/sound: Made a while(true) thing; music should play on m, sfx should play on a and s. You must put files named music.ogg, sfx1.wav and sfx2.wav in the sound folder. At the moment it does not compile out of unknown reasons (i don't understand the problems gcc has…).

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

Legend:

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

    r2974 r2979  
    1818using namespace std;
    1919
    20 // global variables
    21 SoundControl* SoundControl::instance = NULL; // singleton reference
     20SoundControl* SoundControl::instance = NULL;
    2221int volume = SDL_MIX_MAXVOLUME;
    23 int done = 0;
    2422int track_number = 1;
    2523static Mix_Music* music = NULL;
     
    192190}
    193191
    194 /**
    195     \brief Selects the track of all orxonox tracks
    196 */
    197 void SoundControl::trackSelect() {
    198   switch (track_number) {
    199   case 1:
    200     music = Mix_LoadMUS("luke_grey_orxonox1.ogg");
    201     if(Mix_PlayMusic(music, 1) == -1){
    202       printf("Mix_PlayMusic: %s\n",Mix_GetError());
    203     }
    204     Mix_HookMusicFinished(musicDone);
    205     break;
    206   case 2:
    207     music = Mix_LoadMUS("luke_grey_orxonox2.ogg");
    208     if(Mix_PlayMusic(music, 1) == -1){
    209       printf("Mix_PlayMusic: %s\n",Mix_GetError());
    210     }
    211     Mix_HookMusicFinished(musicDone);
    212     break;
    213   case 3:
    214     music = Mix_LoadMUS("luke_grey_orxonox3.ogg");
    215     if(Mix_PlayMusic(music, 1) == -1){
    216       printf("Mix_PlayMusic: %s\n",Mix_GetError());
    217     }
    218     Mix_HookMusicFinished(musicDone);   
    219     break;
    220   case 4:
    221     music = Mix_LoadMUS("luke_grey_and_aquarius_orxonox.ogg");
    222     if(Mix_PlayMusic(music, 1) == -1){
    223       printf("Mix_PlayMusic: %s\n",Mix_GetError());
    224     }
    225     Mix_HookMusicFinished(musicDone);   
    226     break;
    227   case 5:
    228     music = Mix_LoadMUS("nomenes_orxonox.ogg");
    229     if(Mix_PlayMusic(music, 1) == -1){
    230       printf("Mix_PlayMusic: %s\n",Mix_GetError());
    231     }
    232     Mix_HookMusicFinished(musicDone);   
    233     break;
    234   case 6:
    235     music = Mix_LoadMUS("nomenes_funkadudu.ogg");
    236     if(Mix_PlayMusic(music, 1) == -1){
    237       printf("Mix_PlayMusic: %s\n",Mix_GetError());
    238     }
    239     Mix_HookMusicFinished(musicDone);
    240     break;
    241   }
    242 }
    243 
    244192
    245193/**
  • orxonox/branches/sound/sound/sound_control.h

    r2974 r2979  
    2222  void pauseMusic();
    2323  void resumeMusic();
    24   void trackSelect();
    2524  static void musicDone();
     25  int volume;
     26  int track_number;
     27  int audio_rate, audio_channels, audio_buffers;
     28  int done;
     29  Uint16 audio_format;
    2630
    2731protected:
  • orxonox/branches/sound/sound/sound_test.cc

    r2974 r2979  
    1919
    2020SoundControl* sound = NULL;
    21 int counter = 0;
    22 int through = 0;
     21int sfx_channel1 = -1;
     22int sfx_channel2 = -1;
     23int finished = 0;
    2324
    2425SoundTest::SoundTest() {
     
    2627}
    2728
    28 
    2929SoundTest::~SoundTest() {
    3030  sound->deleteInstance();
    3131}
    3232
    33 
    3433int main(void) {
    3534  SoundTest();
    3635  SDL_Surface *screen;
     36  SDL_Event event;
    3737  SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);
    3838  screen = SDL_SetVideoMode(320, 240, 0, 0);
    39   sound->playOgg("music.ogg");
    40   while(!through) {
    41     SDL_Delay(100);
    42     if(counter >= 1000) {
    43         through = 1;
     39  while(!finished) {
     40    while(SDL_PollEvent(&event)) {
     41      switch(event.type) {
     42      case SDL_QUIT:
     43        finished = 1;
     44        break;
     45      case SDL_KEYDOWN:
     46      case SDL_KEYUP:
     47        handleKey(event.key);
     48        break;
     49      }
    4450    }
    45     counter++;
     51    SDL_Delay(50);
    4652  }
    4753  SDL_Quit();
    4854}
     55
     56void handleKey(SDL_KeyboardEvent key) {
     57  switch(key.keysym.sym) {
     58  case SDLK_a:
     59    if(key.type == SDL_KEYDOWN) {
     60      if(sfx_channel1 < 0) {
     61        sfx_channel1 = sound->playWav("sound1.wav");
     62      }
     63    } else {
     64      Mix_HaltChannel(sfx_channel1);
     65      sfx_channel1 = -1;
     66    }
     67    break;
     68  case SDLK_s:
     69    if(key.type == SDL_KEYDOWN) {
     70      if(sfx_channel2 < 0) {
     71        sfx_channel2 = sound->playWav("sound2.wav");
     72      }
     73    } else {
     74      Mix_HaltChannel(sfx_channel2);
     75      sfx_channel2 = -1;
     76    }
     77    break;
     78  case SDLK_m:
     79    if(key.state == SDL_PRESSED) {
     80      if(sound.music == NULL) {
     81        sound->playOgg("music.ogg");
     82      } else {
     83        Mix_HaltMusic();
     84        Mix_FreeMusic(music);
     85        music = NULL;
     86      }
     87    }
     88    break;
     89  case SDLK_q:
     90    finished = 1;
     91    break;
     92  }
     93}
  • orxonox/branches/sound/sound/sound_test.h

    r2974 r2979  
    1212  ~SoundTest();
    1313  int main (void);
     14  void handleKey(SDL_KeyboardEvent key);
    1415  SoundControl* sound;
    15   int counter;
    16   int through;
     16  int sfx_channel1;
     17  int sfx_channel2;
     18  int finished;
    1719};
    1820
Note: See TracChangeset for help on using the changeset viewer.