Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3509 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Mar 11, 2005, 11:33:44 PM (19 years ago)
Author:
bensch
Message:

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

Location:
orxonox/branches/soundEngine/src
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/soundEngine/src/Makefile.am

    r3508 r3509  
    6161                 glmenu/glmenu_imagescreen.cc
    6262
    63 sound_SOURCES = sound_control.cc
     63sound_SOURCES =  sound_test.cc \
     64                 sound_control.cc
    6465
    6566noinst_HEADERS = orxonox.h \
  • orxonox/branches/soundEngine/src/Makefile.in

    r3502 r3509  
    1616
    1717
    18 SOURCES = $(orxonox_SOURCES)
     18SOURCES = $(orxonox_SOURCES) $(sound_SOURCES)
    1919
    2020srcdir = @srcdir@
     
    3939POST_UNINSTALL = :
    4040host_triplet = @host@
    41 bin_PROGRAMS = orxonox$(EXEEXT)
     41bin_PROGRAMS = orxonox$(EXEEXT) sound$(EXEEXT)
    4242subdir = src
    4343DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
     
    6767orxonox_OBJECTS = $(am_orxonox_OBJECTS)
    6868orxonox_LDADD = $(LDADD)
     69am_sound_OBJECTS = sound_test.$(OBJEXT) sound_control.$(OBJEXT)
     70sound_OBJECTS = $(am_sound_OBJECTS)
     71sound_LDADD = $(LDADD)
    6972DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
    7073depcomp = $(SHELL) $(top_srcdir)/depcomp
     
    8790@AMDEP_TRUE@    ./$(DEPDIR)/p_node.Po ./$(DEPDIR)/player.Po \
    8891@AMDEP_TRUE@    ./$(DEPDIR)/skysphere.Po \
     92@AMDEP_TRUE@    ./$(DEPDIR)/sound_control.Po \
     93@AMDEP_TRUE@    ./$(DEPDIR)/sound_test.Po \
    8994@AMDEP_TRUE@    ./$(DEPDIR)/story_entity.Po ./$(DEPDIR)/texture.Po \
    9095@AMDEP_TRUE@    ./$(DEPDIR)/track_manager.Po ./$(DEPDIR)/vector.Po \
     
    95100CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
    96101        -o $@
    97 SOURCES = $(orxonox_SOURCES)
    98 DIST_SOURCES = $(orxonox_SOURCES)
     102SOURCES = $(orxonox_SOURCES) $(sound_SOURCES)
     103DIST_SOURCES = $(orxonox_SOURCES) $(sound_SOURCES)
    99104RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
    100105        html-recursive info-recursive install-data-recursive \
     
    251256                 glmenu/glmenu_imagescreen.cc
    252257
     258sound_SOURCES = sound_test.cc \
     259                 sound_control.cc
     260
    253261noinst_HEADERS = orxonox.h \
    254262                 game_loader.h \
     
    359367        @rm -f orxonox$(EXEEXT)
    360368        $(CXXLINK) $(orxonox_LDFLAGS) $(orxonox_OBJECTS) $(orxonox_LDADD) $(LIBS)
     369sound$(EXEEXT): $(sound_OBJECTS) $(sound_DEPENDENCIES)
     370        @rm -f sound$(EXEEXT)
     371        $(CXXLINK) $(sound_LDFLAGS) $(sound_OBJECTS) $(sound_LDADD) $(LIBS)
    361372
    362373mostlyclean-compile:
     
    393404@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/player.Po@am__quote@
    394405@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/skysphere.Po@am__quote@
     406@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sound_control.Po@am__quote@
     407@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sound_test.Po@am__quote@
    395408@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/story_entity.Po@am__quote@
    396409@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/texture.Po@am__quote@
  • orxonox/branches/soundEngine/src/sound_control.cc

    r3508 r3509  
    1818using namespace std;
    1919
    20 int sfx_channel1 = -1;
    21 int sfx_channel2 = -1;
    22 int finished = 0;
    2320SoundControl* SoundControl::sound = SoundControl::getInstance();
    24 SoundControl* SoundControl::singletonRef = 0;
    25 int volume = SDL_MIX_MAXVOLUME;
    26 int track_number = 1;
    27 Mix_Music* music = NULL;
    28 int audio_rate = 44100, audio_channels = MIX_DEFAULT_CHANNELS,
    29 audio_buffers = 16384, bits = 0;
    30 Uint16 audio_format = MIX_DEFAULT_FORMAT;
    31 SDL_Event event;
     21SoundControl* SoundControl::singletonRef = NULL;
    3222
    3323
     
    3727    All sound output is handled by this singleton object.
    3828*/
    39 SoundControl::SoundControl() { 
     29SoundControl::SoundControl() {
    4030  if(SDL_Init(SDL_INIT_AUDIO)<0) {
    4131    printf("SDL_Init: INIT_AUDIO error.\n");
     
    4434    printf("Mix_OpenAudio: Failed to open audio!\n");
    4535  }
    46   initialise();
     36  init();
    4737}
    4838
     
    5040    \brief Default destructor
    5141*/
    52 SoundControl::~SoundControl() {
     42SoundControl::~SoundControl()
     43{
     44  singletonRef = NULL;
    5345}
    5446
     
    5749*/
    5850SoundControl* SoundControl::getInstance() {
    59   if (!SoundControl::singletonRef)
     51  if (SoundControl::singletonRef)
    6052    return singletonRef;
    6153  else
     
    6658    \brief Is called by SoundControl object to initiate all values and to output some text
    6759*/
    68 void SoundControl::initialise() {
     60void SoundControl::init(void)
     61{
     62  this->sfx_channel1 = -1;
     63  this->sfx_channel2 = -1;
     64  this->finished = 0;
     65  this->volume = SDL_MIX_MAXVOLUME;
     66  this->track_number = 1;
     67  this->music = NULL;
     68  this->audio_rate = 44100;
     69  this->audio_channels = MIX_DEFAULT_CHANNELS;
     70  this->audio_buffers = 16384;
     71  this->bits = 0;
     72  this->audio_format = MIX_DEFAULT_FORMAT;
     73 
     74 
    6975  Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
    7076  bits=audio_format&0xFF;
     
    8591*/
    8692void SoundControl::playMod(char* fileName) {
    87   Mix_Chunk* chunk = NULL;
    88   chunk = Mix_LoadWAV(fileName);
     93  Mix_Chunk* chunk = Mix_LoadWAV(fileName);
    8994  if(Mix_PlayChannel(-1, chunk, 0) == -1) {
    9095    printf("Mix_PlayChannel: %s\n", Mix_GetError());
     
    97102*/
    98103void SoundControl::playWav(char* fileName) {
    99   Mix_Chunk* chunk = NULL;
    100   chunk = Mix_LoadWAV(fileName);
     104  Mix_Chunk* chunk = Mix_LoadWAV(fileName);
    101105  if(Mix_PlayChannel(-1, chunk, 0) == -1) {
    102106    printf("Mix_PlayChannel: %s\n", Mix_GetError());
     
    188192    \brief Hooked by playOgg at end of .ogg playback
    189193*/
    190 void SoundControl::musicDone() {
     194void SoundControl::musicDone()
     195{
     196  Mix_Music* music = SoundControl::getInstance()->music;
    191197  Mix_HaltMusic();
    192198  Mix_FreeMusic(music);
     
    194200}
    195201
    196 /**
    197     \brief Handles input events
    198 */
    199 void SoundControl::handleKey(SDL_KeyboardEvent key) {
    200   SoundControl* sound = SoundControl::getInstance();
    201 
    202   switch(key.keysym.sym) {
    203   case SDLK_a:
    204     if(key.type == SDL_KEYDOWN) {
    205       if(sound->sfx_channel1 < 0) {
    206         sound->sfx_channel1 = 1;
    207         sound->playWav("sound1.wav");
    208       }
    209     } else {
    210       Mix_HaltChannel(sound->sfx_channel1);
    211       sound->sfx_channel1 = -1;
    212     }
    213     break;
    214   case SDLK_s:
    215     if(key.type == SDL_KEYDOWN) {
    216       if(sound->sfx_channel2 < 0) {
    217         sound->sfx_channel2 = 1;
    218         sound->playWav("sound2.wav");
    219       }
    220     } else {
    221       Mix_HaltChannel(sound->sfx_channel2);
    222       sound->sfx_channel2 = -1;
    223     }
    224     break;
    225   case SDLK_m:
    226     if(key.state == SDL_PRESSED) {
    227       sound->playOgg("music.ogg");
    228     }
    229     break;
    230   case SDLK_q:
    231     sound->finished = 1;
    232     break;
    233   default:
    234     break;
    235   }
    236 }
    237 
    238 int main(int argc, char* argv[]) {
    239   SDL_Surface* screen;
    240   SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);
    241   screen = SDL_SetVideoMode(320, 240, 0, 0);
    242   while(!finished) {
    243     while(SDL_PollEvent(&event)) {
    244       switch(event.type) {
    245       case SDL_QUIT:
    246         finished = 1;
    247         break;
    248       case SDL_KEYDOWN:
    249       case SDL_KEYUP:
    250         SoundControl::handleKey(event.key);
    251         break;
    252       default:
    253         break;
    254       }
    255     }
    256     SDL_Delay(50);
    257   }
    258   delete SoundControl::getInstance();
    259   SDL_Quit();
    260   return 0;
    261 }
  • orxonox/branches/soundEngine/src/sound_control.h

    r3508 r3509  
    3030  int main(int argc, char* argv[]);
    3131 
     32
     33 private:
     34  SoundControl();
     35  void init(void);
     36
     37  static SoundControl* singletonRef;
     38
     39 public:
     40  Mix_Music* music;
    3241  static SoundControl* sound;
     42  int bits;
    3343  int volume;
    3444  int track_number;
     
    3949  int sfx_channel2;
    4050  int finished;
    41 
    42  private:
    43   SoundControl();
    44 
    45   static SoundControl* singletonRef;
    46   void initialise();
    47 
    4851};
    4952
Note: See TracChangeset for help on using the changeset viewer.