volume and pan control

git-svn-id: svn://kolibrios.org@368 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2007-02-22 06:40:13 +00:00
parent ea06a9a084
commit cdfbfc7683
11 changed files with 481 additions and 378 deletions

View File

@ -0,0 +1,34 @@
struc CTRL_INFO
{ .pci_cmd dd ?
.irq dd ?
.glob_cntrl dd ?
.glob_sta dd ?
.codec_io_base dd ?
.ctrl_io_base dd ?
.codec_mem_base dd ?
.ctrl_mem_base dd ?
.codec_id dd ?
}
CTRL_INFO_SIZE equ 9*4
SRV_GETVERSION equ 0
SND_CREATE_BUFF equ 1
SND_DESTROY_BUFF equ 2
SND_SETFORMAT equ 3
SND_RESET equ 4
SND_SETPOS equ 5
SND_SETBUFF equ 6
SND_SETVOLUME equ 7
SND_GETVOLUME equ 8
SND_OUT equ 9
SND_PLAY equ 10
SND_STOP equ 11
SND_SETPAN equ 12
DEV_SET_BUFF equ 4
DEV_NOTIFY equ 5
DEV_SET_MASTERVOL equ 6
DEV_GET_MASTERVOL equ 7
DEV_GET_INFO equ 8

View File

@ -11,6 +11,9 @@ extern "C"
#define PCM_ALL 0
#define PCM_STATIC 0x80000000
#define PCM_FILTER 0x40000000
#define PCM_FLOAT 0x20000000
#define PCM_2_16_48 1
#define PCM_1_16_48 2
#define PCM_2_16_44 3
@ -68,13 +71,37 @@ SNDBUF _stdcall CreateBuffer(unsigned int format,int size);
int _stdcall DestroyBuffer(SNDBUF hBuff);
int _stdcall SetBuffer(SNDBUF hBuff,void* buff,
int offs, int size);
int _stdcall SetFormat(SNDBUF hBuff, unsigned int format);
int _stdcall ResetBuffer(SNDBUF hBuff, unsigned int flags);
int _stdcall SetBufferPos(SNDBUF hBuff, int offset);
int _stdcall SetVolume(SNDBUF hBuff, int left, int right);
int _stdcall GetVolume(SNDBUF hBuff, int *left, int *right);
int _stdcall SetPan(SNDBUF hBuff, int pan);
int _stdcall WaveOut(SNDBUF hBuff,void *buff, int size);
int _stdcall PlayBuffer(SNDBUF hBuff);
int _stdcall StopBuffer(SNDBUF hBuff);
int _stdcall GetMasterVol(int* vol);
int _stdcall SetMasterVol(int vol);
typedef struct
{ unsigned int riff_id;
unsigned int riff_size;
unsigned int riff_format;
unsigned int fmt_id;
unsigned int fmt_size;
unsigned short int wFormatTag;
unsigned short int nChannels;
unsigned int nSamplesPerSec;
unsigned int nAvgBytesPerSec;
unsigned short int nBlockAlign;
unsigned short int wBitsPerSample;
unsigned int data_id;
unsigned int data_size;
} WAVEHEADER;
unsigned int _stdcall test_wav(WAVEHEADER *hdr);
#ifdef __cplusplus
extern "C"

View File

@ -26,10 +26,10 @@ proc _InitSound@0
mov ebx, 16
mov ecx, szInfinity
int 0x40
mov [hSound], eax
test eax, eax
jz .fail
mov [hSound], eax
mov eax, 68
mov ebx, 16
mov ecx, szSound
@ -51,6 +51,8 @@ proc _InitSound@0
lea ecx, [handle]
int 0x40
.fail:
.done:
pop ecx
pop ebx
ret

View File

@ -24,7 +24,7 @@ SND_GETVOLUME equ 8
SND_OUT equ 9
SND_PLAY equ 10
SND_STOP equ 11
SND_GETFREESIZE equ 12
SND_SETPAN equ 12
DEV_SET_BUFF equ 4
DEV_NOTIFY equ 5

View File

