drv_hp.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:4k
源码类别:

Windows CE

开发平台:

C/C++

  1. /* MikMod sound library
  2. (c) 1998, 1999, 2000 Miodrag Vallat and others - see file AUTHORS for
  3. complete list.
  4. This library is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of
  7. the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  17. 02111-1307, USA.
  18. */
  19.   
  20. /*==============================================================================
  21.   $Id: drv_hp.c,v 1.2 2004/01/31 22:39:40 raph Exp $
  22.   Driver for output to HP 9000 series /dev/audio
  23. ==============================================================================*/
  24. /*
  25. Written by Lutz Vieweg <lkv@mania.robin.de>
  26. */
  27. #ifdef HAVE_CONFIG_H
  28. #include "config.h"
  29. #endif
  30. #include "mikmod_internals.h"
  31. #ifdef DRV_HP
  32. #ifdef HAVE_UNISTD_H
  33. #include <unistd.h>
  34. #endif
  35. #ifdef HAVE_FCNTL_H
  36. #include <fcntl.h>
  37. #endif
  38. #include <stdlib.h>
  39. #include <sys/audio.h>
  40. #define BUFFERSIZE 15
  41. static int fd=-1;
  42. static SBYTE *audiobuffer=NULL;
  43. static int buffersize=1<<BUFFERSIZE;
  44. static int headphone=0;
  45. static void HP_CommandLine(CHAR *cmdline)
  46. {
  47. char *buffer=MD_GetAtom("buffer",cmdline,0);
  48. if(buffer) {
  49. int buf=atoi(buffer);
  50. if((buf<12)||(buf>19)) buf=BUFFERSIZE;
  51. buffersize=1<<buf;
  52. free(buffer);
  53. }
  54. if((buffer=MD_GetAtom("headphone",cmdline,1))) {
  55. headphone=1;
  56. free(buffer);
  57. } else
  58. headphone=0;
  59. }
  60. static BOOL HP_IsThere(void)
  61. {
  62. int fd;
  63. if((fd=open("/dev/audio",O_WRONLY))>=0) {
  64. close(fd);
  65. return 1;
  66. }
  67. return (errno==EACCES?1:0);
  68. }
  69. static BOOL HP_Init(void)
  70. {
  71. int flags;
  72. if (!(md_mode&DMODE_16BITS)) {
  73. _mm_errno=MMERR_16BIT_ONLY;
  74. return 1;
  75. }
  76. if ((fd=open("/dev/audio",O_WRONLY|O_NDELAY,0))<0) {
  77. _mm_errno=MMERR_OPENING_AUDIO;
  78. return 1;
  79. }
  80. if ((flags=fcntl(fd,F_GETFL,0))<0) {
  81. _mm_errno=MMERR_NON_BLOCK;
  82. return 1;
  83. }
  84. flags|=O_NDELAY;
  85. if (fcntl(fd,F_SETFL,flags)<0) {
  86. _mm_errno=MMERR_NON_BLOCK;
  87. return 1;
  88. }
  89. if (ioctl(fd,AUDIO_SET_DATA_FORMAT,AUDIO_FORMAT_LINEAR16BIT)) {
  90. _mm_errno=MMERR_HP_SETSAMPLESIZE;
  91. return 1;
  92. }
  93. if (ioctl(fd,AUDIO_SET_SAMPLE_RATE,md_mixfreq)) {
  94. _mm_errno=MMERR_HP_SETSPEED;
  95. return 1;
  96. }
  97. if (ioctl(fd,AUDIO_SET_CHANNELS,(md_mode&DMODE_STEREO)?2:1)) {
  98. _mm_errno=MMERR_HP_CHANNELS;
  99. return 1;
  100. }
  101. if (ioctl(fd,AUDIO_SET_OUTPUT,
  102.              headphone?AUDIO_OUT_HEADPHONE:AUDIO_OUT_SPEAKER)) {
  103. _mm_errno=MMERR_HP_AUDIO_OUTPUT;
  104. return 1;
  105. }
  106. if (ioctl(fd,AUDIO_SET_TXBUFSIZE,buffersize<<3)) {
  107. _mm_errno=MMERR_HP_BUFFERSIZE;
  108. return 1;
  109. }
  110. if (!(audiobuffer=(SBYTE*)_mm_malloc(buffersize))) return 1;
  111. return VC_Init();
  112. }
  113. static void HP_Exit(void)
  114. {
  115. VC_Exit();
  116. if (fd>=0) {
  117. ioctl(fd,AUDIO_DRAIN,0);
  118. close(fd);
  119. fd=-1;
  120. }
  121. if (audiobuffer) {
  122. free(audiobuffer);
  123. audiobuffer=NULL;
  124. }
  125. }
  126. static void HP_Update(void)
  127. {
  128. write(fd,audiobuffer,VC_WriteBytes(audiobuffer,buffersize));
  129. }
  130. MIKMODAPI MDRIVER drv_hp={
  131. NULL,
  132. "HP-UX Audio",
  133. "HP-UX Audio driver v1.3",
  134. 0,255,
  135. "hp",
  136. "buffer:r:12,19,15:Audio buffer log2 sizen"
  137.         "headphone:b:0:Use headphonen",
  138. HP_CommandLine,
  139. HP_IsThere,
  140. VC_SampleLoad,
  141. VC_SampleUnload,
  142. VC_SampleSpace,
  143. VC_SampleLength,
  144. HP_Init,
  145. HP_Exit,
  146. NULL,
  147. VC_SetNumVoices,
  148. VC_PlayStart,
  149. VC_PlayStop,
  150. HP_Update,
  151. NULL,
  152. VC_VoiceSetVolume,
  153. VC_VoiceGetVolume,
  154. VC_VoiceSetFrequency,
  155. VC_VoiceGetFrequency,
  156. VC_VoiceSetPanning,
  157. VC_VoiceGetPanning,
  158. VC_VoicePlay,
  159. VC_VoiceStop,
  160. VC_VoiceStopped,
  161. VC_VoiceGetPosition,
  162. VC_VoiceRealVolume
  163. };
  164. #else
  165. MISSING(drv_hp);
  166. #endif
  167. /* ex:set ts=4: */