annotate playercode/unix_drv/drv_sgi.c @ 13:32f80cd7bfee

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