Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3512 in orxonox.OLD


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

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

Location:
orxonox/branches/soundEngine/src
Files:
3 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
  • orxonox/branches/soundEngine/src/sound_control.h

    r3509 r3512  
    22#define SOUNDCONTROL_CLASS_H
    33
    4 #include <SDL/SDL.h>
     4#include "stdincl.h"
    55#include <SDL/SDL_mixer.h>
    6 #include <stdio.h>
    76
    87class SoundControl {
     
    3736  static SoundControl* singletonRef;
    3837
     38  bool isInit;
     39
    3940 public:
     41
    4042  Mix_Music* music;
    4143  static SoundControl* sound;
    4244  int bits;
    4345  int volume;
     46
    4447  int track_number;
    45   int audio_rate, audio_channels, audio_buffers;
     48  int audio_rate;
     49  int audio_channels;
     50  int audio_buffers;
    4651  int done;
    47   Uint16 audio_format;
    4852  int sfx_channel1;
    4953  int sfx_channel2;
    5054  int finished;
     55
     56  Uint16 audio_format;
    5157};
    5258
  • orxonox/branches/soundEngine/src/sound_test.cc

    r3509 r3512  
    33#include "sound_control.h"
    44
     5int verbose = 3;
    56
    67/**
     
    5152  SoundControl* soundControl = SoundControl::getInstance();
    5253
    53   SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);
     54  SDL_Init(SDL_INIT_VIDEO);
    5455  screen = SDL_SetVideoMode(320, 240, 0, 0);
    5556  while(!soundControl->finished) {
Note: See TracChangeset for help on using the changeset viewer.