diff --git a/programs/media/ac97snd/trunk/ac97.sln b/programs/media/ac97snd/trunk/ac97.sln index 31c51b4fd4..388825189d 100644 --- a/programs/media/ac97snd/trunk/ac97.sln +++ b/programs/media/ac97snd/trunk/ac97.sln @@ -5,8 +5,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pe2kos", "pe2kos\pe2kos.vcp EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mp3dec", "mp3dec\mp3dec.vcproj", "{97BF69A3-826A-47D6-94E4-05FDD8CFF1FC}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pow_test", "pow_test\pow_test.vcproj", "{9FE40739-2ADC-4241-8182-20E1B3C661A7}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ac97", "ac97\ac97.vcproj", "{1C94A897-DA4F-45B2-B8A6-B97AD837828E}" ProjectSection(ProjectDependencies) = postProject {CF807B93-2860-41DF-A4D2-5B92B52DFD96} = {CF807B93-2860-41DF-A4D2-5B92B52DFD96} @@ -29,8 +27,6 @@ Global {97BF69A3-826A-47D6-94E4-05FDD8CFF1FC}.Debug|Win32.ActiveCfg = Debug|Win32 {97BF69A3-826A-47D6-94E4-05FDD8CFF1FC}.Release|Win32.ActiveCfg = Release|Win32 {97BF69A3-826A-47D6-94E4-05FDD8CFF1FC}.Release|Win32.Build.0 = Release|Win32 - {9FE40739-2ADC-4241-8182-20E1B3C661A7}.Debug|Win32.ActiveCfg = Debug|Win32 - {9FE40739-2ADC-4241-8182-20E1B3C661A7}.Release|Win32.ActiveCfg = Release|Win32 {1C94A897-DA4F-45B2-B8A6-B97AD837828E}.Debug|Win32.ActiveCfg = Debug|Win32 {1C94A897-DA4F-45B2-B8A6-B97AD837828E}.Release|Win32.ActiveCfg = Release|Win32 {1C94A897-DA4F-45B2-B8A6-B97AD837828E}.Release|Win32.Build.0 = Release|Win32 diff --git a/programs/media/ac97snd/trunk/ac97wav.c b/programs/media/ac97snd/trunk/ac97wav.c index 68c3df44dc..f4c38b5520 100644 --- a/programs/media/ac97snd/trunk/ac97wav.c +++ b/programs/media/ac97snd/trunk/ac97wav.c @@ -22,10 +22,13 @@ #define MP3_ERROR_OUT_OF_BUFFER 5 int m_last_error; -void thread_proc(); +void _stdcall thread_proc(void *param); +void _stdcall create_thread(void *proc, void *param, int stack_size); +void _stdcall send_ipc(int dst, DWORD code); + void touch(char *buf, int size); int mp3FindSync(byte* buf, int size, int* sync); -int stream_read_raw(struct reader *rd,unsigned char *buf, int size); +int stream_read_raw(struct reader *rd,unsigned char *buf, int size); char *fname; @@ -41,8 +44,8 @@ CTRL_INFO info; FILEINFO fileinfo; int m_vol; -int l_vol=-500; -int r_vol=-500; +int l_vol=-700; //-7db +int r_vol=-700; int pan =0; DWORD status; @@ -110,28 +113,32 @@ void debug_out_str(char* str) } int main(int argc, char *argv[]) //int argc, char *argv[]) -{ DWORD fmt; - char *thread_stack; +{ + DWORD fmt; DWORD r_bytes; int retval; int err; int ver; fname = argv[1]; - //debug_out_str(fname); + debug_out_str("\n\rPlay file "); + debug_out_str(fname); + debug_out_str("\n\r"); InitHeap(1024*1024); if(get_fileinfo(fname, &fileinfo)==FILE_NOT_FOUND) + { debug_out_str("\n\rfile not found\n\r"); return 0; + }; - if(err = InitSound(&ver)) { debug_out_str("Sound service not installed\n\r"); return 0; } - if( ver != SOUND_VERSION) + if( (SOUND_VERSION>(ver&0xFFFF)) || + (SOUND_VERSION<(ver >> 16))) { debug_out_str("Sound service version mismatch\n\r"); return 0; @@ -176,14 +183,13 @@ int main(int argc, char *argv[]) //int argc, char *argv[]) if (err = CreateBuffer(fmt,0, &hBuff)) { debug_out_str("create buffer return error\n\r"); - return 0; + ; return 0; } SetVolume(hBuff,l_vol,r_vol); - thread_stack = UserAlloc(4096); - thread_stack+=4092; + GetVolume(hBuff,&l_vol,&r_vol); - CreateThread(thread_proc, thread_stack); + create_thread(thread_proc, 0, 4096); while(1) { delay(10); @@ -250,7 +256,7 @@ void play_mp3() int outcount; // memset(&fr,0,sizeof(fr)); - fr.down_sample_sblimit = 32; + fr.down_sample_sblimit = 32; fr.single = -1; reset_mpg(); @@ -289,17 +295,6 @@ void play_mp3() else if(totalout < 8192) continue; -/* - _asm - { push edx - push eax - mov eax, 0xFF - mov edx, 0x400 - out dx, al - pop eax - pop edx - }; -*/ outPtr = outbuf; while (totalout >= 4096) { @@ -351,7 +346,7 @@ void snd_stop() StopBuffer(hBuff); }; -void thread_proc() +void _stdcall thread_proc(void *param) { int evnt; int pos; int key; diff --git a/programs/media/ac97snd/trunk/ac97wav.h b/programs/media/ac97snd/trunk/ac97wav.h index 2d4379c4ce..65d05e1321 100644 --- a/programs/media/ac97snd/trunk/ac97wav.h +++ b/programs/media/ac97snd/trunk/ac97wav.h @@ -14,28 +14,11 @@ // GNU General Public License for more details. -#define ST_DONE 0x0 -#define ST_PLAY 0x1 -#define ST_EXIT 0x2 -#define ST_STOP 0x4 +#define ST_DONE 0x0 +#define ST_PLAY 0x1 +#define ST_EXIT 0x2 +#define ST_STOP 0x4 -typedef struct -{ DWORD riff_id; - DWORD riff_size; - DWORD riff_format; - - DWORD fmt_id; - DWORD fmt_size; - - WORD wFormatTag; - WORD nChannels; - DWORD nSamplesPerSec; - DWORD nAvgBytesPerSec; - WORD nBlockAlign; - WORD wBitsPerSample; - DWORD data_id; - DWORD data_size; -} WAVEHEADER; DWORD test_mp3(char *buf); diff --git a/programs/media/ac97snd/trunk/k_lib.asm b/programs/media/ac97snd/trunk/k_lib.asm index 6e12be0897..fd0604e2b8 100644 --- a/programs/media/ac97snd/trunk/k_lib.asm +++ b/programs/media/ac97snd/trunk/k_lib.asm @@ -18,6 +18,8 @@ public _draw_bar@20 public _write_text@20 public _debug_out@4 public _debug_out_hex@4 +public _create_thread@12 + public _memset @@ -31,6 +33,49 @@ struc FILEIO .name dd ? }; +align 4 +_create_thread@12: +.thr_proc equ esp+4 +.param equ esp+8 +.stack_size equ esp+12 + + mov eax, 68 + mov ebx, 12 + mov ecx, [.stack_size] + add ecx, 4095 + and ecx, -4096 + int 0x40 + test eax, eax + jz .fail + + lea edx, [eax+ecx-12] + mov [edx], dword .exit_point + mov ebx, [.param] + mov [edx+4], ebx + mov [edx+8], ecx + + mov eax, 51 + mov ebx, 1 + mov ecx, [.thr_proc] + int 0x40 + ret 12 +.fail: + not eax + ret 12 +align 4 +.exit_point: + pop ecx + mov eax, 68 + mov ebx, 13 + int 0x40 + mov eax, -1 + int 0x40 + +restore .thr_proc +restore .param +restore .stack_size + + align 4 proc _get_button_id mov eax,17 @@ -158,7 +203,7 @@ endp align 4 proc _GetMousePos@4 stdcall,rel_type:dword - push ebx + push ebx mov eax, 37 mov ebx, [rel_type] int 0x40 @@ -170,7 +215,7 @@ endp align 4 proc _DrawWindow@36 stdcall, x:dword, y:dword, sx:dword, sy:dword,\ workcolor:dword, style:dword, captioncolor:dword,\ - windowtype:dword, bordercolor:dword + windowtype:dword, bordercolor:dword push ebx edi esi mov ebx, [x] mov ecx, [y] @@ -199,7 +244,7 @@ _make_button@24: ;arg4 - ysize ;arg5 - id ;arg6 - color - + push ebx esi mov ebx,[esp+12] shl ebx,16 @@ -261,7 +306,7 @@ proc _debug_out@4 stdcall, val:dword int 0x40 pop ebx ret -endp +endp align 4 proc _debug_out_hex@4 stdcall val:dword @@ -282,29 +327,29 @@ proc _debug_out_hex@4 stdcall val:dword jnz .new_char ret endp - + align 4 _memset: mov edx,[esp + 0ch] - mov ecx,[esp + 4] + mov ecx,[esp + 4] + + test edx,edx + jz short toend - test edx,edx - jz short toend - xor eax,eax mov al,[esp + 8] - push edi - mov edi,ecx + push edi + mov edi,ecx cmp edx,4 - jb tail - + jb tail + neg ecx - and ecx,3 - jz short dwords - - sub edx,ecx + and ecx,3 + jz short dwords + + sub edx,ecx adjust_loop: mov [edi],al add edi,1 @@ -312,66 +357,66 @@ adjust_loop: jnz adjust_loop dwords: - mov ecx,eax - shl eax,8 - add eax,ecx - mov ecx,eax - shl eax,10h - add eax,ecx - - mov ecx,edx - and edx,3 - shr ecx,2 - jz tail + mov ecx,eax + shl eax,8 + add eax,ecx + mov ecx,eax + shl eax,10h + add eax,ecx - cld + mov ecx,edx + and edx,3 + shr ecx,2 + jz tail + + cld rep stosd main_loop_tail: - test edx,edx - jz finish + test edx,edx + jz finish tail: - mov [edi],al + mov [edi],al add edi,1 - sub edx,1 - jnz tail + sub edx,1 + jnz tail finish: - mov eax,[esp + 8] - pop edi + mov eax,[esp + 8] + pop edi ret toend: - mov eax,[esp + 4] + mov eax,[esp + 4] ret public _allmul -_allmul: +_allmul: mov eax, [esp+8] mov ecx, [esp+16] - or ecx,eax + or ecx,eax mov ecx, [esp+12] - jnz .hard + jnz .hard mov eax, [esp+4] mul ecx - ret 16 + ret 16 .hard: push ebx - mul ecx + mul ecx mov ebx,eax mov eax, [esp+8] mul dword [esp+20] - add ebx,eax + add ebx,eax mov eax,[esp+8] - mul ecx - add edx,ebx + mul ecx + add edx,ebx pop ebx - ret 16 + ret 16 align 4 _allshr: @@ -410,7 +455,7 @@ __ftol2_sse: mov eax, [esp+10] test eax, eax jz .QnaNZ - + .not_QnaNZ: fsubp st1, st0 test edx, edx @@ -435,13 +480,13 @@ __ftol2_sse: jne .not_QnaNZ fstp dword [esp+18] fstp dword [esp+18] -.exit: +.exit: leave ret public __fltused __fltused dd 0 - + align 4 __hexdigits db '0123456789ABCDEF' diff --git a/programs/media/ac97snd/trunk/kolibri.h b/programs/media/ac97snd/trunk/kolibri.h index 4685d26c3d..d2898ab88a 100644 --- a/programs/media/ac97snd/trunk/kolibri.h +++ b/programs/media/ac97snd/trunk/kolibri.h @@ -4,6 +4,7 @@ extern "C" { #endif + #define FONT0 0x00000000 #define FONT1 0x10000000 @@ -15,6 +16,7 @@ extern "C" #define EV_REDRAW 1 #define EV_KEY 2 #define EV_BUTTON 3 +#define EV_IPC 7 #define REL_SCREEN 0 #define REL_WINDOW 1 @@ -22,9 +24,9 @@ extern "C" #define FILE_NOT_FOUND 5 #define FILE_EOF 6 + typedef unsigned int DWORD; typedef unsigned short int WORD; -typedef unsigned int size_t; typedef struct { DWORD pci_cmd; @@ -61,26 +63,37 @@ typedef struct DWORD size_high; } FILEINFO; -void _stdcall InitHeap(size_t heap_size); -void* _stdcall UserAlloc(size_t size); +void _stdcall InitHeap(int heap_size); +void* _stdcall UserAlloc(int size); +int _stdcall UserFree(void* p); + +void _stdcall GetNotify(void *event); void _stdcall CreateThread(void *fn, char *p_stack); + DWORD _stdcall GetMousePos(DWORD rel_type); void _stdcall debug_out_hex(DWORD val); void debug_out_str(char* str); -int _stdcall get_fileinfo(char *name,FILEINFO* pinfo); -int _stdcall read_file (char *name,char*buff,int offset,int count,int *reads); +int _stdcall get_fileinfo(const char *name,FILEINFO* pinfo); +int _stdcall create_file(const char *name); +int _stdcall read_file (const char *name,char*buff,DWORD offset, DWORD count,DWORD *reads); +int _stdcall write_file(const char *name,char*buff,int offset,int count,int *writes); -void exit(); +//void exit(); int _stdcall get_key(int *key); +int _stdcall remap_key(int key); + int _cdecl get_button_id(); + void delay(int val); int wait_for_event(int time); int wait_for_event_infinite(); void BeginDraw(void); void EndDraw(void); + +void _stdcall GetScreenSize(int *x, int*y); void _stdcall DrawWindow(int x,int y, int sx, int sy,int workcolor,int style, int captioncolor,int windowtype,int bordercolor); void _stdcall debug_out(int ch); diff --git a/programs/media/ac97snd/trunk/sound.h b/programs/media/ac97snd/trunk/sound.h new file mode 100644 index 0000000000..430c210e36 --- /dev/null +++ b/programs/media/ac97snd/trunk/sound.h @@ -0,0 +1,133 @@ + +#ifndef _SOUND_H_ +#define _SOUND_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define SOUND_VERSION 0x0100 +#define PCM_ALL 0 + +#define PCM_OUT 0x08000000 +#define PCM_RING 0x10000000 +#define PCM_STATIC 0x20000000 +#define PCM_FLOAT 0x40000000 +#define PCM_FILTER 0x80000000 + +#define PCM_2_16_48 1 +#define PCM_1_16_48 2 +#define PCM_2_16_44 3 +#define PCM_1_16_44 4 +#define PCM_2_16_32 5 +#define PCM_1_16_32 6 +#define PCM_2_16_24 7 +#define PCM_1_16_24 8 +#define PCM_2_16_22 9 +#define PCM_1_16_22 10 +#define PCM_2_16_16 11 +#define PCM_1_16_16 12 +#define PCM_2_16_12 13 +#define PCM_1_16_12 14 +#define PCM_2_16_11 15 +#define PCM_1_16_11 16 +#define PCM_2_16_8 17 +#define PCM_1_16_8 18 +#define PCM_2_8_48 19 +#define PCM_1_8_48 20 +#define PCM_2_8_44 21 +#define PCM_1_8_44 22 +#define PCM_2_8_32 23 +#define PCM_1_8_32 24 +#define PCM_2_8_24 25 +#define PCM_1_8_24 26 +#define PCM_2_8_22 27 +#define PCM_1_8_22 28 +#define PCM_2_8_16 29 +#define PCM_1_8_16 30 +#define PCM_2_8_12 31 +#define PCM_1_8_12 32 +#define PCM_2_8_11 33 +#define PCM_1_8_11 34 +#define PCM_2_8_8 35 +#define PCM_1_8_8 36 + +#define SRV_GETVERSION 0 +#define SND_CREATE_BUFF 1 +#define SND_DESTROY_BUFF 2 +#define SND_SETFORMAT 3 +#define SND_GETFORMAT 4 +#define SND_RESET 5 +#define SND_SETPOS 6 +#define SND_GETPOS 7 +#define SND_SETBUFF 8 +#define SND_OUT 9 +#define SND_PLAY 10 +#define SND_STOP 11 +#define SND_SETVOLUME 12 +#define SND_GETVOLUME 13 +#define SND_SETPAN 14 +#define SND_GETPAN 15 +#define SND_GETBUFFSIZE 16 + +#define PLAY_SYNC 0x80000000 + +typedef unsigned int SNDBUF; + +int _stdcall InitSound(int *version); + +int _stdcall CreateBuffer(unsigned int format,int size,SNDBUF *buf); +int _stdcall DestroyBuffer(SNDBUF hBuff); + +int _stdcall SetFormat(SNDBUF hBuff, unsigned int format); +int _stdcall GetFormat(SNDBUF hBuff, unsigned int *format); + +int _stdcall ResetBuffer(SNDBUF hBuff, unsigned int flags); +int _stdcall SetBufferPos(SNDBUF hBuff, int offset); +int _stdcall GetBufferPos(SNDBUF hBuff, int *offset); +int _stdcall GetBufferSize(SNDBUF hBuff, int *size); + +int _stdcall SetBuffer(SNDBUF hBuff,void* buff, + int offs, int size); +int _stdcall WaveOut(SNDBUF hBuff,void *buff, int size); +int _stdcall PlayBuffer(SNDBUF hBuff,unsigned int flags); +int _stdcall StopBuffer(SNDBUF hBuff); + +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 GetPan(SNDBUF hBuff, int *pan); + +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" +} +#endif + +#endif //_SOUND_H_