/[rdesktop]/sourceforge.net/trunk/rdesktop/rdpsnd_sgi.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /sourceforge.net/trunk/rdesktop/rdpsnd_sgi.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1256 - (show annotations)
Sun Sep 17 11:42:22 2006 UTC (17 years, 7 months ago) by stargo
File MIME type: text/plain
File size: 7884 byte(s)
fix SunCC errors/warnings and configure-variable-usage (LIBS/LDFLAGS)

1 /* -*- c-basic-offset: 8 -*-
2 rdesktop: A Remote Desktop Protocol client.
3 Sound Channel Process Functions - SGI/IRIX
4 Copyright (C) Matthew Chapman 2003
5 Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003
6 Copyright (C) Jeremy Meng void.foo@gmail.com 2004, 2005
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "rdesktop.h"
24 #include <errno.h>
25 #include <dmedia/audio.h>
26
27 /* #define IRIX_DEBUG 1 */
28
29 #define IRIX_MAX_VOL 65535
30
31 ALconfig audioconfig;
32 ALport output_port;
33
34 static BOOL g_swapaudio;
35 static int g_snd_rate;
36 static BOOL g_swapaudio;
37 static int width = AL_SAMPLE_16;
38 static char *sgi_output_device = NULL;
39
40 double min_volume, max_volume, volume_range;
41 int resource, maxFillable;
42 int combinedFrameSize;
43
44 BOOL
45 sgi_open(void)
46 {
47 ALparamInfo pinfo;
48 static int warned = 0;
49
50 #if (defined(IRIX_DEBUG))
51 fprintf(stderr, "sgi_open: begin\n");
52 #endif
53
54 if (!warned && sgi_output_device)
55 {
56 warning("device-options not supported for libao-driver\n");
57 warned = 1;
58 }
59
60 if (alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0)
61 {
62 fprintf(stderr, "sgi_open: alGetParamInfo failed: %s\n",
63 alGetErrorString(oserror()));
64 }
65 min_volume = alFixedToDouble(pinfo.min.ll);
66 max_volume = alFixedToDouble(pinfo.max.ll);
67 volume_range = (max_volume - min_volume);
68 #if (defined(IRIX_DEBUG))
69 fprintf(stderr, "sgi_open: minvol = %lf, maxvol= %lf, range = %lf.\n",
70 min_volume, max_volume, volume_range);
71 #endif
72
73 rdpsnd_queue_init();
74
75 audioconfig = alNewConfig();
76 if (audioconfig == (ALconfig) 0)
77 {
78 fprintf(stderr, "sgi_open: alNewConfig failed: %s\n", alGetErrorString(oserror()));
79 return False;
80 }
81
82 output_port = alOpenPort("rdpsnd", "w", 0);
83 if (output_port == (ALport) 0)
84 {
85 fprintf(stderr, "sgi_open: alOpenPort failed: %s\n", alGetErrorString(oserror()));
86 return False;
87 }
88
89 #if (defined(IRIX_DEBUG))
90 fprintf(stderr, "sgi_open: returning\n");
91 #endif
92 return True;
93 }
94
95 void
96 sgi_close(void)
97 {
98 /* Ack all remaining packets */
99 #if (defined(IRIX_DEBUG))
100 fprintf(stderr, "sgi_close: begin\n");
101 #endif
102
103 while (!rdpsnd_queue_empty())
104 {
105 /* We need to add 50 to tell windows that time has passed while
106 * playing this packet */
107 rdpsnd_send_completion(rdpsnd_queue_current_packet()->tick + 50,
108 rdpsnd_queue_current_packet()->index);
109 rdpsnd_queue_next();
110 }
111 alDiscardFrames(output_port, 0);
112
113 alClosePort(output_port);
114 alFreeConfig(audioconfig);
115 #if (defined(IRIX_DEBUG))
116 fprintf(stderr, "sgi_close: returning\n");
117 #endif
118 }
119
120 BOOL
121 sgi_format_supported(WAVEFORMATEX * pwfx)
122 {
123 if (pwfx->wFormatTag != WAVE_FORMAT_PCM)
124 return False;
125 if ((pwfx->nChannels != 1) && (pwfx->nChannels != 2))
126 return False;
127 if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16))
128 return False;
129
130 return True;
131 }
132
133 BOOL
134 sgi_set_format(WAVEFORMATEX * pwfx)
135 {
136 int channels;
137 int frameSize, channelCount;
138 ALpv params;
139
140 #if (defined(IRIX_DEBUG))
141 fprintf(stderr, "sgi_set_format: init...\n");
142 #endif
143
144 g_swapaudio = False;
145 if (pwfx->wBitsPerSample == 8)
146 width = AL_SAMPLE_8;
147 else if (pwfx->wBitsPerSample == 16)
148 {
149 width = AL_SAMPLE_16;
150 /* Do we need to swap the 16bit values? (Are we BigEndian) */
151 #if (defined(B_ENDIAN))
152 g_swapaudio = 1;
153 #else
154 g_swapaudio = 0;
155 #endif
156 }
157
158 /* Limited support to configure an opened audio port in IRIX. The
159 number of channels is a static setting and can not be changed after
160 a port is opened. So if the number of channels remains the same, we
161 can configure other settings; otherwise we have to reopen the audio
162 port, using same config. */
163
164 channels = pwfx->nChannels;
165 g_snd_rate = pwfx->nSamplesPerSec;
166
167 alSetSampFmt(audioconfig, AL_SAMPFMT_TWOSCOMP);
168 alSetWidth(audioconfig, width);
169 if (channels != alGetChannels(audioconfig))
170 {
171 alClosePort(output_port);
172 alSetChannels(audioconfig, channels);
173 output_port = alOpenPort("rdpsnd", "w", audioconfig);
174
175 if (output_port == (ALport) 0)
176 {
177 fprintf(stderr, "sgi_set_format: alOpenPort failed: %s\n",
178 alGetErrorString(oserror()));
179 return False;
180 }
181
182 }
183
184 resource = alGetResource(output_port);
185 maxFillable = alGetFillable(output_port);
186 channelCount = alGetChannels(audioconfig);
187 frameSize = alGetWidth(audioconfig);
188
189 if (frameSize == 0 || channelCount == 0)
190 {
191 fprintf(stderr, "sgi_set_format: bad frameSize or channelCount\n");
192 return False;
193 }
194 combinedFrameSize = frameSize * channelCount;
195
196 params.param = AL_RATE;
197 params.value.ll = (long long) g_snd_rate << 32;
198
199 if (alSetParams(resource, &params, 1) < 0)
200 {
201 fprintf(stderr, "wave_set_format: alSetParams failed: %s\n",
202 alGetErrorString(oserror()));
203 return False;
204 }
205 if (params.sizeOut < 0)
206 {
207 fprintf(stderr, "wave_set_format: invalid rate %d\n", g_snd_rate);
208 return False;
209 }
210
211 #if (defined(IRIX_DEBUG))
212 fprintf(stderr, "sgi_set_format: returning...\n");
213 #endif
214 return True;
215 }
216
217 void
218 sgi_volume(uint16 left, uint16 right)
219 {
220 double gainleft, gainright;
221 ALpv pv[1];
222 ALfixed gain[8];
223
224 #if (defined(IRIX_DEBUG))
225 fprintf(stderr, "sgi_volume: begin\n");
226 fprintf(stderr, "left='%d', right='%d'\n", left, right);
227 #endif
228
229 gainleft = (double) left / IRIX_MAX_VOL;
230 gainright = (double) right / IRIX_MAX_VOL;
231
232 gain[0] = alDoubleToFixed(min_volume + gainleft * volume_range);
233 gain[1] = alDoubleToFixed(min_volume + gainright * volume_range);
234
235 pv[0].param = AL_GAIN;
236 pv[0].value.ptr = gain;
237 pv[0].sizeIn = 8;
238 if (alSetParams(AL_DEFAULT_OUTPUT, pv, 1) < 0)
239 {
240 fprintf(stderr, "sgi_volume: alSetParams failed: %s\n",
241 alGetErrorString(oserror()));
242 return;
243 }
244
245 #if (defined(IRIX_DEBUG))
246 fprintf(stderr, "sgi_volume: returning\n");
247 #endif
248 }
249
250 void
251 sgi_play(void)
252 {
253 struct audio_packet *packet;
254 ssize_t len;
255 unsigned int i;
256 uint8 swap;
257 STREAM out;
258 static BOOL swapped = False;
259 int gf;
260
261 while (1)
262 {
263 if (rdpsnd_queue_empty())
264 {
265 g_dsp_busy = False;
266 return;
267 }
268
269 packet = rdpsnd_queue_current_packet();
270 out = &packet->s;
271
272 /* Swap the current packet, but only once */
273 if (g_swapaudio && !swapped)
274 {
275 for (i = 0; i < out->end - out->p; i += 2)
276 {
277 swap = *(out->p + i);
278 *(out->p + i) = *(out->p + i + 1);
279 *(out->p + i + 1) = swap;
280 }
281 swapped = True;
282 }
283
284 len = out->end - out->p;
285
286 alWriteFrames(output_port, out->p, len / combinedFrameSize);
287
288 out->p += len;
289 if (out->p == out->end)
290 {
291 gf = alGetFilled(output_port);
292 if (gf < (4 * maxFillable / 10))
293 {
294 rdpsnd_send_completion(packet->tick, packet->index);
295 rdpsnd_queue_next();
296 swapped = False;
297 }
298 else
299 {
300 #if (defined(IRIX_DEBUG))
301 /* fprintf(stderr,"Busy playing...\n"); */
302 #endif
303 g_dsp_busy = True;
304 usleep(10);
305 return;
306 }
307 }
308 }
309 }
310
311 struct audio_driver *
312 sgi_register(char *options)
313 {
314 static struct audio_driver sgi_driver;
315
316 sgi_driver.wave_out_write = rdpsnd_queue_write;
317 sgi_driver.wave_out_open = sgi_open;
318 sgi_driver.wave_out_close = sgi_close;
319 sgi_driver.wave_out_format_supported = sgi_format_supported;
320 sgi_driver.wave_out_set_format = sgi_set_format;
321 sgi_driver.wave_out_volume = sgi_volume;
322 sgi_driver.wave_out_play = sgi_play;
323 sgi_driver.name = xstrdup("sgi");
324 sgi_driver.description = xstrdup("SGI output driver");
325 sgi_driver.next = NULL;
326
327 if (options)
328 {
329 sgi_output_device = xstrdup(options);
330 }
331 return &sgi_driver;
332 }

  ViewVC Help
Powered by ViewVC 1.1.26