| 1 | #include <stdio.h> |
| 2 | #include <termio.h> |
| 3 | #include "SDL.h" |
| 4 | #include "SDL_mixer.h" //Docs: http://www.libsdl.org/projects/SDL_mixer/docs/ |
| 5 | //example http://www.kekkai.org/roger/sdl/mixer/ |
| 6 | |
| 7 | static struct termios stored_settings; |
| 8 | void icanon_on() { |
| 9 | struct termios new_settings; |
| 10 | tcgetattr(0,&stored_settings); |
| 11 | new_settings = stored_settings; |
| 12 | new_settings.c_lflag &= (~ICANON); |
| 13 | new_settings.c_cc[VTIME] = 0; |
| 14 | new_settings.c_cc[VMIN] = 1; |
| 15 | tcsetattr(0,TCSANOW,&new_settings); |
| 16 | } |
| 17 | |
| 18 | void icanon_off() { |
| 19 | tcsetattr(0,TCSANOW,&stored_settings); |
| 20 | } |
| 21 | |
| 22 | char gethit() { |
| 23 | icanon_on(); |
| 24 | char c = getchar(); |
| 25 | icanon_off(); |
| 26 | return c; |
| 27 | } |
| 28 | |
| 29 | Mix_Music *play_sound = NULL; |
| 30 | Mix_Chunk *play_sound2 = NULL; |
| 31 | |
| 32 | void cleanUp() { |
| 33 | Mix_FreeMusic(play_sound); |
| 34 | Mix_FreeChunk(play_sound2); |
| 35 | Mix_CloseAudio(); |
| 36 | SDL_Quit(); |
| 37 | } |
| 38 | |
| 39 | |
| 40 | int main(int argc, char* args[]) |
| 41 | { |
| 42 | SDL_Init(SDL_INIT_EVERYTHING); |
| 43 | Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096); |
| 44 | |
| 45 | play_sound = Mix_LoadMUS("/home/harvie/Downloads/Shared/Shaggy-Mr._Bombastic.mp3"); |
| 46 | play_sound2 = Mix_LoadWAV("bd.wav"); |
| 47 | |
| 48 | Mix_PlayMusic(play_sound, 0); //(Mix_Music, loops) -1 = infinite loop, 0 = play 1time |
| 49 | Mix_PlayChannel(-1, play_sound2, 9); |
| 50 | |
| 51 | //while(Mix_PlayingMusic() || Mix_Playing(-1)) sleep(1); |
| 52 | puts("press any key to exit!"); gethit(); |
| 53 | |
| 54 | |
| 55 | cleanUp(); |
| 56 | return 0; |
| 57 | } |
| 58 | |