Rev 376 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 376 | Rev 570 | ||
---|---|---|---|
1 | // |
1 | // |
2 | // This file is part of the AC97 mp3 player. |
2 | // This file is part of the AC97 mp3 player. |
3 | // (C) copyright Serge 2006 |
3 | // (C) copyright Serge 2006 |
4 | // email: infinity_sound@mail.ru |
4 | // email: infinity_sound@mail.ru |
5 | // |
5 | // |
6 | // This program is free software; you can redistribute it and/or modify |
6 | // This program is free software; you can redistribute it and/or modify |
7 | // it under the terms of the GNU General Public License as published by |
7 | // it under the terms of the GNU General Public License as published by |
8 | // the Free Software Foundation; either version 2 of the License, or |
8 | // the Free Software Foundation; either version 2 of the License, or |
9 | // (at your option) any later version. |
9 | // (at your option) any later version. |
10 | // |
10 | // |
11 | // This program is distributed in the hope that it will be useful, |
11 | // This program is distributed in the hope that it will be useful, |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | // GNU General Public License for more details. |
14 | // GNU General Public License for more details. |
15 | 15 | ||
16 | #include "kolibri.h" |
16 | #include "kolibri.h" |
17 | #include "string.h" |
17 | #include "string.h" |
18 | #include "ac97wav.h" |
18 | #include "ac97wav.h" |
19 | #include "mpg/mpg123.h" |
19 | #include "mpg/mpg123.h" |
20 | #include "sound.h" |
20 | #include "sound.h" |
21 | 21 | ||
22 | #define MP3_ERROR_OUT_OF_BUFFER 5 |
22 | #define MP3_ERROR_OUT_OF_BUFFER 5 |
23 | int m_last_error; |
23 | int m_last_error; |
24 | 24 | ||
- | 25 | void _stdcall thread_proc(void *param); |
|
- | 26 | void _stdcall create_thread(void *proc, void *param, int stack_size); |
|
- | 27 | void _stdcall send_ipc(int dst, DWORD code); |
|
25 | void thread_proc(); |
28 | |
26 | void touch(char *buf, int size); |
29 | void touch(char *buf, int size); |
27 | int mp3FindSync(byte* buf, int size, int* sync); |
30 | int mp3FindSync(byte* buf, int size, int* sync); |
28 | int stream_read_raw(struct reader *rd,unsigned char *buf, int size); |
31 | int stream_read_raw(struct reader *rd,unsigned char *buf, int size); |
29 | 32 | ||
30 | char *fname; |
33 | char *fname; |
31 | 34 | ||
32 | struct reader rd; |
35 | struct reader rd; |
33 | struct frame fr; |
36 | struct frame fr; |
34 | 37 | ||
35 | DWORD hDrv; |
38 | DWORD hDrv; |
36 | DWORD hSound; |
39 | DWORD hSound; |
37 | SNDBUF hBuff; |
40 | SNDBUF hBuff; |
38 | 41 | ||
39 | CTRL_INFO info; |
42 | CTRL_INFO info; |
40 | 43 | ||
41 | FILEINFO fileinfo; |
44 | FILEINFO fileinfo; |
42 | 45 | ||
43 | int m_vol; |
46 | int m_vol; |
44 | int l_vol=-500; |
47 | int l_vol=-700; //-7db |
45 | int r_vol=-500; |
48 | int r_vol=-700; |
46 | int pan =0; |
49 | int pan =0; |
47 | 50 | ||
48 | DWORD status; |
51 | DWORD status; |
49 | DWORD offset; |
52 | DWORD offset; |
50 | DWORD first_sync; |
53 | DWORD first_sync; |
51 | 54 | ||
52 | unsigned char *testbuff; |
55 | unsigned char *testbuff; |
53 | unsigned char *outbuf; |
56 | unsigned char *outbuf; |
54 | unsigned char *inpbuf; |
57 | unsigned char *inpbuf; |
55 | unsigned char *outPtr; |
58 | unsigned char *outPtr; |
56 | 59 | ||
57 | int inpsize; |
60 | int inpsize; |
58 | int outsize; |
61 | int outsize; |
59 | int outremain; |
62 | int outremain; |
60 | int totalout; |
63 | int totalout; |
61 | int done; |
64 | int done; |
62 | 65 | ||
63 | char header[] = "AC97 MP3 player"; |
66 | char header[] = "AC97 MP3 player"; |
64 | char buttons_text[]=" Play Stop << >> Vol- Vol+"; |
67 | char buttons_text[]=" Play Stop << >> Vol- Vol+"; |
65 | 68 | ||
66 | void (*snd_play)(); |
69 | void (*snd_play)(); |
67 | 70 | ||
68 | void draw_window() |
71 | void draw_window() |
69 | { |
72 | { |
70 | BeginDraw(); |
73 | BeginDraw(); |
71 | 74 | ||
72 | DrawWindow(100,100,299,72,0x404040,3,0,0,0); |
75 | DrawWindow(100,100,299,72,0x404040,3,0,0,0); |
73 | 76 | ||
74 | make_button(7,24,45,13, 0x10|BT_NORMAL,0x808080); |
77 | make_button(7,24,45,13, 0x10|BT_NORMAL,0x808080); |
75 | make_button(56,24,45,13, 0x11|BT_NORMAL,0x808080); |
78 | make_button(56,24,45,13, 0x11|BT_NORMAL,0x808080); |
76 | make_button(104,24,45,13, 0x12|BT_NORMAL,0x808080); |
79 | make_button(104,24,45,13, 0x12|BT_NORMAL,0x808080); |
77 | make_button(152,24,45,13, 0x13|BT_NORMAL,0x808080); |
80 | make_button(152,24,45,13, 0x13|BT_NORMAL,0x808080); |
78 | make_button(200,24,45,13, 0x14|BT_NORMAL,0x808080); |
81 | make_button(200,24,45,13, 0x14|BT_NORMAL,0x808080); |
79 | make_button(248,24,45,13, 0x15|BT_NORMAL,0x808080); |
82 | make_button(248,24,45,13, 0x15|BT_NORMAL,0x808080); |
80 | 83 | ||
81 | make_button(7,41,286,11, 0x30|BT_HIDE|BT_NOFRAME,0x404040); |
84 | make_button(7,41,286,11, 0x30|BT_HIDE|BT_NOFRAME,0x404040); |
82 | draw_bar(7,41,286,11,0x404040); |
85 | draw_bar(7,41,286,11,0x404040); |
83 | 86 | ||
84 | draw_bar(7,55,286,11,0x404040); |
87 | draw_bar(7,55,286,11,0x404040); |
85 | write_text(12,58,0x004000|FONT0, fname, strlen(fname)); |
88 | write_text(12,58,0x004000|FONT0, fname, strlen(fname)); |
86 | write_text(11,57,0x00FF20|FONT0, fname, strlen(fname)); |
89 | write_text(11,57,0x00FF20|FONT0, fname, strlen(fname)); |
87 | 90 | ||
88 | write_text(8,8,0xFFFFFF|FONT0, header, strlen(header)); |
91 | write_text(8,8,0xFFFFFF|FONT0, header, strlen(header)); |
89 | write_text(12,28,0x404040|FONT0,buttons_text,strlen(buttons_text)); |
92 | write_text(12,28,0x404040|FONT0,buttons_text,strlen(buttons_text)); |
90 | write_text(11,27,0xA0FFA0|FONT0,buttons_text,strlen(buttons_text)); |
93 | write_text(11,27,0xA0FFA0|FONT0,buttons_text,strlen(buttons_text)); |
91 | 94 | ||
92 | EndDraw(); |
95 | EndDraw(); |
93 | }; |
96 | }; |
94 | 97 | ||
95 | void draw_progress_bar() |
98 | void draw_progress_bar() |
96 | { DWORD x; |
99 | { DWORD x; |
97 | x = 287.0f * (float)(rd.filepos-rd.strremain)/(float)fileinfo.size; |
100 | x = 287.0f * (float)(rd.filepos-rd.strremain)/(float)fileinfo.size; |
98 | if(x==0) return; |
101 | if(x==0) return; |
99 | draw_bar(7,41,x,11,0xA0A0A0); |
102 | draw_bar(7,41,x,11,0xA0A0A0); |
100 | draw_bar(x+7,41,287-x,11,0x404040); |
103 | draw_bar(x+7,41,287-x,11,0x404040); |
101 | }; |
104 | }; |
102 | 105 | ||
103 | void debug_out_str(char* str) |
106 | void debug_out_str(char* str) |
104 | { |
107 | { |
105 | while (*str != 0) |
108 | while (*str != 0) |
106 | { |
109 | { |
107 | debug_out(*str); |
110 | debug_out(*str); |
108 | str++; |
111 | str++; |
109 | } |
112 | } |
110 | } |
113 | } |
111 | 114 | ||
112 | int main(int argc, char *argv[]) //int argc, char *argv[]) |
115 | int main(int argc, char *argv[]) //int argc, char *argv[]) |
- | 116 | { |
|
113 | { DWORD fmt; |
117 | DWORD fmt; |
114 | char *thread_stack; |
- | |
115 | DWORD r_bytes; |
118 | DWORD r_bytes; |
116 | int retval; |
119 | int retval; |
117 | int err; |
120 | int err; |
118 | int ver; |
121 | int ver; |
119 | 122 | ||
120 | fname = argv[1]; |
123 | fname = argv[1]; |
- | 124 | debug_out_str("\n\rPlay file "); |
|
121 | //debug_out_str(fname); |
125 | debug_out_str(fname); |
- | 126 | debug_out_str("\n\r"); |
|
122 | 127 | ||
123 | InitHeap(1024*1024); |
128 | InitHeap(1024*1024); |
124 | if(get_fileinfo(fname, &fileinfo)==FILE_NOT_FOUND) |
129 | if(get_fileinfo(fname, &fileinfo)==FILE_NOT_FOUND) |
- | 130 | { debug_out_str("\n\rfile not found\n\r"); |
|
125 | return 0; |
131 | return 0; |
126 | 132 | }; |
|
127 | 133 | ||
128 | if(err = InitSound(&ver)) |
134 | if(err = InitSound(&ver)) |
129 | { |
135 | { |
130 | debug_out_str("Sound service not installed\n\r"); |
136 | debug_out_str("Sound service not installed\n\r"); |
131 | return 0; |
137 | return 0; |
132 | } |
138 | } |
- | 139 | ||
133 | 140 | if( (SOUND_VERSION>(ver&0xFFFF)) || |
|
134 | if( ver != SOUND_VERSION) |
141 | (SOUND_VERSION<(ver >> 16))) |
135 | { |
142 | { |
136 | debug_out_str("Sound service version mismatch\n\r"); |
143 | debug_out_str("Sound service version mismatch\n\r"); |
137 | return 0; |
144 | return 0; |
138 | } |
145 | } |
139 | 146 | ||
140 | testbuff = UserAlloc(4096); |
147 | testbuff = UserAlloc(4096); |
141 | get_fileinfo(fname, &fileinfo); |
148 | get_fileinfo(fname, &fileinfo); |
142 | offset = 0; |
149 | offset = 0; |
143 | retval=read_file (fname,testbuff,0,2048,&r_bytes); |
150 | retval=read_file (fname,testbuff,0,2048,&r_bytes); |
144 | if (retval) return 0; |
151 | if (retval) return 0; |
145 | 152 | ||
146 | inpbuf = UserAlloc(0x10000); |
153 | inpbuf = UserAlloc(0x10000); |
147 | touch(inpbuf, 0x10000); |
154 | touch(inpbuf, 0x10000); |
148 | 155 | ||
149 | create_reader(&rd, inpbuf, 0x10000); |
156 | create_reader(&rd, inpbuf, 0x10000); |
150 | init_reader(&rd,fname); |
157 | init_reader(&rd,fname); |
151 | 158 | ||
152 | fmt = test_wav((WAVEHEADER*)testbuff); |
159 | fmt = test_wav((WAVEHEADER*)testbuff); |
153 | if (fmt != 0) |
160 | if (fmt != 0) |
154 | { |
161 | { |
155 | snd_play = &play_wave; |
162 | snd_play = &play_wave; |
156 | set_reader(&rd, 44); |
163 | set_reader(&rd, 44); |
157 | outbuf = UserAlloc(32*1024); |
164 | outbuf = UserAlloc(32*1024); |
158 | touch(outbuf, 32768); |
165 | touch(outbuf, 32768); |
159 | } |
166 | } |
160 | else |
167 | else |
161 | { fmt = test_mp3(testbuff); |
168 | { fmt = test_mp3(testbuff); |
162 | if(fmt ==0) return 0; |
169 | if(fmt ==0) return 0; |
163 | snd_play = &play_mp3; |
170 | snd_play = &play_mp3; |
164 | 171 | ||
165 | outremain = 0x40000 ; |
172 | outremain = 0x40000 ; |
166 | outbuf = UserAlloc(outremain); |
173 | outbuf = UserAlloc(outremain); |
167 | touch(outbuf, outremain); |
174 | touch(outbuf, outremain); |
168 | make_decode_tables(32767); |
175 | make_decode_tables(32767); |
169 | init_layer2(); |
176 | init_layer2(); |
170 | init_layer3(32); |
177 | init_layer3(32); |
171 | fr.single = -1; |
178 | fr.single = -1; |
172 | }; |
179 | }; |
173 | 180 | ||
174 | status = ST_PLAY; |
181 | status = ST_PLAY; |
175 | 182 | ||
176 | if (err = CreateBuffer(fmt,0, &hBuff)) |
183 | if (err = CreateBuffer(fmt,0, &hBuff)) |
177 | { |
184 | { |
178 | debug_out_str("create buffer return error\n\r"); |
185 | debug_out_str("create buffer return error\n\r"); |
179 | return 0; |
186 | ; return 0; |
180 | } |
187 | } |
181 | 188 | ||
182 | SetVolume(hBuff,l_vol,r_vol); |
189 | SetVolume(hBuff,l_vol,r_vol); |
183 | thread_stack = UserAlloc(4096); |
190 | GetVolume(hBuff,&l_vol,&r_vol); |
184 | thread_stack+=4092; |
- | |
185 | 191 | ||
186 | CreateThread(thread_proc, thread_stack); |
192 | create_thread(thread_proc, 0, 4096); |
187 | 193 | ||
188 | while(1) |
194 | while(1) |
189 | { delay(10); |
195 | { delay(10); |
190 | switch(status) |
196 | switch(status) |
191 | { case ST_PLAY: |
197 | { case ST_PLAY: |
192 | snd_play(); |
198 | snd_play(); |
193 | continue; |
199 | continue; |
194 | 200 | ||
195 | case ST_STOP: |
201 | case ST_STOP: |
196 | StopBuffer(hBuff); |
202 | StopBuffer(hBuff); |
197 | status = ST_DONE; |
203 | status = ST_DONE; |
198 | continue; |
204 | continue; |
199 | 205 | ||
200 | case ST_EXIT: |
206 | case ST_EXIT: |
201 | StopBuffer(hBuff); |
207 | StopBuffer(hBuff); |
202 | DestroyBuffer(hBuff); |
208 | DestroyBuffer(hBuff); |
203 | return 0; |
209 | return 0; |
204 | }; |
210 | }; |
205 | }; |
211 | }; |
206 | return 0; |
212 | return 0; |
207 | }; |
213 | }; |
208 | 214 | ||
209 | void touch(char *buf, int size) |
215 | void touch(char *buf, int size) |
210 | { int i; |
216 | { int i; |
211 | char a; |
217 | char a; |
212 | for ( i = 0;i < size; i+=4096) |
218 | for ( i = 0;i < size; i+=4096) |
213 | a = buf[i]; |
219 | a = buf[i]; |
214 | }; |
220 | }; |
215 | 221 | ||
216 | DWORD test_mp3(char *buf) |
222 | DWORD test_mp3(char *buf) |
217 | { unsigned long hdr; |
223 | { unsigned long hdr; |
218 | WAVEHEADER whdr; |
224 | WAVEHEADER whdr; |
219 | 225 | ||
220 | while (1) |
226 | while (1) |
221 | { if(rd.filepos > 102400) |
227 | { if(rd.filepos > 102400) |
222 | return 0; |
228 | return 0; |
223 | if(!rd.head_read(&rd,&hdr)) |
229 | if(!rd.head_read(&rd,&hdr)) |
224 | return 0; |
230 | return 0; |
225 | if(!decode_header(&fr,hdr)) |
231 | if(!decode_header(&fr,hdr)) |
226 | { rd.strpos-=3; |
232 | { rd.strpos-=3; |
227 | rd.stream-=3; |
233 | rd.stream-=3; |
228 | rd.strremain+=3; |
234 | rd.strremain+=3; |
229 | continue; |
235 | continue; |
230 | }; |
236 | }; |
231 | break; |
237 | break; |
232 | }; |
238 | }; |
233 | 239 | ||
234 | first_sync = rd.filepos-rd.strremain-4; |
240 | first_sync = rd.filepos-rd.strremain-4; |
235 | 241 | ||
236 | whdr.riff_id = 0x46464952; |
242 | whdr.riff_id = 0x46464952; |
237 | whdr.riff_format = 0x45564157; |
243 | whdr.riff_format = 0x45564157; |
238 | whdr.wFormatTag = 0x01; |
244 | whdr.wFormatTag = 0x01; |
239 | whdr.nSamplesPerSec = freqs[fr.sampling_frequency]; |
245 | whdr.nSamplesPerSec = freqs[fr.sampling_frequency]; |
240 | whdr.nChannels = 2; //mpginfo.channels; |
246 | whdr.nChannels = 2; //mpginfo.channels; |
241 | whdr.wBitsPerSample = 16; |
247 | whdr.wBitsPerSample = 16; |
242 | 248 | ||
243 | return test_wav(&whdr); |
249 | return test_wav(&whdr); |
244 | }; |
250 | }; |
245 | 251 | ||
246 | 252 | ||
247 | void play_mp3() |
253 | void play_mp3() |
248 | { char *outPtr; |
254 | { char *outPtr; |
249 | int totalout; |
255 | int totalout; |
250 | int outcount; |
256 | int outcount; |
251 | 257 | ||
252 | // memset(&fr,0,sizeof(fr)); |
258 | // memset(&fr,0,sizeof(fr)); |
253 | fr.down_sample_sblimit = 32; |
259 | fr.down_sample_sblimit = 32; |
254 | fr.single = -1; |
260 | fr.single = -1; |
255 | reset_mpg(); |
261 | reset_mpg(); |
256 | 262 | ||
257 | outPtr = outbuf; |
263 | outPtr = outbuf; |
258 | totalout=0; |
264 | totalout=0; |
259 | done = 0; |
265 | done = 0; |
260 | outremain=0x40000; |
266 | outremain=0x40000; |
261 | 267 | ||
262 | memset(outbuf,0,0x40000); |
268 | memset(outbuf,0,0x40000); |
263 | set_reader(&rd, 0); //;first_sync); |
269 | set_reader(&rd, 0); //;first_sync); |
264 | 270 | ||
265 | while(1) |
271 | while(1) |
266 | { if(status!=ST_PLAY) |
272 | { if(status!=ST_PLAY) |
267 | break; |
273 | break; |
268 | 274 | ||
269 | for(;;) |
275 | for(;;) |
270 | { outcount = 0; |
276 | { outcount = 0; |
271 | if( !read_frame(&rd, &fr)) |
277 | if( !read_frame(&rd, &fr)) |
272 | { done = 1; |
278 | { done = 1; |
273 | break; |
279 | break; |
274 | }; |
280 | }; |
275 | fr.do_layer(&fr, outPtr,&outcount); |
281 | fr.do_layer(&fr, outPtr,&outcount); |
276 | outPtr+= outcount; |
282 | outPtr+= outcount; |
277 | totalout+=outcount; |
283 | totalout+=outcount; |
278 | outremain-=outcount; |
284 | outremain-=outcount; |
279 | if(outremain < outcount*2) |
285 | if(outremain < outcount*2) |
280 | break; |
286 | break; |
281 | }; |
287 | }; |
282 | 288 | ||
283 | if(done) |
289 | if(done) |
284 | { if(totalout < 4096) |
290 | { if(totalout < 4096) |
285 | { memset(outPtr,0,4096-totalout); |
291 | { memset(outPtr,0,4096-totalout); |
286 | totalout = 4096; |
292 | totalout = 4096; |
287 | }; |
293 | }; |
288 | } |
294 | } |
289 | else |
295 | else |
290 | if(totalout < 8192) |
296 | if(totalout < 8192) |
291 | continue; |
297 | continue; |
292 | /* |
- | |
293 | _asm |
- | |
294 | { push edx |
- | |
295 | push eax |
- | |
296 | mov eax, 0xFF |
- | |
297 | mov edx, 0x400 |
- | |
298 | out dx, al |
- | |
299 | pop eax |
- | |
300 | pop edx |
- | |
301 | }; |
- | |
302 | */ |
- | |
303 | outPtr = outbuf; |
298 | outPtr = outbuf; |
304 | while (totalout >= 4096) |
299 | while (totalout >= 4096) |
305 | { |
300 | { |
306 | 301 | ||
307 | WaveOut(hBuff,outPtr,4096); |
302 | WaveOut(hBuff,outPtr,4096); |
308 | if(status!=ST_PLAY) |
303 | if(status!=ST_PLAY) |
309 | { if(status != ST_EXIT) |
304 | { if(status != ST_EXIT) |
310 | status = ST_STOP; |
305 | status = ST_STOP; |
311 | return; |
306 | return; |
312 | }; |
307 | }; |
313 | totalout-=4096; |
308 | totalout-=4096; |
314 | outPtr+=4096; |
309 | outPtr+=4096; |
315 | outremain+=4096; |
310 | outremain+=4096; |
316 | }; |
311 | }; |
317 | if(done) |
312 | if(done) |
318 | break; |
313 | break; |
319 | 314 | ||
320 | memmove(outbuf,outPtr, totalout); |
315 | memmove(outbuf,outPtr, totalout); |
321 | outPtr = outbuf+totalout; |
316 | outPtr = outbuf+totalout; |
322 | } |
317 | } |
323 | 318 | ||
324 | if(status != ST_EXIT) |
319 | if(status != ST_EXIT) |
325 | status = ST_STOP; |
320 | status = ST_STOP; |
326 | }; |
321 | }; |
327 | 322 | ||
328 | void play_wave() |
323 | void play_wave() |
329 | { int retval; |
324 | { int retval; |
330 | 325 | ||
331 | set_reader(&rd,44); |
326 | set_reader(&rd,44); |
332 | retval = 0; |
327 | retval = 0; |
333 | while(1) |
328 | while(1) |
334 | { |
329 | { |
335 | if(status!=ST_PLAY) |
330 | if(status!=ST_PLAY) |
336 | break; |
331 | break; |
337 | 332 | ||
338 | if( !stream_read_raw(&rd,outbuf,32768)) |
333 | if( !stream_read_raw(&rd,outbuf,32768)) |
339 | { done = 1; |
334 | { done = 1; |
340 | break; |
335 | break; |
341 | }; |
336 | }; |
342 | WaveOut(hBuff,outbuf,32768); |
337 | WaveOut(hBuff,outbuf,32768); |
343 | }; |
338 | }; |
344 | 339 | ||
345 | if(status != ST_EXIT) |
340 | if(status != ST_EXIT) |
346 | status = ST_STOP; |
341 | status = ST_STOP; |
347 | }; |
342 | }; |
348 | 343 | ||
349 | void snd_stop() |
344 | void snd_stop() |
350 | { |
345 | { |
351 | StopBuffer(hBuff); |
346 | StopBuffer(hBuff); |
352 | }; |
347 | }; |
353 | 348 | ||
354 | void thread_proc() |
349 | void _stdcall thread_proc(void *param) |
355 | { int evnt; |
350 | { int evnt; |
356 | int pos; |
351 | int pos; |
357 | int key; |
352 | int key; |
358 | 353 | ||
359 | _asm |
354 | _asm |
360 | { |
355 | { |
361 | mov eax, 66 |
356 | mov eax, 66 |
362 | mov ebx, 1 |
357 | mov ebx, 1 |
363 | mov ecx, 1 |
358 | mov ecx, 1 |
364 | int 0x40 |
359 | int 0x40 |
365 | }; |
360 | }; |
366 | 361 | ||
367 | draw_window(); |
362 | draw_window(); |
368 | 363 | ||
369 | while(1) |
364 | while(1) |
370 | { if(status==ST_PLAY) |
365 | { if(status==ST_PLAY) |
371 | { draw_progress_bar(); |
366 | { draw_progress_bar(); |
372 | evnt = wait_for_event(80); |
367 | evnt = wait_for_event(80); |
373 | } |
368 | } |
374 | else |
369 | else |
375 | evnt = wait_for_event_infinite(); |
370 | evnt = wait_for_event_infinite(); |
376 | 371 | ||
377 | switch(evnt) |
372 | switch(evnt) |
378 | { |
373 | { |
379 | case EV_REDRAW: |
374 | case EV_REDRAW: |
380 | draw_window(); |
375 | draw_window(); |
381 | break; |
376 | break; |
382 | 377 | ||
383 | case EV_KEY: |
378 | case EV_KEY: |
384 | if(!get_key(&key)) |
379 | if(!get_key(&key)) |
385 | { |
380 | { |
386 | 381 | ||
387 | switch(key) |
382 | switch(key) |
388 | { case 0xE0: |
383 | { case 0xE0: |
389 | case 0xE1: |
384 | case 0xE1: |
390 | break; |
385 | break; |
391 | default: |
386 | default: |
392 | switch (key) |
387 | switch (key) |
393 | { |
388 | { |
394 | case 0x01: //Esc |
389 | case 0x01: //Esc |
395 | status = ST_EXIT; |
390 | status = ST_EXIT; |
396 | exit(); |
391 | exit(); |
397 | break; |
392 | break; |
398 | 393 | ||
399 | case 0x47: //Home |
394 | case 0x47: //Home |
400 | if(l_vol < 0) |
395 | if(l_vol < 0) |
401 | { l_vol+=100; |
396 | { l_vol+=100; |
402 | r_vol+=100; |
397 | r_vol+=100; |
403 | SetVolume(hBuff,l_vol,r_vol); |
398 | SetVolume(hBuff,l_vol,r_vol); |
404 | }; |
399 | }; |
405 | break; |
400 | break; |
406 | case 0x4F: //End |
401 | case 0x4F: //End |
407 | if(l_vol > -10000) |
402 | if(l_vol > -10000) |
408 | { l_vol-=100; |
403 | { l_vol-=100; |
409 | r_vol-=100; |
404 | r_vol-=100; |
410 | SetVolume(hBuff,l_vol,r_vol); |
405 | SetVolume(hBuff,l_vol,r_vol); |
411 | }; |
406 | }; |
412 | break; |
407 | break; |
413 | case 0x53: |
408 | case 0x53: |
414 | if(pan > -10000) |
409 | if(pan > -10000) |
415 | { pan -=100; |
410 | { pan -=100; |
416 | SetPan(hBuff,pan); |
411 | SetPan(hBuff,pan); |
417 | }; |
412 | }; |
418 | break; |
413 | break; |
419 | case 0x51: |
414 | case 0x51: |
420 | if(pan < 10000) |
415 | if(pan < 10000) |
421 | { pan +=100; |
416 | { pan +=100; |
422 | SetPan(hBuff,pan); |
417 | SetPan(hBuff,pan); |
423 | }; |
418 | }; |
424 | break; |
419 | break; |
425 | } |
420 | } |
426 | }; |
421 | }; |
427 | }; |
422 | }; |
428 | break; |
423 | break; |
429 | 424 | ||
430 | case EV_BUTTON: |
425 | case EV_BUTTON: |
431 | switch(get_button_id()) |
426 | switch(get_button_id()) |
432 | { case 1: |
427 | { case 1: |
433 | status = ST_EXIT; |
428 | status = ST_EXIT; |
434 | exit(); |
429 | exit(); |
435 | break; |
430 | break; |
436 | 431 | ||
437 | case 0x10: |
432 | case 0x10: |
438 | status = ST_PLAY; |
433 | status = ST_PLAY; |
439 | continue; |
434 | continue; |
440 | 435 | ||
441 | case 0x11: |
436 | case 0x11: |
442 | status = ST_STOP; |
437 | status = ST_STOP; |
443 | break; |
438 | break; |
444 | // case 0x12: |
439 | // case 0x12: |
445 | // case 0x13: |
440 | // case 0x13: |
446 | case 0x14: |
441 | case 0x14: |
447 | if(l_vol > -10000) |
442 | if(l_vol > -10000) |
448 | { |
443 | { |
449 | l_vol-=100; |
444 | l_vol-=100; |
450 | r_vol-=100; |
445 | r_vol-=100; |
451 | SetVolume(hBuff,l_vol,r_vol); |
446 | SetVolume(hBuff,l_vol,r_vol); |
452 | }; |
447 | }; |
453 | break; |
448 | break; |
454 | 449 | ||
455 | case 0x15: |
450 | case 0x15: |
456 | if(l_vol < 0) |
451 | if(l_vol < 0) |
457 | { l_vol+=100; |
452 | { l_vol+=100; |
458 | r_vol+=100; |
453 | r_vol+=100; |
459 | SetVolume(hBuff,l_vol,r_vol); |
454 | SetVolume(hBuff,l_vol,r_vol); |
460 | }; |
455 | }; |
461 | break; |
456 | break; |
462 | 457 | ||
463 | case 0x30: |
458 | case 0x30: |
464 | if(status==ST_DONE) |
459 | if(status==ST_DONE) |
465 | break; |
460 | break; |
466 | pos = (GetMousePos(REL_WINDOW)>>16)-7; |
461 | pos = (GetMousePos(REL_WINDOW)>>16)-7; |
467 | offset = ((fileinfo.size-44)/286*pos+44)&0xFFFFFFFC; |
462 | offset = ((fileinfo.size-44)/286*pos+44)&0xFFFFFFFC; |
468 | set_reader(&rd, offset); |
463 | set_reader(&rd, offset); |
469 | draw_progress_bar(); |
464 | draw_progress_bar(); |
470 | break; |
465 | break; |
471 | }; |
466 | }; |
472 | }; |
467 | }; |
473 | }; |
468 | }; |
474 | }; |
469 | }; |
475 | 470 | ||
476 | void delay (int val) |
471 | void delay (int val) |
477 | { |
472 | { |
478 | _asm |
473 | _asm |
479 | { mov eax,5 |
474 | { mov eax,5 |
480 | mov ebx, [val] |
475 | mov ebx, [val] |
481 | int 0x40 |
476 | int 0x40 |
482 | }; |
477 | }; |
483 | } |
478 | } |
484 | 479 | ||
485 | int wait_for_event(int time) |
480 | int wait_for_event(int time) |
486 | { int retval; |
481 | { int retval; |
487 | _asm |
482 | _asm |
488 | { mov eax,23 |
483 | { mov eax,23 |
489 | mov ebx,[time] |
484 | mov ebx,[time] |
490 | int 0x40 |
485 | int 0x40 |
491 | mov [retval], eax |
486 | mov [retval], eax |
492 | }; |
487 | }; |
493 | return retval; |
488 | return retval; |
494 | }; |
489 | }; |
495 | 490 | ||
496 | int wait_for_event_infinite() |
491 | int wait_for_event_infinite() |
497 | { int retval; |
492 | { int retval; |
498 | _asm |
493 | _asm |
499 | { mov eax,10 |
494 | { mov eax,10 |
500 | int 0x40 |
495 | int 0x40 |
501 | mov [retval], eax |
496 | mov [retval], eax |
502 | }; |
497 | }; |
503 | return retval; |
498 | return retval; |
504 | }; |
499 | }; |
505 | 500 | ||
506 | void BeginDraw() |
501 | void BeginDraw() |
507 | {_asm |
502 | {_asm |
508 | { mov eax,12 |
503 | { mov eax,12 |
509 | mov ebx, 1 |
504 | mov ebx, 1 |
510 | int 0x40 |
505 | int 0x40 |
511 | }; |
506 | }; |
512 | }; |
507 | }; |
513 | 508 | ||
514 | void EndDraw() |
509 | void EndDraw() |
515 | { _asm |
510 | { _asm |
516 | { mov eax,12 |
511 | { mov eax,12 |
517 | mov ebx, 2 |
512 | mov ebx, 2 |
518 | int 0x40 |
513 | int 0x40 |
519 | }; |
514 | }; |
520 | }; |
515 | }; |
521 | 516 | ||
522 | ///********* |
517 | ///********* |
523 | void *memmove ( void * dst, void * src, int count) |
518 | void *memmove ( void * dst, void * src, int count) |
524 | { void *ret; |
519 | { void *ret; |
525 | ret = dst; |
520 | ret = dst; |
526 | 521 | ||
527 | if (dst <= src || (char *)dst >= ((char *)src + count)) |
522 | if (dst <= src || (char *)dst >= ((char *)src + count)) |
528 | { |
523 | { |
529 | while (count--) |
524 | while (count--) |
530 | { *(char *)dst = *(char *)src; |
525 | { *(char *)dst = *(char *)src; |
531 | dst = (char *)dst + 1; |
526 | dst = (char *)dst + 1; |
532 | src = (char *)src + 1; |
527 | src = (char *)src + 1; |
533 | } |
528 | } |
534 | } |
529 | } |
535 | else |
530 | else |
536 | { |
531 | { |
537 | dst = (char *)dst + count - 1; |
532 | dst = (char *)dst + count - 1; |
538 | src = (char *)src + count - 1; |
533 | src = (char *)src + count - 1; |
539 | while (count--) |
534 | while (count--) |
540 | { *(char *)dst = *(char *)src; |
535 | { *(char *)dst = *(char *)src; |
541 | dst = (char *)dst - 1; |
536 | dst = (char *)dst - 1; |
542 | src = (char *)src - 1; |
537 | src = (char *)src - 1; |
543 | } |
538 | } |
544 | } |
539 | } |
545 | return ret; |
540 | return ret; |
546 | }; |
541 | }; |
547 | //**********/ |
542 | //**********/ |
548 | 543 | ||
549 | void * __cdecl mem_cpy(void * dst,const void * src,size_t count) |
544 | void * __cdecl mem_cpy(void * dst,const void * src,size_t count) |
550 | { void * ret = dst; |
545 | { void * ret = dst; |
551 | while (count--) |
546 | while (count--) |
552 | { *(char *)dst = *(char *)src; |
547 | { *(char *)dst = *(char *)src; |
553 | dst = (char *)dst + 1; |
548 | dst = (char *)dst + 1; |
554 | src = (char *)src + 1; |
549 | src = (char *)src + 1; |
555 | }; |
550 | }; |
556 | return(ret); |
551 | return(ret); |
557 | } |
552 | } |
558 | 553 | ||
559 | // debug_out_str(formats[fmt]); |
554 | // debug_out_str(formats[fmt]); |
560 | // debug_out_str("\x0D\x0A\x00"); |
555 | // debug_out_str("\x0D\x0A\x00"); |
561 | 556 | ||
562 | // debug_out_str("pci cmd: "); |
557 | // debug_out_str("pci cmd: "); |
563 | // debug_out_hex(info.pci_cmd); |
558 | // debug_out_hex(info.pci_cmd); |
564 | // debug_out_str("\x0D\x0A\x00"); |
559 | // debug_out_str("\x0D\x0A\x00"); |
565 | 560 | ||
566 | // debug_out_str("irq line: "); |
561 | // debug_out_str("irq line: "); |
567 | // debug_out_hex(info.irq); |
562 | // debug_out_hex(info.irq); |
568 | // debug_out_str("\x0D\x0A\x00"); |
563 | // debug_out_str("\x0D\x0A\x00"); |
569 | 564 | ||
570 | // debug_out_str("global control: "); |
565 | // debug_out_str("global control: "); |
571 | // debug_out_hex(info.glob_cntrl); |
566 | // debug_out_hex(info.glob_cntrl); |
572 | // debug_out_str("\x0D\x0A\x00"); |
567 | // debug_out_str("\x0D\x0A\x00"); |
573 | 568 | ||
574 | // debug_out_str("global status: "); |
569 | // debug_out_str("global status: "); |
575 | // debug_out_hex(info.glob_sta); |
570 | // debug_out_hex(info.glob_sta); |
576 | // debug_out_str("\x0D\x0A\x00"); |
571 | // debug_out_str("\x0D\x0A\x00"); |
577 | 572 | ||
578 | 573 | ||
579 | // call _print_volume |
574 | // call _print_volume |
580 | 575 | ||
581 | // debug_out_hex(whdr.nChannels); |
576 | // debug_out_hex(whdr.nChannels); |
582 | // debug_out_str("\x0D\x0A\x00"); |
577 | // debug_out_str("\x0D\x0A\x00"); |
583 | // debug_out_hex(whdr.nSamplesPerSec); |
578 | // debug_out_hex(whdr.nSamplesPerSec); |
584 | // debug_out_str("\x0D\x0A\x00"); |
579 | // debug_out_str("\x0D\x0A\x00"); |
585 | 580 | ||
586 | // debug_out_hex(fmt); |
581 | // debug_out_hex(fmt); |
587 | // debug_out_str("\x0D\x0A\x00");=>>>>>>>>><> |
582 | // debug_out_str("\x0D\x0A\x00");=>>>>>>>>(ver>><> |