Keypad
[mirrors/Programs.git] / c / ghetto-sound-system / sandbox / sdl-sampler_backup.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <termio.h>
4 #include "SDL.h"
5 #include "SDL_mixer.h" //Docs: http://www.libsdl.org/projects/SDL_mixer/docs/
6 //example http://www.kekkai.org/roger/sdl/mixer/
7
8 static struct termios stored_settings;
9 void tc_reset() { tcsetattr(0,TCSANOW,&stored_settings); }
10 void icanon_off() {
11 struct termios new_settings;
12 tcgetattr(0,&stored_settings);
13 new_settings = stored_settings;
14 new_settings.c_lflag &= (~ICANON);
15 new_settings.c_lflag &= (~ECHO);
16 new_settings.c_cc[VTIME] = 0;
17 new_settings.c_cc[VMIN] = 1;
18 tcsetattr(0,TCSANOW,&new_settings);
19 atexit(tc_reset);
20 }
21
22 char gethit() {
23 icanon_off();
24 char c = getchar();
25 tc_reset();
26 return c;
27 }
28
29 Mix_Music *play_sound = NULL;
30 Mix_Chunk *play_sound2 = NULL;
31 Mix_Chunk *play_sound3 = NULL;
32
33 void cleanUp() {
34 Mix_FreeMusic(play_sound);
35 Mix_FreeChunk(play_sound2);
36 Mix_CloseAudio();
37 SDL_Quit();
38 }
39
40 char map[] = "hgjfkdlsa" "nbmvcxz" "yturieowpq";
41
42 int main(int argc, char* args[])
43 {
44 SDL_Init(SDL_INIT_AUDIO); atexit(cleanUp);
45 //Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096);
46 Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 256);
47
48 //play_sound = Mix_LoadMUS("/home/harvie/Downloads/Shared/Shaggy-Mr._Bombastic.mp3");
49 play_sound2 = Mix_LoadWAV("bd.wav");
50 play_sound3 = Mix_LoadWAV("s.wav");
51
52 //Mix_PlayMusic(play_sound, 0); //(Mix_Music, loops) -1 = infinite loop, 0 = play 1time
53 //Mix_PlayChannel(-1, play_sound2, 9); //(channel, sample, loop)
54
55 //while(Mix_PlayingMusic() || Mix_Playing(-1)) sleep(1);
56
57 puts("Press Q to exit!");
58 char c;
59 //for(c=0;c<20;c++) Mix_PlayChannel(1, play_sound2, 0);
60 icanon_off();
61 while(c = getchar()) {
62 switch(c) {
63 case 'Q': exit(0); break;
64 case 'a': case 'A': Mix_PlayChannel(-1, play_sound3, 0); break;
65 default: Mix_PlayChannel(-1, play_sound2, 0);
66 }
67 }
68
69 exit(0);
70 }
71
This page took 0.393738 seconds and 4 git commands to generate.