Mercurial > ~darius > hgwebdir.cgi > mikmod
comparison playercode/unix_drv/drv_hp.c @ 8:b30908f9d9f9
Initial entry of mikmod into the CVS tree.
author | darius |
---|---|
date | Fri, 23 Jan 1998 16:05:10 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7:de95ce2eacfd | 8:b30908f9d9f9 |
---|---|
1 /* | |
2 | |
3 Name: | |
4 drv_hp.c | |
5 | |
6 Description: | |
7 Mikmod driver for output to HP 9000 series /dev/audio | |
8 | |
9 Portability: | |
10 | |
11 HP-UX only | |
12 | |
13 Written by Lutz Vieweg <lkv@mania.robin.de> | |
14 based on drv_raw.c | |
15 | |
16 Feel free to distribute just as you like. | |
17 No warranties at all. | |
18 | |
19 */ | |
20 | |
21 #include <stdio.h> | |
22 #include <stdlib.h> | |
23 | |
24 #include <sys/audio.h> | |
25 #include <unistd.h> | |
26 #include <fcntl.h> | |
27 #include <sys/ioctl.h> | |
28 | |
29 #include "mikmod.h" | |
30 | |
31 static int fd; | |
32 #define RAWBUFFERSIZE 16384 | |
33 static char RAW_DMABUF[RAWBUFFERSIZE]; | |
34 | |
35 static BOOL HP_IsThere(void) | |
36 { | |
37 return 1; | |
38 } | |
39 | |
40 static BOOL HP_Init(void) | |
41 { | |
42 int flags; | |
43 | |
44 if (! (md_mode & DMODE_16BITS)) { | |
45 myerr = "sorry, this driver supports 16-bit linear output only"; | |
46 return 0; | |
47 } | |
48 | |
49 if ((fd = open("/dev/audio", O_WRONLY | O_NDELAY, 0)) < 0) { | |
50 myerr = "unable to open /dev/audio"; | |
51 return 0; | |
52 } | |
53 | |
54 if ((flags = fcntl (fd, F_GETFL, 0)) < 0) { | |
55 myerr = "unable to set non-blocking mode for /dev/audio"; | |
56 return 0; | |
57 } | |
58 flags |= O_NDELAY; | |
59 if (fcntl (fd, F_SETFL, flags) < 0) { | |
60 myerr = "unable to set non-blocking mode for /dev/audio"; | |
61 return 0; | |
62 } | |
63 | |
64 if (ioctl(fd, AUDIO_SET_DATA_FORMAT, AUDIO_FORMAT_LINEAR16BIT)) { | |
65 myerr = "unable to select 16bit-linear sample format"; | |
66 return 0; | |
67 } | |
68 | |
69 if (ioctl(fd, AUDIO_SET_SAMPLE_RATE, md_mixfreq)) { | |
70 myerr = "unable to select requested sample-rate"; | |
71 return 0; | |
72 } | |
73 | |
74 if (ioctl(fd, AUDIO_SET_CHANNELS, (md_mode & DMODE_STEREO)? 2 : 1)) { | |
75 myerr = "unable to select requested number of channels"; | |
76 return 0; | |
77 } | |
78 | |
79 /* | |
80 choose between: | |
81 AUDIO_OUT_SPEAKER | |
82 AUDIO_OUT_HEADPHONE | |
83 AUDIO_OUT_LINE | |
84 */ | |
85 if (ioctl(fd, AUDIO_SET_OUTPUT, | |
86 AUDIO_OUT_SPEAKER | AUDIO_OUT_HEADPHONE | AUDIO_OUT_LINE)) { | |
87 myerr = "unable to select audio output"; | |
88 return 0; | |
89 } | |
90 | |
91 { | |
92 struct audio_describe description; | |
93 struct audio_gains gains; | |
94 float volume = 1.0; | |
95 if (ioctl(fd, AUDIO_DESCRIBE, &description)) { | |
96 myerr = "unable to get audio description"; | |
97 return 0; | |
98 } | |
99 if (ioctl (fd, AUDIO_GET_GAINS, &gains)) { | |
100 myerr = "unable to get gain values"; | |
101 return 0; | |
102 } | |
103 | |
104 gains.transmit_gain = (int)((float)description.min_transmit_gain + | |
105 (float)(description.max_transmit_gain | |
106 - description.min_transmit_gain) | |
107 * volume); | |
108 if (ioctl (fd, AUDIO_SET_GAINS, &gains)) { | |
109 myerr = "unable to set gain values"; | |
110 return 0; | |
111 } | |
112 } | |
113 | |
114 if (ioctl(fd, AUDIO_SET_TXBUFSIZE, RAWBUFFERSIZE*8)) { | |
115 myerr = "unable to set transmission buffer size"; | |
116 return 0; | |
117 } | |
118 | |
119 if(!VC_Init()){ | |
120 close(fd); | |
121 return 0; | |
122 } | |
123 | |
124 return 1; | |
125 } | |
126 | |
127 | |
128 | |
129 static void HP_Exit(void) | |
130 { | |
131 VC_Exit(); | |
132 close(fd); | |
133 } | |
134 | |
135 | |
136 static void HP_Update(void) | |
137 { | |
138 VC_WriteBytes(RAW_DMABUF,RAWBUFFERSIZE); | |
139 write(fd, RAW_DMABUF, RAWBUFFERSIZE); | |
140 } | |
141 | |
142 | |
143 DRIVER drv_hp={ | |
144 NULL, | |
145 "HP-UX /dev/audio", | |
146 "MikMod HP-UX /dev/audio driver v1.10", | |
147 HP_IsThere, | |
148 VC_SampleLoad, | |
149 VC_SampleUnload, | |
150 VC_SampleSpace, | |
151 VC_SampleLength, | |
152 HP_Init, | |
153 HP_Exit, | |
154 VC_SetNumChannels, | |
155 VC_PlayStart, | |
156 VC_PlayStop, | |
157 HP_Update, | |
158 VC_VoiceSetVolume, | |
159 VC_VoiceSetFrequency, | |
160 VC_VoiceSetPanning, | |
161 VC_VoicePlay, | |
162 VC_VoiceStop, | |
163 VC_VoiceStopped, | |
164 VC_VoiceReleaseSustain, | |
165 VC_VoiceGetPosition, | |
166 VC_RealVolume | |
167 }; |