Subversion Repositories Kolibri OS

Rev

Rev 328 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 328 Rev 346
1
;
1
;
2
;   This file is part of the Infinity sound library.
2
;   This file is part of the Infinity sound library.
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
format MS COFF
16
format MS COFF
17
 
17
 
18
include 'proc32.inc'
18
include 'proc32.inc'
19
include 'main.inc'
19
include 'main.inc'
20
include 'imports.inc'
20
include 'imports.inc'
21
 
21
 
22
FORCE_MMX        equ 0  ;set to 1 to force use mmx or
22
FORCE_MMX        equ 0  ;set to 1 to force use mmx or
23
FORCE_MMX_128    equ 0  ;integer sse2 extensions
23
FORCE_MMX_128    equ 0  ;integer sse2 extensions
24
                        ;and reduce driver size
24
                        ;and reduce driver size
25
;USE_SSE         equ 0
25
;USE_SSE         equ 0
26
 
26
 
27
DEBUG            equ 1
27
DEBUG            equ 1
28
 
28
 
29
EVENT_NOTIFY     equ 0x00000200
29
EVENT_NOTIFY     equ 0x00000200
30
 
30
 
31
OS_BASE          equ 0
31
OS_BASE          equ 0
32
new_app_base     equ 0x60400000
32
new_app_base     equ 0x60400000
33
PROC_BASE        equ OS_BASE+0x0080000
33
PROC_BASE        equ OS_BASE+0x0080000
34
 
34
 
35
CAPS_SSE2        equ 26
35
CAPS_SSE2        equ 26
36
PG_SW            equ 0x003
36
PG_SW            equ 0x003
37
 
37
 
38
 
38
 
39
public START
39
public START
40
public service_proc
40
public service_proc
41
public version
41
public version
42
 
42
 
43
SND_CREATE_BUFF     equ 2
43
SND_CREATE_BUFF     equ 2
44
SND_PLAY            equ 3
44
SND_PLAY            equ 3
45
SND_STOP            equ 4
45
SND_STOP            equ 4
46
SND_SETBUFF         equ 5
46
SND_SETBUFF         equ 5
47
SND_DESTROY_BUFF    equ 6
47
SND_DESTROY_BUFF    equ 6
48
 
48
 
49
DEV_PLAY            equ 1
49
DEV_PLAY            equ 1
50
DEV_STOP            equ 2
50
DEV_STOP            equ 2
51
DEV_CALLBACK        equ 3
51
DEV_CALLBACK        equ 3
52
 
52
 
53
struc IOCTL
53
struc IOCTL
54
{  .handle           dd ?
54
{  .handle           dd ?
55
   .io_code          dd ?
55
   .io_code          dd ?
56
   .input            dd ?
56
   .input            dd ?
57
   .inp_size         dd ?
57
   .inp_size         dd ?
58
   .output           dd ?
58
   .output           dd ?
59
   .out_size         dd ?
59
   .out_size         dd ?
60
}
60
}
61
 
61
 
62
virtual at 0
62
virtual at 0
63
  IOCTL IOCTL
63
  IOCTL IOCTL
64
end virtual
64
end virtual
65
 
65
 
66
section '.flat' code readable align 16
66
section '.flat' code readable align 16
67
 
67
 
68
proc START stdcall, state:dword
68
proc START stdcall, state:dword
69
 
69
 
70
           cmp [state], 1
70
           cmp [state], 1
71
           jne .exit
71
           jne .exit
72
 
72
 
73
           stdcall GetService, szSound
73
           stdcall GetService, szSound
74
           test eax, eax
74
           test eax, eax
75
           jz .fail
75
           jz .fail
76
           mov [hSound], eax
76
           mov [hSound], eax
77
 
77
 
78
           stdcall KernelAlloc, 16*512
78
           stdcall KernelAlloc, 16*512
79
           test eax, eax
79
           test eax, eax
80
           jz .out_of_mem
80
           jz .out_of_mem
81
           mov [mix_buff], eax
81
           mov [mix_buff], eax
82
 
82
 
83
           mov eax, str.fd-FD_OFFSET
83
           mov eax, str.fd-FD_OFFSET
84
           mov [str.fd], eax
84
           mov [str.fd], eax
85
           mov [str.bk], eax
85
           mov [str.bk], eax
86
 
86
 
87
if FORCE_MMX
87
if FORCE_MMX
88
 if FORCE_MMX_128
88
 if FORCE_MMX_128
89
  display 'Use only FORCE_MMX or FORCE_MMX_128 not both together',13,10
89
  display 'Use only FORCE_MMX or FORCE_MMX_128 not both together',13,10
90
  stop
90
  stop
91
 end if
91
 end if
92
           mov [mix_2_core], mmx_mix_2
92
           mov [mix_2_core], mmx_mix_2
93
           mov [mix_3_core], mmx_mix_3
93
           mov [mix_3_core], mmx_mix_3
94
           mov [mix_4_core], mmx_mix_4
94
           mov [mix_4_core], mmx_mix_4
95
end if
95
end if
96
 
96
 
97
if FORCE_MMX_128
97
if FORCE_MMX_128
98
 if FORCE_MMX
98
 if FORCE_MMX
99
  display 'Use only FORCE_MMX or FORCE_MMX_128 not both together',13,10
99
  display 'Use only FORCE_MMX or FORCE_MMX_128 not both together',13,10
100
  stop
100
  stop
101
 end if
101
 end if
102
           mov [mix_2_core], mmx128_mix_2
102
           mov [mix_2_core], mmx128_mix_2
103
           mov [mix_3_core], mmx128_mix_3
103
           mov [mix_3_core], mmx128_mix_3
104
           mov [mix_4_core], mmx128_mix_4
104
           mov [mix_4_core], mmx128_mix_4
105
end if
105
end if
106
 
106
 
107
if ~(FORCE_MMX or FORCE_MMX_128)  ;autodetect
107
if ~(FORCE_MMX or FORCE_MMX_128)  ;autodetect
108
           mov eax, 1
108
           mov eax, 1
109
           cpuid
109
           cpuid
110
           bt edx, CAPS_SSE2
