1 /* MikMod sound library
2 (c) 1998, 1999, 2000 Miodrag Vallat and others - see file AUTHORS for
3 complete list.
4
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 02111-1307, USA.
19 */
20
21 /*==============================================================================
22
23 Driver for output to a file called MUSIC.RAW
24
25 ==============================================================================*/
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #ifdef DRV_RAW
32
33 #ifdef HAVE_UNISTD_H
34 #include <unistd.h>
35 #endif
36
37 #include <stdio.h>
38
39 #include "mikmod_internals.h"
40
41 #ifdef __VBCC__
42 #define unlink remove
43 #endif
44 #ifdef _WIN32
45 #define unlink _unlink
46 #endif
47
48 #define BUFFERSIZE 32768
49 #define FILENAME "music.raw"
50
51 static FILE *rawout=NULL;
52 static SBYTE *audiobuffer=NULL;
53 static CHAR *filename=NULL;
54
RAW_CommandLine(const CHAR * cmdline)55 static void RAW_CommandLine(const CHAR *cmdline)
56 {
57 CHAR *ptr=MD_GetAtom("file",cmdline,0);
58
59 if(ptr) {
60 MikMod_free(filename);
61 filename=ptr;
62 }
63 }
64
RAW_IsThere(void)65 static BOOL RAW_IsThere(void)
66 {
67 return 1;
68 }
69
RAW_Init(void)70 static int RAW_Init(void)
71 {
72 #if (MIKMOD_UNIX)
73 if(!MD_Access(filename?filename:FILENAME)) {
74 _mm_errno=MMERR_OPENING_FILE;
75 return 1;
76 }
77 #endif
78
79 rawout=fopen(filename?filename:FILENAME,"wb");
80 if(!rawout) {
81 _mm_errno=MMERR_OPENING_FILE;
82 return 1;
83 }
84 md_mode|=DMODE_SOFT_MUSIC|DMODE_SOFT_SNDFX;
85
86 if (!(audiobuffer=(SBYTE*)MikMod_malloc(BUFFERSIZE))) {
87 fclose(rawout);
88 unlink(filename?filename:FILENAME);
89 rawout=NULL;
90 return 1;
91 }
92
93 if ((VC_Init())) {
94 fclose(rawout);
95 unlink(filename?filename:FILENAME);
96 rawout=NULL;
97 return 1;
98 }
99 return 0;
100 }
101
RAW_Exit(void)102 static void RAW_Exit(void)
103 {
104 VC_Exit();
105 if (rawout) {
106 fclose(rawout);
107 rawout=NULL;
108 }
109 MikMod_free(audiobuffer);
110 audiobuffer = NULL;
111 }
112
RAW_Update(void)113 static void RAW_Update(void)
114 {
115 fwrite(audiobuffer,VC_WriteBytes(audiobuffer,BUFFERSIZE),1,rawout);
116 }
117
RAW_Reset(void)118 static int RAW_Reset(void)
119 {
120 fclose(rawout);
121 rawout=fopen(filename?filename:FILENAME,"wb");
122 if(!rawout) {
123 _mm_errno=MMERR_OPENING_FILE;
124 return 1;
125 }
126
127 return 0;
128 }
129
130 MIKMODAPI MDRIVER drv_raw={
131 NULL,
132 "Disk writer (raw data)",
133 "Raw disk writer (music.raw) v1.1",
134 0,255,
135 "raw",
136 "file:t:music.raw:Output file name\n",
137 RAW_CommandLine,
138 RAW_IsThere,
139 VC_SampleLoad,
140 VC_SampleUnload,
141 VC_SampleSpace,
142 VC_SampleLength,
143 RAW_Init,
144 RAW_Exit,
145 RAW_Reset,
146 VC_SetNumVoices,
147 VC_PlayStart,
148 VC_PlayStop,
149 RAW_Update,
150 NULL,
151 VC_VoiceSetVolume,
152 VC_VoiceGetVolume,
153 VC_VoiceSetFrequency,
154 VC_VoiceGetFrequency,
155 VC_VoiceSetPanning,
156 VC_VoiceGetPanning,
157 VC_VoicePlay,
158 VC_VoiceStop,
159 VC_VoiceStopped,
160 VC_VoiceGetPosition,
161 VC_VoiceRealVolume
162 };
163
164 #else
165 #include "mikmod_internals.h"
166 MISSING(drv_raw);
167
168 #endif
169
170 /* ex:set ts=4: */
171