/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1256 - (hide annotations)
Sun Sep 17 11:42:22 2006 UTC (17 years, 8 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 astrand 963 /* -*- c-basic-offset: 8 -*-
2 stargo 744 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 astrand 1032 Copyright (C) Jeremy Meng void.foo@gmail.com 2004, 2005
7 stargo 744
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 astrand 1032 /* #define IRIX_DEBUG 1 */
28 stargo 744
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 stargo 1255 static char *sgi_output_device = NULL;
39 stargo 744
40     double min_volume, max_volume, volume_range;
41     int resource, maxFillable;
42     int combinedFrameSize;
43    
44     BOOL
45 stargo 1255 sgi_open(void)
46 stargo 744 {
47 astrand 746 ALparamInfo pinfo;
48 stargo 1255 static int warned = 0;
49 stargo 744
50     #if (defined(IRIX_DEBUG))
51 stargo 1254 fprintf(stderr, "sgi_open: begin\n");
52 stargo 744 #endif
53    
54 stargo 1255 if (!warned && sgi_output_device)
55     {
56     warning("device-options not supported for libao-driver\n");
57     warned = 1;
58     }
59    
60 astrand 746 if (alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0)
61     {
62 stargo 1254 fprintf(stderr, "sgi_open: alGetParamInfo failed: %s\n",
63 astrand 746 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 stargo 744 #if (defined(IRIX_DEBUG))
69 stargo 1254 fprintf(stderr, "sgi_open: minvol = %lf, maxvol= %lf, range = %lf.\n",
70 astrand 746 min_volume, max_volume, volume_range);
71 stargo 744 #endif
72    
73 stargo 1254 rdpsnd_queue_init();
74 stargo 744
75     audioconfig = alNewConfig();
76 stargo 912 if (audioconfig == (ALconfig) 0)
77 astrand 746 {
78 stargo 1254 fprintf(stderr, "sgi_open: alNewConfig failed: %s\n", alGetErrorString(oserror()));
79 stargo 744 return False;
80     }
81    
82     output_port = alOpenPort("rdpsnd", "w", 0);
83 astrand 746 if (output_port == (ALport) 0)
84     {
85 stargo 1254 fprintf(stderr, "sgi_open: alOpenPort failed: %s\n", alGetErrorString(oserror()));
86 stargo 744 return False;
87     }
88    
89     #if (defined(IRIX_DEBUG))
90 stargo 1254 fprintf(stderr, "sgi_open: returning\n");
91 stargo 744 #endif
92     return True;
93     }
94    
95     void
96 stargo 1255 sgi_close(void)
97 stargo 744 {
98     /* Ack all remaining packets */
99     #if (defined(IRIX_DEBUG))
100 stargo 1254 fprintf(stderr, "sgi_close: begin\n");
101 stargo 744 #endif
102 astrand 746
103 stargo 1254 while (!rdpsnd_queue_empty())
104 stargo 744 {
105 stargo 1254 /* 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 stargo 744 }
111 astrand 746 alDiscardFrames(output_port, 0);
112    
113 stargo 744 alClosePort(output_port);
114     alFreeConfig(audioconfig);
115     #if (defined(IRIX_DEBUG))
116 stargo 1254 fprintf(stderr, "sgi_close: returning\n");
117 stargo 744 #endif
118     }
119    
120     BOOL
121 stargo 1255 sgi_format_supported(WAVEFORMATEX * pwfx)
122 stargo 744 {
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 stargo 1255 sgi_set_format(WAVEFORMATEX * pwfx)
135 stargo 744 {
136     int channels;
137 astrand 746 int frameSize, channelCount;
138     ALpv params;
139    
140 stargo 744 #if (defined(IRIX_DEBUG))
141 stargo 1254 fprintf(stderr, "sgi_set_format: init...\n");
142 stargo 744 #endif
143    
144     g_swapaudio = False;
145     if (pwfx->wBitsPerSample == 8)
146     width = AL_SAMPLE_8;
147 astrand 746 else if (pwfx->wBitsPerSample == 16)
148     {
149 stargo 744 width = AL_SAMPLE_16;
150     /* Do we need to swap the 16bit values? (Are we BigEndian) */
151 stargo 897 #if (defined(B_ENDIAN))
152 stargo 744 g_swapaudio = 1;
153     #else
154     g_swapaudio = 0;
155     #endif
156     }
157    
158 stargo 912 /* Limited support to configure an opened audio port in IRIX. The
159 astrand 909 number of channels is a static setting and can not be changed after
160 stargo 912 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 astrand 909 port, using same config. */
163 stargo 897
164 stargo 744 channels = pwfx->nChannels;
165     g_snd_rate = pwfx->nSamplesPerSec;
166    
167     alSetSampFmt(audioconfig, AL_SAMPFMT_TWOSCOMP);
168     alSetWidth(audioconfig, width);
169 astrand 909 if (channels != alGetChannels(audioconfig))
170 stargo 897 {
171     alClosePort(output_port);
172     alSetChannels(audioconfig, channels);
173     output_port = alOpenPort("rdpsnd", "w", audioconfig);
174 stargo 744
175 stargo 897 if (output_port == (ALport) 0)
176     {
177 stargo 1254 fprintf(stderr, "sgi_set_format: alOpenPort failed: %s\n",
178 astrand 909 alGetErrorString(oserror()));
179 stargo 897 return False;
180     }
181 stargo 744
182     }
183    
184     resource = alGetResource(output_port);
185     maxFillable = alGetFillable(output_port);
186 astrand 746 channelCount = alGetChannels(audioconfig);
187     frameSize = alGetWidth(audioconfig);
188 stargo 744
189 astrand 746 if (frameSize == 0 || channelCount == 0)
190     {
191 stargo 1254 fprintf(stderr, "sgi_set_format: bad frameSize or channelCount\n");
192 astrand 746 return False;
193     }
194     combinedFrameSize = frameSize * channelCount;
195 stargo 744
196 astrand 746 params.param = AL_RATE;
197     params.value.ll = (long long) g_snd_rate << 32;
198 stargo 744
199 astrand 746 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 stargo 744
211     #if (defined(IRIX_DEBUG))
212 stargo 1254 fprintf(stderr, "sgi_set_format: returning...\n");
213 stargo 744 #endif
214     return True;
215     }
216    
217     void
218 stargo 1255 sgi_volume(uint16 left, uint16 right)
219 stargo 744 {
220 astrand 746 double gainleft, gainright;
221     ALpv pv[1];
222     ALfixed gain[8];
223 stargo 744
224     #if (defined(IRIX_DEBUG))
225 stargo 1254 fprintf(stderr, "sgi_volume: begin\n");
226 astrand 746 fprintf(stderr, "left='%d', right='%d'\n", left, right);
227 stargo 744 #endif
228 astrand 746
229     gainleft = (double) left / IRIX_MAX_VOL;
230 stargo 744 gainright = (double) right / IRIX_MAX_VOL;
231    
232 astrand 746 gain[0] = alDoubleToFixed(min_volume + gainleft * volume_range);
233     gain[1] = alDoubleToFixed(min_volume + gainright * volume_range);
234 stargo 744
235 astrand 746 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 stargo 1254 fprintf(stderr, "sgi_volume: alSetParams failed: %s\n",
241 astrand 746 alGetErrorString(oserror()));
242     return;
243     }
244 stargo 744
245     #if (defined(IRIX_DEBUG))
246 stargo 1254 fprintf(stderr, "sgi_volume: returning\n");
247 stargo 744 #endif
248     }
249    
250     void
251 stargo 1255 sgi_play(void)
252 stargo 744 {
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 stargo 1254 if (rdpsnd_queue_empty())
264 stargo 744 {
265     g_dsp_busy = False;
266     return;
267     }
268    
269 stargo 1254 packet = rdpsnd_queue_current_packet();
270 stargo 744 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 astrand 746 alWriteFrames(output_port, out->p, len / combinedFrameSize);
287 stargo 744
288     out->p += len;
289     if (out->p == out->end)
290     {
291 stargo 897 gf = alGetFilled(output_port);
292 astrand 909 if (gf < (4 * maxFillable / 10))
293 stargo 744 {
294     rdpsnd_send_completion(packet->tick, packet->index);
295 stargo 1254 rdpsnd_queue_next();
296 stargo 744 swapped = False;
297     }
298     else
299     {
300     #if (defined(IRIX_DEBUG))
301 stargo 897 /* fprintf(stderr,"Busy playing...\n"); */
302 stargo 744 #endif
303     g_dsp_busy = True;
304 astrand 1032 usleep(10);
305 stargo 744 return;
306     }
307     }
308     }
309     }
310 stargo 1255
311     struct audio_driver *
312     sgi_register(char *options)
313     {
314 stargo 1256 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 stargo 1255 if (options)
328     {
329     sgi_output_device = xstrdup(options);
330     }
331     return &sgi_driver;
332     }

  ViewVC Help
Powered by ViewVC 1.1.26