110
           bt edx, CAPS_SSE2
111
           jc .mmx128
111
           jc .mmx128
112
                                           ;old 64-bit mmx
112
                                           ;old 64-bit mmx
113
           mov [mix_2_core], mmx_mix_2
113
           mov [mix_2_core], mmx_mix_2
114
           mov [mix_3_core], mmx_mix_3
114
           mov [mix_3_core], mmx_mix_3
115
           mov [mix_4_core], mmx_mix_4
115
           mov [mix_4_core], mmx_mix_4
116
           jmp @F
116
           jmp @F
117
.mmx128:                                   ;128-bit integer sse2 extensions
117
.mmx128:                                   ;128-bit integer sse2 extensions
118
           mov [mix_2_core], mmx128_mix_2
118
           mov [mix_2_core], mmx128_mix_2
119
           mov [mix_3_core], mmx128_mix_3
119
           mov [mix_3_core], mmx128_mix_3
120
           mov [mix_4_core], mmx128_mix_4
120
           mov [mix_4_core], mmx128_mix_4
121
@@:
121
@@:
122
end if
122
end if
123
           stdcall set_handler, [hSound], new_mix
123
           stdcall set_handler, [hSound], new_mix
124
           stdcall RegService, szInfinity, service_proc
124
           stdcall RegService, szInfinity, service_proc
125
           ret
125
           ret
126
.fail:
126
.fail:
127
     if DEBUG
127
     if DEBUG
128
           mov esi, msgFail
128
           mov esi, msgFail
129
           call SysMsgBoardStr
129
           call SysMsgBoardStr
130
     end if
130
     end if
131
.exit:
131
.exit:
132
           xor eax, eax
132
           xor eax, eax
133
           ret
133
           ret
134
 
134
 
135
.out_of_mem:
135
.out_of_mem:
136
     if DEBUG
136
     if DEBUG
137
           mov esi, msgMem
137
           mov esi, msgMem
138
           call SysMsgBoardStr
138
           call SysMsgBoardStr
139
     end if
139
     end if
140
           xor eax, eax
140
           xor eax, eax
141
           ret
141
           ret
142
endp
142
endp
143
 
143
 
144
handle     equ  IOCTL.handle
144
handle     equ  IOCTL.handle
145
io_code    equ  IOCTL.io_code
145
io_code    equ  IOCTL.io_code
146
input      equ  IOCTL.input
146
input      equ  IOCTL.input
147
inp_size   equ  IOCTL.inp_size
147
inp_size   equ  IOCTL.inp_size
148
output     equ  IOCTL.output
148
output     equ  IOCTL.output
149
out_size   equ  IOCTL.out_size
149
out_size   equ  IOCTL.out_size
150
 
150
 
151
align 4
151
align 4
152
proc service_proc stdcall, ioctl:dword
152
proc service_proc stdcall, ioctl:dword
153
 
153
 
154
           mov edi, [ioctl]
154
           mov edi, [ioctl]
155
           mov eax, [edi+io_code]
155
           mov eax, [edi+io_code]
156
 
156
 
157
           cmp eax, SND_CREATE_BUFF
157
           cmp eax, SND_CREATE_BUFF
158
           jne @F
158
           jne @F
159
           mov ebx, [edi+input]
159
           mov ebx, [edi+input]
160
           stdcall CreateBuffer,[ebx]
160
           stdcall CreateBuffer,[ebx]
161
           ret
161
           ret
162
@@:
162
@@:
163
           cmp eax, SND_PLAY
163
           cmp eax, SND_PLAY
164
           jne @F
164
           jne @F
165
 
165
 
166
           mov ebx, [edi+input]
166
           mov ebx, [edi+input]
167
           stdcall play_buffer, [ebx]
167
           stdcall play_buffer, [ebx]
168
           ret
168
           ret
169
@@:
169
@@:
170
           cmp eax, SND_STOP
170
           cmp eax, SND_STOP
171
           jne @F
171
           jne @F
172
 
172
 
173
;       if DEBUG
173
;       if DEBUG
174
;          mov esi, msgStop
174
;          mov esi, msgStop
175
;          call   [SysMsgBoardStr]
175
;          call   [SysMsgBoardStr]
176
;       end if
176
;       end if
177
 
177
 
178
           mov ebx, [edi+input]
178
           mov ebx, [edi+input]
179
           stdcall stop_buffer, [ebx]
179
           stdcall stop_buffer, [ebx]
180
           ret
180
           ret
181
@@:
181
@@:
182
           cmp eax, SND_SETBUFF
182
           cmp eax, SND_SETBUFF
183
           jne @F
183
           jne @F
184
 
184
 
185
           mov ebx, [edi+input]
185
           mov ebx, [edi+input]
186
           mov eax, [ebx+4]
186
           mov eax, [ebx+4]
187
           add eax, new_app_base
187
           add eax, new_app_base
188
           stdcall set_buffer, [ebx],eax,[ebx+8],[ebx+12]
188
           stdcall set_buffer, [ebx],eax,[ebx+8],[ebx+12]
189
           ret
189
           ret
190
@@:
190
@@:
191
           cmp eax, SND_DESTROY_BUFF
191
           cmp eax, SND_DESTROY_BUFF
192
           jne @F
192
           jne @F
193
 
193
 
194
           mov eax, [edi+input]
194
           mov eax, [edi+input]
195
           mov eax, [eax]
195
           mov eax, [eax]
196
           call DestroyBuffer    ;eax
196
           call DestroyBuffer    ;eax
197
           ret
197
           ret
198
@@:
198
@@:
199
           xor eax, eax
199
           xor eax, eax
200
           ret
200
           ret
201
endp
201
endp
202
 
202
 
203
restore   handle
203
restore   handle
204
restore   io_code
204
restore   io_code
205
restore   input
205
restore   input
206
restore   inp_size
206
restore   inp_size
207
restore   output
207
restore   output
208
restore   out_size
208
restore   out_size
209
 
209
 
210
TASK_COUNT    equ 0x0003004
210
TASK_COUNT    equ 0x0003004
211
CURRENT_TASK  equ 0x0003000
211
CURRENT_TASK  equ 0x0003000
212
 