@ -0,0 +1,43 @@
format MS COFF
include "snd.inc"
include "proc32.inc"
section '.text' align 16 code readable executable
extrn hSound
public _SetFormat@8
align 4
proc _SetFormat@8 stdcall, str:dword, fmt:dword
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
push ecx
mov eax, [hSound]
lea ebx, [str]
xor ecx, ecx
mov [handle], eax
mov [io_code], SND_SETFORMAT
mov [input], ebx
mov [inp_size], 8
mov [output], ecx
mov [out_size], ecx
mov eax, 68
mov ebx, 17
lea ecx, [handle]
int 0x40
pop ecx
pop ebx
ret
endp

View File

@ -0,0 +1,44 @@
format MS COFF
include "snd.inc"
include "proc32.inc"
section '.text' align 16 code readable executable
public _SetPan@8
;public _GetPan@4
extrn hSound
align 4
proc _SetPan@8 stdcall, str:dword, pan:dword
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
push ecx
mov eax, [hSound]
lea ebx, [str]
xor ecx, ecx
mov [handle], eax
mov [io_code], SND_SETPAN
mov [input], ebx
mov [inp_size], 8
mov [output], ecx
mov [out_size], ecx
mov eax, 68
mov ebx, 17
lea ecx, [handle]
int 0x40
pop ecx
pop ebx
ret
endp

View File

@ -0,0 +1,43 @@
format MS COFF
include "snd.inc"
include "proc32.inc"
section '.text' align 16 code readable executable
extrn hSound
public _ResetBuffer@8
align 4
proc _ResetBuffer@8 stdcall, str:dword, flags:dword
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
push ecx
mov eax, [hSound]
lea ebx, [str]
xor ecx, ecx
mov [handle], eax
mov [io_code], SND_RESET
mov [input], ebx
mov [inp_size], 8
mov [output], ecx
mov [out_size], ecx
mov eax, 68
mov ebx, 17
lea ecx, [handle]
int 0x40
pop ecx
pop ebx
ret
endp

View File

@ -0,0 +1,43 @@
format MS COFF
include "snd.inc"
include "proc32.inc"
section '.text' align 16 code readable executable
extrn hSound
public _SetBufferPos@8
align 4
proc _SetBufferPos@8 stdcall, str:dword, offs:dword
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
push ecx
mov eax, [hSound]
lea ebx, [str]
xor ecx, ecx
mov [handle], eax
mov [io_code], SND_SETPOS
mov [input], ebx
mov [inp_size], 8
mov [output], ecx
mov [out_size], ecx
mov eax, 68
mov ebx, 17
lea ecx, [handle]
int 0x40
pop ecx
pop ebx
ret
endp

View File

@ -5,11 +5,80 @@ include "proc32.inc"
section '.text' align 16 code readable executable
public _SetVolume@12
public _GetVolume@12
public _GetMasterVol@4
public _SetMasterVol@4
extrn hSound
extrn hrdwSound
align 4
proc _SetVolume@12 stdcall, str:dword, lvol:dword,rvol:dword
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
push ecx
mov eax, [hSound]
lea ebx, [str]
xor ecx, ecx
mov [handle], eax
mov [io_code], SND_SETVOLUME
mov [input], ebx
mov [inp_size], 12
mov [output], ecx
mov [out_size], ecx
mov eax, 68
mov ebx, 17
lea ecx, [handle]
int 0x40
pop ecx
pop ebx
ret
endp
align 4
proc _GetVolume@12 stdcall, str:dword, pleft:dword,pright:dword
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
push ecx
mov eax, [hSound]
lea ebx, [str]
lea ecx, [pleft]
mov [handle], eax
mov [io_code], SND_GETVOLUME
mov [input], ebx
mov [inp_size], 4
mov [output], ecx
mov [out_size], 8
mov eax, 68
mov ebx, 17
lea ecx, [handle]
int 0x40
pop ecx
pop ebx
ret
endp
align 4
proc _GetMasterVol@4 stdcall, pvol:dword
locals

View File

