annotate playercode/unix_drv/drv_oss.c @ 14:6218f9885552

Clean up the Makefile
author darius
date Thu, 23 Apr 1998 07:21:28 +0000
parents 32f80cd7bfee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
1 /*
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
2 * Name: DRV_VOX.C
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
3 *
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
4 * Description: Mikmod driver for output on linux and FreeBSD Open Sound System
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
5 * (OSS) (/dev/dsp)
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
6 *
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
7 * Portability: VoxWare/SS/OSS land. Linux, FreeBSD (NetBSD & SCO?)
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
8 *
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
9 * New fragment configuration code done by Rao:
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
10 * ============================================
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
11 *
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
12 * You can use the environment variables 'MM_FRAGSIZE' and 'MM_NUMFRAGS' to
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
13 * override the default size & number of audio buffer fragments. If you
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
14 * experience crackles & pops, try experimenting with these values.
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
15 *
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
16 * Read experimental.txt within the VoxWare package for information on these
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
17 * options. They are _VERY_ important with relation to sound popping and
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
18 * smooth playback.
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
19 *
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
20 * In general, the slower your system, the higher these values need to be.
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
21 *
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
22 * MM_NUMFRAGS is within the range 2 to 255 (decimal)
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
23 *
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
24 * MM_FRAGSIZE is is within the range 7 to 17 (dec). The requested fragment size
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
25 * will be 2^MM_FRAGSIZE
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
26 *
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
27 * - This driver DOES work with MikMod 3.0 - modifed to use an ioctl() to figure
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
28 * out how much data to do with each write, keeps us from blocking extensivly
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
29 *
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
30 */
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
31 #include <stdio.h>
990c9dadb348 Initial revision
darius
parents:
diff changeset
32 #include <stdlib.h>
990c9dadb348 Initial revision
darius
parents:
diff changeset
33 #include <unistd.h>
990c9dadb348 Initial revision
darius
parents:
diff changeset
34 #include <sys/types.h>
990c9dadb348 Initial revision
darius
parents:
diff changeset
35 #include <sys/time.h>
990c9dadb348 Initial revision
darius
parents:
diff changeset
36 #include <sys/stat.h>
990c9dadb348 Initial revision
darius
parents:
diff changeset
37 #include <fcntl.h>
990c9dadb348 Initial revision
darius
parents:
diff changeset
38 #ifdef __FreeBSD__
990c9dadb348 Initial revision
darius
parents:
diff changeset
39 #include <machine/soundcard.h>
990c9dadb348 Initial revision
darius
parents:
diff changeset
40 #else
990c9dadb348 Initial revision
darius
parents:
diff changeset
41 #include <sys/soundcard.h>
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
42 #endif /* __FreeBSD__ */
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
43 #include <sys/ioctl.h>
990c9dadb348 Initial revision
darius
parents:
diff changeset
44 #include <sys/wait.h>
990c9dadb348 Initial revision
darius
parents:
diff changeset
45 #include "mikmod.h"
990c9dadb348 Initial revision
darius
parents:
diff changeset
46 #include "mmio.h"
990c9dadb348 Initial revision
darius
parents:
diff changeset
47
990c9dadb348 Initial revision
darius
parents:
diff changeset
48 #define DEFAULT_FRAGSIZE 17
990c9dadb348 Initial revision
darius
parents:
diff changeset
49 #define DEFAULT_NUMFRAGS 4
990c9dadb348 Initial revision
darius
parents:
diff changeset
50
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
51 static int sndfd;
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
52 static int fragmentsize;
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
53 static char *audiobuffer;
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
54
990c9dadb348 Initial revision
darius
parents:
diff changeset
55
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
56 static BOOL
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
57 OSS_IsThere(void)
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
58 {
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
59 return (access("/dev/dsp", W_OK) == 0);
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
60 }
990c9dadb348 Initial revision
darius
parents:
diff changeset
61
990c9dadb348 Initial revision
darius
parents:
diff changeset
62
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
63 static BOOL
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
64 OSS_Init(void)
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
65 {
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
66 char *env;
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
67 int play_precision, play_stereo, play_rate;
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
68 int fragsize, numfrags;
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
69
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
70 if ((sndfd = open("/dev/dsp", O_WRONLY)) < 0) {
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
71 return 1;
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
72 }
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
73 fragsize = (env = getenv("MM_FRAGSIZE")) ? atoi(env) : DEFAULT_FRAGSIZE;
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
74 numfrags = (env = getenv("MM_NUMFRAGS")) ? atoi(env) : DEFAULT_NUMFRAGS;
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
75
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
76 if (fragsize < 7 || fragsize > 17)
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
77 fragsize = DEFAULT_FRAGSIZE;
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
78
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
79 if (numfrags < 2 || numfrags > 255)
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
80 numfrags = DEFAULT_NUMFRAGS;
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
81
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
82 fragmentsize = (numfrags << 16) | fragsize;
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
83
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
84 #ifndef __FreeBSD__
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
85 if (ioctl(sndfd, SNDCTL_DSP_SETFRAGMENT, &fragmentsize) < 0) {
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
86 close(sndfd);
990c9dadb348 Initial revision
darius
parents:
diff changeset
87 return 1;
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
88 }
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
89 #endif /* __FreeBSD__ */
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
90
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
91 play_precision = (md_mode & DMODE_16BITS) ? 16 : 8;
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
92 play_stereo = (md_mode & DMODE_STEREO) ? 1 : 0;
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
93 play_rate = md_mixfreq;
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
94
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
95 if (ioctl(sndfd, SNDCTL_DSP_SAMPLESIZE, &play_precision) == -1 ||
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
96 ioctl(sndfd, SNDCTL_DSP_STEREO, &play_stereo) == -1 ||
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
97 ioctl(sndfd, SNDCTL_DSP_SPEED, &play_rate) == -1) {
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
98
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
99 close(sndfd);
990c9dadb348 Initial revision
darius
parents:
diff changeset
100 return 1;
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
101 }
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
102
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
103 ioctl(sndfd, SNDCTL_DSP_GETBLKSIZE, &fragmentsize);
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
104
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
105 /*
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
106 * Lose this for now - it will confuse ncurses etc... printf("Fragment
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
107 * size is %ld\n",fragmentsize);
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
108 */
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
109
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
110 if (VC_Init()) {
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
111 close(sndfd);
990c9dadb348 Initial revision
darius
parents:
diff changeset
112 return 1;
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
113 }
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
114 audiobuffer = (char *) _mm_malloc(fragmentsize * sizeof(char) * 2);
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
115
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
116 if (audiobuffer == NULL) {
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
117 VC_Exit();
990c9dadb348 Initial revision
darius
parents:
diff changeset
118 close(sndfd);
990c9dadb348 Initial revision
darius
parents:
diff changeset
119 return 1;
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
120 }
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
121 return 0;
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
122 }
990c9dadb348 Initial revision
darius
parents:
diff changeset
123
990c9dadb348 Initial revision
darius
parents:
diff changeset
124
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
125 static void
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
126 OSS_Exit(void)
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
127 {
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
128 free(audiobuffer);
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
129 VC_Exit();
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
130 close(sndfd);
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
131 }
990c9dadb348 Initial revision
darius
parents:
diff changeset
132
990c9dadb348 Initial revision
darius
parents:
diff changeset
133
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
134 static void
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
135 OSS_Update(void)
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
136 {
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
137 audio_buf_info buffinf;
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
138
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
139 ioctl(sndfd, SNDCTL_DSP_GETOSPACE, &buffinf);
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
140 VC_WriteBytes(audiobuffer, buffinf.fragments * buffinf.fragsize);
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
141 write(sndfd, audiobuffer, buffinf.fragments * buffinf.fragsize);
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
142 }
990c9dadb348 Initial revision
darius
parents:
diff changeset
143
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
144 BOOL
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
145 OSS_Reset(void)
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
146 {
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
147 ioctl(sndfd, SNDCTL_DSP_RESET);
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
148 VC_Exit();
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
149 return VC_Init();
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
150 }
990c9dadb348 Initial revision
darius
parents:
diff changeset
151
990c9dadb348 Initial revision
darius
parents:
diff changeset
152
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
153 MDRIVER drv_oss =
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
154 {
13
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
155 NULL,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
156 "Open Sound System (OSS)",
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
157 "Open Sound System (OSS) Driver v1.3 - by Rao & MikMak (with a little hacking from Pete)",
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
158 0, 255,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
159 OSS_IsThere,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
160 VC_SampleLoad,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
161 VC_SampleUnload,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
162 VC_SampleSpace,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
163 VC_SampleLength,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
164 OSS_Init,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
165 OSS_Exit,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
166 OSS_Reset,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
167 VC_SetNumVoices,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
168 VC_PlayStart,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
169 VC_PlayStop,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
170 OSS_Update,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
171 VC_VoiceSetVolume,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
172 VC_VoiceSetFrequency,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
173 VC_VoiceSetPanning,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
174 VC_VoicePlay,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
175 VC_VoiceStop,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
176 VC_VoiceStopped,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
177 VC_VoiceReleaseSustain,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
178 VC_VoiceGetPosition,
32f80cd7bfee General tidy up..
darius
parents: 9
diff changeset
179 VC_VoiceRealVolume
9
990c9dadb348 Initial revision
darius
parents:
diff changeset
180 };