212
 
213
align 4
213
align 4
214
proc CreateBuffer stdcall, format:dword
214
proc CreateBuffer stdcall, format:dword
215
           locals
215
           locals
216
             str dd ?
216
             str dd ?
217
           endl
217
           endl
218
 
218
 
219
           mov ebx, [CURRENT_TASK]      ;hack: direct accsess
219
           mov ebx, [CURRENT_TASK]      ;hack: direct accsess
220
           shl ebx, 5                   ;to kernel data
220
           shl ebx, 5                   ;to kernel data
221
           mov ebx, [0x3000+ebx+4]
221
           mov ebx, [0x3000+ebx+4]
222
           mov eax, STREAM_SIZE
222
           mov eax, STREAM_SIZE
223
 
223
 
224
           call CreateObject
224
           call CreateObject
225
           test eax, eax
225
           test eax, eax
226
           jz .fail
226
           jz .fail
227
           mov [str], eax
227
           mov [str], eax
228
 
228
 
229
           mov [eax+STREAM.magic], 'WAVE'
229
           mov [eax+STREAM.magic], 'WAVE'
230
           mov [eax+STREAM.destroy], DestroyBuffer.destroy
230
           mov [eax+STREAM.destroy], DestroyBuffer.destroy
231
           mov [eax+STREAM.size], STREAM_SIZE
231
           mov [eax+STREAM.size], STREAM_SIZE
232
 
232
 
233
           pushf
233
           pushf
234
           cli
234
           cli
235
           mov ebx, str.fd-FD_OFFSET
235
           mov ebx, str.fd-FD_OFFSET
236
           mov edx, [ebx+STREAM.str_fd]
236
           mov edx, [ebx+STREAM.str_fd]
237
           mov [eax+STREAM.str_fd], edx
237
           mov [eax+STREAM.str_fd], edx
238
           mov [eax+STREAM.str_bk], ebx
238
           mov [eax+STREAM.str_bk], ebx
239
           mov [ebx+STREAM.str_fd], eax
239
           mov [ebx+STREAM.str_fd], eax
240
           mov [edx+STREAM.str_bk], eax
240
           mov [edx+STREAM.str_bk], eax
241
           popf
241
           popf
242
 
242
 
243
           stdcall KernelAlloc, dword 72*1024
243
           stdcall KernelAlloc, dword 72*1024
244
 
244
 
245
           mov edi, [str]
245
           mov edi, [str]
246
           mov [edi+STREAM.base], eax
246
           mov [edi+STREAM.base], eax
247
           add eax, 0x1000
247
           add eax, 0x1000
248
           mov [edi+STREAM.seg_0], eax
248
           mov [edi+STREAM.seg_0], eax
249
           mov [edi+STREAM.curr_seg], eax
249
           mov [edi+STREAM.curr_seg], eax
250
           mov [edi+STREAM.notify_off1], eax
250
           mov [edi+STREAM.notify_off1], eax
251
           add eax, 0x8000
251
           add eax, 0x8000
252
           mov [edi+STREAM.lim_0], eax
252
           mov [edi+STREAM.lim_0], eax
253
           add eax, 0x1000
253
           add eax, 0x1000
254
           mov [edi+STREAM.seg_1], eax
254
           mov [edi+STREAM.seg_1], eax
255
           mov [edi+STREAM.notify_off2], eax
255
           mov [edi+STREAM.notify_off2], eax
256
           add eax, 0x8000
256
           add eax, 0x8000
257
           mov [edi+STREAM.limit], eax
257
           mov [edi+STREAM.limit], eax
258
           mov [edi+STREAM.lim_1], eax
258
           mov [edi+STREAM.lim_1], eax
259
 
259
 
260
; create ring buffer
260
; create ring buffer
261
 
261
 
262
           stdcall AllocKernelSpace, dword 128*1024
262
           stdcall AllocKernelSpace, dword 128*1024
263
 
263
 
264
           mov edi, [str]
264
           mov edi, [str]
265
           mov [edi+STREAM.work_buff], eax
265
           mov [edi+STREAM.work_buff], eax
266
           mov [edi+STREAM.work_read], eax
266
           mov [edi+STREAM.work_read], eax
267
           mov [edi+STREAM.work_write], eax
267
           mov [edi+STREAM.work_write], eax
268
           mov [edi+STREAM.work_count], 0
268
           mov [edi+STREAM.work_count], 0
269
           add eax, 64*1024
269
           add eax, 64*1024
270
           mov [edi+STREAM.work_top], eax
270
           mov [edi+STREAM.work_top], eax
271
 
271
 
272
           stdcall AllocPages, dword 64/4
272
           stdcall AllocPages, dword 64/4
273
           mov edi, [str]
273
           mov edi, [str]
274
           mov ebx, [edi+STREAM.work_buff]
274
           mov ebx, [edi+STREAM.work_buff]
275
           mov ecx, 16
275
           mov ecx, 16
276
           or eax, PG_SW
276
           or eax, PG_SW
277
           push eax
277
           push eax
278
           push ebx
278
           push ebx
279
           call CommitPages ;eax, ebx, ecx
279
           call CommitPages ;eax, ebx, ecx
280
           mov ecx, 16
280
           mov ecx, 16
281
           pop ebx
281
           pop ebx
282
           pop eax
282
           pop eax
283
           add ebx, 64*1024
283
           add ebx, 64*1024
284
           call CommitPages    ;double mapped
284
           call CommitPages    ;double mapped
285
 
285
 
286
           mov edi, [str]
286
           mov edi, [str]
287
           mov eax, [format]
287
           mov eax, [format]
288
           mov [edi+STREAM.format], eax
288
           mov [edi+STREAM.format], eax
289
           mov [edi+STREAM.flags], SND_STOP
289
           mov [edi+STREAM.flags], SND_STOP
290
 
290
 
291
           xor ebx, ebx
291
           xor ebx, ebx
292
           cmp eax, 19
292
           cmp eax, 19
293
           jb @f
293
           jb @f
294
           mov ebx, 0x80808080
294
           mov ebx, 0x80808080
