audio.c (711B)
1 #include "audio.h" 2 3 void * 4 play_audio(void *tid) 5 { 6 /*int tid = (long)threadid;*/ 7 Mix_Music *music = NULL; 8 SDL_Init(SDL_INIT_AUDIO); 9 Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 1, 4096); 10 music = Mix_LoadMUS(AUDIO_PATH); 11 12 Mix_PlayMusic(music, -1); 13 while (Mix_PlayingMusic()) ; 14 Mix_FreeMusic(music); 15 Mix_CloseAudio(); 16 return NULL; 17 } 18 19 void 20 volume(char option) 21 { 22 static int volume = MIX_MAX_VOLUME; 23 24 switch (option) 25 { 26 case '+': 27 if (volume == MIX_MAX_VOLUME) break; 28 else Mix_VolumeMusic(volume += 10); 29 break; 30 case '-': 31 if (volume == 0) break; 32 else Mix_VolumeMusic(volume -= 10); 33 break; 34 } 35 } 36 37 void 38 pause_audio(void) 39 { 40 (Mix_PausedMusic() == 1) ? Mix_ResumeMusic() : Mix_PauseMusic(); 41 }