2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
4 Copyright (C) <ARembo@gmail.com> 2011
6 This file is part of the Doom2D:Rembo project.
8 Doom2D:Rembo is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
12 Doom2D:Rembo is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/> or
19 write to the Free Software Foundation, Inc.,
20 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <SDL_mixer.h>
32 char music_random
= ON
;
36 static Uint32 muscount
;
37 static Mix_Music
* muslo
;
38 static int musdisabled
= 1;
39 static int volsetcount
= 0;
41 void S_initmusic (void) {
42 if (!SDL_WasInit(SDL_INIT_AUDIO
)) {
43 if (SDL_InitSubSystem(SDL_INIT_AUDIO
) < 0) {
44 fprintf(stderr
, "\nUnable to initialize audio: %s\n", SDL_GetError());
49 if (Mix_OpenAudio(22050, AUDIO_S16
, 1, 1000) < 0) {
50 fprintf(stderr
, "Error initializing SDL_mixer: %s\n", Mix_GetError());
60 musdisabled
= (mus_vol
==0);
62 S_volumemusic(mus_vol
);
65 void S_donemusic (void) {
66 if (SDL_WasInit(SDL_INIT_AUDIO
)) {
69 SDL_QuitSubSystem(SDL_INIT_AUDIO
);
73 void S_startmusic (int time
) {
74 if (musdisabled
) return;
75 Mix_PlayMusic(muslo
, -1);
76 Mix_VolumeMusic(mus_vol
);
77 muscount
=time
*60*1000/DELAY
;
80 void S_stopmusic (void) {
81 if (musdisabled
) return;
86 void S_volumemusic (int v
) {
87 if (musdisabled
) return;
89 if (mus_vol
>128) mus_vol
=128;
90 if (mus_vol
<0) mus_vol
=0;
91 if (mus_vol
==0 && Mix_PlayingMusic()) {
94 else if (mus_vol
>0 && !Mix_PlayingMusic()) {
95 S_startmusic(music_time
);
107 {0x80, 0xA0, "A"},//А
108 {0x81, 0xA1, "B"},//Б
109 {0x82, 0xA2, "V"},//В
110 {0x83, 0xA3, "G"},//Г
111 {0x84, 0xA4, "D"},//Д
112 {0x85, 0xA5, "E"},//Е
113 {0x86, 0xA6, "ZH"},//Ж
114 {0x87, 0xA7, "Z"},//З
115 {0x88, 0xA8, "I"},//И
116 {0x89, 0xA9, "J"},//Й
117 {0x8A, 0xAA, "K"},//К
118 {0x8B, 0xAB, "L"},//Л
119 {0x8C, 0xAC, "M"},//М
120 {0x8D, 0xAD, "N"},//Н
121 {0x8E, 0xAE, "O"},//О
122 {0x8F, 0xAF, "P"},//П
123 {0x90, 0xE0, "R"},//Р
124 {0x91, 0xE1, "S"},//С
125 {0x92, 0xE2, "T"},//Т
126 {0x93, 0xE3, "U"},//У
127 {0x94, 0xE4, "F"},//Ф
128 {0x95, 0xE5, "H"},//Х
129 {0x96, 0xE6, "C"},//Ц
130 {0x97, 0xE7, "CH"},//Ч
131 {0x98, 0xE8, "SH"},//Ш
132 {0x99, 0xE9, "SCH"},//Щ
133 {0x9A, 0xEA, "X"},//Ъ
134 {0x9B, 0xEB, "Y"},//Ы
135 {0x9C, 0xEC, "J"},//Ь
136 {0x9D, 0xED, "E"},//Э
137 {0x9E, 0xEE, "JU"},//Ю
138 {0x9F, 0xEF, "JA"},//Я
142 static char *get_trans_char (Uint8 c
)
145 while (atrans
[i
].ascii
) {
147 if (atrans
[i
].ascii
== c
|| atrans
[i
].asciilc
== c
) {
155 static void trans_ascii_str (char *dest
, char *src
)
159 for (i
=0; i
<strlen(src
); i
++) {
160 char *ch
= get_trans_char(src
[i
]);
166 strncpy(p
,&src
[i
],1);
173 void F_loadmus (char n
[8]) {
174 if (musdisabled
) return;
178 strcpy(f
, "/usr/share/doom2d-rembo/music/");
180 strcpy(f
, "music\\");
183 strncpy(&f
[l
], n
, 8);
185 trans_ascii_str(name
, f
);
186 muslo
= Mix_LoadMUS(name
);
192 strncpy(&f
[l
], n
, 8);
194 trans_ascii_str(name
, f
);
195 muslo
= Mix_LoadMUS(name
);
198 if (!muslo
) logo("Music not found '%s'\n", name
);
202 void F_freemus (void) {
203 if (musdisabled
) return;
206 Mix_FreeMusic(muslo
);
211 void S_updatemusic (void) {
212 if (musdisabled
) return;
214 //періодично встановлюю гучність музикі, так як вона сама підвищується до максимуму через певний час
216 if (volsetcount
%(5*1000/DELAY
)==0) {
217 S_volumemusic(mus_vol
);
221 if (muscount
< music_fade
*1100/DELAY
) {
222 Mix_FadeOutMusic(music_fade
*1000);
226 if (music_random
) F_randmus(g_music
);
227 else F_nextmus(g_music
);
230 S_startmusic(music_time
);