295
@@:
295
@@:
296
           mov [edi+STREAM.r_silence], ebx
296
           mov [edi+STREAM.r_silence], ebx
297
 
297
 
298
           shl eax, 4
298
           shl eax, 4
299
           mov ebx, [resampler_params+eax]
299
           mov ebx, [resampler_params+eax]
300
           mov ecx, [resampler_params+eax+4]
300
           mov ecx, [resampler_params+eax+4]
301
           mov edx, [resampler_params+eax+8]
301
           mov edx, [resampler_params+eax+8]
302
 
302
 
303
           mov [edi+STREAM.r_size],ebx
303
           mov [edi+STREAM.r_size],ebx
304
           mov [edi+STREAM.r_end], ecx
304
           mov [edi+STREAM.r_end], ecx
305
           mov [edi+STREAM.r_dt],  edx
305
           mov [edi+STREAM.r_dt],  edx
306
 
306
 
307
           mov ebx, [resampler_params+eax+12]
307
           mov ebx, [resampler_params+eax+12]
308
           mov [edi+STREAM.resample], ebx
308
           mov [edi+STREAM.resample], ebx
309
 
309
 
310
           mov edx, [edi+STREAM.base]
310
           mov edx, [edi+STREAM.base]
311
           lea eax, [edx+0x9000]
311
           lea eax, [edx+0x9000]
312
           call GetPgAddr  ;eax
312
           call GetPgAddr  ;eax
313
           call FreePage   ;eax
313
           call FreePage   ;eax
314
 
314
 
315
           mov eax, edx
315
           mov eax, edx
316
           lea ebx, [edx+0x9000]
316
           lea ebx, [edx+0x9000]
317
           call GetPgAddr  ;eax
317
           call GetPgAddr  ;eax
318
           stdcall MapPage, ebx, eax, dword 3
318
           stdcall MapPage, ebx, eax, dword 3
319
 
319
 
320
           mov edi, [edi+STREAM.base]
320
           mov edi, [edi+STREAM.base]
321
           mov ecx, (72*1024)/4
321
           mov ecx, (72*1024)/4
322
           xor eax, eax
322
           xor eax, eax
323
           cld
323
           cld
324
           rep stosd
324
           rep stosd
325
 
325
 
326
           mov edi, [str]
326
           mov edi, [str]
327
           mov edi, [edi+STREAM.work_buff]
327
           mov edi, [edi+STREAM.work_buff]
328
           mov ecx, (64*1024)/4
328
           mov ecx, (64*1024)/4
329
           rep stosd
329
           rep stosd
330
 
330
 
331
           mov eax, [str]
331
           mov eax, [str]
332
           ret
332
           ret
333
.fail:
333
.fail:
334
           xor eax, eax
334
           xor eax, eax
335
           ret
335
           ret
336
endp
336
endp
337
 
337
 
338
if 0
338
if 0
339
align 4
339
align 4
340
pid_to_slot:
340
pid_to_slot:
341
 
341
 
342
           push   ebx
342
           push   ebx
343
           push   ecx
343
           push   ecx
344
           mov    ebx,[TASK_COUNT]
344
           mov    ebx,[TASK_COUNT]
345
           shl    ebx,5
345
           shl    ebx,5
346
           mov    ecx,2*32
346
           mov    ecx,2*32
347
.loop:
347
.loop:
348
           cmp    byte [CURRENT_TASK+ecx+0xa],9
348
           cmp    byte [CURRENT_TASK+ecx+0xa],9
349
           jz     .endloop              ;skip empty slots
349
           jz     .endloop              ;skip empty slots
350
           cmp    [CURRENT_TASK+ecx+0x4],eax ;check PID
350
           cmp    [CURRENT_TASK+ecx+0x4],eax ;check PID
351
           jz     .pid_found
351
           jz     .pid_found
352
.endloop:
352
.endloop:
353
           add    ecx,32
353
           add    ecx,32
354
           cmp    ecx,ebx
354
           cmp    ecx,ebx
355
           jle    .loop
355
           jle    .loop
356
           pop    ecx
356
           pop    ecx
357
           pop    ebx
357
           pop    ebx
358
           xor    eax,eax
358
           xor    eax,eax
359
           ret
359
           ret
360
 
360
 
361
.pid_found:
361
.pid_found:
362
           shr    ecx,5
362
           shr    ecx,5
363
           mov    eax,ecx
363
           mov    eax,ecx
364
           pop    ecx
364
           pop    ecx
365
           pop    ebx
365
           pop    ebx
366
           ret
366
           ret
367
 
367
 
368
end if
368
end if
369
 
369
 
370
;param
370
;param
371
; eax= buffer handle
371
; eax= buffer handle
372
 
372
 
373
align 4
373
align 4
374
DestroyBuffer:
374
DestroyBuffer:
375
           .handle  equ esp       ;local
375
           .handle  equ esp       ;local
376
 
376
 
377
           cmp [eax+STREAM.magic], 'WAVE'
377
           cmp [eax+STREAM.magic], 'WAVE'
378
           jne .fail
378
           jne .fail
379
 
379
 
380
           cmp [eax+STREAM.size], STREAM_SIZE
380
           cmp [eax+STREAM.size], STREAM_SIZE
381
           jne .fail
381
           jne .fail
382
.destroy:
382
.destroy:
383
           push eax
383
           push eax
384
 
384
 
385
           pushf
385
           pushf
386
           cli
386
           cli
387
           mov ebx, [eax+STREAM.str_fd]
387
           mov ebx, [eax+STREAM.str_fd]
388
           mov ecx, [eax+STREAM.str_bk]
388
           mov ecx, [eax+STREAM.str_bk]
389
           mov [ebx+STREAM.str_bk], ecx
389
           mov [ebx+STREAM.str_bk], ecx
390
           mov [ecx+STREAM.str_fd], ebx
390
           mov [ecx+STREAM.str_fd], ebx
391
           popf
391
           popf
392
 
392
 
393
           stdcall KernelFree, [eax+STREAM.base]
393
           stdcall KernelFree, [eax+STREAM.base]
394
           mov eax, [.handle]
394
           mov eax, [.handle]