@ -1,372 +0,0 @@
format MS COFF
include "snd.inc"
include "proc32.inc"
section '.text' align 16 code readable executable
public _InitSound@0
public _CreateBuffer@8
public _DestroyBuffer@4
public _SetBuffer@16
public _WaveOut@12
public _PlayBuffer@4
public _StopBuffer@4
public _GetMasterVol@4
public _SetMasterVol@4
align 4
proc _InitSound@0
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
push ecx
mov eax, 68
mov ebx, 16
mov ecx, szInfinity
int 0x40
test eax, eax
jz .fail
mov [hSound], eax
mov eax, 68
mov ebx, 16
mov ecx, szSound
int 0x40
mov [hrdwSound], eax
mov eax, [hSound]
xor ebx, ebx
mov [handle], eax
mov [io_code], SRV_GETVERSION
mov [input], ebx
mov [inp_size], ebx
mov [output], ebx
mov [out_size], ebx
mov eax, 68
mov ebx, 17
lea ecx, [handle]
int 0x40
.fail:
pop ecx
pop ebx
ret
endp
align 4
proc _CreateBuffer@8 stdcall, format:dword, size:dword
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
push ecx
mov eax, [hSound]
lea ebx, [format]
xor ecx, ecx
mov [handle], eax
mov [io_code], SND_CREATE_BUFF
mov [input], ebx
mov [inp_size], 4
mov [output], ecx
mov [out_size], ecx
mov eax, 68
mov ebx, 17
lea ecx, [handle]
int 0x40
pop ecx
pop ebx
ret
endp
align 4
proc _DestroyBuffer@4 stdcall, str:dword
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
push ecx
mov eax, [hSound]
lea ebx, [str]
xor ecx, ecx
mov [handle], eax
mov [io_code], SND_DESTROY_BUFF
mov [input], ebx
mov [inp_size], 4
mov [output], ecx
mov [out_size], ecx
mov eax, 68
mov ebx, 17
lea ecx, [handle]
int 0x40
pop ecx
pop ebx
ret
endp
align 4
proc _SetBuffer@16 stdcall,str:dword, src:dword, offs:dword, size:dword
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
push ecx
mov eax, [hSound]
lea ebx, [str]
xor ecx, ecx
mov [handle], eax
mov [io_code], SND_SETBUFF
mov [input], ebx
mov [inp_size], 16
mov [output], ecx
mov [out_size], ecx
mov eax, 68
mov ebx, 17
lea ecx, [handle]
int 0x40
pop ecx
pop ebx
ret
endp
align 4
proc _WaveOut@12 stdcall,str:dword, src:dword, size:dword
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
push ecx
mov eax, [hSound]
lea ebx, [str]
xor ecx, ecx
mov [handle], eax
mov [io_code], SND_OUT
mov [input], ebx
mov [inp_size], 12
mov [output], ecx
mov [out_size], ecx
mov eax, 68
mov ebx, 17
lea ecx, [handle]
int 0x40
pop ecx
pop ebx
ret
endp
align 4
proc _PlayBuffer@4 stdcall, str:dword
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
push ecx
mov eax, [hSound]
lea ebx, [str]
xor ecx, ecx
mov [handle], eax
mov [io_code], SND_PLAY
mov [input], ebx
mov [inp_size], 4
mov [output], ecx
mov [out_size], ecx
mov eax, 68
mov ebx, 17
lea ecx, [handle]
int 0x40
pop ecx
pop ebx
ret
endp
align 4
proc _StopBuffer@4 stdcall, str:dword
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
push ecx
mov eax, [hSound]
lea ebx, [str]
xor ecx, ecx
mov [handle], eax
mov [io_code], SND_STOP
mov [input], ebx
mov [inp_size], 4
mov [output], ecx
mov [out_size], ecx
mov eax, 68
mov ebx, 17
lea ecx, [handle]
int 0x40
pop ecx
pop ebx
ret
endp
align 4
proc _GetMasterVol@4 stdcall, pvol:dword
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
push ecx
mov eax, [hrdwSound]
mov ecx, [pvol]
xor ebx, ebx
mov [handle], eax
mov [io_code], DEV_GET_MASTERVOL
mov [input], ebx
mov [inp_size], ebx
mov [output], ecx
mov [out_size], 4
mov eax, 68
mov ebx, 17
lea ecx, [handle]
int 0x40
pop ecx
pop ebx
ret
endp
align 4
proc _SetMasterVol@4 stdcall,vol:dword
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
push ecx
mov eax, [hrdwSound]
lea ebx, [vol]
xor ecx, ecx
mov [handle], eax
mov [io_code], DEV_SET_MASTERVOL
mov [input], ebx
mov [inp_size], 4
mov [output], ecx
mov [out_size], ecx
mov eax, 68
mov ebx, 17
lea ecx, [handle]
int 0x40
pop ecx
pop ebx
ret
endp
if 0
align 4
proc _GetDevInfo@8 stdcall, hSrv:dword, p_info:dword
locals
handle dd ?
io_code dd ?
input dd ?
inp_size dd ?
output dd ?
out_size dd ?
endl
push ebx
mov eax, [hSrv]
xor ebx, ebx
mov ecx, [p_info]
mov [handle], eax
mov [io_code], DEV_GET_INFO
mov [input], ebx
mov [inp_size], ebx
mov [output], ecx
mov [out_size], CTRL_INFO_SIZE
lea eax, [handle]
stdcall CallServiceEx, eax
pop ebx
ret
endp
end if
section '.data' align 16 data readable writable
szInfinity db 'INFINITY',0
szSound db 'SOUND',0
align 4
hSound dd ?
hrdwSound dd ?

