- Timestamp:
- Mar 11, 2005, 11:33:44 PM (20 years ago)
- Location:
- orxonox/branches/soundEngine/src
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/soundEngine/src/Makefile.am
r3508 r3509 61 61 glmenu/glmenu_imagescreen.cc 62 62 63 sound_SOURCES = sound_control.cc 63 sound_SOURCES = sound_test.cc \ 64 sound_control.cc 64 65 65 66 noinst_HEADERS = orxonox.h \ -
orxonox/branches/soundEngine/src/Makefile.in
r3502 r3509 16 16 17 17 18 SOURCES = $(orxonox_SOURCES) 18 SOURCES = $(orxonox_SOURCES) $(sound_SOURCES) 19 19 20 20 srcdir = @srcdir@ … … 39 39 POST_UNINSTALL = : 40 40 host_triplet = @host@ 41 bin_PROGRAMS = orxonox$(EXEEXT) 41 bin_PROGRAMS = orxonox$(EXEEXT) sound$(EXEEXT) 42 42 subdir = src 43 43 DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \ … … 67 67 orxonox_OBJECTS = $(am_orxonox_OBJECTS) 68 68 orxonox_LDADD = $(LDADD) 69 am_sound_OBJECTS = sound_test.$(OBJEXT) sound_control.$(OBJEXT) 70 sound_OBJECTS = $(am_sound_OBJECTS) 71 sound_LDADD = $(LDADD) 69 72 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) 70 73 depcomp = $(SHELL) $(top_srcdir)/depcomp … … 87 90 @AMDEP_TRUE@ ./$(DEPDIR)/p_node.Po ./$(DEPDIR)/player.Po \ 88 91 @AMDEP_TRUE@ ./$(DEPDIR)/skysphere.Po \ 92 @AMDEP_TRUE@ ./$(DEPDIR)/sound_control.Po \ 93 @AMDEP_TRUE@ ./$(DEPDIR)/sound_test.Po \ 89 94 @AMDEP_TRUE@ ./$(DEPDIR)/story_entity.Po ./$(DEPDIR)/texture.Po \ 90 95 @AMDEP_TRUE@ ./$(DEPDIR)/track_manager.Po ./$(DEPDIR)/vector.Po \ … … 95 100 CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \ 96 101 -o $@ 97 SOURCES = $(orxonox_SOURCES) 98 DIST_SOURCES = $(orxonox_SOURCES) 102 SOURCES = $(orxonox_SOURCES) $(sound_SOURCES) 103 DIST_SOURCES = $(orxonox_SOURCES) $(sound_SOURCES) 99 104 RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ 100 105 html-recursive info-recursive install-data-recursive \ … … 251 256 glmenu/glmenu_imagescreen.cc 252 257 258 sound_SOURCES = sound_test.cc \ 259 sound_control.cc 260 253 261 noinst_HEADERS = orxonox.h \ 254 262 game_loader.h \ … … 359 367 @rm -f orxonox$(EXEEXT) 360 368 $(CXXLINK) $(orxonox_LDFLAGS) $(orxonox_OBJECTS) $(orxonox_LDADD) $(LIBS) 369 sound$(EXEEXT): $(sound_OBJECTS) $(sound_DEPENDENCIES) 370 @rm -f sound$(EXEEXT) 371 $(CXXLINK) $(sound_LDFLAGS) $(sound_OBJECTS) $(sound_LDADD) $(LIBS) 361 372 362 373 mostlyclean-compile: … … 393 404 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/player.Po@am__quote@ 394 405 @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@ 395 408 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/story_entity.Po@am__quote@ 396 409 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/texture.Po@am__quote@ -
orxonox/branches/soundEngine/src/sound_control.cc
r3508 r3509 18 18 using namespace std; 19 19 20 int sfx_channel1 = -1;21 int sfx_channel2 = -1;22 int finished = 0;23 20 SoundControl* 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; 21 SoundControl* SoundControl::singletonRef = NULL; 32 22 33 23 … … 37 27 All sound output is handled by this singleton object. 38 28 */ 39 SoundControl::SoundControl() { 29 SoundControl::SoundControl() { 40 30 if(SDL_Init(SDL_INIT_AUDIO)<0) { 41 31 printf("SDL_Init: INIT_AUDIO error.\n"); … … 44 34 printf("Mix_OpenAudio: Failed to open audio!\n"); 45 35 } 46 init ialise();36 init(); 47 37 } 48 38 … … 50 40 \brief Default destructor 51 41 */ 52 SoundControl::~SoundControl() { 42 SoundControl::~SoundControl() 43 { 44 singletonRef = NULL; 53 45 } 54 46 … … 57 49 */ 58 50 SoundControl* SoundControl::getInstance() { 59 if ( !SoundControl::singletonRef)51 if (SoundControl::singletonRef) 60 52 return singletonRef; 61 53 else … … 66 58 \brief Is called by SoundControl object to initiate all values and to output some text 67 59 */ 68 void SoundControl::initialise() { 60 void 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 69 75 Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels); 70 76 bits=audio_format&0xFF; … … 85 91 */ 86 92 void SoundControl::playMod(char* fileName) { 87 Mix_Chunk* chunk = NULL; 88 chunk = Mix_LoadWAV(fileName); 93 Mix_Chunk* chunk = Mix_LoadWAV(fileName); 89 94 if(Mix_PlayChannel(-1, chunk, 0) == -1) { 90 95 printf("Mix_PlayChannel: %s\n", Mix_GetError()); … … 97 102 */ 98 103 void SoundControl::playWav(char* fileName) { 99 Mix_Chunk* chunk = NULL; 100 chunk = Mix_LoadWAV(fileName); 104 Mix_Chunk* chunk = Mix_LoadWAV(fileName); 101 105 if(Mix_PlayChannel(-1, chunk, 0) == -1) { 102 106 printf("Mix_PlayChannel: %s\n", Mix_GetError()); … … 188 192 \brief Hooked by playOgg at end of .ogg playback 189 193 */ 190 void SoundControl::musicDone() { 194 void SoundControl::musicDone() 195 { 196 Mix_Music* music = SoundControl::getInstance()->music; 191 197 Mix_HaltMusic(); 192 198 Mix_FreeMusic(music); … … 194 200 } 195 201 196 /**197 \brief Handles input events198 */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 30 30 int main(int argc, char* argv[]); 31 31 32 33 private: 34 SoundControl(); 35 void init(void); 36 37 static SoundControl* singletonRef; 38 39 public: 40 Mix_Music* music; 32 41 static SoundControl* sound; 42 int bits; 33 43 int volume; 34 44 int track_number; … … 39 49 int sfx_channel2; 40 50 int finished; 41 42 private:43 SoundControl();44 45 static SoundControl* singletonRef;46 void initialise();47 48 51 }; 49 52
Note: See TracChangeset
for help on using the changeset viewer.