comparison playercode/unix_drv/drv_oss.c @ 13:32f80cd7bfee

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