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
26 #include <SDL_mixer.h>
32 char music_random
= ON
;
40 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)
67 if (SDL_WasInit(SDL_INIT_AUDIO
)) {
70 SDL_QuitSubSystem(SDL_INIT_AUDIO
);
74 void S_startmusic(int time
)
76 if (musdisabled
) return;
77 Mix_PlayMusic(muslo
, -1);
78 Mix_VolumeMusic(mus_vol
);
79 muscount
=time
*60*1000/DELAY
;
82 void S_stopmusic(void)
84 if (musdisabled
) return;
89 void S_volumemusic(int v
)
91 if (musdisabled
) return;
93 if (mus_vol
>128) mus_vol
=128;
94 if (mus_vol
<0) mus_vol
=0;
95 if (mus_vol
==0 && Mix_PlayingMusic()) {
98 else if (mus_vol
>0 && !Mix_PlayingMusic()) {
99 S_startmusic(music_time
);
111 {0x80, 0xA0, "A"},//А
112 {0x81, 0xA1, "B"},//Б
113 {0x82, 0xA2, "V"},//В
114 {0x83, 0xA3, "G"},//Г
115 {0x84, 0xA4, "D"},//Д
116 {0x85, 0xA5, "E"},//Е
117 {0x86, 0xA6, "ZH"},//Ж
118 {0x87, 0xA7, "Z"},//З
119 {0x88, 0xA8, "I"},//И
120 {0x89, 0xA9, "J"},//Й
121 {0x8A, 0xAA, "K"},//К
122 {0x8B, 0xAB, "L"},//Л
123 {0x8C, 0xAC, "M"},//М
124 {0x8D, 0xAD, "N"},//Н
125 {0x8E, 0xAE, "O"},//О
126 {0x8F, 0xAF, "P"},//П
127 {0x90, 0xE0, "R"},//Р
128 {0x91, 0xE1, "S"},//С
129 {0x92, 0xE2, "T"},//Т
130 {0x93, 0xE3, "U"},//У
131 {0x94, 0xE4, "F"},//Ф
132 {0x95, 0xE5, "H"},//Х
133 {0x96, 0xE6, "C"},//Ц
134 {0x97, 0xE7, "CH"},//Ч
135 {0x98, 0xE8, "SH"},//Ш
136 {0x99, 0xE9, "SCH"},//Щ
137 {0x9A, 0xEA, "X"},//Ъ
138 {0x9B, 0xEB, "Y"},//Ы
139 {0x9C, 0xEC, "J"},//Ь
140 {0x9D, 0xED, "E"},//Э
141 {0x9E, 0xEE, "JU"},//Ю
142 {0x9F, 0xEF, "JA"},//Я
146 char *get_trans_char (Uint8 c
)
149 while (atrans
[i
].ascii
) {
151 if (atrans
[i
].ascii
== c
|| atrans
[i
].asciilc
== c
) {
159 void trans_ascii_str (char *dest
, char *src
)
163 for (i
=0; i
<strlen(src
); i
++) {
164 char *ch
= get_trans_char(src
[i
]);
170 strncpy(p
,&src
[i
],1);
177 void F_loadmus(char n
[8]) {
178 if (musdisabled
) return;
182 strcpy(f
, "/usr/share/doom2d-rembo/music/");
184 strcpy(f
, "music\\");
187 strncpy(&f
[l
], n
, 8);
189 trans_ascii_str(name
, f
);
190 muslo
= Mix_LoadMUS(name
);
196 strncpy(&f
[l
], n
, 8);
198 trans_ascii_str(name
, f
);
199 muslo
= Mix_LoadMUS(name
);
202 if (!muslo
) logo("Music not found '%s'\n", name
);
206 void F_freemus(void) {
207 if (musdisabled
) return;
210 Mix_FreeMusic(muslo
);
215 extern byte g_music
[8];
217 static int volsetcount
= 0;
221 if (musdisabled
) return;
223 //періодично встановлюю гучність музикі, так як вона сама підвищується до максимуму через певний час
225 if (volsetcount
%(5*1000/DELAY
)==0) {
226 S_volumemusic(mus_vol
);
230 if (muscount
< music_fade
*1100/DELAY
) {
231 Mix_FadeOutMusic(music_fade
*1000);
235 if (music_random
) F_randmus(g_music
);
236 else F_nextmus(g_music
);
239 S_startmusic(music_time
);