395
           stdcall KernelFree, [eax+STREAM.work_buff]
395
           stdcall KernelFree, [eax+STREAM.work_buff]
396
 
396
 
397
           pop eax               ;restore stack
397
           pop eax               ;restore stack
398
           call DestroyObject    ;eax
398
           call DestroyObject    ;eax
399
.fail:
399
.fail:
400
           ret
400
           ret
401
 
401
 
402
align 4
402
align 4
403
proc play_buffer stdcall, str:dword
403
proc play_buffer stdcall, str:dword
404
 
404
 
405
           mov ebx, [str]
405
           mov ebx, [str]
406
           cmp [ebx+STREAM.magic], 'WAVE'
406
           cmp [ebx+STREAM.magic], 'WAVE'
407
           jne .fail
407
           jne .fail
408
 
408
 
409
           cmp [ebx+STREAM.size], STREAM_SIZE
409
           cmp [ebx+STREAM.size], STREAM_SIZE
410
           jne .fail
410
           jne .fail
411
 
411
 
412
           mov edi,[ebx+STREAM.work_buff]
412
           mov edi,[ebx+STREAM.work_buff]
413
           mov [ebx+STREAM.work_read], edi
413
           mov [ebx+STREAM.work_read], edi
414
           mov [ebx+STREAM.work_write], edi
414
           mov [ebx+STREAM.work_write], edi
415
           mov [ebx+STREAM.work_count], 0
415
           mov [ebx+STREAM.work_count], 0
416
 
416
 
417
           mov edx, [ebx+STREAM.base]
417
           mov edx, [ebx+STREAM.base]
418
           add edx, 0x1000
418
           add edx, 0x1000
419
           mov [ebx+STREAM.seg_0], edx
419
           mov [ebx+STREAM.seg_0], edx
420
           mov [ebx+STREAM.curr_seg], edx
420
           mov [ebx+STREAM.curr_seg], edx
421
           add edx, 0x8000
421
           add edx, 0x8000
422
           mov [ebx+STREAM.lim_0], edx
422
           mov [ebx+STREAM.lim_0], edx
423
           add edx, 0x1000
423
           add edx, 0x1000
424
           mov [ebx+STREAM.seg_1], edx
424
           mov [ebx+STREAM.seg_1], edx
425
           add edx, 0x8000
425
           add edx, 0x8000
426
           mov [ebx+STREAM.lim_1], edx
426
           mov [ebx+STREAM.lim_1], edx
427
 
427
 
428
           mov edx, [ebx+STREAM.seg_0]
428
           mov edx, [ebx+STREAM.seg_0]
429
           mov ecx, -128
429
           mov ecx, -128
430
           mov eax, [ebx+STREAM.r_silence]
430
           mov eax, [ebx+STREAM.r_silence]
431
@@:
431
@@:
432
           mov [edx+ecx], eax
432
           mov [edx+ecx], eax
433
           add ecx, 4
433
           add ecx, 4
434
           jnz @B
434
           jnz @B
435
 
435
 
436
           stdcall [ebx+STREAM.resample], edi, edx,\
436
           stdcall [ebx+STREAM.resample], edi, edx,\
437
           [ebx+STREAM.r_dt],[ebx+STREAM.r_size],[ebx+STREAM.r_end]
437
           [ebx+STREAM.r_dt],[ebx+STREAM.r_size],[ebx+STREAM.r_end]
438
 
438
 
439
           mov ebx, [str]
439
           mov ebx, [str]
440
 
440
 
441
           add [ebx+STREAM.work_count], eax
441
           add [ebx+STREAM.work_count], eax
442
           add [ebx+STREAM.work_write], eax
442
           add [ebx+STREAM.work_write], eax
443
 
443
 
444
           mov edx, [ebx+STREAM.r_size]
444
           mov edx, [ebx+STREAM.r_size]
445
           add [ebx+STREAM.curr_seg], edx
445
           add [ebx+STREAM.curr_seg], edx
446
 
446
 
447
           mov [ebx+STREAM.flags], SND_PLAY
447
           mov [ebx+STREAM.flags], SND_PLAY
448
 
448
 
449
           mov eax, [ebx+STREAM.r_silence]
449
           mov eax, [ebx+STREAM.r_silence]
450
           mov edi, [ebx+STREAM.work_write]
450
           mov edi, [ebx+STREAM.work_write]
451
           mov ecx, [ebx+STREAM.work_top]
451
           mov ecx, [ebx+STREAM.work_top]
452
           sub ecx, edi
452
           sub ecx, edi
453
           shr ecx, 2
453
           shr ecx, 2
454
           cld
454
           cld
455
           rep stosd
455
           rep stosd
456
 
456
 
457
           stdcall  dev_play, [hSound]
457
           stdcall  dev_play, [hSound]
458
           xor eax, eax
458
           xor eax, eax
459
           inc eax
459
           inc eax
460
           ret
460
           ret
461
.fail:
461
.fail:
462
           xor eax, eax
462
           xor eax, eax
463
           ret
463
           ret
464
endp
464
endp
465
 
465
 
466
align 4
466
align 4
467
proc stop_buffer stdcall, str:dword
467
proc stop_buffer stdcall, str:dword
468
 
468
 
469
           mov edi, [str]
469
           mov edi, [str]
470
 
470
 
471
           cmp [edi+STREAM.magic], 'WAVE'
471
           cmp [edi+STREAM.magic], 'WAVE'
472
           jne .fail
472
           jne .fail
473
 
473
 
474
           cmp [edi+STREAM.size], STREAM_SIZE
474
           cmp [edi+STREAM.size], STREAM_SIZE
475
           jne .fail
475
           jne .fail
476
 
476
 
477
           mov [edi+STREAM.flags], SND_STOP
477
           mov [edi+STREAM.flags], SND_STOP
478
 
478
 
479
;           stdcall [ServiceHandler], [hSound], dword DEV_STOP, 0
479
;           stdcall [ServiceHandler], [hSound], dword DEV_STOP, 0
480
 
480
 
481
           xor eax, eax
481
           xor eax, eax
482
           inc eax
482
           inc eax
483
           ret
483
           ret
