ReactOS 0.4.15-dev-8428-g6910fa6
rdpsnd_sgi.c File Reference
#include "rdesktop.h"
#include <errno.h>
#include <dmedia/audio.h>
Include dependency graph for rdpsnd_sgi.c:

Go to the source code of this file.

Classes

struct  audio_packet
 

Macros

#define IRIX_MAX_VOL   65535
 
#define MAX_QUEUE   10
 

Functions

BOOL wave_out_open (void)
 
void wave_out_close (void)
 
BOOL wave_out_format_supported (WAVEFORMATEX *pwfx)
 
BOOL wave_out_set_format (WAVEFORMATEX *pwfx)
 
void wave_out_volume (uint16 left, uint16 right)
 
void wave_out_write (STREAM s, uint16 tick, uint8 index)
 
void wave_out_play (void)
 

Variables

int This dsp_
 
ALconfig audioconfig
 
ALport output_port
 
BOOL This dsp_bu = False
 
static BOOL g_swapaudio
 
static int g_snd_rate
 
static int width = AL_SAMPLE_16
 
double min_volume
 
double max_volume
 
double volume_range
 
int resource
 
int maxFillable
 
int combinedFrameSize
 
static struct audio_packet packet_queue [MAX_QUEUE]
 
static unsigned int queue_hi
 
static unsigned int queue_lo
 

Macro Definition Documentation

◆ IRIX_MAX_VOL

#define IRIX_MAX_VOL   65535

Definition at line 29 of file rdpsnd_sgi.c.

◆ MAX_QUEUE

#define MAX_QUEUE   10

Definition at line 31 of file rdpsnd_sgi.c.

Function Documentation

◆ wave_out_close()

void wave_out_close ( void  )

Definition at line 102 of file rdpsnd_sgi.c.

103{
104 /* Ack all remaining packets */
105#if (defined(IRIX_DEBUG))
106 fprintf(stderr, "wave_out_close: begin\n");
107#endif
108
109 while (queue_lo != queue_hi)
110 {
113 queue_lo = (queue_lo + 1) % MAX_QUEUE;
114 }
115 alDiscardFrames(output_port, 0);
116
117 alClosePort(output_port);
118 alFreeConfig(audioconfig);
119#if (defined(IRIX_DEBUG))
120 fprintf(stderr, "wave_out_close: returning\n");
121#endif
122}
#define free
Definition: debug_ros.c:5
GLdouble s
Definition: gl.h:2039
GLuint index
Definition: glext.h:6031
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
void rdpsnd_send_completion(RDPCLIENT *This, uint16 tick, uint8 packet_index)
Definition: rdpsnd.c:55
ALport output_port
Definition: rdpsnd_sgi.c:35
static unsigned int queue_lo
Definition: rdpsnd_sgi.c:53
ALconfig audioconfig
Definition: rdpsnd_sgi.c:34
static unsigned int queue_hi
Definition: rdpsnd_sgi.c:53
#define MAX_QUEUE
Definition: rdpsnd_sgi.c:31
static struct audio_packet packet_queue[MAX_QUEUE]

◆ wave_out_format_supported()

BOOL wave_out_format_supported ( WAVEFORMATEX pwfx)

Definition at line 125 of file rdpsnd_sgi.c.

126{
127 if (pwfx->wFormatTag != WAVE_FORMAT_PCM)
128 return False;
129 if ((pwfx->nChannels != 1) && (pwfx->nChannels != 2))
130 return False;
131 if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16))
132 return False;
133
134 return True;
135}
#define WAVE_FORMAT_PCM
Definition: constants.h:425
#define False
Definition: types.h:25
#define True
Definition: types.h:24
WORD wBitsPerSample
Definition: audioclient.idl:45

◆ wave_out_open()

BOOL wave_out_open ( void  )

Definition at line 56 of file rdpsnd_sgi.c.

