Commit | Line | Data |
---|---|---|
8de51304 H |
1 | #include <stdlib.h>\r |
2 | #include <SDL.h>\r | |
3 | #include <SDL_mixer.h>\r | |
4 | \r | |
5 | const max_sounds=50;\r | |
6 | Mix_Chunk *sounds[max_sounds];\r | |
7 | Mix_Music *music;\r | |
8 | \r | |
9 | //kanaly\r | |
10 | enum {\r | |
11 | SNDT_0,\r | |
12 | SNDT_1,\r | |
13 | SNDT_2,\r | |
14 | SNDT_3,\r | |
15 | SNDT_4,\r | |
16 | SNDT_5,\r | |
17 | SNDT_6,\r | |
18 | SNDT_7\r | |
19 | };\r | |
20 | \r | |
21 | //zvuky\r | |
22 | enum {\r | |
23 | SND_ZVUK,\r | |
24 | SND_NUM\r | |
25 | };\r | |
26 | \r | |
27 | int main(int argc,char *argv[])\r | |
28 | {\r | |
29 | if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {\r | |
30 | fprintf(stderr, "Problem: %s\n", SDL_GetError());\r | |
31 | exit(1); \r | |
32 | }\r | |
33 | atexit(SDL_Quit);\r | |
34 | \r | |
35 | //frekvence 22050 Hz\r | |
36 | //MIX_DEFAULT_FORMAT - Signed 16-bit zvuky, v systemovem bytovem poradi (little,big endian)\r | |
37 | //mono-stereo: pro mono vlozte 1, pro stereo 2\r | |
38 | \r | |
39 | if (Mix_OpenAudio(22050/*frekvence [Hz]*/, MIX_DEFAULT_FORMAT, 2/*mono-stereo*/,1024/*velikost bloku*/)==-1)\r | |
40 | {\r | |
41 | fprintf(stderr,"Mix_OpenAudio: %s\n", Mix_GetError());\r | |
42 | exit(1);\r | |
43 | }\r | |
44 | \r | |
45 | sounds[SND_ZVUK] = Mix_LoadWAV("zvuk.wav");\r | |
46 | if (sounds[SND_ZVUK]==NULL) \r | |
47 | {\r | |
48 | fprintf(stderr,"zvuk [zvuk.wav] nebyl nahran\n");exit(2);}\r | |
49 | \r | |
50 | //kanal: -1 pro prvni volny kanal\r | |
51 | //pocet opakovani x: zvuk se bude opakovat x+1 krat,x=-1 pro stale opakovani.\r | |
52 | Mix_PlayChannel(-1/*kanal*/,sounds[SND_ZVUK]/*Mix_Chunk*/,0/*pocet opakovani*/);\r | |
53 | \r | |
54 | music=Mix_LoadMUS("music.mp3");\r | |
55 | if (!music) {\r | |
56 | printf("Mix_LoadMUS(\"music.mp3\"): %s\n", Mix_GetError());\r | |
57 | exit(2);\r | |
58 | }\r | |
59 | \r | |
60 | //pocet opakovani x: hudba se bude opakovat x krat,x=-1 pro stale opakovani.\r | |
61 | //postupne zvysuje hlasitost hudby od 0 do 100% za 2000 ms po spusteni\r | |
62 | \r | |
63 | Mix_FadeInMusic(music, -1/*pocet opakovani*/,2000 /*cas[ms]*/);\r | |
64 | \r | |
65 | //lze i jen provest pouhe spusteni hudby\r | |
66 | //Mix_PlayMusic(music, -1/*pocet opakovani*/);\r | |
67 | \r | |
68 | SDL_Delay(5000);\r | |
69 | \r | |
70 | //ztlumi hudbu az do ticha a vypne\r | |
71 | Mix_FadeOutMusic(2000);\r | |
72 | \r | |
73 | SDL_Delay(1000);\r | |
74 | \r | |
75 | Mix_CloseAudio();\r | |
76 | return 0;\r | |
77 | } |