Subversion Repositories Kolibri OS

Rev

Rev 5253 | Blame | Last modification | View Log | Download | RSS feed

  1. struc CTRL_INFO
  2. {   .pci_cmd        dd  ?
  3.     .irq            dd  ?
  4.     .glob_cntrl     dd  ?
  5.     .glob_sta       dd  ?
  6.     .codec_io_base  dd  ?
  7.     .ctrl_io_base   dd  ?
  8.     .codec_mem_base dd  ?
  9.     .ctrl_mem_base  dd  ?
  10.     .codec_id       dd  ?
  11. }
  12. CTRL_INFO_SIZE          equ 9*4
  13.  
  14. SRV_GETVERSION          equ 0
  15. SND_CREATE_BUFF         equ 1
  16. SND_DESTROY_BUFF        equ 2
  17. SND_SETFORMAT           equ 3
  18. SND_GETFORMAT           equ 4
  19. SND_RESET               equ 5
  20. SND_SETPOS              equ 6
  21. SND_GETPOS              equ 7
  22. SND_SETBUFF             equ 8
  23. SND_OUT                 equ 9
  24. SND_PLAY                equ 10
  25. SND_STOP                equ 11
  26. SND_SETVOLUME           equ 12
  27. SND_GETVOLUME           equ 13
  28. SND_SETPAN              equ 14
  29. SND_GETPAN              equ 15
  30. SND_GETBUFFSIZE         equ 16
  31. SND_GETFREESPACE        equ 17
  32. SND_SETTIMEBASE         equ 18
  33. SND_GETTIMESTAMP        equ 19
  34.  
  35. DEV_SET_BUFF            equ  4
  36. DEV_NOTIFY              equ  5
  37. DEV_SET_MASTERVOL       equ  6
  38. DEV_GET_MASTERVOL       equ  7
  39. DEV_GET_INFO            equ  8
  40.  
  41. SOUND_VERSION   equ 0x0101
  42. PCM_ALL         equ 0
  43.  
  44. PCM_OUT         equ 0x08000000
  45. PCM_RING        equ 0x10000000
  46. PCM_STATIC      equ 0x20000000
  47. PCM_FLOAT       equ 0x40000000
  48. PCM_FILTER      equ 0x80000000
  49.  
  50. PCM_2_16_48     equ 1
  51. PCM_1_16_48     equ 2
  52. PCM_2_16_44     equ 3
  53. PCM_1_16_44     equ 4
  54. PCM_2_16_32     equ 5
  55. PCM_1_16_32     equ 6
  56. PCM_2_16_24     equ 7
  57. PCM_1_16_24     equ 8
  58. PCM_2_16_22     equ 9
  59. PCM_1_16_22     equ 10
  60. PCM_2_16_16     equ 11
  61. PCM_1_16_16     equ 12
  62. PCM_2_16_12     equ 13
  63. PCM_1_16_12     equ 14
  64. PCM_2_16_11     equ 15
  65. PCM_1_16_11     equ 16
  66. PCM_2_16_8      equ 17
  67. PCM_1_16_8      equ 18
  68. PCM_2_8_48      equ 19
  69. PCM_1_8_48      equ 20
  70. PCM_2_8_44      equ 21
  71. PCM_1_8_44      equ 22
  72. PCM_2_8_32      equ 23
  73. PCM_1_8_32      equ 24
  74. PCM_2_8_24      equ 25
  75. PCM_1_8_24      equ 26
  76. PCM_2_8_22      equ 27
  77. PCM_1_8_22      equ 28
  78. PCM_2_8_16      equ 29
  79. PCM_1_8_16      equ 30
  80. PCM_2_8_12      equ 31
  81. PCM_1_8_12      equ 32
  82. PCM_2_8_11      equ 33
  83. PCM_1_8_11      equ 34
  84. PCM_2_8_8       equ 35
  85. PCM_1_8_8       equ 36
  86.  
  87. ; i_data
  88. szInfinity      db 'INFINITY',0
  89. szSound         db 'SOUND',0
  90. ; u_data
  91. hSound          dd ?
  92. hrdwSound       dd ?
  93. ;------------------------------------------------------------------------------
  94. align 4
  95. _InitSound@4:       ;p_ver:dword
  96.        
  97.         push    ebx ecx
  98.         mcall   68,16,szInfinity
  99.         mov     [hSound],eax
  100.         test    eax,eax
  101.         jz      .fail
  102.        
  103.         mcall   68,16,szSound
  104.         mov     [hrdwSound],eax
  105.         test    eax,eax
  106.         jz      .fail
  107.        
  108.         lea     eax,[esp+12]   ;p_ver
  109.         xor     ebx,ebx
  110.        
  111.         push    4              ;.out_size
  112.         push    eax            ;.output
  113.         push    ebx            ;.inp_size
  114.         push    ebx            ;.input
  115.         push    SRV_GETVERSION ;.code
  116.         push    [hSound]       ;.handle
  117.        
  118.         mov     ecx,esp        ;[handle]
  119.         mcall   68,17
  120.         add     esp,24
  121.         jmp     .exit
  122. ;--------------------------------------
  123. align 4
  124. .fail:
  125.         or      eax, -1
  126. ;--------------------------------------
  127. align 4
  128. .exit:
  129.         pop     ecx ebx
  130.         ret     4
  131. ;------------------------------------------------------------------------------
  132. align 4
  133. _CreateBuffer@12:   ;format:dword,size:dword,p_str:dword
  134.         push    ebx ecx
  135.         lea     eax,[esp+20]   ;p_str
  136.         lea     ebx,[esp+12]   ;format
  137.  
  138.         push    4              ;.out_size
  139.         push    eax            ;.output
  140.         push    8              ;.inp_size
  141.         push    ebx            ;.input
  142.         push    SND_CREATE_BUFF;.code
  143.         push    [hSound]       ;.handle
  144.  
  145.         mov     ecx,esp
  146.         mcall   68,17
  147.         add     esp,24       ;io_cintrol
  148.         pop     ecx ebx
  149.         ret     12
  150. ;------------------------------------------------------------------------------
  151. ;align 4
  152. ;_DestroyBuffer@4:     ;str:dword
  153. ;       push    ebx ecx
  154. ;       xor     eax,eax
  155. ;       lea     ebx,[esp+12]   ;[stream]
  156. ;      
  157. ;       push    eax            ;.out_size
  158. ;       push    eax            ;.output
  159. ;       push    4              ;.inp_size
  160. ;       push    ebx            ;.input
  161. ;       push    SND_DESTROY_BUFF;.code
  162. ;       push    [hSound]       ;.handle
  163. ;      
  164. ;       mov     ecx, esp        ;[handle]
  165. ;       mcall   68,17
  166. ;       add     esp,24
  167. ;       pop     ecx ebx
  168. ;       ret     4
  169. ;------------------------------------------------------------------------------
  170. ;align 4
  171. ;_WaveOut@12:        ;str:dword, src:dword, size:dword
  172. ;       push    ebx ecx
  173. ;       xor     eax,eax
  174. ;       lea     ebx,[esp+12]   ;[stream]
  175. ;      
  176. ;       push    eax            ;.out_size
  177. ;       push    eax            ;.output
  178. ;       push    12             ;.inp_size
  179. ;       push    ebx            ;.input
  180. ;       push    SND_OUT        ;.code
  181. ;       push    dword [hSound] ;.handle
  182. ;      
  183. ;       mov     ecx,esp
  184. ;       mcall   68,17
  185. ;       add     esp,24
  186. ;       pop     ecx ebx
  187. ;       ret     12
  188. ;------------------------------------------------------------------------------
  189. align 4
  190. _GetBufferSize@8:      ;str:dword, p_size:dword
  191.         push    ebx ecx
  192.         lea     eax,[esp+16]
  193.         lea     ebx,[esp+12]   ;[stream]
  194.        
  195.         push    4              ;.out_size
  196.         push    eax            ;.output
  197.         push    4              ;.inp_size
  198.         push    ebx            ;.input
  199.         push    SND_GETBUFFSIZE;.code
  200.         push    dword [hSound] ;.handle
  201.        
  202.         mov     ecx,esp
  203.         mcall   68,17
  204.         add     esp,24
  205.         pop     ecx ebx
  206.         ret     8
  207. ;------------------------------------------------------------------------------          
  208. ;align 4
  209. ;_GetBufferFree@8:      ;str:dword, p_free:dword
  210. ;       push    ebx ecx
  211. ;       lea     ebx,[esp+12]      ;[stream]
  212. ;       push    0                 ;storage for free_space    
  213. ;       mov     eax,esp
  214. ;      
  215. ;       push    4                 ;.out_size
  216. ;       push    eax               ;.output
  217. ;       push    4                 ;.inp_size
  218. ;       push    ebx               ;.input
  219. ;       push    SND_GETFREESPACE  ;.code
  220. ;       push    dword [hSound]    ;.handle
  221. ;      
  222. ;       mov     ecx,esp
  223. ;       mcall   68,17
  224. ;       add     esp, 24
  225. ;       mov     ecx,[esp+20]      ; p_free  
  226. ;       pop     dword [ecx]
  227. ;       pop     ecx ebx
  228. ;       ret     8
  229. ;------------------------------------------------------------------------------
  230. align 4
  231. _SetBuffer@16:   ;str:dword, src:dword, offs:dword, size:dword
  232.         push    ebx ecx
  233.         xor     eax,eax
  234.         lea     ebx,[esp+12]   ;[stream]
  235.  
  236.         push    eax            ;.out_size
  237.         push    eax            ;.output
  238.         push    16             ;.inp_size
  239.         push    ebx            ;.input
  240.         push    SND_SETBUFF    ;.code
  241.         push    dword [hSound] ;.handle
  242.  
  243.         mov     ecx,esp
  244.         mcall   68,17
  245.         add     esp,24
  246.         pop     ecx ebx
  247.         ret     16
  248. ;------------------------------------------------------------------------------
  249. align 4
  250. _PlayBuffer@8:          ;str:dword,flags:dword
  251.         push    ebx ecx
  252.         xor     eax,eax
  253.         lea     ebx,[esp+12]   ;[stream]
  254.        
  255.         push    eax            ;.out_size
  256.         push    eax            ;.output
  257.         push    8              ;.inp_size
  258.         push    ebx            ;.input
  259.         push    SND_PLAY       ;.code
  260.         push    dword [hSound] ;.handle
  261.  
  262.         mov     ecx, esp
  263.         mcall   68,17
  264.         add     esp, 24
  265.         pop     ecx ebx
  266.         ret     8
  267. ;------------------------------------------------------------------------------
  268. align 4
  269. _StopBuffer@4:          ;str:dword
  270.         push    ebx ecx
  271.         xor     eax,eax
  272.         lea     ebx,[esp+12]   ;[stream]
  273.        
  274.         push    eax            ;.out_size
  275.         push    eax            ;.output
  276.         push    4              ;.inp_size
  277.         push    ebx            ;.input
  278.         push    SND_STOP       ;.code
  279.         push    dword [hSound] ;.handle
  280.        
  281.         mov     ecx,esp
  282.         mcall   68,17
  283.         add     esp,24
  284.         pop     ecx ebx
  285.         ret     4
  286. ;------------------------------------------------------------------------------
  287. ;align 4
  288. ;_GetBufferPos@8:     ;str:dword, p_pos:dword
  289. ;       push    ebx ecx
  290. ;       lea     eax,[esp+16]
  291. ;       lea     ebx,[esp+12]   ;[stream]
  292. ;      
  293. ;       push    4              ;.out_size
  294. ;       push    eax            ;.output
  295. ;       push    4              ;.inp_size
  296. ;       push    ebx            ;.input
  297. ;       push    SND_GETPOS     ;.code
  298. ;       push    dword [hSound] ;.handle
  299. ;      
  300. ;       mov     ecx,esp
  301. ;       mcall   68,17
  302. ;       add     esp,24
  303. ;       pop     ecx ebx
  304. ;       ret     8
  305. ;------------------------------------------------------------------------------
  306. ;align 4
  307. ;_SetBufferPos@8:        ;str:dword, offs:dword
  308. ;       push    ebx ecx
  309. ;       xor     eax,eax
  310. ;       lea     ebx,[esp+12]   ;[stream]
  311. ;      
  312. ;       push    eax            ;.out_size
  313. ;       push    eax            ;.output
  314. ;       push    8              ;.inp_size
  315. ;       push    ebx            ;.input
  316. ;       push    SND_SETPOS     ;.code
  317. ;       push    dword [hSound] ;.handle
  318. ;      
  319. ;       mov     ecx,esp
  320. ;       mcall   68,17
  321. ;       add     esp,24
  322. ;       pop     ecx ebx
  323. ;       ret     8
  324. ;------------------------------------------------------------------------------
  325. align 4
  326. proc _test_wav@4 stdcall, hdr:dword
  327.         mov     eax,[hdr]
  328.         cmp     dword [eax],0x46464952
  329.         jne     .fail
  330.        
  331.         cmp     dword [eax+8],0x45564157
  332.         jne     .fail
  333.        
  334.         cmp     word [eax+20],1
  335.         jne     .fail
  336.        
  337.         mov     ecx,dword [eax+24]
  338.         mov     edx,22050
  339.         cmp     ecx,edx
  340.         ja      .high
  341.         je      .l_22
  342.        
  343.         cmp     ecx,8000
  344.         je      .l_8
  345.        
  346.         cmp     ecx,11025
  347.         je      .l_11
  348.        
  349.         cmp     ecx,12000
  350.         je      .l_12
  351.        
  352.         cmp     ecx,16000
  353.         je      .l_16
  354. ;--------------------------------------
  355. align 4
  356. .fail:
  357.         xor     eax,eax
  358.         ret
  359. ;--------------------------------------
  360. align 4
  361. .high:
  362.         cmp     ecx,24000
  363.         je      .LN56
  364.  
  365.         cmp     ecx,32000
  366.         je      .LN65
  367.  
  368.         cmp     ecx,44100
  369.         je      .LN74
  370.  
  371.         cmp     ecx,48000
  372.         jne     .fail
  373.        
  374.         movzx   ecx,word [eax+22]
  375.         dec     ecx
  376.         je      .LN79
  377.  
  378.         dec     ecx
  379.         jne     .LN74
  380.        
  381.         mov     edx,19
  382.         jmp     .done
  383. ;--------------------------------------
  384. align 4
  385. .LN79:
  386.         mov     edx,20
  387.         jmp     .done
  388. ;--------------------------------------
  389. align 4
  390. .LN74:
  391.         movzx   ecx,word [eax+22]
  392.         dec     ecx
  393.         je      .LN70
  394.  
  395.         dec     ecx
  396.         jne     .LN65
  397.        
  398.         mov     edx,21
  399.         jmp     .done
  400. ;--------------------------------------
  401. align 4
  402. .LN70:
  403.         mov     edx,22
  404.         jmp     .done
  405. ;--------------------------------------
  406. align 4
  407. .LN65:
  408.         movzx   ecx,word [eax+22]
  409.         dec     ecx
  410.         je      .LN61
  411.  
  412.         dec     ecx
  413.         jne     .LN56
  414.        
  415.         mov     edx,23
  416.         jmp     .done
  417. ;--------------------------------------
  418. align 4
  419. .LN61:
  420.         mov     edx,24
  421.         jmp     .done
  422. ;--------------------------------------
  423. align 4
  424. .LN56:
  425.         movzx   ecx,word [eax+22]
  426.         dec     ecx
  427.         je      .LN52
  428.  
  429.         dec     ecx
  430.         je      .LN50
  431. ;--------------------------------------
  432. align 4
  433. .l_22:
  434.         movzx   ecx,word [eax+22]
  435.         dec     ecx
  436.         je      .LN43
  437.  
  438.         dec     ecx
  439.         je      .LN41
  440. ;--------------------------------------
  441. align 4
  442. .l_16:
  443.         movzx   ecx,word [eax+22]
  444.         dec     ecx
  445.         je      .LN34
  446.  
  447.         dec     ecx
  448.         je      .LN32
  449. ;--------------------------------------
  450. align 4
  451. .l_12:
  452.         movzx   ecx,word [eax+22]
  453.         dec     ecx
  454.         je      .LN25
  455.  
  456.         dec     ecx
  457.         je      .LN23
  458. ;--------------------------------------
  459. align 4
  460. .l_11:
  461.         movzx   ecx,word [eax+22]
  462.         dec     ecx
  463.         je      .LN16
  464.  
  465.         dec     ecx
  466.         je      .LN14
  467. ;--------------------------------------
  468. align 4
  469. .l_8:
  470.         movzx   ecx,word [eax+22]
  471.         dec     ecx
  472.         je      .LN7
  473.  
  474.         dec     ecx
  475.         jne     .fail
  476.        
  477.         mov     edx,35
  478.         jmp     .done
  479. ;--------------------------------------
  480. align 4
  481. .LN7:
  482.         mov     edx,36
  483.         jmp     .done
  484. ;--------------------------------------
  485. align 4
  486. .LN14:
  487.         mov     edx,33
  488.         jmp     .done
  489. ;--------------------------------------
  490. align 4
  491. .LN16:
  492.         mov     edx,34
  493.         jmp     .done
  494. ;--------------------------------------
  495. align 4
  496. .LN23:
  497.         mov     edx,31
  498.         jmp     .done
  499. ;--------------------------------------
  500. align 4
  501. .LN25:
  502.         mov     edx,32
  503.         jmp     .done
  504. ;--------------------------------------
  505. align 4
  506. .LN32:
  507.         mov     edx,29
  508.         jmp     .done
  509. ;--------------------------------------
  510. align 4
  511. .LN34:
  512.         mov     edx,30
  513.         jmp     .done
  514. ;--------------------------------------
  515. align 4
  516. .LN41:
  517.         mov     edx,27
  518.         jmp     .done
  519. ;--------------------------------------
  520. align 4
  521. .LN43:
  522.         mov     edx,28
  523.         jmp     .done
  524. ;--------------------------------------
  525. align 4
  526. .LN50:
  527.         mov     edx,25
  528.         jmp     .done
  529. ;--------------------------------------
  530. align 4
  531. .LN52:
  532.         mov     edx,26
  533. ;--------------------------------------
  534. align 4
  535. .done:
  536.         xor     ecx,ecx
  537.         cmp     word [eax+34],16
  538.         setne   cl
  539.         dec     ecx
  540.         and     ecx,-18
  541.         add     ecx,edx
  542.         mov     eax,ecx
  543.         ret
  544. endp
  545. ;------------------------------------------------------------------------------