View File

@ -0,0 +1,170 @@
format MS COFF
include "snd.inc"
include "proc32.inc"
section '.text' align 16 code readable executable
public _test_wav@4
; convert WAVEHEADER into PCM_x_xx_xx constant
align 4
proc _test_wav@4 stdcall, hdr:dword
mov eax, [hdr]
cmp dword [eax], 0x46464952
jne .fail
cmp dword [eax+8], 0x45564157
jne .fail
cmp word [eax+20], 1
jne .fail
mov ecx, dword [eax+24]
mov edx, 22050
cmp ecx, edx
ja .high
je .l_22
cmp ecx, 8000
je .l_8
cmp ecx, 11025
je .l_11
cmp ecx, 12000
je .l_12
cmp ecx, 16000
je .l_16
.fail:
xor eax, eax
ret
.high:
cmp ecx, 24000
je .LN56
cmp ecx, 32000
je .LN65
cmp ecx, 44100
je .LN74
cmp ecx, 48000
jne .fail
movzx ecx, word [eax+22]
dec ecx
je .LN79
dec ecx
jne .LN74
mov edx, 19
jmp .done
.LN79:
mov edx, 20
jmp .done
.LN74:
movzx ecx, word [eax+22]
dec ecx
je .LN70
dec ecx
jne .LN65
mov edx, 21
jmp .done
.LN70:
mov edx, 22
jmp .done
.LN65:
movzx ecx, word [eax+22]
dec ecx
je .LN61
dec ecx
jne .LN56
mov edx, 23
jmp .done
.LN61:
mov edx, 24
jmp .done
.LN56:
movzx ecx, word [eax+22]
dec ecx
je .LN52
dec ecx
je .LN50
.l_22:
movzx ecx, word [eax+22]
dec ecx
je .LN43
dec ecx
je .LN41
.l_16:
movzx ecx, word [eax+22]
dec ecx
je .LN34
dec ecx
je .LN32
.l_12:
movzx ecx, word [eax+22]
dec ecx
je .LN25
dec ecx
je .LN23
.l_11:
movzx ecx, word [eax+22]
dec ecx
je .LN16
dec ecx
je .LN14
.l_8:
movzx ecx, word [eax+22]
dec ecx
je .LN7
dec ecx
jne .fail
mov edx, 35
jmp .done
.LN7:
mov edx, 36
jmp .done
.LN14:
mov edx, 33
jmp .done
.LN16:
mov edx, 34
jmp .done
.LN23:
mov edx, 31
jmp .done
.LN25:
mov edx, 32
jmp .done
.LN32:
mov edx, 29
jmp .done
.LN34:
mov edx, 30
jmp .done
.LN41:
mov edx, 27
jmp .done
.LN43:
mov edx, 28
jmp .done
.LN50:
mov edx, 25
jmp .done
.LN52:
mov edx, 26
.done:
xor ecx, ecx
cmp word [eax+34], 16
setne cl
dec ecx
and ecx, -18
add ecx, edx
mov eax, ecx
ret
endp