Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 29, 2004, 1:04:28 PM (21 years ago)
Author:
simon
Message:

/branches/sound/sound, branches/sound/hud: Made a few changes like a version which no longer compiles… Ah life is so hard on me. If it would compile, you would need to make a folder Data in hud and add a tga file named Font.tga with the letters in it.

File:
1 edited

Legend:

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

    r2979 r3020  
    1818using namespace std;
    1919
    20 SoundControl* SoundControl::instance = NULL;
     20int sfx_channel1 = -1;
     21int sfx_channel2 = -1;
     22int finished = 0;
     23static SoundControl* instance = NULL;
     24static SoundControl* sound = SoundControl::getInstance();
    2125int volume = SDL_MIX_MAXVOLUME;
    2226int track_number = 1;
    2327static Mix_Music* music = NULL;
    24 int audio_rate = MIX_DEFAULT_FREQUENCY, audio_channels = MIX_DEFAULT_CHANNELS, audio_buffers = 16384, bits = 0;
     28int audio_rate = 44100, audio_channels = MIX_DEFAULT_CHANNELS,
     29audio_buffers = 16384, bits = 0;
    2530Uint16 audio_format = MIX_DEFAULT_FORMAT;
     31SDL_Event event;
    2632
    2733
     
    3339*/
    3440SoundControl::SoundControl () {
    35 
    36   /*
    37   initializing sound and calling Mix_OpenAudio
    38   if(SDL_Init(SDL_INIT_AUDIO)<0){
     41  if(SDL_Init(SDL_INIT_AUDIO)<0) {
    3942    printf("SDL_Init: INIT_AUDIO error.\n");
    4043  }
    41   */
    42  
    43   if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)){
     44  if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
    4445    printf("Mix_OpenAudio: Failed to open audio!\n");
    4546  }
    46  
    4747  initialise();
    4848}
    4949
    50 
    5150/**
    5251    \brief Default destructor
    5352*/
    54 SoundControl::~SoundControl () { 
     53SoundControl::~SoundControl () {
    5554}
    5655
     
    7170
    7271/**
    73     \brief Is called by SoundControl object to initiate all values
     72    \brief Is called by SoundControl object to initiate all values and to output some text
    7473*/
    7574void SoundControl::initialise() {
    76  
    77   // Print some info
    7875  Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
    7976  bits=audio_format&0xFF;
     
    8279}
    8380
    84 
    85 /**
    86     \brief Sets the number of output Channels (should not be used)
     81/**
     82    \brief Sets the number of output Channels
    8783*/
    8884void SoundControl::setNumberOfChannels (int number_of_channels) {
     
    9086}
    9187
    92 
    9388/**
    9489    \brief May be called from any WorldEntity to play a .xm file
    9590    \param filename: self-explanatory
    9691*/
    97 int SoundControl::playMod (char* fileName) {
     92void SoundControl::playMod (char* fileName) {
    9893  Mix_Chunk* chunk = NULL;
    9994  chunk = Mix_LoadWAV(fileName);
     
    10398}
    10499
    105 
    106100/**
    107101    \brief May be called from any WorldEntity to play a .wav file
    108102    \param filename: self-explanatory
    109103*/
    110 int SoundControl::playWav (char* fileName) {
     104void SoundControl::playWav (char* fileName) {
    111105  Mix_Chunk* chunk = NULL;
    112106  chunk = Mix_LoadWAV(fileName);
     
    116110}
    117111
    118 
    119112/**
    120113    \brief May be called from any WorldEntity to play a .ogg file
    121114    \param filename: self-explanatory
    122115*/
    123 int SoundControl::playOgg (char* fileName) {
     116void SoundControl::playOgg (char* fileName) {
    124117  Mix_Music* music = NULL;
    125118  music = Mix_LoadMUS(fileName);
    126   if(Mix_PlayMusic(music, 1) == -1){
     119  if(Mix_PlayMusic(music, 1) == -1) {
    127120    printf("Mix_PlayMusic: %s\n",Mix_GetError());
    128121  }
    129122  Mix_HookMusicFinished(musicDone);
    130123}
    131 
    132124
    133125/**
     
    150142}
    151143
    152 
    153144/**
    154145    \brief Rewinds music to the beginning
     
    158149}
    159150
    160 
    161151/**
    162152    \brief Rewinds the music 5 seconds
     
    166156}
    167157
    168 
    169158/**
    170159    \brief Forwards the music 5 seconds
     
    174163}
    175164
    176 
    177165/**
    178166    \brief Pauses music output
     
    182170}
    183171
    184 
    185172/**
    186173    \brief this function pauses music output
     
    189176  Mix_ResumeMusic();
    190177}
    191 
    192178
    193179/**
     
    199185  music = NULL;
    200186}
     187
     188/**
     189    \brief Handles input events
     190*/
     191void SoundControl::handleKey(SDL_KeyboardEvent key) {
     192  switch(key.keysym.sym) {
     193  case SDLK_a:
     194    if(key.type == SDL_KEYDOWN) {
     195      if(sfx_channel1 < 0) {
     196        sfx_channel1 = sound->playWav("sound1.wav");
     197      }
     198    } else {
     199      Mix_HaltChannel(sfx_channel1);
     200      sfx_channel1 = -1;
     201    }
     202    break;
     203  case SDLK_s:
     204    if(key.type == SDL_KEYDOWN) {
     205      if(sfx_channel2 < 0) {
     206        sfx_channel2 = sound->playWav("sound2.wav");
     207      }
     208    } else {
     209      Mix_HaltChannel(sfx_channel2);
     210      sfx_channel2 = -1;
     211    }
     212    break;
     213  case SDLK_m:
     214    if(key.state == SDL_PRESSED) {
     215      sound->playOgg("music.ogg");
     216    }
     217    break;
     218  case SDLK_q:
     219    finished = 1;
     220    break;
     221  default:
     222    break;
     223  }
     224}
     225
     226int SoundControl::main(void) {
     227  SDL_Surface* screen;
     228  SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);
     229  screen = SDL_SetVideoMode(320, 240, 0, 0);
     230  while(!finished) {
     231    while(SDL_PollEvent(&event)) {
     232      switch(event.type) {
     233      case SDL_QUIT:
     234        finished = 1;
     235        break;
     236      case SDL_KEYDOWN:
     237      case SDL_KEYUP:
     238        SoundControl::handleKey(event.key);
     239        break;
     240      default:
     241        break;
     242      }
     243    }
     244    SDL_Delay(50);
     245  }
     246  deleteInstance();
     247  SDL_Quit();
     248  return 0;
     249}
Note: See TracChangeset for help on using the changeset viewer.