Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. /*
  3.  * Author: JohnXenox aka Aleksandr Igorevich.
  4.  *
  5.  * PlayNote_lib2.h
  6. */
  7.  
  8. #ifndef __PlayNote_lib2_h__
  9. #define __PlayNote_lib2_h__
  10.  
  11. /*
  12. struct CTRL_INFO
  13. {   int  pci_cmd;
  14.     int  irq;
  15.     int  glob_cntrl;
  16.     int  glob_sta;
  17.     int  codec_io_base;
  18.     int  ctrl_io_base;
  19.     int  codec_mem_base;
  20.     int  ctrl_mem_base;
  21.     int  codec_id;
  22. };
  23. #define  CTRL_INFO_SIZE     (9*4)
  24. */
  25.  
  26. //====================================//
  27.  
  28. #define  SRV_GETVERSION     0
  29. #define  SND_CREATE_BUFF    1
  30. #define  SND_DESTROY_BUFF   2
  31. #define  SND_SETFORMAT      3
  32. #define  SND_GETFORMAT      4
  33. #define  SND_RESET          5
  34. #define  SND_SETPOS         6
  35. #define  SND_GETPOS         7
  36. #define  SND_SETBUFF        8
  37. #define  SND_OUT            9
  38. #define  SND_PLAY          10
  39. #define  SND_STOP          11
  40. #define  SND_SETVOLUME     12
  41. #define  SND_GETVOLUME     13
  42. #define  SND_SETPAN        14
  43. #define  SND_GETPAN        15
  44. #define  SND_GETBUFFSIZE   16
  45. #define  SND_GETFREESPACE  17
  46. #define  SND_SETTIMEBASE   18
  47. #define  SND_GETTIMESTAMP  19
  48.  
  49.  
  50. #define  DEV_SET_BUFF       4
  51. #define  DEV_NOTIFY         5
  52. #define  DEV_SET_MASTERVOL  6
  53. #define  DEV_GET_MASTERVOL  7
  54. #define  DEV_GET_INFO       8
  55.  
  56. //====================================//
  57.  
  58. #define  SOUND_VERSION 0x0101
  59. #define  PCM_ALL       0
  60.  
  61. #define  PCM_OUT     0x08000000
  62. #define  PCM_RING    0x10000000
  63. #define  PCM_STATIC  0x20000000
  64. #define  PCM_FLOAT   0x40000000
  65. #define  PCM_FILTER  0x80000000
  66.  
  67. #define  PCM_2_16_48   1
  68. #define  PCM_1_16_48   2
  69. #define  PCM_2_16_44   3
  70. #define  PCM_1_16_44   4
  71. #define  PCM_2_16_32   5
  72. #define  PCM_1_16_32   6
  73. #define  PCM_2_16_24   7
  74. #define  PCM_1_16_24   8
  75. #define  PCM_2_16_22   9
  76. #define  PCM_1_16_22  10
  77. #define  PCM_2_16_16  11
  78. #define  PCM_1_16_16  12
  79. #define  PCM_2_16_12  13
  80. #define  PCM_1_16_12  14
  81. #define  PCM_2_16_11  15
  82. #define  PCM_1_16_11  16
  83. #define  PCM_2_16_8   17
  84. #define  PCM_1_16_8   18
  85. #define  PCM_2_8_48   19
  86. #define  PCM_1_8_48   20
  87. #define  PCM_2_8_44   21
  88. #define  PCM_1_8_44   22
  89. #define  PCM_2_8_32   23
  90. #define  PCM_1_8_32   24
  91. #define  PCM_2_8_24   25
  92. #define  PCM_1_8_24   26
  93. #define  PCM_2_8_22   27
  94. #define  PCM_1_8_22   28
  95. #define  PCM_2_8_16   29
  96. #define  PCM_1_8_16   30
  97. #define  PCM_2_8_12   31
  98. #define  PCM_1_8_12   32
  99. #define  PCM_2_8_11   33
  100. #define  PCM_1_8_11   34
  101. #define  PCM_2_8_8    35
  102. #define  PCM_1_8_8    36
  103.  
  104. //====================================//
  105.  
  106. const char szInfinity[] = "INFINITY";
  107. const char szSound[]    = "SOUND";
  108.  
  109. int *hSound = 0;
  110. int *hrdwSound = 0;
  111.  
  112. struct MNG_DRV
  113. {
  114.     int *handle;
  115.     int code;
  116.     int **input;
  117.     int inp_size;
  118.     int **output;
  119.     int out_size;
  120. };
  121.  
  122. static inline void *LoadDriver(void *ptr)
  123. {
  124.     void  *val;
  125.     __asm__ __volatile__("int $0x40":"=a"(val):"a"(68), "b"(16),"c"(ptr));
  126.     return val;
  127. }
  128.  
  129. static inline int ManageDriver(void *ptr)
  130. {
  131.     int val;
  132.     __asm__ __volatile__("int $0x40":"=a"(val):"a"(68), "b"(17),"c"(ptr));
  133.     return val;
  134. }
  135.  
  136.  
  137.  
  138. static int _InitSound(int* p_ver)
  139. {
  140.     hSound = LoadDriver(&szInfinity);
  141.     if(hSound == 0) return -1;
  142.     hrdwSound = LoadDriver(&szSound);
  143.  
  144.     struct MNG_DRV MNG_DRV = {
  145.         .handle    =  hSound,
  146.         .code      =  SRV_GETVERSION,
  147.         .input     =  0,
  148.         .inp_size  =  0,
  149.         .output    =  &p_ver,
  150.         .out_size  =  4
  151.     };
  152.  
  153.     return ManageDriver(&MNG_DRV);
  154. }
  155.  
  156.  
  157.  
  158. static int _CreateBuffer(int format, int size, int *p_str)
  159. {
  160.     struct MNG_DRV MNG_DRV = {
  161.         .handle = hSound,
  162.         .code = SND_CREATE_BUFF,
  163.         .input = &(int*)format,
  164.         .inp_size = 8,
  165.         .output = &p_str,
  166.         .out_size = 4
  167.     };
  168.  
  169.     return ManageDriver(&MNG_DRV);
  170. }
  171.  
  172.  
  173.  
  174. static int _SetBuffer(int *str, int* src, int offs, int size)
  175. {
  176.     struct MNG_DRV MNG_DRV = {
  177.         .handle = hSound,
  178.         .code = SND_SETBUFF,
  179.         .input = &(int*)str,
  180.         .inp_size = 16,
  181.         .output = 0,
  182.         .out_size = 0
  183.     };
  184.  
  185.     return ManageDriver(&MNG_DRV);
  186. }
  187.  
  188.  
  189.  
  190. static int _PlayBuffer(int* str, int flags)
  191. {
  192.     struct MNG_DRV MNG_DRV = {
  193.         .handle = hSound,
  194.         .code = SND_PLAY,
  195.         .input = &(int*)str,
  196.         .inp_size = 8,
  197.         .output = 0,
  198.         .out_size = 0
  199.     };
  200.  
  201.     return ManageDriver(&MNG_DRV);
  202. }
  203.  
  204.  
  205.  
  206. static int _SetBufferPos(int *str, int offs)
  207. {
  208.     struct MNG_DRV MNG_DRV = {
  209.         .handle = hSound,
  210.         .code = SND_SETPOS,
  211.         .input = &(int*)str,
  212.         .inp_size = 8,
  213.         .output = 0,
  214.         .out_size = 0
  215.     };
  216.  
  217.     return ManageDriver(&MNG_DRV);
  218. }
  219.  
  220.  
  221.  
  222. static int _StopBuffer(int* str)
  223. {
  224.     struct MNG_DRV MNG_DRV = {
  225.         .handle = hSound,
  226.         .code = SND_STOP,
  227.         .input = &(int*)str,
  228.         .inp_size = 4,
  229.         .output = 0,
  230.         .out_size = 0
  231.     };
  232.  
  233.     return ManageDriver(&MNG_DRV);
  234. }
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244. #endif
  245.  
  246.  
  247.