Mercurial > mplayer.hg
comparison libao2/ao_sgi.c @ 2451:a56bf9c0e76f
SGI audio driver by oliver.schoenbrunner@jku.at
author | arpi |
---|---|
date | Wed, 24 Oct 2001 14:06:36 +0000 |
parents | |
children | 981a9e5118ce |
comparison
equal
deleted
inserted
replaced
2450:f51307170f69 | 2451:a56bf9c0e76f |
---|---|
1 /* | |
2 ao_sgi - sgi/irix output plugin for MPlayer | |
3 | |
4 22oct2001 oliver.schoenbrunner@jku.at | |
5 | |
6 */ | |
7 | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include <dmedia/audio.h> | |
11 | |
12 #include "audio_out.h" | |
13 #include "audio_out_internal.h" | |
14 | |
15 static ao_info_t info = | |
16 { | |
17 "sgi audio output", | |
18 "sgi", | |
19 "kopflos", | |
20 "" | |
21 }; | |
22 | |
23 LIBAO_EXTERN(sgi) | |
24 | |
25 // there are some globals: | |
26 // ao_samplerate | |
27 // ao_channels | |
28 // ao_format | |
29 // ao_bps | |
30 // ao_outburst | |
31 // ao_buffersize | |
32 | |
33 static ALconfig ao_config; | |
34 static ALport ao_port; | |
35 | |
36 // to set/get/query special features/parameters | |
37 static int control(int cmd, int arg){ | |
38 | |
39 printf("ao_sgi, control\n"); | |
40 | |
41 return -1; | |
42 } | |
43 | |
44 // open & setup audio device | |
45 // return: 1=success 0=fail | |
46 static int init(int rate, int channels, int format, int flags) { | |
47 | |
48 printf("ao_sgi, init: Samplerate: %iHz Channels: %s Format %s\n", rate, (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format)); | |
49 | |
50 { /* from /usr/share/src/dmedia/audio/setrate.c */ | |
51 | |
52 int fd; | |
53 int rv; | |
54 double frate; | |
55 ALpv x[2]; | |
56 | |
57 rv = alGetResourceByName(AL_SYSTEM, "out.analog", AL_DEVICE_TYPE); | |
58 if (!rv) { | |
59 printf("ao_sgi, play: invalid device\n"); | |
60 return 0; | |
61 } | |
62 | |
63 frate = rate; | |
64 | |
65 x[0].param = AL_RATE; | |
66 x[0].value.ll = alDoubleToFixed(rate); | |
67 x[1].param = AL_MASTER_CLOCK; | |
68 x[1].value.i = AL_CRYSTAL_MCLK_TYPE; | |
69 | |
70 if (alSetParams(rv,x, 2)<0) { | |
71 printf("ao_sgi, init: setparams failed: %s\n", alGetErrorString(oserror())); | |
72 printf("ao_sgi, init: could not set desired samplerate\n"); | |
73 } | |
74 | |
75 if (x[0].sizeOut < 0) { | |
76 printf("ao_sgi, init: AL_RATE was not accepted on the given resource\n"); | |
77 } | |
78 | |
79 if (alGetParams(rv,x, 1)<0) { | |
80 printf("ao_sgi, init: getparams failed: %s\n", alGetErrorString(oserror())); | |
81 } | |
82 | |
83 if (frate != alFixedToDouble(x[0].value.ll)) { | |
84 printf("ao_sgi, init: samplerate is now %lf (desired rate is %lf)\n", alFixedToDouble(x[0].value.ll), frate); | |
85 } | |
86 | |
87 } | |
88 | |
89 ao_buffersize=131072; | |
90 ao_outburst = ao_buffersize/16; | |
91 ao_channels = channels; | |
92 | |
93 ao_config = alNewConfig(); | |
94 | |
95 if (!ao_config) { | |
96 printf("ao_sgi, init: %s\n", alGetErrorString(oserror())); | |
97 return 0; | |
98 } | |
99 | |
100 if(channels == 2) alSetChannels(ao_config, AL_STEREO); | |
101 else alSetChannels(ao_config, AL_MONO); | |
102 | |
103 alSetWidth(ao_config, AL_SAMPLE_16); | |
104 alSetSampFmt(ao_config, AL_SAMPFMT_TWOSCOMP); | |
105 alSetQueueSize(ao_config, 48000); | |
106 | |
107 if (alSetDevice(ao_config, AL_DEFAULT_OUTPUT) < 0) { | |
108 printf("ao_sgi, init: %s\n", alGetErrorString(oserror())); | |
109 return 0; | |
110 } | |
111 | |
112 ao_port = alOpenPort("mplayer", "w", ao_config); | |
113 | |
114 if (!ao_port) { | |
115 printf("ao_sgi, init: Unable to open audio channel: %s\n", alGetErrorString(oserror())); | |
116 return 0; | |
117 } | |
118 | |
119 // printf("ao_sgi, init: port %d config %d\n", ao_port, ao_config); | |
120 | |
121 return 1; | |
122 | |
123 } | |
124 | |
125 // close audio device | |
126 static void uninit() { | |
127 | |
128 /* TODO: samplerate should be set back to the value before mplayer was started! */ | |
129 | |
130 printf("ao_sgi, uninit: ...\n"); | |
131 | |
132 if (ao_port) { | |
133 while(alGetFilled(ao_port) > 0) sginap(1); | |
134 alClosePort(ao_port); | |
135 alFreeConfig(ao_config); | |
136 } | |
137 | |
138 } | |
139 | |
140 // stop playing and empty buffers (for seeking/pause) | |
141 static void reset() { | |
142 | |
143 printf("ao_sgi, reset: ...\n"); | |
144 | |
145 } | |
146 | |
147 // stop playing, keep buffers (for pause) | |
148 static void audio_pause() { | |
149 | |
150 printf("ao_sgi, audio_pause: ...\n"); | |
151 | |
152 } | |
153 | |
154 // resume playing, after audio_pause() | |
155 static void audio_resume() { | |
156 | |
157 printf("ao_sgi, audio_resume: ...\n"); | |
158 | |
159 } | |
160 | |
161 // return: how many bytes can be played without blocking | |
162 static int get_space() { | |
163 | |
164 // printf("ao_sgi, get_space: (ao_outburst %d)\n", ao_outburst); | |
165 // printf("ao_sgi, get_space: alGetFillable [%d] \n", alGetFillable(ao_port)); | |
166 | |
167 return alGetFillable(ao_port)*(2*ao_channels); | |
168 | |
169 } | |
170 | |
171 | |
172 // plays 'len' bytes of 'data' | |
173 // it should round it down to outburst*n | |
174 // return: number of bytes played | |
175 static int play(void* data, int len, int flags) { | |
176 | |
177 // printf("ao_sgi, play: len %d flags %d (%d %d)\n", len, flags, ao_port, ao_config); | |
178 // printf("channels %d\n", ao_channels); | |
179 | |
180 alWriteFrames(ao_port, data, len/(2*ao_channels)); | |
181 | |
182 return len; | |
183 | |
184 } | |
185 | |
186 // return: how many unplayed bytes are in the buffer | |
187 static int get_delay(){ | |
188 | |
189 // printf("ao_sgi, get_delay: (ao_buffersize %d)\n", ao_buffersize); | |
190 | |
191 return 0; | |
192 | |
193 } | |
194 | |
195 | |
196 | |
197 | |
198 | |
199 |