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