57{
58 ALparamInfo pinfo;
59
60#if (defined(IRIX_DEBUG))
61 fprintf(stderr, "wave_out_open: begin\n");
62#endif
63
64 if (alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0)
65 {
66 fprintf(stderr, "wave_out_open: alGetParamInfo failed: %s\n",
67 alGetErrorString(oserror()));
68 }
69 min_volume = alFixedToDouble(pinfo.min.ll);
70 max_volume = alFixedToDouble(pinfo.max.ll);
72#if (defined(IRIX_DEBUG))
73 fprintf(stderr, "wave_out_open: minvol = %lf, maxvol= %lf, range = %lf.\n",
75#endif
76
77 queue_lo = queue_hi = 0;
78
79 audioconfig = alNewConfig();
80 if (audioconfig == (ALconfig) 0)
81 {
82 fprintf(stderr, "wave_out_open: alNewConfig failed: %s\n",
83 alGetErrorString(oserror()));
84 return False;
85 }
86
87 output_port = alOpenPort("rdpsnd", "w", 0);
88 if (output_port == (ALport) 0)
89 {
90 fprintf(stderr, "wave_out_open: alOpenPort failed: %s\n",
91 alGetErrorString(oserror()));
92 return False;
93 }
94
95#if (defined(IRIX_DEBUG))
96 fprintf(stderr, "wave_out_open: returning\n");
97#endif
98 return True;
99}
double max_volume
Definition: rdpsnd_sgi.c:43
double volume_range
Definition: rdpsnd_sgi.c:43
double min_volume
Definition: rdpsnd_sgi.c:43

◆ wave_out_play()

void wave_out_play ( void  )

Definition at line 281 of file rdpsnd_sgi.c.

282{
283 struct audio_packet *packet;
284 ssize_t len;
285 unsigned int i;
286 uint8 swap;
287 STREAM out;
288 static BOOL swapped = False;
289 int gf;
290
291 while (1)
292 {
293 if (queue_lo == queue_hi)
294 {
295 This->dsp_bu = False;
296 return;
297 }
298
300 out = &packet->s;
301
302 /* Swap the current packet, but only once */
303 if (g_swapaudio && !swapped)
304 {
305 for (i = 0; i < out->end - out->p; i += 2)
306 {
307 swap = *(out->p + i);
308 *(out->p + i) = *(out->p + i + 1);
309 *(out->p + i + 1) = swap;
310 }
311 swapped = True;
312 }
313
314 len = out->end - out->p;
315
316 alWriteFrames(output_port, out->p, len / combinedFrameSize);
317
318 out->p += len;
319 if (out->p == out->end)
320 {
321 gf = alGetFilled(output_port);
322 if (gf < (4 * maxFillable / 10))
323 {
324 rdpsnd_send_completion(packet->tick, packet->index);
325 free(out->data);
326 queue_lo = (queue_lo + 1) % MAX_QUEUE;
327 swapped = False;
328 }
329 else
330 {
331#if (defined(IRIX_DEBUG))
332/* fprintf(stderr,"Busy playing...\n"); */
333#endif
334 This->dsp_bu = True;
335 usleep(10);
336 return;
337 }
338 }
339 }
340}
unsigned char uint8
Definition: types.h:28
unsigned int BOOL
Definition: ntddk_ex.h:94
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int usleep(unsigned int useconds)
#define swap(a, b)
Definition: qsort.c:63
static BOOL g_swapaudio
Definition: rdpsnd_sgi.c:38
int combinedFrameSize
Definition: rdpsnd_sgi.c:45
int maxFillable
Definition: rdpsnd_sgi.c:44
static FILE * out
Definition: regtests2xml.c:44
int ssize_t
Definition: rosdhcp.h:48
Definition: dhcpd.h:135
Definition: parse.h:23

Referenced by wave_out_write().

◆ wave_out_set_format()

BOOL wave_out_set_format ( WAVEFORMATEX pwfx)

Definition at line 138 of file rdpsnd_sgi.c.

139{
140 int channels;
141 int frameSize, channelCount;
142 ALpv params;
143
144#if (defined(IRIX_DEBUG))
145 fprintf(stderr, "wave_out_set_format: init...\n");
146#endif
147
149 if (pwfx->wBitsPerSample == 8)
150 width = AL_SAMPLE_8;
151 else if (pwfx->wBitsPerSample == 16)
152 {
153 width = AL_SAMPLE_16;
154 /* Do we need to swap the 16bit values? (Are we BigEndian) */
155#if (defined(B_ENDIAN))
156 g_swapaudio = 1;
157#else
158 g_swapaudio = 0;
159#endif
160 }
161
162 /* Limited support to configure an opened audio port in IRIX. The
163 number of channels is a static setting and can not be changed after
164 a port is opened. So if the number of channels remains the same, we
165 can configure other settings; otherwise we have to reopen the audio
166 port, using same config. */
167
168 channels = pwfx->nChannels;
170
171 alSetSampFmt(audioconfig, AL_SAMPFMT_TWOSCOMP);
172 alSetWidth(audioconfig, width);
173 if (channels != alGetChannels(audioconfig))
174 {
175 alClosePort(output_port);
176 alSetChannels(audioconfig, channels);
177 output_port = alOpenPort("rdpsnd", "w", audioconfig);
178
179 if (output_port == (ALport) 0)
180 {
181 fprintf(stderr, "wave_out_set_format: alOpenPort failed: %s\n",
182 alGetErrorString(oserror()));
183 return False;
184 }
185
186 }
187
188 resource = alGetResource(output_port);
189 maxFillable = alGetFillable(output_port);
190 channelCount = alGetChannels(audioconfig);
191 frameSize = alGetWidth(audioconfig);
192
193 if (frameSize == 0 || channelCount == 0)
194 {
195 fprintf(stderr, "wave_out_set_format: bad frameSize or channelCount\n");
196 return False;
197 }
198 combinedFrameSize = frameSize * channelCount;
199
200 params.param = AL_RATE;
201 params.value.ll = (long long) g_snd_rate << 32;
202
203 if (alSetParams(resource, &params, 1) < 0)
204 {
205 fprintf(stderr, "wave_set_format: alSetParams failed: %s\n",
206 alGetErrorString(oserror()));
207 return False;
208 }
209 if (params.sizeOut < 0)
210 {
211 fprintf(stderr, "wave_set_format: invalid rate %d\n", g_snd_rate);
212 return False;
213 }
214
215#if (defined(IRIX_DEBUG))
216 fprintf(stderr, "wave_out_set_format: returning...\n");
217#endif
218 return True;
219}
GLint GLint GLsizei width
Definition: gl.h:1546
GLenum const GLfloat * params
Definition: glext.h:5645
#define long
Definition: qsort.c:33
int This channels
Definition: rdpsnd_libao.c:37
static int g_snd_rate
Definition: rdpsnd_sgi.c:39
DWORD nSamplesPerSec
Definition: audioclient.idl:42

◆ wave_out_volume()

void wave_out_volume ( uint16  left,
uint16  right 
)

Definition at line 222 of file rdpsnd_sgi.c.

223{
224 double gainleft, gainright;
225 ALpv pv[1];
226 ALfixed gain[8];
227
228#if (defined(IRIX_DEBUG))
229 fprintf(stderr, "wave_out_volume: begin\n");
230 fprintf(stderr, "left='%d', right='%d'\n", left, right);
231#endif
232
233 gainleft = (double) left / IRIX_MAX_VOL;
234 gainright = (double) right / IRIX_MAX_VOL;
235
236 gain[0] = alDoubleToFixed(min_volume + gainleft * volume_range);
237 gain[1] = alDoubleToFixed(min_volume + gainright * volume_range);
238
239 pv[0].param = AL_GAIN;
240 pv[0].value.ptr = gain;
241 pv[0].sizeIn = 8;
242 if (alSetParams(AL_DEFAULT_OUTPUT, pv, 1) < 0)
243 {
244 fprintf(stderr, "wave_out_volume: alSetParams failed: %s\n",
245 alGetErrorString(oserror()));
246 return;
247 }
248
249#if (defined(IRIX_DEBUG))
250 fprintf(stderr, "wave_out_volume: returning\n");
251#endif
252}
GLdouble GLdouble right
Definition: glext.h:10859
GLint left
Definition: glext.h:7726
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
#define IRIX_MAX_VOL
Definition: rdpsnd_sgi.c:29

◆ wave_out_write()

void wave_out_write ( STREAM  s,
uint16  tick,
uint8  index 
)

Definition at line 255 of file rdpsnd_sgi.c.

256{
258 unsigned int next_hi = (queue_hi + 1) % MAX_QUEUE;
259
260 if (next_hi == queue_lo)
261 {
262 fprintf(stderr, "No space to queue audio packet\n");
263 return;
264 }
265
266 queue_hi = next_hi;
267
268 packet->s = *s;
269 packet->tick = tick;
270 packet->index = index;
271 packet->s.p += 4;
272
273 /* we steal the data buffer from s, give it a new one */
274 s->data = malloc(s->size);
275
276 if (!This->dsp_bu)
278}
#define index(s, c)
Definition: various.h:29
#define malloc
Definition: debug_ros.c:4
void wave_out_play(void)
Definition: rdpsnd_sgi.c:281

Variable Documentation

◆ audioconfig

ALconfig audioconfig

Definition at line 34 of file rdpsnd_sgi.c.

Referenced by wave_out_close(), wave_out_open(), and wave_out_set_format().

◆ combinedFrameSize

int combinedFrameSize

Definition at line 45 of file rdpsnd_sgi.c.

Referenced by wave_out_play(), and wave_out_set_format().

◆ dsp_

int This dsp_

Definition at line 33 of file rdpsnd_sgi.c.

◆ dsp_bu

BOOL This dsp_bu = False

Definition at line 37 of file rdpsnd_sgi.c.

◆ g_snd_rate

int g_snd_rate
static

Definition at line 39 of file rdpsnd_sgi.c.

Referenced by wave_out_set_format().

◆ g_swapaudio

static BOOL g_swapaudio
static

Definition at line 38 of file rdpsnd_sgi.c.

Referenced by wave_out_play(), and wave_out_set_format().

◆ max_volume

double max_volume

Definition at line 43 of file rdpsnd_sgi.c.

Referenced by wave_out_open().

◆ maxFillable

int maxFillable

Definition at line 44 of file rdpsnd_sgi.c.

Referenced by wave_out_play(), and wave_out_set_format().

◆ min_volume

double min_volume

Definition at line 43 of file rdpsnd_sgi.c.

Referenced by wave_out_open(), and wave_out_volume().

◆ output_port

ALport output_port

Definition at line 35 of file rdpsnd_sgi.c.

Referenced by wave_out_close(), wave_out_open(), wave_out_play(), and wave_out_set_format().

◆ packet_queue

◆ queue_hi

unsigned int queue_hi
static

Definition at line 53 of file rdpsnd_sgi.c.

Referenced by wave_out_close(), wave_out_open(), wave_out_play(), and wave_out_write().

◆ queue_lo

unsigned int queue_lo
static

Definition at line 53 of file rdpsnd_sgi.c.

Referenced by wave_out_close(), wave_out_open(), wave_out_play(), and wave_out_write().

◆ resource

Definition at line 44 of file rdpsnd_sgi.c.

◆ volume_range

double volume_range

Definition at line 43 of file rdpsnd_sgi.c.

Referenced by wave_out_open(), and wave_out_volume().

◆ width

int width = AL_SAMPLE_16
static

Definition at line 41 of file rdpsnd_sgi.c.