drv_raw.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.   $Id: drv_raw.c,v 1.4 2004/01/31 22:39:40 raph Exp $
  21.   Driver for output to a file called MUSIC.RAW
  22. ==============================================================================*/
  23. #ifdef HAVE_CONFIG_H
  24. #include "config.h"
  25. #endif
  26. #ifdef HAVE_UNISTD_H
  27. #include <unistd.h>
  28. #endif
  29. #ifdef HAVE_FCNTL_H
  30. #include <fcntl.h>
  31. #endif
  32. #ifndef macintosh
  33. #include <sys/types.h>
  34. #include <sys/stat.h>
  35. #endif
  36. #include "mikmod_internals.h"
  37. #define BUFFERSIZE 32768
  38. #define FILENAME "music.raw"
  39. #ifndef O_BINARY
  40. #define O_BINARY 0
  41. #endif
  42. #if defined(WIN32) && !defined(__MWERKS__)
  43. #define open _open
  44. #endif
  45. static int rawout=-1;
  46. static SBYTE *audiobuffer=NULL;
  47. static CHAR *filename=NULL;
  48. static void RAW_CommandLine(CHAR *cmdline)
  49. {
  50. CHAR *ptr=MD_GetAtom("file",cmdline,0);
  51. if(ptr) {
  52. _mm_free(filename);
  53. filename=ptr;
  54. }
  55. }
  56. static BOOL RAW_IsThere(void)
  57. {
  58. return 1;
  59. }
  60. static BOOL RAW_Init(void)
  61. {
  62. #if defined unix || (defined __APPLE__ && defined __MACH__)
  63. if(!MD_Access(filename?filename:FILENAME)) {
  64. _mm_errno=MMERR_OPENING_FILE;
  65. return 1;
  66. }
  67. #endif
  68. if((rawout=open(filename?filename:FILENAME,O_RDWR|O_TRUNC|O_CREAT|O_BINARY
  69. #if !defined(macintosh) && !defined(__MWERKS__)
  70.                 ,S_IREAD|S_IWRITE
  71. #endif
  72.                ))<0) {
  73. _mm_errno=MMERR_OPENING_FILE;
  74. return 1;
  75. }
  76. md_mode|=DMODE_SOFT_MUSIC|DMODE_SOFT_SNDFX;
  77. if (!(audiobuffer=(SBYTE*)_mm_malloc(BUFFERSIZE))) {
  78. close(rawout);unlink(filename?filename:FILENAME);
  79. rawout=-1;
  80. return 1;
  81. }
  82. if ((VC_Init())) {
  83. close(rawout);unlink(filename?filename:FILENAME);
  84. rawout=-1;
  85. return 1;
  86. }
  87. return 0;
  88. }
  89. static void RAW_Exit(void)
  90. {
  91. VC_Exit();
  92. if (rawout!=-1) {
  93. close(rawout);
  94. rawout=-1;
  95. }
  96. _mm_free(audiobuffer);
  97. }
  98. static void RAW_Update(void)
  99. {
  100. write(rawout,audiobuffer,VC_WriteBytes(audiobuffer,BUFFERSIZE));
  101. }
  102. static BOOL RAW_Reset(void)
  103. {
  104. close(rawout);
  105. if((rawout=open(filename?filename:FILENAME,O_RDWR|O_TRUNC|O_CREAT|O_BINARY
  106. #if !defined(macintosh) && !defined(__MWERKS__)
  107.                 ,S_IREAD|S_IWRITE
  108. #endif
  109.                ))<0) {
  110. _mm_errno=MMERR_OPENING_FILE;
  111. return 1;
  112. }
  113. return 0;
  114. }
  115. MIKMODAPI MDRIVER drv_raw={
  116. NULL,
  117. "Disk writer (raw data)",
  118. "Raw disk writer (music.raw) v1.1",
  119. 0,255,
  120. "raw",
  121. "file:t:music.raw:Output file namen",
  122. RAW_CommandLine,
  123. RAW_IsThere,
  124. VC_SampleLoad,
  125. VC_SampleUnload,
  126. VC_SampleSpace,
  127. VC_SampleLength,
  128. RAW_Init,
  129. RAW_Exit,
  130. RAW_Reset,
  131. VC_SetNumVoices,
  132. VC_PlayStart,
  133. VC_PlayStop,
  134. RAW_Update,
  135. NULL,
  136. VC_VoiceSetVolume,
  137. VC_VoiceGetVolume,
  138. VC_VoiceSetFrequency,
  139. VC_VoiceGetFrequency,
  140. VC_VoiceSetPanning,
  141. VC_VoiceGetPanning,
  142. VC_VoicePlay,
  143. VC_VoiceStop,
  144. VC_VoiceStopped,
  145. VC_VoiceGetPosition,
  146. VC_VoiceRealVolume
  147. };
  148. /* ex:set ts=4: */