- Timestamp:
- Nov 10, 2004, 10:37:57 PM (20 years ago)
- Location:
- orxonox/branches/sound/src
- Files:
-
- 2 added
- 2 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 } -
orxonox/branches/sound/src/sound_control.h
r2777 r2793 1 2 #ifndef PROTO_CLASS_H 3 #define PROTO_CLASS_H 1 #ifndef SOUNDCONTROL_CLASS_H 2 #define SOUNDCONTROL_CLASS_H 4 3 5 4 #include "data_tank.h" 6 5 7 8 class ProtoClass { 6 class SoundControl { 9 7 10 8 public: 11 ProtoClass (); 12 ~ProtoClass (); 9 SoundControl (); 10 ~SoundControl (); 11 void setNumberOfChannels(int number_of channels); 12 int playMod(char* filename); 13 int playWav(char* filename); 14 int playOgg(char* filename); 15 void volumeUp(); 16 void volumeDown(); 17 void trackRewind(); 18 void forwardMusic(); 19 void rewindMusic(); 20 void pauseMusic(); 21 void resumeMusic(); 22 void trackSelect(); 13 23 14 }; 24 private: 25 void postConstruction(); 26 SoundControl* singleton; 27 28 } 15 29 16 30 #endif
Note: See TracChangeset
for help on using the changeset viewer.