Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/soundEngine/src/sound_test.cc @ 3509

Last change on this file since 3509 was 3509, checked in by bensch, 19 years ago

orxonox/branches/soundEngine: moved unrelevant stuff out of sound_control.

File size: 1.4 KB
Line 
1
2
3#include "sound_control.h"
4
5
6/**
7    \brief Handles input events
8*/ 
9void handleKey(SDL_KeyboardEvent key) {
10  SoundControl* sound = SoundControl::getInstance();
11
12  switch(key.keysym.sym) {
13  case SDLK_a:
14    if(key.type == SDL_KEYDOWN) {
15      if(sound->sfx_channel1 < 0) {
16        sound->sfx_channel1 = 1;
17        sound->playWav("sound1.wav");
18      }
19    } else {
20      Mix_HaltChannel(sound->sfx_channel1);
21      sound->sfx_channel1 = -1;
22    }
23    break;
24  case SDLK_s:
25    if(key.type == SDL_KEYDOWN) {
26      if(sound->sfx_channel2 < 0) {
27        sound->sfx_channel2 = 1;
28        sound->playWav("sound2.wav");
29      }
30    } else {
31      Mix_HaltChannel(sound->sfx_channel2);
32      sound->sfx_channel2 = -1;
33    }
34    break;
35  case SDLK_m:
36    if(key.state == SDL_PRESSED) {
37      sound->playOgg("music.ogg");
38    }
39    break;
40  case SDLK_q:
41    sound->finished = 1;
42    break;
43  default:
44    break;
45  }
46}
47
48int main(int argc, char* argv[]) {
49  SDL_Surface* screen;
50  SDL_Event event;
51  SoundControl* soundControl = SoundControl::getInstance();
52
53  SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);
54  screen = SDL_SetVideoMode(320, 240, 0, 0);
55  while(!soundControl->finished) {
56    while(SDL_PollEvent(&event)) {
57      switch(event.type) {
58      case SDL_QUIT:
59        soundControl->finished = 1;
60        break;
61      case SDL_KEYDOWN:
62      case SDL_KEYUP:
63        handleKey(event.key);
64        break;
65      default:
66        break;
67      }
68    }
69    SDL_Delay(50);
70  }
71  delete SoundControl::getInstance();
72  SDL_Quit();
73  return 0;
74}
75
Note: See TracBrowser for help on using the repository browser.