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; |
|
34 |
static BOOL g_swapaudio; |
static BOOL g_swapaudio; |
35 |
static int g_snd_rate; |
static int g_snd_rate; |
36 |
static BOOL g_swapaudio; |
static BOOL g_swapaudio; |
40 |
int resource, maxFillable; |
int resource, maxFillable; |
41 |
int combinedFrameSize; |
int combinedFrameSize; |
42 |
|
|
|
static struct audio_packet |
|
|
{ |
|
|
struct stream s; |
|
|
uint16 tick; |
|
|
uint8 index; |
|
|
} packet_queue[MAX_QUEUE]; |
|
|
static unsigned int queue_hi, queue_lo; |
|
|
|
|
43 |
BOOL |
BOOL |
44 |
wave_out_open(void) |
wave_out_open(void) |
45 |
{ |
{ |
46 |
ALparamInfo pinfo; |
ALparamInfo pinfo; |
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 (alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0) |
if (alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0) |
53 |
{ |
{ |
54 |
fprintf(stderr, "wave_out_open: alGetParamInfo failed: %s\n", |
fprintf(stderr, "sgi_open: alGetParamInfo failed: %s\n", |
55 |
alGetErrorString(oserror())); |
alGetErrorString(oserror())); |
56 |
} |
} |
57 |
min_volume = alFixedToDouble(pinfo.min.ll); |
min_volume = alFixedToDouble(pinfo.min.ll); |
58 |
max_volume = alFixedToDouble(pinfo.max.ll); |
max_volume = alFixedToDouble(pinfo.max.ll); |
59 |
volume_range = (max_volume - min_volume); |
volume_range = (max_volume - min_volume); |
60 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
61 |
fprintf(stderr, "wave_out_open: minvol = %lf, maxvol= %lf, range = %lf.\n", |
fprintf(stderr, "sgi_open: minvol = %lf, maxvol= %lf, range = %lf.\n", |
62 |
min_volume, max_volume, volume_range); |
min_volume, max_volume, volume_range); |
63 |
#endif |
#endif |
64 |
|
|
65 |
queue_lo = queue_hi = 0; |
rdpsnd_queue_init(); |
66 |
|
|
67 |
audioconfig = alNewConfig(); |
audioconfig = alNewConfig(); |
68 |
if (audioconfig == (ALconfig) 0) |
if (audioconfig == (ALconfig) 0) |
69 |
{ |
{ |
70 |
fprintf(stderr, "wave_out_open: alNewConfig failed: %s\n", |
fprintf(stderr, "sgi_open: alNewConfig failed: %s\n", alGetErrorString(oserror())); |
|
alGetErrorString(oserror())); |
|
71 |
return False; |
return False; |
72 |
} |
} |
73 |
|
|
74 |
output_port = alOpenPort("rdpsnd", "w", 0); |
output_port = alOpenPort("rdpsnd", "w", 0); |
75 |
if (output_port == (ALport) 0) |
if (output_port == (ALport) 0) |
76 |
{ |
{ |
77 |
fprintf(stderr, "wave_out_open: alOpenPort failed: %s\n", |
fprintf(stderr, "sgi_open: alOpenPort failed: %s\n", alGetErrorString(oserror())); |
|
alGetErrorString(oserror())); |
|
78 |
return False; |
return False; |
79 |
} |
} |
80 |
|
|
81 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
82 |
fprintf(stderr, "wave_out_open: returning\n"); |
fprintf(stderr, "sgi_open: returning\n"); |
83 |
#endif |
#endif |
84 |
return True; |
return True; |
85 |
} |
} |
89 |
{ |
{ |
90 |
/* Ack all remaining packets */ |
/* Ack all remaining packets */ |
91 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
92 |
fprintf(stderr, "wave_out_close: begin\n"); |
fprintf(stderr, "sgi_close: begin\n"); |
93 |
#endif |
#endif |
94 |
|
|
95 |
while (queue_lo != queue_hi) |
while (!rdpsnd_queue_empty()) |
96 |
{ |
{ |
97 |
rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index); |
/* We need to add 50 to tell windows that time has passed while |
98 |
free(packet_queue[queue_lo].s.data); |
* playing this packet */ |
99 |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
rdpsnd_send_completion(rdpsnd_queue_current_packet()->tick + 50, |
100 |
|
rdpsnd_queue_current_packet()->index); |
101 |
|
rdpsnd_queue_next(); |
102 |
} |
} |
103 |
alDiscardFrames(output_port, 0); |
alDiscardFrames(output_port, 0); |
104 |
|
|
105 |
alClosePort(output_port); |
alClosePort(output_port); |
106 |
alFreeConfig(audioconfig); |
alFreeConfig(audioconfig); |
107 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
108 |
fprintf(stderr, "wave_out_close: returning\n"); |
fprintf(stderr, "sgi_close: returning\n"); |
109 |
#endif |
#endif |
110 |
} |
} |
111 |
|
|
130 |
ALpv params; |
ALpv params; |
131 |
|
|
132 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
133 |
fprintf(stderr, "wave_out_set_format: init...\n"); |
fprintf(stderr, "sgi_set_format: init...\n"); |
134 |
#endif |
#endif |
135 |
|
|
136 |
g_swapaudio = False; |
g_swapaudio = False; |
166 |
|
|
167 |
if (output_port == (ALport) 0) |
if (output_port == (ALport) 0) |
168 |
{ |
{ |
169 |
fprintf(stderr, "wave_out_set_format: alOpenPort failed: %s\n", |
fprintf(stderr, "sgi_set_format: alOpenPort failed: %s\n", |
170 |
alGetErrorString(oserror())); |
alGetErrorString(oserror())); |
171 |
return False; |
return False; |
172 |
} |
} |
180 |
|
|
181 |
if (frameSize == 0 || channelCount == 0) |
if (frameSize == 0 || channelCount == 0) |
182 |
{ |
{ |
183 |
fprintf(stderr, "wave_out_set_format: bad frameSize or channelCount\n"); |
fprintf(stderr, "sgi_set_format: bad frameSize or channelCount\n"); |
184 |
return False; |
return False; |
185 |
} |
} |
186 |
combinedFrameSize = frameSize * channelCount; |
combinedFrameSize = frameSize * channelCount; |
201 |
} |
} |
202 |
|
|
203 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
204 |
fprintf(stderr, "wave_out_set_format: returning...\n"); |
fprintf(stderr, "sgi_set_format: returning...\n"); |
205 |
#endif |
#endif |
206 |
return True; |
return True; |
207 |
} |
} |
214 |
ALfixed gain[8]; |
ALfixed gain[8]; |
215 |
|
|
216 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
217 |
fprintf(stderr, "wave_out_volume: begin\n"); |
fprintf(stderr, "sgi_volume: begin\n"); |
218 |
fprintf(stderr, "left='%d', right='%d'\n", left, right); |
fprintf(stderr, "left='%d', right='%d'\n", left, right); |
219 |
#endif |
#endif |
220 |
|
|
229 |
pv[0].sizeIn = 8; |
pv[0].sizeIn = 8; |
230 |
if (alSetParams(AL_DEFAULT_OUTPUT, pv, 1) < 0) |
if (alSetParams(AL_DEFAULT_OUTPUT, pv, 1) < 0) |
231 |
{ |
{ |
232 |
fprintf(stderr, "wave_out_volume: alSetParams failed: %s\n", |
fprintf(stderr, "sgi_volume: alSetParams failed: %s\n", |
233 |
alGetErrorString(oserror())); |
alGetErrorString(oserror())); |
234 |
return; |
return; |
235 |
} |
} |
236 |
|
|
237 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
238 |
fprintf(stderr, "wave_out_volume: returning\n"); |
fprintf(stderr, "sgi_volume: returning\n"); |
239 |
#endif |
#endif |
240 |
} |
} |
241 |
|
|
242 |
void |
void |
|
wave_out_write(STREAM s, uint16 tick, uint8 index) |
|
|
{ |
|
|
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 |
|
243 |
wave_out_play(void) |
wave_out_play(void) |
244 |
{ |
{ |
245 |
struct audio_packet *packet; |
struct audio_packet *packet; |
252 |
|
|
253 |
while (1) |
while (1) |
254 |
{ |
{ |
255 |
if (queue_lo == queue_hi) |
if (rdpsnd_queue_empty()) |
256 |
{ |
{ |
257 |
g_dsp_busy = False; |
g_dsp_busy = False; |
258 |
return; |
return; |
259 |
} |
} |
260 |
|
|
261 |
packet = &packet_queue[queue_lo]; |
packet = rdpsnd_queue_current_packet(); |
262 |
out = &packet->s; |
out = &packet->s; |
263 |
|
|
264 |
/* Swap the current packet, but only once */ |
/* Swap the current packet, but only once */ |
284 |
if (gf < (4 * maxFillable / 10)) |
if (gf < (4 * maxFillable / 10)) |
285 |
{ |
{ |
286 |
rdpsnd_send_completion(packet->tick, packet->index); |
rdpsnd_send_completion(packet->tick, packet->index); |
287 |
free(out->data); |
rdpsnd_queue_next(); |
|
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
|
288 |
swapped = False; |
swapped = False; |
289 |
} |
} |
290 |
else |
else |