Changeset 2793 in orxonox.OLD for orxonox/branches/sound/src/sound_control.cc
- Timestamp:
- Nov 10, 2004, 10:37:57 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/sound/src/sound_control.cc
r2777 r2793 14 14 */ 15 15 16 #include " Sound_control.h"16 #include "sound_control.h" 17 17 #include <string.h> 18 18 #include "SDL_mixer.h" … … 29 29 */ 30 30 SoundControl::SoundControl () { 31 31 32 32 //setup parameters 33 33 int audio_rate = MIX_DEFAULT_FREQUENCY, audio_channels = MIX_DEFAULT_CHANNELS, audio_buffers = 8192, bits = 0; … … 37 37 //initializing sound and calling Mix_OpenAudio 38 38 if(SDL_Init(SDL_INIT_AUDIO)<0){ 39 printf("SDL_Init: \n");39 printf("SDL_Init: \n"); 40 40 exit(1); 41 41 } 42 42 43 43 if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)){ 44 printf("Mix_OpenAudio: \n");44 printf("Mix_OpenAudio: \n"); 45 45 exit(1); 46 46 } … … 49 49 } 50 50 51 SoundControl::SoundControl (int audio_rate audiorate, Uint16 audio_format audioformat, int audio_channels audiochannels, int audio_buffers audiobuffers) { 52 53 //setup parameters 54 int audio_rate = audiorate, audio_channels = audiochannels, audio_buffers = audiobuffers, bits = 0; 55 Uint16 audio_format = audioformat; 56 Mix_Music* music = NULL; 57 58 //initializing sound and calling Mix_OpenAudio 59 if(SDL_Init(SDL_INIT_AUDIO)<0){ 60 printf("SDL_Init: \n"); 61 exit(1); 62 } 63 64 if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)){ 65 printf("Mix_OpenAudio: \n"); 66 exit(1); 67 } 68 69 postConstruction(); 70 } 71 51 72 52 73 /** … … 54 75 */ 55 76 SoundControl::~SoundControl () { 56 } 77 SoundControl* SoundControl::singleton = NULL; 78 } 79 80 SoundControl* SoundControl::singleton = NULL; 57 81 58 82 … … 65 89 Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels); 66 90 bits=audio_format&0xFF; 67 printf("Opened audio at %d Hz %d bit %s, %d bytes audio buffer\n", audio_rate, 68 bits, audio_channels > 1 ? "stereo" : "mono", audio_buffers ); 91 printf("Opened audio at %d Hz %d bit %s, %d bytes audio buffer\n", audio_rate, bits, audio_channels > 1 ? "stereo" : "mono", audio_buffers ); 69 92 70 93 int volume = SDL_MIX_MAXVOLUME; … … 72 95 int track_number = 1; 73 96 int done = 0; 74 int free = 1; 75 } 76 77 78 /** 79 \brief Returns false if a sound_control object has been made 80 */ 81 void SoundControl::isFree () { 82 return free; 83 } 97 } 84 98 85 99 … … 96 110 \param filename: self-explanatory 97 111 */ 98 void SoundControl::playMod (char* fileName) { 99 100 } 101 102 103 /** 104 \brief May be called from any WorldEntity to play a .wav file 105 \param filename: self-explanatory 106 */ 107 void SoundControl::playWav (char* fileName) { 112 int SoundControl::playMod (char* fileName) { 108 113 Mix_Chunk* chunk = NULL; 109 114 chunk = Mix_LoadWAV(fileName); … … 111 116 printf("Mix_PlayChannel: %s\n", Mix_GetError()); 112 117 } 118 } 119 120 121 /** 122 \brief May be called from any WorldEntity to play a .wav file 123 \param filename: self-explanatory 124 */ 125 int SoundControl::playWav (char* fileName) { 126 Mix_Chunk* chunk = NULL; 127 chunk = Mix_LoadWAV(fileName); 128 if(Mix_PlayChannel(-1, chunk, 0) == -1) { 129 printf("Mix_PlayChannel: %s\n", Mix_GetError()); 130 } 113 131 } 114 132 … … 118 136 \param filename: self-explanatory 119 137 */ 120 voidSoundControl::playOgg (char* fileName) {138 int SoundControl::playOgg (char* fileName) { 121 139 Mix_Music* music = NULL; 122 140 music = Mix_LoadMUS(fileName); … … 212 230 213 231 /** 214 \brief Called by playOgg232 \brief Hooked by playOgg at end of .ogg playback 215 233 */ 216 234 void SoundControl::musicDone () { 217 235 track_number++; 218 } 219 236 Mix_HaltMusic(); 237 Mix_FreeMusic(music); 238 music = NULL; 239 }
Note: See TracChangeset
for help on using the changeset viewer.