484
.fail:
484
.fail:
485
           xor eax, eax
485
           xor eax, eax
486
           ret
486
           ret
487
endp
487
endp
488
 
488
 
489
align 4
489
align 4
490
proc set_buffer stdcall, str:dword,src:dword,offs:dword,size:dword
490
proc set_buffer stdcall, str:dword,src:dword,offs:dword,size:dword
491
 
491
 
492
           mov edx, [str]
492
           mov edx, [str]
493
           test edx, edx
493
           test edx, edx
494
           jz .fail
494
           jz .fail
495
 
495
 
496
           cmp [edx+STREAM.magic], 'WAVE'
496
           cmp [edx+STREAM.magic], 'WAVE'
497
           jne .fail
497
           jne .fail
498
 
498
 
499
           cmp [edx+STREAM.size], STREAM_SIZE
499
           cmp [edx+STREAM.size], STREAM_SIZE
500
           jne .fail
500
           jne .fail
501
 
501
 
502
           mov esi,[src]
502
           mov esi,[src]
503
           test esi, esi
503
           test esi, esi
504
           jz .fail
504
           jz .fail
505
 
505
 
506
           cmp esi, new_app_base
506
           cmp esi, new_app_base
507
           jb .fail
507
           jb .fail
508
 
508
 
509
           mov edi, [offs]
509
           mov edi, [offs]
510
           mov ecx, 0x8000
510
           mov ecx, 0x8000
511
 
511
 
512
           sub ecx, edi
512
           sub ecx, edi
513
           jbe .seg_1
513
           jbe .seg_1
514
 
514
 
515
           sub [size], ecx
515
           sub [size], ecx
516
           jb .fail
516
           jb .fail
517
 
517
 
518
           add edi, [edx+STREAM.base]
518
           add edi, [edx+STREAM.base]
519
           add edi, 0x1000
519
           add edi, 0x1000
520
           shr ecx, 2
520
           shr ecx, 2
521
           cld
521
           cld
522
           rep movsd
522
           rep movsd
523
           jmp @F
523
           jmp @F
524
.seg_1:
524
.seg_1:
525
           add edi, [edx+STREAM.base]
525
           add edi, [edx+STREAM.base]
526
           add edi, 0x1000
526
           add edi, 0x1000
527
@@:
527
@@:
528
           add edi, 0x1000
528
           add edi, 0x1000
529
           mov ecx, [size]
529
           mov ecx, [size]
530
           test ecx, ecx
530
           test ecx, ecx
531
           jz .done
531
           jz .done
532
           cmp ecx, 0x8000
532
           cmp ecx, 0x8000
533
           ja .fail
533
           ja .fail
534
 
534
 
535
           shr ecx, 2
535
           shr ecx, 2
536
           rep movsd
536
           rep movsd
537
.done:
537
.done:
538
           xor eax, eax
538
           xor eax, eax
539
           inc eax
539
           inc eax
540
           ret
540
           ret
541
.fail:
541
.fail:
542
           xor eax, eax
542
           xor eax, eax
543
           ret
543
           ret
544
endp
544
endp
545
 
545
 
546
align 4
546
align 4
547
prepare_playlist:
547
prepare_playlist:
548
 
548
 
549
           xor edx, edx
549
           xor edx, edx
550
           mov [play_count], edx
550
           mov [play_count], edx
551
           mov esi, str.fd-FD_OFFSET
551
           mov esi, str.fd-FD_OFFSET
552
           mov edi, [esi+STREAM.str_fd]
552
           mov edi, [esi+STREAM.str_fd]
553
@@:
553
@@:
554
           cmp edi, esi
554
           cmp edi, esi
555
           je .done
555
           je .done
556
 
556
 
557
           cmp [edi+STREAM.magic], 'WAVE'
557
           cmp [edi+STREAM.magic], 'WAVE'
558
           jne .next
558
           jne .next
559
 
559
 
560
           cmp [edi+STREAM.size], STREAM_SIZE
560
           cmp [edi+STREAM.size], STREAM_SIZE
561
           jne .next
561
           jne .next
562
 
562
 
563
           cmp [edi+STREAM.flags], SND_PLAY;
563
           cmp [edi+STREAM.flags], SND_PLAY;
564
           jne .next
564
           jne .next
565
           cmp [edi+STREAM.work_count], 16384
565
           cmp [edi+STREAM.work_count], 16384
566
           jb .next
566
           jb .next
567
 
567
 
568
           mov [play_list+edx], edi
568
           mov [play_list+edx], edi
569
           inc [play_count]
569
           inc [play_count]
570
           add edx, 4
570
           add edx, 4
571
.next:
571
.next:
572
           mov edi, [edi+STREAM.str_fd]
572
           mov edi, [edi+STREAM.str_fd]
573
           jmp @B
573
           jmp @B
574
.done:
574
.done:
575
           ret
575
           ret
576
 
576
 
577
align 4
577
align 4
578
proc set_handler stdcall, hsrv:dword, handler_proc:dword
578
proc set_handler stdcall, hsrv:dword, handler_proc:dword
579
           locals
579
           locals
580
             handler    dd ?
580
             handler    dd ?
581
             io_code    dd ?
581
             io_code    dd ?
582
             input      dd ?
582
             input      dd ?
583
             inp_size   dd ?
583
             inp_size   dd ?
584
             output     dd ?
584
             output     dd ?
585
             out_size   dd ?
585
             out_size   dd ?
586
             val        dd ?
586
             val        dd ?
587
           endl
587
           endl
588
 
588
 
589
           mov eax, [hsrv]
589
           mov eax, [hsrv]
590
           lea ecx, [handler_proc]
590
           lea ecx, [handler_proc]
591
           xor ebx, ebx
591
           xor ebx, ebx
592
 
592
 
593
           mov [handler], eax
593
           mov [handler], eax
594
           mov [io_code], DEV_CALLBACK
594
           mov [io_code], DEV_CALLBACK
595
           mov [input], ecx
595
           mov [input], ecx
596
           mov [inp_size], 4
596
           mov [inp_size], 4
597
           mov [output], ebx
597
           mov [output], ebx
598
           mov [out_size], 0
