comparison playercode/drv_wav.c @ 4:5d614bcc4287

Initial entry of mikmod into the CVS tree.
author darius
date Fri, 23 Jan 1998 16:05:08 +0000
parents
children
comparison
equal deleted inserted replaced
3:71e20a32bd84 4:5d614bcc4287
1
2 #include "mikmod.h"
3
4 #ifdef __GNUC__
5 #include <sys/types.h>
6 #else
7 #include <io.h>
8 #endif
9 #include <sys/stat.h>
10 #include <fcntl.h>
11
12 #define WAVBUFFERSIZE 65536
13
14 static FILE *wavout;
15
16 static SBYTE *WAV_DMABUF;
17 static ULONG dumpsize;
18
19 static BOOL WAV_IsThere(void)
20 {
21 return 1;
22 }
23
24
25 static BOOL WAV_Init(void)
26 {
27 if(NULL == (wavout = fopen("music.wav", "wb"))) return 1;
28 if(NULL == (WAV_DMABUF = _mm_malloc(WAVBUFFERSIZE))) return 1;
29
30 md_mode |= DMODE_SOFT_MUSIC | DMODE_SOFT_SNDFX;
31
32 if(VC_Init()) return 1;
33
34 _mm_write_string("RIFF WAVEfmt ",wavout);
35 _mm_write_I_ULONG(16,wavout); // length of this RIFF block crap
36
37 _mm_write_I_UWORD(1, wavout); // microsoft format type
38 _mm_write_I_UWORD((md_mode & DMODE_STEREO) ? 2 : 1, wavout);
39 _mm_write_I_ULONG(md_mixfreq, wavout);
40 _mm_write_I_ULONG(md_mixfreq * ((md_mode & DMODE_STEREO) ? 2 : 1) *
41 ((md_mode & DMODE_16BITS) ? 2 : 1), wavout);
42
43 _mm_write_I_UWORD(((md_mode & DMODE_16BITS) ? 2 : 1) *
44 ((md_mode & DMODE_STEREO) ? 2 : 1), wavout); // block alignment (8/16 bit)
45
46 _mm_write_I_UWORD((md_mode & DMODE_16BITS) ? 16 : 8,wavout);
47
48 _mm_write_string("data",wavout);
49
50 dumpsize = 0;
51
52 return 0;
53 }
54
55
56 static void WAV_Exit(void)
57 {
58 VC_Exit();
59
60 // write in the actual sizes now
61
62 if(wavout!=NULL)
63 { _mm_fseek(wavout,4,SEEK_SET);
64 _mm_write_I_ULONG(dumpsize + 32, wavout);
65 _mm_fseek(wavout,40,SEEK_SET);
66 _mm_write_I_ULONG(dumpsize, wavout);
67
68 fclose(wavout);
69
70 if(WAV_DMABUF != NULL) free(WAV_DMABUF);
71 }
72 }
73
74
75 static void WAV_Update(void)
76 {
77 VC_WriteBytes(WAV_DMABUF, WAVBUFFERSIZE);
78 fwrite(WAV_DMABUF, 1, WAVBUFFERSIZE, wavout);
79 dumpsize += WAVBUFFERSIZE;
80 }
81
82
83 static BOOL WAV_Reset(void)
84 {
85 return 0;
86 }
87
88
89 MDRIVER drv_wav =
90 { NULL,
91 "music.wav file",
92 "WAV [music.wav] file output driver v1.0",
93 0,255,
94 WAV_IsThere,
95 VC_SampleLoad,
96 VC_SampleUnload,
97 VC_SampleSpace,
98 VC_SampleLength,
99 WAV_Init,
100 WAV_Exit,
101 WAV_Reset,
102 VC_SetNumVoices,
103 VC_PlayStart,
104 VC_PlayStop,
105 WAV_Update,
106 VC_VoiceSetVolume,
107 VC_VoiceSetFrequency,
108 VC_VoiceSetPanning,
109 VC_VoicePlay,
110 VC_VoiceStop,
111 VC_VoiceStopped,
112 VC_VoiceReleaseSustain,
113 VC_VoiceGetPosition,
114 NULL
115 };
116