Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2854 in orxonox.OLD for orxonox/branches/sound/src


Ignore:
Timestamp:
Nov 14, 2004, 4:44:31 PM (20 years ago)
Author:
simon
Message:

/branches/sound: finally a running version. To test, you can switch the parameters in the test class sound_test. A .ogg file named music.ogg from the directory . is played. The test class is really ugly, I know.

Location:
orxonox/branches/sound/src
Files:
1 added
6 edited

Legend:

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

    r2636 r2854  
    55
    66
    7 bin_PROGRAMS=orxonox
     7bin_PROGRAMS=orxonox sound
    88orxonox_SOURCES=orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc base_entity.cc game_loader.cc campaign.cc story_entity.cc
     9
     10sound_SOURCES=sound_test.cc sound_control.cc
    911
    1012noinst_HEADERS=ability.h data_tank.h npc.h stdincl.h ai.h environment.h orxonox.h synchronisable.h base_entity.h error.h player.h track.h camera.h ini_parser.h power_up.h vector.h collision.h keynames.h proto_class.h world.h command_node.h list.h shoot_laser.h world_entity.h coordinates.h message_structures.h shoot_rocket.h
  • orxonox/branches/sound/src/Makefile.in

    r2640 r2854  
    116116
    117117#"-O3 -pedantic -fPIC -ffast-math -I/usr/X11R6/include"
    118 bin_PROGRAMS = orxonox
     118bin_PROGRAMS = orxonox sound
    119119orxonox_SOURCES = orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc base_entity.cc game_loader.cc campaign.cc story_entity.cc
     120
     121sound_SOURCES = sound_test.cc sound_control.cc
    120122
    121123noinst_HEADERS = ability.h data_tank.h npc.h stdincl.h ai.h environment.h orxonox.h synchronisable.h base_entity.h error.h player.h track.h camera.h ini_parser.h power_up.h vector.h collision.h keynames.h proto_class.h world.h command_node.h list.h shoot_laser.h world_entity.h coordinates.h message_structures.h shoot_rocket.h
     
    125127CONFIG_HEADER = $(top_builddir)/config.h
    126128CONFIG_CLEAN_FILES =
    127 bin_PROGRAMS = orxonox$(EXEEXT)
     129bin_PROGRAMS = orxonox$(EXEEXT) sound$(EXEEXT)
    128130PROGRAMS = $(bin_PROGRAMS)
    129131
     
    138140orxonox_DEPENDENCIES =
    139141orxonox_LDFLAGS =
     142am_sound_OBJECTS = sound_test.$(OBJEXT) sound_control.$(OBJEXT)
     143sound_OBJECTS = $(am_sound_OBJECTS)
     144sound_LDADD = $(LDADD)
     145sound_DEPENDENCIES =
     146sound_LDFLAGS =
    140147
    141148DEFAULT_INCLUDES =  -I. -I$(srcdir) -I$(top_builddir)
     
    148155@AMDEP_TRUE@    ./$(DEPDIR)/ini_parser.Po ./$(DEPDIR)/keynames.Po \
    149156@AMDEP_TRUE@    ./$(DEPDIR)/orxonox.Po ./$(DEPDIR)/player.Po \
     157@AMDEP_TRUE@    ./$(DEPDIR)/sound_control.Po \
     158@AMDEP_TRUE@    ./$(DEPDIR)/sound_test.Po \
    150159@AMDEP_TRUE@    ./$(DEPDIR)/story_entity.Po ./$(DEPDIR)/track.Po \
    151160@AMDEP_TRUE@    ./$(DEPDIR)/vector.Po ./$(DEPDIR)/world.Po \
     
    156165CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
    157166        -o $@
    158 DIST_SOURCES = $(orxonox_SOURCES)
     167DIST_SOURCES = $(orxonox_SOURCES) $(sound_SOURCES)
    159168HEADERS = $(noinst_HEADERS)
    160169
    161170DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.in INSTALL \
    162171        Makefile.am
    163 SOURCES = $(orxonox_SOURCES)
     172SOURCES = $(orxonox_SOURCES) $(sound_SOURCES)
    164173
    165174all: all-am
     
    199208        @rm -f orxonox$(EXEEXT)
    200209        $(CXXLINK) $(orxonox_LDFLAGS) $(orxonox_OBJECTS) $(orxonox_LDADD) $(LIBS)
     210sound$(EXEEXT): $(sound_OBJECTS) $(sound_DEPENDENCIES)
     211        @rm -f sound$(EXEEXT)
     212        $(CXXLINK) $(sound_LDFLAGS) $(sound_OBJECTS) $(sound_LDADD) $(LIBS)
    201213
    202214mostlyclean-compile:
     
    217229@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox.Po@am__quote@
    218230@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/player.Po@am__quote@
     231@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sound_control.Po@am__quote@
     232@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sound_test.Po@am__quote@
    219233@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/story_entity.Po@am__quote@
    220234@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/track.Po@am__quote@
  • orxonox/branches/sound/src/sound_control.cc

    r2838 r2854  
    1515
    1616#include "sound_control.h"
    17 #include <string.h>
    18 #include "SDL_mixer.h"
    1917
    2018using namespace std;
    2119
    2220// global variables
    23 
    24 SoundControl* SoundControl::instance = 0; // singleton reference
    25 int volume = SDL_MIX_MAXVOLUME; // volume
    26 int done = 0; //
     21SoundControl* SoundControl::instance = NULL; // singleton reference
     22int volume = SDL_MIX_MAXVOLUME;
     23int done = 0;
    2724int track_number = 1;
    28 Mix_Music* music = NULL;
     25static Mix_Music* music = NULL;
     26int audio_rate = MIX_DEFAULT_FREQUENCY, audio_channels = MIX_DEFAULT_CHANNELS, audio_buffers = 16384, bits = 0;
     27Uint16 audio_format = MIX_DEFAULT_FORMAT;
     28
    2929
    3030/**
     
    3535*/
    3636SoundControl::SoundControl () {
    37  
    38   //setup parameters
    39   int audio_rate = MIX_DEFAULT_FREQUENCY, audio_channels = MIX_DEFAULT_CHANNELS, audio_buffers = 8192, bits = 0;
    40   Uint16 audio_format = MIX_DEFAULT_FORMAT;
    41 
    42   //initializing sound and calling Mix_OpenAudio
     37
     38  /*
     39  initializing sound and calling Mix_OpenAudio
    4340  if(SDL_Init(SDL_INIT_AUDIO)<0){
    44     printf("SDL_Init: \n");
    45     exit(1);
     41    printf("SDL_Init: INIT_AUDIO error.\n");
    4642  }
     43  */
    4744 
    4845  if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)){
    49     printf("Mix_OpenAudio: \n");
    50     exit(1);
     46    printf("Mix_OpenAudio: Failed to open audio!\n");
    5147  }
    5248 
     
    5652
    5753/**
    58     \brief Destructor for the singleton instance
     54    \brief Default destructor
    5955*/
    6056SoundControl::~SoundControl () {
    61   delete instance;
    62   instance = 0;
    6357}
    6458
     
    6761*/
    6862SoundControl* SoundControl::getInstance() {
    69   if (instance == 0) {
     63  if (instance == NULL) {
    7064    instance = new SoundControl;
    7165  }
     
    7468
    7569void SoundControl::deleteInstance() {
    76   ~SoundControl();
     70  delete instance;
     71  instance = NULL;
    7772}
    7873
     
    186181*/
    187182void SoundControl::pauseMusic () {
    188   Mix_PauseMusic()
     183  Mix_PauseMusic();
    189184}
    190185
     
    194189*/
    195190void SoundControl::resumeMusic () {
    196   Mix_ResumeMusic()
     191  Mix_ResumeMusic();
    197192}
    198193
     
    200195    \brief Selects the track of all orxonox tracks
    201196*/
    202 void SoundControl::trackSelect () {
     197void SoundControl::trackSelect() {
    203198  switch (track_number) {
    204199  case 1:
     
    219214    music = Mix_LoadMUS("luke_grey_orxonox3.ogg");
    220215    if(Mix_PlayMusic(music, 1) == -1){
    221     printf("Mix_PlayMusic: %s\n",Mix_GetError());
    222   }
    223   Mix_HookMusicFinished(musicDone);   
    224   break;
     216      printf("Mix_PlayMusic: %s\n",Mix_GetError());
     217    }
     218    Mix_HookMusicFinished(musicDone);   
     219    break;
    225220  case 4:
    226221    music = Mix_LoadMUS("luke_grey_and_aquarius_orxonox.ogg");
     
    239234  case 6:
    240235    music = Mix_LoadMUS("nomenes_funkadudu.ogg");
    241   if(Mix_PlayMusic(music, 1) == -1){
    242     printf("Mix_PlayMusic: %s\n",Mix_GetError());
    243   }
    244   Mix_HookMusicFinished(musicDone);   
    245 break;
     236    if(Mix_PlayMusic(music, 1) == -1){
     237      printf("Mix_PlayMusic: %s\n",Mix_GetError());
     238    }
     239    Mix_HookMusicFinished(musicDone);
     240    break;
    246241  }
    247242}
     
    251246    \brief Hooked by playOgg at end of .ogg playback
    252247*/
    253 void SoundControl::musicDone () {
    254   track_number++;
     248void SoundControl::musicDone() {
    255249  Mix_HaltMusic();
    256250  Mix_FreeMusic(music);
  • orxonox/branches/sound/src/sound_control.h

    r2838 r2854  
    22#define SOUNDCONTROL_CLASS_H
    33
    4 #include "data_tank.h"
     4#include "SDL/SDL.h"
     5#include "SDL/SDL_mixer.h"
     6#include <stdio.h>
    57
    68class SoundControl {
     
    911  static SoundControl* getInstance();
    1012  static void deleteInstance();
    11   void setNumberOfChannels(int number_of channels);
     13  void setNumberOfChannels(int number_of_channels);
    1214  int playMod(char* filename);
    1315  int playWav(char* filename);
     
    2123  void resumeMusic();
    2224  void trackSelect();
     25  static void musicDone();
    2326
    2427protected:
     
    2932private:
    3033  static SoundControl* instance;
    31 
    32 }
     34};
    3335
    3436#endif
  • orxonox/branches/sound/src/sound_test.cc

    r2838 r2854  
    1414*/
    1515
    16 
    1716#include "sound_test.h"
    18 #include "SDL.h"
    19 #include "SDL_mixer.h"
    2017
    2118using namespace std;
    2219
    23 SoundControl* test;
     20SoundControl* sound = NULL;
     21int counter = 0;
     22int through = 0;
    2423
    25 SoundTest::SoundTest () {
    26   test = SoundControl::getInstance();
     24SoundTest::SoundTest() {
     25  sound = SoundControl::getInstance();
    2726}
    2827
    2928
    30 SoundTest::~SoundTest () {
    31  
     29SoundTest::~SoundTest() {
     30  sound->deleteInstance();
    3231}
    3332
    3433
    35 void main (void) {
     34int main(void) {
     35  SoundTest();
    3636  SDL_Surface *screen;
    37   SDL_Init(SDL_INIT_VIDEO);
     37  SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);
    3838  screen = SDL_SetVideoMode(320, 240, 0, 0);
    39   SoundControl* sound = new SoundControl;
    40   sound.SoundControl();
    41   sound->playOgg(music.ogg);
    42   sound.~SoundControl();
     39  sound->playOgg("music.ogg");
     40  while(!through) {
     41    SDL_Delay(100);
     42    if(counter >= 1000) {
     43        through = 1;
     44    }
     45    counter++;
     46  }
     47  SDL_Quit();
    4348}
  • orxonox/branches/sound/src/sound_test.h

    r2838 r2854  
    1 
    21#ifndef SOUND_TEST_H
    32#define SOUND_TEST_H
    43
    5 #include "data_tank.h"
    6 
     4#include "sound_control.h"
     5#include "SDL/SDL.h"
     6#include "SDL/SDL_mixer.h"
    77
    88class SoundTest {
    99
    1010 public:
    11   SoundTest ();
    12   ~SoundTest ();
    13   void main (void);
     11  SoundTest();
     12  ~SoundTest();
     13  int main (void);
     14  SoundControl* sound;
     15  int counter;
     16  int through;
    1417};
    1518
Note: See TracChangeset for help on using the changeset viewer.