598
           mov [out_size], 0
599
 
599
 
600
           lea eax, [handler]
600
           lea eax, [handler]
601
           stdcall ServiceHandler, eax
601
           stdcall ServiceHandler, eax
602
           ret
602
           ret
603
endp
603
endp
604
 
604
 
605
align 4
605
align 4
606
proc dev_play stdcall, hsrv:dword
606
proc dev_play stdcall, hsrv:dword
607
           locals
607
           locals
608
             handle     dd ?
608
             handle     dd ?
609
             io_code    dd ?
609
             io_code    dd ?
610
             input      dd ?
610
             input      dd ?
611
             inp_size   dd ?
611
             inp_size   dd ?
612
             output     dd ?
612
             output     dd ?
613
             out_size   dd ?
613
             out_size   dd ?
614
             val        dd ?
614
             val        dd ?
615
           endl
615
           endl
616
 
616
 
617
           mov eax, [hsrv]
617
           mov eax, [hsrv]
618
           xor ebx, ebx
618
           xor ebx, ebx
619
 
619
 
620
           mov [handle], eax
620
           mov [handle], eax
621
           mov [io_code], DEV_PLAY
621
           mov [io_code], DEV_PLAY
622
           mov [input], ebx
622
           mov [input], ebx
623
           mov [inp_size], ebx
623
           mov [inp_size], ebx
624
           mov [output], ebx
624
           mov [output], ebx
625
           mov [out_size], ebx
625
           mov [out_size], ebx
626
 
626
 
627
           lea eax, [handle]
627
           lea eax, [handle]
628
           stdcall ServiceHandler, eax
628
           stdcall ServiceHandler, eax
629
           ret
629
           ret
630
endp
630
endp
631
 
631
 
632
include 'mixer.asm'
632
include 'mixer.asm'
633
include 'mix_mmx.inc'
633
include 'mix_mmx.inc'
634
include 'mix_sse2.inc'
634
include 'mix_sse2.inc'
635
 
635
 
636
;if USE_SSE
636
;if USE_SSE
637
; include 'mix_sse.inc'
637
; include 'mix_sse.inc'
638
;end if
638
;end if
639
 
639
 
640
align 16
640
align 16
641
resampler_params:
641
resampler_params:
642
     ;r_size    r_end   r_dt   resampler_func
642
     ;r_size    r_end   r_dt   resampler_func
643
     dd 0,0,0,0                                  ; 0  PCM_ALL
643
     dd 0,0,0,0                                  ; 0  PCM_ALL
644
     dd 16384,          0,     0, copy_stream    ; 1  PCM_2_16_48
644
     dd 16384,          0,     0, copy_stream    ; 1  PCM_2_16_48
645
     dd 16384,          0,     0, m16_stereo     ; 2  PCM_1_16_48
645
     dd 16384,          0,     0, m16_stereo     ; 2  PCM_1_16_48
646
 
646
 
647
     dd 16384, 0x08000000, 30109, resample_2     ; 3  PCM_2_16_44
647
     dd 16384, 0x08000000, 30109, resample_2     ; 3  PCM_2_16_44
648
     dd  8192, 0x08000000, 30109, resample_1     ; 4  PCM_1_16_44
648
     dd  8192, 0x08000000, 30109, resample_1     ; 4  PCM_1_16_44
649
 
649
 
650
     dd 16384, 0x08000000, 21846, resample_2     ; 5  PCM_2_16_32
650
     dd 16384, 0x08000000, 21846, resample_2     ; 5  PCM_2_16_32
651
     dd  8192, 0x08000000, 21846, resample_1     ; 6  PCM_1_16_32
651
     dd  8192, 0x08000000, 21846, resample_1     ; 6  PCM_1_16_32
652
 
652
 
653
     dd 16384, 0x08000000, 16384, resample_2     ; 7  PCM_2_16_24
653
     dd 16384, 0x08000000, 16384, resample_2     ; 7  PCM_2_16_24
654
     dd  8192, 0x08000000, 16384, resample_1     ; 8  PCM_1_16_24
654
     dd  8192, 0x08000000, 16384, resample_1     ; 8  PCM_1_16_24
655
 
655
 
656
     dd  8192, 0x04000000, 15052, resample_2     ; 9  PCM_2_16_22
656
     dd  8192, 0x04000000, 15052, resample_2     ; 9  PCM_2_16_22
657
     dd  4096, 0x04000000, 15052, resample_1     ;10  PCM_1_16_22
657
     dd  4096, 0x04000000, 15052, resample_1     ;10  PCM_1_16_22
658
 
658
 
659
     dd  8192, 0x04000000, 10923, resample_2     ;11  PCM_2_16_16
659
     dd  8192, 0x04000000, 10923, resample_2     ;11  PCM_2_16_16
660
     dd  4096, 0x04000000, 10923, resample_1     ;12  PCM_1_16_16
660
     dd  4096, 0x04000000, 10923, resample_1     ;12  PCM_1_16_16
661
 
661
 
662
     dd  8192, 0x04000000,  8192, resample_2     ;13  PCM_2_16_12
662
     dd  8192, 0x04000000,  8192, resample_2     ;13  PCM_2_16_12
663
     dd  4096, 0x04000000,  8192, resample_1     ;14  PCM_1_16_12
663
     dd  4096, 0x04000000,  8192, resample_1     ;14  PCM_1_16_12
664
 
664
 
665
     dd  4096, 0x02000000,  7527, resample_2     ;15  PCM_2_16_11
665
     dd  4096, 0x02000000,  7527, resample_2     ;15  PCM_2_16_11
666
     dd  2048, 0x02000000,  7527, resample_1     ;16  PCM_1_16_11
666
     dd  2048, 0x02000000,  7527, resample_1     ;16  PCM_1_16_11
667
 
667
 
668
     dd  4096, 0x02000000,  5462, resample_2     ;17  PCM_2_16_8
668
     dd  4096, 0x02000000,  5462, resample_2     ;17  PCM_2_16_8
669
     dd  2048, 0x02000000,  5462, resample_1     ;18  PCM_1_16_8
