8
|
1 /*
|
|
2
|
|
3 Name:
|
|
4 drv_aix.c
|
|
5
|
|
6 Description:
|
|
7 Mikmod driver for output to AIX series audio device
|
|
8
|
|
9 Portability:
|
|
10
|
|
11 AIX >= 3.25 with appropriate audio hardware.
|
|
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 <unistd.h>
|
|
25 #include <fcntl.h>
|
|
26 #include <errno.h>
|
|
27 #include <sys/stat.h>
|
|
28 #include <sys/audio.h>
|
|
29
|
|
30 #include "mikmod.h"
|
|
31
|
|
32 struct _track_info
|
|
33 {
|
|
34 unsigned short master_volume;
|
|
35 unsigned short dither_percent;
|
|
36 unsigned short reserved[3];
|
|
37 } t_info;
|
|
38 audio_init a_init;
|
|
39 audio_control a_control;
|
|
40 audio_change a_change;
|
|
41
|
|
42
|
|
43 static int fd;
|
|
44 #define RAWBUFFERSIZE 32768
|
|
45 static char RAW_DMABUF[RAWBUFFERSIZE];
|
|
46
|
|
47 static BOOL AIX_IsThere(void)
|
|
48 {
|
|
49 return 1;
|
|
50 }
|
|
51
|
|
52 static BOOL AIX_Init(void)
|
|
53 {
|
|
54 float volume = (float)1.0;
|
|
55 int flags;
|
|
56
|
|
57 if (! (md_mode & DMODE_16BITS)) {
|
|
58 myerr = "sorry, this driver supports 16-bit linear output only";
|
|
59 return 0;
|
|
60 }
|
|
61
|
|
62 if ((fd = open ("/dev/acpa0/1", O_WRONLY)) < 3)
|
|
63 if ((fd = open ("/dev/paud0/1", O_WRONLY)) < 3)
|
|
64 if ((fd = open ("/dev/baud0/1", O_WRONLY)) < 3)
|
|
65 {
|
|
66 myerr = "unable to open audio-device";
|
|
67 return 0;
|
|
68 }
|
|
69
|
|
70
|
|
71 t_info.master_volume=0x7fff;
|
|
72 t_info.dither_percent=0;
|
|
73
|
|
74 a_init.srate=md_mixfreq;
|
|
75 a_init.bits_per_sample=16;
|
|
76 a_init.channels=(md_mode & DMODE_STEREO)? 2 : 1;
|
|
77 a_init.mode=PCM;
|
|
78 a_init.flags=FIXED | BIG_ENDIAN | TWOS_COMPLEMENT;
|
|
79 a_init.operation=PLAY;
|
|
80
|
|
81 a_change.balance=0x3fff0000;
|
|
82 a_change.balance_delay=0;
|
|
83 a_change.volume=(long)(volume * (float)0x7FFFFFFF);
|
|
84 a_change.volume_delay=0;
|
|
85 a_change.monitor=AUDIO_IGNORE;
|
|
86 a_change.input=AUDIO_IGNORE;
|
|
87 a_change.output=OUTPUT_1;
|
|
88 a_change.dev_info=&t_info;
|
|
89
|
|
90 a_control.ioctl_request=AUDIO_CHANGE;
|
|
91 a_control.position=0;
|
|
92 a_control.request_info=&a_change;
|
|
93
|
|
94 if (ioctl(fd, AUDIO_INIT, &a_init) == -1 )
|
|
95 {
|
|
96 myerr = "configuration (init) of audio device failed";
|
|
97 return 0;
|
|
98 }
|
|
99 if (ioctl(fd, AUDIO_CONTROL, &a_control) == -1 )
|
|
100 {
|
|
101 myerr = "configuration (control) of audio device failed";
|
|
102 return 0;
|
|
103 }
|
|
104
|
|
105 a_control.ioctl_request=AUDIO_START;
|
|
106 a_control.request_info=NULL;
|
|
107 if (ioctl(fd, AUDIO_CONTROL, &a_control) == -1 )
|
|
108 {
|
|
109 myerr = "configuration (start) of audio device failed";
|
|
110 return 0;
|
|
111 }
|
|
112
|
|
113 #if 0
|
|
114 if ((flags = fcntl (fd, F_GETFL, 0)) < 0) {
|
|
115 myerr = "unable to set non-blocking mode for /dev/audio";
|
|
116 return 0;
|
|
117 }
|
|
118 flags |= O_NDELAY;
|
|
119 if (fcntl (fd, F_SETFL, flags) < 0) {
|
|
120 myerr = "unable to set non-blocking mode for /dev/audio";
|
|
121 return 0;
|
|
122 }
|
|
123 #endif
|
|
124
|
|
125 if(!VC_Init()){
|
|
126 close(fd);
|
|
127 return 0;
|
|
128 }
|
|
129
|
|
130 return 1;
|
|
131 }
|
|
132
|
|
133
|
|
134
|
|
135 static void AIX_Exit(void)
|
|
136 {
|
|
137 VC_Exit();
|
|
138 close(fd);
|
|
139 }
|
|
140
|
|
141
|
|
142 static void AIX_Update(void)
|
|
143 {
|
|
144 VC_WriteBytes(RAW_DMABUF,RAWBUFFERSIZE);
|
|
145 write(fd, RAW_DMABUF, RAWBUFFERSIZE);
|
|
146 }
|
|
147
|
|
148
|
|
149 DRIVER drv_aix={
|
|
150 NULL,
|
|
151 "AIX audio-device",
|
|
152 "MikMod AIX audio-device driver v1.10",
|
|
153 AIX_IsThere,
|
|
154 VC_SampleLoad,
|
|
155 VC_SampleUnload,
|
|
156 VC_SampleSpace,
|
|
157 VC_SampleLength,
|
|
158 AIX_Init,
|
|
159 AIX_Exit,
|
|
160 VC_SetNumChannels,
|
|
161 VC_PlayStart,
|
|
162 VC_PlayStop,
|
|
163 AIX_Update,
|
|
164 VC_VoiceSetVolume,
|
|
165 VC_VoiceSetFrequency,
|
|
166 VC_VoiceSetPanning,
|
|
167 VC_VoicePlay,
|
|
168 VC_VoiceStop,
|
|
169 VC_VoiceStopped,
|
|
170 VC_VoiceReleaseSustain,
|
|
171 VC_VoiceGetPosition,
|
|
172 VC_RealVolume
|
|
173 };
|