28 |
|
|
29 |
#define IRIX_MAX_VOL 65535 |
#define IRIX_MAX_VOL 65535 |
30 |
|
|
|
#define MAX_QUEUE 10 |
|
|
|
|
|
int g_dsp_fd; |
|
31 |
ALconfig audioconfig; |
ALconfig audioconfig; |
32 |
ALport output_port; |
ALport output_port; |
33 |
|
|
|
BOOL g_dsp_busy = False; |
|
|
static BOOL g_swapaudio; |
|
34 |
static int g_snd_rate; |
static int g_snd_rate; |
|
static BOOL g_swapaudio; |
|
35 |
static int width = AL_SAMPLE_16; |
static int width = AL_SAMPLE_16; |
36 |
|
static char *sgi_output_device = NULL; |
37 |
|
|
38 |
double min_volume, max_volume, volume_range; |
double min_volume, max_volume, volume_range; |
39 |
int resource, maxFillable; |
int resource, maxFillable; |
40 |
int combinedFrameSize; |
int combinedFrameSize; |
41 |
|
|
|
static struct audio_packet |
|
|
{ |
|
|
struct stream s; |
|
|
uint16 tick; |
|
|
uint8 index; |
|
|
} packet_queue[MAX_QUEUE]; |
|
|
static unsigned int queue_hi, queue_lo; |
|
|
|
|
42 |
BOOL |
BOOL |
43 |
wave_out_open(void) |
sgi_open(void) |
44 |
{ |
{ |
45 |
ALparamInfo pinfo; |
ALparamInfo pinfo; |
46 |
|
static int warned = 0; |
47 |
|
|
48 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
49 |
fprintf(stderr, "wave_out_open: begin\n"); |
fprintf(stderr, "sgi_open: begin\n"); |
50 |
#endif |
#endif |
51 |
|
|
52 |
|
if (!warned && sgi_output_device) |
53 |
|
{ |
54 |
|
warning("device-options not supported for libao-driver\n"); |
55 |
|
warned = 1; |
56 |
|
} |
57 |
|
|
58 |
if (alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0) |
if (alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0) |
59 |
{ |
{ |
60 |
fprintf(stderr, "wave_out_open: alGetParamInfo failed: %s\n", |
fprintf(stderr, "sgi_open: alGetParamInfo failed: %s\n", |
61 |
alGetErrorString(oserror())); |
alGetErrorString(oserror())); |
62 |
} |
} |
63 |
min_volume = alFixedToDouble(pinfo.min.ll); |
min_volume = alFixedToDouble(pinfo.min.ll); |
64 |
max_volume = alFixedToDouble(pinfo.max.ll); |
max_volume = alFixedToDouble(pinfo.max.ll); |
65 |
volume_range = (max_volume - min_volume); |
volume_range = (max_volume - min_volume); |
66 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
67 |
fprintf(stderr, "wave_out_open: minvol = %lf, maxvol= %lf, range = %lf.\n", |
fprintf(stderr, "sgi_open: minvol = %lf, maxvol= %lf, range = %lf.\n", |
68 |
min_volume, max_volume, volume_range); |
min_volume, max_volume, volume_range); |
69 |
#endif |
#endif |
70 |
|
|
|
queue_lo = queue_hi = 0; |
|
|
|
|
71 |
audioconfig = alNewConfig(); |
audioconfig = alNewConfig(); |
72 |
if (audioconfig == (ALconfig) 0) |
if (audioconfig == (ALconfig) 0) |
73 |
{ |
{ |
74 |
fprintf(stderr, "wave_out_open: alNewConfig failed: %s\n", |
fprintf(stderr, "sgi_open: alNewConfig failed: %s\n", alGetErrorString(oserror())); |
|
alGetErrorString(oserror())); |
|
75 |
return False; |
return False; |
76 |
} |
} |
77 |
|
|
78 |
output_port = alOpenPort("rdpsnd", "w", 0); |
output_port = alOpenPort("rdpsnd", "w", 0); |
79 |
if (output_port == (ALport) 0) |
if (output_port == (ALport) 0) |
80 |
{ |
{ |
81 |
fprintf(stderr, "wave_out_open: alOpenPort failed: %s\n", |
fprintf(stderr, "sgi_open: alOpenPort failed: %s\n", alGetErrorString(oserror())); |
|
alGetErrorString(oserror())); |
|
82 |
return False; |
return False; |
83 |
} |
} |
84 |
|
|
85 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
86 |
fprintf(stderr, "wave_out_open: returning\n"); |
fprintf(stderr, "sgi_open: returning\n"); |
87 |
#endif |
#endif |
88 |
return True; |
return True; |
89 |
} |
} |
90 |
|
|
91 |
void |
void |
92 |
wave_out_close(void) |
sgi_close(void) |
93 |
{ |
{ |
94 |
/* Ack all remaining packets */ |
/* Ack all remaining packets */ |
95 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
96 |
fprintf(stderr, "wave_out_close: begin\n"); |
fprintf(stderr, "sgi_close: begin\n"); |
97 |
#endif |
#endif |
98 |
|
|
99 |
while (queue_lo != queue_hi) |
while (!rdpsnd_queue_empty()) |
100 |
{ |
rdpsnd_queue_next(0); |
|
rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index); |
|
|
free(packet_queue[queue_lo].s.data); |
|
|
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
|
|
} |
|
101 |
alDiscardFrames(output_port, 0); |
alDiscardFrames(output_port, 0); |
102 |
|
|
103 |
alClosePort(output_port); |
alClosePort(output_port); |
104 |
alFreeConfig(audioconfig); |
alFreeConfig(audioconfig); |
105 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
106 |
fprintf(stderr, "wave_out_close: returning\n"); |
fprintf(stderr, "sgi_close: returning\n"); |
107 |
#endif |
#endif |
108 |
} |
} |
109 |
|
|
110 |
BOOL |
BOOL |
111 |
wave_out_format_supported(WAVEFORMATEX * pwfx) |
sgi_format_supported(WAVEFORMATEX * pwfx) |
112 |
{ |
{ |
113 |
if (pwfx->wFormatTag != WAVE_FORMAT_PCM) |
if (pwfx->wFormatTag != WAVE_FORMAT_PCM) |
114 |
return False; |
return False; |
121 |
} |
} |
122 |
|
|
123 |
BOOL |
BOOL |
124 |
wave_out_set_format(WAVEFORMATEX * pwfx) |
sgi_set_format(WAVEFORMATEX * pwfx) |
125 |
{ |
{ |
126 |
int channels; |
int channels; |
127 |
int frameSize, channelCount; |
int frameSize, channelCount; |
128 |
ALpv params; |
ALpv params; |
129 |
|
|
130 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
131 |
fprintf(stderr, "wave_out_set_format: init...\n"); |
fprintf(stderr, "sgi_set_format: init...\n"); |
132 |
#endif |
#endif |
133 |
|
|
|
g_swapaudio = False; |
|
134 |
if (pwfx->wBitsPerSample == 8) |
if (pwfx->wBitsPerSample == 8) |
135 |
width = AL_SAMPLE_8; |
width = AL_SAMPLE_8; |
136 |
else if (pwfx->wBitsPerSample == 16) |
else if (pwfx->wBitsPerSample == 16) |
|
{ |
|
137 |
width = AL_SAMPLE_16; |
width = AL_SAMPLE_16; |
|
/* Do we need to swap the 16bit values? (Are we BigEndian) */ |
|
|
#if (defined(B_ENDIAN)) |
|
|
g_swapaudio = 1; |
|
|
#else |
|
|
g_swapaudio = 0; |
|
|
#endif |
|
|
} |
|
138 |
|
|
139 |
/* Limited support to configure an opened audio port in IRIX. The |
/* Limited support to configure an opened audio port in IRIX. The |
140 |
number of channels is a static setting and can not be changed after |
number of channels is a static setting and can not be changed after |
155 |
|
|
156 |
if (output_port == (ALport) 0) |
if (output_port == (ALport) 0) |
157 |
{ |
{ |
158 |
fprintf(stderr, "wave_out_set_format: alOpenPort failed: %s\n", |
fprintf(stderr, "sgi_set_format: alOpenPort failed: %s\n", |
159 |
alGetErrorString(oserror())); |
alGetErrorString(oserror())); |
160 |
return False; |
return False; |
161 |
} |
} |
169 |
|
|
170 |
if (frameSize == 0 || channelCount == 0) |
if (frameSize == 0 || channelCount == 0) |
171 |
{ |
{ |
172 |
fprintf(stderr, "wave_out_set_format: bad frameSize or channelCount\n"); |
fprintf(stderr, "sgi_set_format: bad frameSize or channelCount\n"); |
173 |
return False; |
return False; |
174 |
} |
} |
175 |
combinedFrameSize = frameSize * channelCount; |
combinedFrameSize = frameSize * channelCount; |
190 |
} |
} |
191 |
|
|
192 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
193 |
fprintf(stderr, "wave_out_set_format: returning...\n"); |
fprintf(stderr, "sgi_set_format: returning...\n"); |
194 |
#endif |
#endif |
195 |
return True; |
return True; |
196 |
} |
} |
197 |
|
|
198 |
void |
void |
199 |
wave_out_volume(uint16 left, uint16 right) |
sgi_volume(uint16 left, uint16 right) |
200 |
{ |
{ |
201 |
double gainleft, gainright; |
double gainleft, gainright; |
202 |
ALpv pv[1]; |
ALpv pv[1]; |
203 |
ALfixed gain[8]; |
ALfixed gain[8]; |
204 |
|
|
205 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
206 |
fprintf(stderr, "wave_out_volume: begin\n"); |
fprintf(stderr, "sgi_volume: begin\n"); |
207 |
fprintf(stderr, "left='%d', right='%d'\n", left, right); |
fprintf(stderr, "left='%d', right='%d'\n", left, right); |
208 |
#endif |
#endif |
209 |
|
|
218 |
pv[0].sizeIn = 8; |
pv[0].sizeIn = 8; |
219 |
if (alSetParams(AL_DEFAULT_OUTPUT, pv, 1) < 0) |
if (alSetParams(AL_DEFAULT_OUTPUT, pv, 1) < 0) |
220 |
{ |
{ |
221 |
fprintf(stderr, "wave_out_volume: alSetParams failed: %s\n", |
fprintf(stderr, "sgi_volume: alSetParams failed: %s\n", |
222 |
alGetErrorString(oserror())); |
alGetErrorString(oserror())); |
223 |
return; |
return; |
224 |
} |
} |
225 |
|
|
226 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
227 |
fprintf(stderr, "wave_out_volume: returning\n"); |
fprintf(stderr, "sgi_volume: returning\n"); |
228 |
#endif |
#endif |
229 |
} |
} |
230 |
|
|
231 |
void |
void |
232 |
wave_out_write(STREAM s, uint16 tick, uint8 index) |
sgi_play(void) |
|
{ |
|
|
struct audio_packet *packet = &packet_queue[queue_hi]; |
|
|
unsigned int next_hi = (queue_hi + 1) % MAX_QUEUE; |
|
|
|
|
|
if (next_hi == queue_lo) |
|
|
{ |
|
|
fprintf(stderr, "No space to queue audio packet\n"); |
|
|
return; |
|
|
} |
|
|
|
|
|
queue_hi = next_hi; |
|
|
|
|
|
packet->s = *s; |
|
|
packet->tick = tick; |
|
|
packet->index = index; |
|
|
packet->s.p += 4; |
|
|
|
|
|
/* we steal the data buffer from s, give it a new one */ |
|
|
s->data = malloc(s->size); |
|
|
|
|
|
if (!g_dsp_busy) |
|
|
wave_out_play(); |
|
|
} |
|
|
|
|
|
void |
|
|
wave_out_play(void) |
|
233 |
{ |
{ |
234 |
struct audio_packet *packet; |
struct audio_packet *packet; |
235 |
ssize_t len; |
ssize_t len; |
236 |
unsigned int i; |
unsigned int i; |
|
uint8 swap; |
|
237 |
STREAM out; |
STREAM out; |
|
static BOOL swapped = False; |
|
238 |
int gf; |
int gf; |
239 |
|
|
240 |
while (1) |
while (1) |
241 |
{ |
{ |
242 |
if (queue_lo == queue_hi) |
if (rdpsnd_queue_empty()) |
243 |
{ |
{ |
244 |
g_dsp_busy = False; |
g_dsp_busy = False; |
245 |
return; |
return; |
246 |
} |
} |
247 |
|
|
248 |
packet = &packet_queue[queue_lo]; |
packet = rdpsnd_queue_current_packet(); |
249 |
out = &packet->s; |
out = &packet->s; |
250 |
|
|
|
/* Swap the current packet, but only once */ |
|
|
if (g_swapaudio && !swapped) |
|
|
{ |
|
|
for (i = 0; i < out->end - out->p; i += 2) |
|
|
{ |
|
|
swap = *(out->p + i); |
|
|
*(out->p + i) = *(out->p + i + 1); |
|
|
*(out->p + i + 1) = swap; |
|
|
} |
|
|
swapped = True; |
|
|
} |
|
|
|
|
251 |
len = out->end - out->p; |
len = out->end - out->p; |
252 |
|
|
253 |
alWriteFrames(output_port, out->p, len / combinedFrameSize); |
alWriteFrames(output_port, out->p, len / combinedFrameSize); |
258 |
gf = alGetFilled(output_port); |
gf = alGetFilled(output_port); |
259 |
if (gf < (4 * maxFillable / 10)) |
if (gf < (4 * maxFillable / 10)) |
260 |
{ |
{ |
261 |
rdpsnd_send_completion(packet->tick, packet->index); |
rdpsnd_queue_next(0); |
|
free(out->data); |
|
|
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
|
|
swapped = False; |
|
262 |
} |
} |
263 |
else |
else |
264 |
{ |
{ |
272 |
} |
} |
273 |
} |
} |
274 |
} |
} |
275 |
|
|
276 |
|
struct audio_driver * |
277 |
|
sgi_register(char *options) |
278 |
|
{ |
279 |
|
static struct audio_driver sgi_driver; |
280 |
|
|
281 |
|
sgi_driver.wave_out_open = sgi_open; |
282 |
|
sgi_driver.wave_out_close = sgi_close; |
283 |
|
sgi_driver.wave_out_format_supported = sgi_format_supported; |
284 |
|
sgi_driver.wave_out_set_format = sgi_set_format; |
285 |
|
sgi_driver.wave_out_volume = sgi_volume; |
286 |
|
sgi_driver.wave_out_play = sgi_play; |
287 |
|
sgi_driver.name = xstrdup("sgi"); |
288 |
|
sgi_driver.description = xstrdup("SGI output driver"); |
289 |
|
sgi_driver.need_byteswap_on_be = 1; |
290 |
|
sgi_driver.need_resampling = 0; |
291 |
|
sgi_driver.next = NULL; |
292 |
|
|
293 |
|
if (options) |
294 |
|
{ |
295 |
|
sgi_output_device = xstrdup(options); |
296 |
|
} |
297 |
|
return &sgi_driver; |
298 |
|
} |