669
     dd  2048, 0x02000000,  5462, resample_1     ;18  PCM_1_16_8
670
 
670
 
671
     dd 16384,          0,     0, s8_stereo      ;19  PCM_2_8_48
671
     dd 16384,          0,     0, s8_stereo      ;19  PCM_2_8_48
672
     dd  8192,          0,     0, m8_stereo      ;20  PCM_1_8_48
672
     dd  8192,          0,     0, m8_stereo      ;20  PCM_1_8_48
673
 
673
 
674
     dd  8192, 0x08000000, 30109, resample_28    ;21  PCM_2_8_44
674
     dd  8192, 0x08000000, 30109, resample_28    ;21  PCM_2_8_44
675
     dd  4096, 0x08000000, 30109, resample_18    ;22  PCM_1_8_44
675
     dd  4096, 0x08000000, 30109, resample_18    ;22  PCM_1_8_44
676
 
676
 
677
     dd  8192, 0x08000000, 21846, resample_28    ;23  PCM_2_8_32
677
     dd  8192, 0x08000000, 21846, resample_28    ;23  PCM_2_8_32
678
     dd  4096, 0x08000000, 21846, resample_18    ;24  PCM_1_8_32
678
     dd  4096, 0x08000000, 21846, resample_18    ;24  PCM_1_8_32
679
 
679
 
680
     dd  8192, 0x08000000, 16384, resample_28    ;25  PCM_2_8_24
680
     dd  8192, 0x08000000, 16384, resample_28    ;25  PCM_2_8_24
681
     dd  4096, 0x08000000, 16384, resample_18    ;26  PCM_1_8_24
681
     dd  4096, 0x08000000, 16384, resample_18    ;26  PCM_1_8_24
682
 
682
 
683
     dd  4096, 0x04000000, 15052, resample_28    ;27  PCM_2_8_22
683
     dd  4096, 0x04000000, 15052, resample_28    ;27  PCM_2_8_22
684
     dd  2048, 0x04000000, 15052, resample_18    ;28  PCM_1_8_22
684
     dd  2048, 0x04000000, 15052, resample_18    ;28  PCM_1_8_22
685
 
685
 
686
     dd  4096, 0x04000000, 10923, resample_28    ;29  PCM_2_8_16
686
     dd  4096, 0x04000000, 10923, resample_28    ;29  PCM_2_8_16
687
     dd  2048, 0x04000000, 10923, resample_18    ;30  PCM_1_8_16
687
     dd  2048, 0x04000000, 10923, resample_18    ;30  PCM_1_8_16
688
 
688
 
689
     dd  4096, 0x04000000,  8192, resample_28    ;31  PCM_2_8_12
689
     dd  4096, 0x04000000,  8192, resample_28    ;31  PCM_2_8_12
690
     dd  2048, 0x04000000,  8192, resample_18    ;32  PCM_1_8_12
690
     dd  2048, 0x04000000,  8192, resample_18    ;32  PCM_1_8_12
691
 
691
 
692
     dd  2048, 0x02000000,  7527, resample_28    ;33  PCM_2_8_11
692
     dd  2048, 0x02000000,  7527, resample_28    ;33  PCM_2_8_11
693
     dd  1024, 0x02000000,  7527, resample_18    ;34  PCM_1_8_11
693
     dd  1024, 0x02000000,  7527, resample_18    ;34  PCM_1_8_11
694
 
694
 
695
     dd  2048, 0x02000000,  5462, resample_28    ;35  PCM_2_8_8
695
     dd  2048, 0x02000000,  5462, resample_28    ;35  PCM_2_8_8
696
     dd  1024, 0x02000000,  5462, resample_18    ;36  PCM_1_8_8
696
     dd  1024, 0x02000000,  5462, resample_18    ;36  PCM_1_8_8
697
 
697
 
698
m7            dw 0x8000,0x8000,0x8000,0x8000
698
m7            dw 0x8000,0x8000,0x8000,0x8000
699
mm80          dq 0x8080808080808080
699
mm80          dq 0x8080808080808080
700
mm_mask       dq 0xFF00FF00FF00FF00
700
mm_mask       dq 0xFF00FF00FF00FF00
701
 
701
 
702
;stream_map    dd 0xFFFF       ; 16
702
;stream_map    dd 0xFFFF       ; 16
703
version       dd 0x00030004
703
version       dd 0x00030003
704
 
704
 
705
szInfinity    db 'INFINITY',0
705
szInfinity    db 'INFINITY',0
706
szSound       db 'SOUND',0
706
szSound       db 'SOUND',0
707
 
707
 
708
if DEBUG
708
if DEBUG
709
msgFail       db 'Sound service not loaded',13,10,0
709
msgFail       db 'Sound service not loaded',13,10,0
710
msgPlay       db 'Play buffer',13,10,0
710
msgPlay       db 'Play buffer',13,10,0
711
msgStop       db 'Stop',13,10,0
711
msgStop       db 'Stop',13,10,0
712
msgUser       db 'User callback',13,10,0
712
msgUser       db 'User callback',13,10,0
713
msgMem        db 'Not enough memory',13,10,0
713
msgMem        db 'Not enough memory',13,10,0
714
msgDestroy    db 'Destroy sound buffer', 13,10,0
714
msgDestroy    db 'Destroy sound buffer', 13,10,0
715
end if
715
end if
716
 
716
 
717
section '.data' data readable writable align 16
717
section '.data' data readable writable align 16
718
 
718
 
719
play_list     rd 16
719
play_list     rd 16
720
mix_input     rd 16
720
mix_input     rd 16
721
play_count    rd 1
721
play_count    rd 1
722
hSound        rd 1
722
hSound        rd 1
723
mix_buff      rd 1
723
mix_buff      rd 1
724
mix_buff_map  rd 1
724
mix_buff_map  rd 1
725
str.fd        rd 1
725
str.fd        rd 1
726
str.bk        rd 1
726
str.bk        rd 1
727
 
727
 
728
mix_2_core    rd 1
728
mix_2_core    rd 1
729
mix_3_core    rd 1
729
mix_3_core    rd 1
730
mix_4_core    rd 1
730
mix_4_core    rd 1