Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 12, 2005, 12:41:09 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/soundEngine: modified, so it has some more c++ style

File:
1 edited

Legend:

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

    r3510 r3512  
    1616#include "sound_control.h"
    1717
     18
    1819using namespace std;
    1920
     
    2829*/
    2930SoundControl::SoundControl() {
    30   init();
     31  this->init();
    3132
    3233}
     
    6667  this->bits = 0;
    6768  this->audio_format = MIX_DEFAULT_FORMAT;
     69
     70  // initialize SDL
     71  this->isInit = false;
     72  if (!SDL_Init(SDL_INIT_AUDIO))
     73    {
     74      PRINTF(1)("SDL-sound could not be initialized\n");
     75      return;
     76    }
     77  else
     78    this->isInit = true;
    6879 
    69  
    70   Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
    71   bits=audio_format&0xFF;
    72   printf("Opened audio at %d Hz %d bit %s, %d bytes audio buffer\n", audio_rate, bits, audio_channels > 1 ? "stereo" : "mono", audio_buffers );
    73   Mix_VolumeMusic(volume);
    74 
    75   if(SDL_Init(SDL_INIT_AUDIO)<0)
    76     printf("SDL_Init: INIT_AUDIO error.\n");
    77   if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers))
    78     printf("Mix_OpenAudio: Failed to open audio!\n");
     80  Mix_QuerySpec(&this->audio_rate, &this->audio_format, &this->audio_channels);
     81  this->bits=this->audio_format&0xFF;
     82  PRINTF(3)("Opened audio at %d Hz %d bit %s, %d bytes audio buffer\n", this->audio_rate, this->bits, this->audio_channels > 1 ? "stereo" : "mono", this->audio_buffers );
     83  Mix_VolumeMusic(this->volume);
     84
     85  if(Mix_OpenAudio(this->audio_rate, this->audio_format, this->audio_channels, this->audio_buffers))
     86    PRINTF(1)("Mix_OpenAudio: Failed to open audio!\n");
    7987 
    8088 
     
    115123*/
    116124void SoundControl::playOgg(char* fileName) {
    117   Mix_Music* music = NULL;
    118   music = Mix_LoadMUS(fileName);
     125  Mix_Music* music = Mix_LoadMUS(fileName);
    119126  if(Mix_PlayMusic(music, 1) == -1) {
    120127    printf("Mix_PlayMusic: %s\n",Mix_GetError());
     
    127134*/
    128135void SoundControl::volumeUp() {
    129   volume = (volume + 1) << 1;
    130   if(volume > SDL_MIX_MAXVOLUME)
    131     volume = SDL_MIX_MAXVOLUME;
    132   Mix_VolumeMusic(volume);
     136  this->volume = (this->volume++) << 1;
     137  if(this->volume > SDL_MIX_MAXVOLUME)
     138    this->volume = SDL_MIX_MAXVOLUME;
     139  Mix_VolumeMusic(this->volume);
    133140}
    134141
     
    138145*/ 
    139146void SoundControl::volumeDown() {
    140   volume >>= 1;
    141   Mix_VolumeMusic(volume);
     147  this->volume >>= 1;
     148  if(this->volume < 0)
     149    this->volume = 1;
     150  Mix_VolumeMusic(this->volume);
    142151}
    143152
Note: See TracChangeset for help on using the changeset viewer.