/[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 1254 - (hide annotations)
Sun Sep 17 10:32:18 2006 UTC (17 years, 9 months ago) by stargo
File MIME type: text/plain
File size: 7120 byte(s)
unify queue-handling in rdpsnd.c (remove private copies from all
drivers)

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    
39     double min_volume, max_volume, volume_range;
40     int resource, maxFillable;
41     int combinedFrameSize;
42    
43     BOOL
44     wave_out_open(void)
45     {
46 astrand 746 ALparamInfo pinfo;
47 stargo 744
48     #if (defined(IRIX_DEBUG))
49 stargo 1254 fprintf(stderr, "sgi_open: begin\n");
50 stargo 744 #endif
51    
52 astrand 746 if (alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0)
53     {
54 stargo 1254 fprintf(stderr, "sgi_open: alGetParamInfo failed: %s\n",
55 astrand 746 alGetErrorString(oserror()));
56     }
57     min_volume = alFixedToDouble(pinfo.min.ll);
58     max_volume = alFixedToDouble(pinfo.max.ll);
59     volume_range = (max_volume - min_volume);
60 stargo 744 #if (defined(IRIX_DEBUG))
61 stargo 1254 fprintf(stderr, "sgi_open: minvol = %lf, maxvol= %lf, range = %lf.\n",
62 astrand 746 min_volume, max_volume, volume_range);
63 stargo 744 #endif
64    
65 stargo 1254 rdpsnd_queue_init();
66 stargo 744
67     audioconfig = alNewConfig();
68 stargo 912 if (audioconfig == (ALconfig) 0)
69 astrand 746 {
70 stargo 1254 fprintf(stderr, "sgi_open: alNewConfig failed: %s\n", alGetErrorString(oserror()));
71 stargo 744 return False;
72     }
73    
74     output_port = alOpenPort("rdpsnd", "w", 0);
75 astrand 746 if (output_port == (ALport) 0)
76     {
77 stargo 1254 fprintf(stderr, "sgi_open: alOpenPort failed: %s\n", alGetErrorString(oserror()));
78 stargo 744 return False;
79     }
80    
81     #if (defined(IRIX_DEBUG))
82 stargo 1254 fprintf(stderr, "sgi_open: returning\n");
83 stargo 744 #endif
84     return True;
85     }
86    
87     void
88     wave_out_close(void)
89     {
90     /* Ack all remaining packets */
91     #if (defined(IRIX_DEBUG))
92 stargo 1254 fprintf(stderr, "sgi_close: begin\n");
93 stargo 744 #endif
94 astrand 746
95 stargo 1254 while (!rdpsnd_queue_empty())
96 stargo 744 {
97 stargo 1254 /* We need to add 50 to tell windows that time has passed while
98     * playing this packet */
99     rdpsnd_send_completion(rdpsnd_queue_current_packet()->tick + 50,
100     rdpsnd_queue_current_packet()->index);
101     rdpsnd_queue_next();
102 stargo 744 }
103 astrand 746 alDiscardFrames(output_port, 0);
104    
105 stargo 744 alClosePort(output_port);
106     alFreeConfig(audioconfig);
107     #if (defined(IRIX_DEBUG))
108 stargo 1254 fprintf(stderr, "sgi_close: returning\n");
109 stargo 744 #endif
110     }
111    
112     BOOL
113     wave_out_format_supported(WAVEFORMATEX * pwfx)
114     {
115     if (pwfx->wFormatTag != WAVE_FORMAT_PCM)
116     return False;
117     if ((pwfx->nChannels != 1) && (pwfx->nChannels != 2))
118     return False;
119     if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16))
120     return False;
121    
122     return True;
123     }
124    
125     BOOL
126     wave_out_set_format(WAVEFORMATEX * pwfx)
127     {
128     int channels;
129 astrand 746 int frameSize, channelCount;
130     ALpv params;
131    
132 stargo 744 #if (defined(IRIX_DEBUG))
133 stargo 1254 fprintf(stderr, "sgi_set_format: init...\n");
134 stargo 744 #endif
135    
136     g_swapaudio = False;
137     if (pwfx->wBitsPerSample == 8)
138     width = AL_SAMPLE_8;
139 astrand 746 else if (pwfx->wBitsPerSample == 16)
140     {
141 stargo 744 width = AL_SAMPLE_16;
142     /* Do we need to swap the 16bit values? (Are we BigEndian) */
143 stargo 897 #if (defined(B_ENDIAN))
144 stargo 744 g_swapaudio = 1;
145     #else
146     g_swapaudio = 0;
147     #endif
148     }
149    
150 stargo 912 /* Limited support to configure an opened audio port in IRIX. The
151 astrand 909 number of channels is a static setting and can not be changed after
152 stargo 912 a port is opened. So if the number of channels remains the same, we
153     can configure other settings; otherwise we have to reopen the audio
154 astrand 909 port, using same config. */
155 stargo 897
156 stargo 744 channels = pwfx->nChannels;
157     g_snd_rate = pwfx->nSamplesPerSec;
158    
159     alSetSampFmt(audioconfig, AL_SAMPFMT_TWOSCOMP);
160     alSetWidth(audioconfig, width);
161 astrand 909 if (channels != alGetChannels(audioconfig))
162 stargo 897 {
163     alClosePort(output_port);
164     alSetChannels(audioconfig, channels);
165     output_port = alOpenPort("rdpsnd", "w", audioconfig);
166 stargo 744
167 stargo 897 if (output_port == (ALport) 0)
168     {
169 stargo 1254 fprintf(stderr, "sgi_set_format: alOpenPort failed: %s\n",
170 astrand 909 alGetErrorString(oserror()));
171 stargo 897 return False;
172     }
173 stargo 744
174     }
175    
176     resource = alGetResource(output_port);
177     maxFillable = alGetFillable(output_port);
178 astrand 746 channelCount = alGetChannels(audioconfig);
179     frameSize = alGetWidth(audioconfig);
180 stargo 744
181 astrand 746 if (frameSize == 0 || channelCount == 0)
182     {
183 stargo 1254 fprintf(stderr, "sgi_set_format: bad frameSize or channelCount\n");
184 astrand 746 return False;
185     }
186     combinedFrameSize = frameSize * channelCount;
187 stargo 744
188 astrand 746 params.param = AL_RATE;
189     params.value.ll = (long long) g_snd_rate << 32;
190 stargo 744
191 astrand 746 if (alSetParams(resource, &params, 1) < 0)
192     {
193     fprintf(stderr, "wave_set_format: alSetParams failed: %s\n",
194     alGetErrorString(oserror()));
195     return False;
196     }
197     if (params.sizeOut < 0)
198     {
199     fprintf(stderr, "wave_set_format: invalid rate %d\n", g_snd_rate);
200     return False;
201     }
202 stargo 744
203     #if (defined(IRIX_DEBUG))
204 stargo 1254 fprintf(stderr, "sgi_set_format: returning...\n");
205 stargo 744 #endif
206     return True;
207     }
208    
209     void
210     wave_out_volume(uint16 left, uint16 right)
211     {
212 astrand 746 double gainleft, gainright;
213     ALpv pv[1];
214     ALfixed gain[8];
215 stargo 744
216     #if (defined(IRIX_DEBUG))
217 stargo 1254 fprintf(stderr, "sgi_volume: begin\n");
218 astrand 746 fprintf(stderr, "left='%d', right='%d'\n", left, right);
219 stargo 744 #endif
220 astrand 746
221     gainleft = (double) left / IRIX_MAX_VOL;
222 stargo 744 gainright = (double) right / IRIX_MAX_VOL;
223    
224 astrand 746 gain[0] = alDoubleToFixed(min_volume + gainleft * volume_range);
225     gain[1] = alDoubleToFixed(min_volume + gainright * volume_range);
226 stargo 744
227 astrand 746 pv[0].param = AL_GAIN;
228     pv[0].value.ptr = gain;
229     pv[0].sizeIn = 8;
230     if (alSetParams(AL_DEFAULT_OUTPUT, pv, 1) < 0)
231     {
232 stargo 1254 fprintf(stderr, "sgi_volume: alSetParams failed: %s\n",
233 astrand 746 alGetErrorString(oserror()));
234     return;
235     }
236 stargo 744
237     #if (defined(IRIX_DEBUG))
238 stargo 1254 fprintf(stderr, "sgi_volume: returning\n");
239 stargo 744 #endif
240     }
241    
242     void
243     wave_out_play(void)
244     {
245     struct audio_packet *packet;
246     ssize_t len;
247     unsigned int i;
248     uint8 swap;
249     STREAM out;
250     static BOOL swapped = False;
251     int gf;
252    
253     while (1)
254     {
255 stargo 1254 if (rdpsnd_queue_empty())
256 stargo 744 {
257     g_dsp_busy = False;
258     return;
259     }
260    
261 stargo 1254 packet = rdpsnd_queue_current_packet();
262 stargo 744 out = &packet->s;
263    
264     /* Swap the current packet, but only once */
265     if (g_swapaudio && !swapped)
266     {
267     for (i = 0; i < out->end - out->p; i += 2)
268     {
269     swap = *(out->p + i);
270     *(out->p + i) = *(out->p + i + 1);
271     *(out->p + i + 1) = swap;
272     }
273     swapped = True;
274     }
275    
276     len = out->end - out->p;
277    
278 astrand 746 alWriteFrames(output_port, out->p, len / combinedFrameSize);
279 stargo 744
280     out->p += len;
281     if (out->p == out->end)
282     {
283 stargo 897 gf = alGetFilled(output_port);
284 astrand 909 if (gf < (4 * maxFillable / 10))
285 stargo 744 {
286     rdpsnd_send_completion(packet->tick, packet->index);
287 stargo 1254 rdpsnd_queue_next();
288 stargo 744 swapped = False;
289     }
290     else
291     {
292     #if (defined(IRIX_DEBUG))
293 stargo 897 /* fprintf(stderr,"Busy playing...\n"); */
294 stargo 744 #endif
295     g_dsp_busy = True;
296 astrand 1032 usleep(10);
297 stargo 744 return;
298     }
299     }
300     }
301     }

  ViewVC Help
Powered by ViewVC 1.1.26