8
|
1 /*
|
|
2
|
|
3 Name:
|
|
4 DRV_SGI.C, version 0.2
|
|
5 Copyright 1996 by Stephan Kanthak, kanthak@i6.informatik.rwth-aachen.de
|
|
6
|
|
7 Version 0.2 - updated to use new driver API
|
|
8
|
|
9 Description:
|
|
10 Mikmod driver for output on SGI audio system (needs libaudio from the
|
|
11 dmedia package).
|
|
12
|
|
13 Portability:
|
|
14 SGI only. Mainly based on voxware driver.
|
|
15
|
|
16 Fragment configuration:
|
|
17 =======================
|
|
18
|
|
19 You can use the environment variables 'MM_SGI_FRAGSIZE' and
|
|
20 'MM_SGI_BUFSIZE' to override the default size of the audio buffer. If you
|
|
21 experience crackles & pops, try experimenting with these values.
|
|
22
|
|
23 Please read README.SGI first before contacting the author because there are
|
|
24 some things to know about the specials of the SGI audio driver.
|
|
25
|
|
26 */
|
|
27
|
|
28
|
|
29 #include <stdio.h>
|
|
30 #include <stdlib.h>
|
|
31 #include <unistd.h>
|
|
32 #include <dmedia/audio.h>
|
|
33 #include "mikmod.h"
|
|
34
|
|
35 #define DEFAULT_SGI_FRAGSIZE 5000
|
|
36 #define DEFAULT_SGI_BUFSIZE 10000
|
|
37
|
|
38 static ALconfig sgi_config;
|
|
39 static ALport sgi_port;
|
|
40 static int sample_factor;
|
|
41 static int sgi_fragsize;
|
|
42 static int sgi_bufsize;
|
|
43 static char* audiobuffer;
|
|
44
|
|
45
|
|
46 static BOOL SGI_IsThere(void)
|
|
47 {
|
|
48 long params[] = { AL_OUTPUT_RATE, 0 };
|
|
49
|
|
50 ALqueryparams(AL_DEFAULT_DEVICE, params, 2);
|
|
51 if (params[1] != 0) return 1;
|
|
52 else return 0;
|
|
53 }
|
|
54
|
|
55 static BOOL SGI_Init(void)
|
|
56 {
|
|
57 char *env;
|
|
58 int play_rate;
|
|
59 int fragsize,numfrags;
|
|
60 long chpars[] = { AL_OUTPUT_RATE, AL_RATE_22050 };
|
|
61
|
|
62 printf("SGI audio driver: ");
|
|
63 switch(md_mixfreq) {
|
|
64 case 22050:
|
|
65 chpars[1] = AL_RATE_22050;
|
|
66 break;
|
|
67 case 44100:
|
|
68 chpars[1] = AL_RATE_44100;
|
|
69 break;
|
|
70 default:
|
|
71 printf("mixing rate not supported.\n");
|
|
72 return 0;
|
|
73 break;
|
|
74 }
|
|
75 ALsetparams(AL_DEFAULT_DEVICE, chpars, 2);
|
|
76
|
|
77 if ((sgi_config = ALnewconfig()) == 0) {
|
|
78 printf("cannot configure sound device.\n");
|
|
79 return 0;
|
|
80 }
|
|
81
|
|
82 if (md_mode & DMODE_16BITS) {
|
|
83 if (ALsetwidth(sgi_config, AL_SAMPLE_16) < 0) {
|
|
84 printf("samplesize of 16 bits not supported.\n");
|
|
85 return 0;
|
|
86 }
|
|
87 sample_factor = 2;
|
|
88 } else {
|
|
89 if (ALsetwidth(sgi_config, AL_SAMPLE_8) < 0) {
|
|
90 printf("samplesize of 8 bits not supported.\n");
|
|
91 return 0;
|
|
92 }
|
|
93 sample_factor = 1;
|
|
94 }
|
|
95
|
|
96 if (md_mode & DMODE_STEREO) {
|
|
97 if (ALsetchannels(sgi_config, AL_STEREO) < 0) {
|
|
98 printf("stereo mode not supported.\n");
|
|
99 return 0;
|
|
100 }
|
|
101 } else{
|
|
102 if (ALsetchannels(sgi_config, AL_MONO) < 0) {
|
|
103 printf("mono mode not supported.\n");
|
|
104 return 0;
|
|
105 }
|
|
106 }
|
|
107
|
|
108 if(!VC_Init()){
|
|
109 return 0;
|
|
110 }
|
|
111
|
|
112 sgi_fragsize=(env=getenv("MM_SGI_FRAGSIZE")) ? atol(env) : DEFAULT_SGI_BUFSIZE;
|
|
113 sgi_bufsize=(env=getenv("MM_SGI_BUFSIZE")) ? atol(env) : DEFAULT_SGI_BUFSIZE;
|
|
114
|
|
115 ALsetqueuesize(sgi_config, sgi_bufsize);
|
|
116 if ((sgi_port = ALopenport("Mod4X", "w", sgi_config)) == 0) {
|
|
117 printf("cannot open SGI audio port.\n");
|
|
118 return 0;
|
|
119 }
|
|
120 printf("%dHz/%dBits/", md_mixfreq, 8*sample_factor);
|
|
121 if (md_mode & DMODE_STEREO) printf("stereo.\n");
|
|
122 else printf("mono.\n");
|
|
123
|
|
124
|
|
125 audiobuffer = (char*) MyMalloc(sgi_fragsize * sizeof(char));
|
|
126
|
|
127 if(audiobuffer==NULL){
|
|
128 VC_Exit();
|
|
129 return 0;
|
|
130 }
|
|
131
|
|
132 return 1;
|
|
133 }
|
|
134
|
|
135
|
|
136 static void SGI_Exit(void)
|
|
137 {
|
|
138 free(audiobuffer);
|
|
139 VC_Exit();
|
|
140 }
|
|
141
|
|
142
|
|
143 static void SGI_Update(void)
|
|
144 {
|
|
145 VC_WriteBytes(audiobuffer, sgi_fragsize);
|
|
146 ALwritesamps(sgi_port,audiobuffer, sgi_fragsize/sample_factor);
|
|
147 }
|
|
148
|
|
149
|
|
150 DRIVER drv_sgi={
|
|
151 NULL,
|
|
152 "SGI Audio System",
|
|
153 "SGI Audio System Driver v0.2 - by Stephan Kanthak",
|
|
154 SGI_IsThere,
|
|
155 VC_SampleLoad,
|
|
156 VC_SampleUnload,
|
|
157 VC_SampleSpace,
|
|
158 VC_SampleLength,
|
|
159 SGI_Init,
|
|
160 SGI_Exit,
|
|
161 VC_SetNumChannels,
|
|
162 VC_PlayStart,
|
|
163 VC_PlayStop,
|
|
164 SGI_Update,
|
|
165 VC_VoiceSetVolume,
|
|
166 VC_VoiceSetFrequency,
|
|
167 VC_VoiceSetPanning,
|
|
168 VC_VoicePlay,
|
|
169 VC_VoiceStop,
|
|
170 VC_VoiceStopped,
|
|
171 VC_VoiceReleaseSustain,
|
|
172 VC_VoiceGetPosition,
|
|
173 VC_RealVolume
|
|
174 };
|