3 |
Sound Channel Process Functions - SGI/IRIX |
Sound Channel Process Functions - SGI/IRIX |
4 |
Copyright (C) Matthew Chapman 2003 |
Copyright (C) Matthew Chapman 2003 |
5 |
Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003 |
Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003 |
6 |
Copyright (C) Michael Gernoth mike@zerfleddert.de 2003 |
Copyright (C) Jeremy Meng voidfoo@cwazy.co.uk 2004 |
7 |
|
|
8 |
This program is free software; you can redistribute it and/or modify |
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 |
it under the terms of the GNU General Public License as published by |
38 |
static BOOL g_swapaudio; |
static BOOL g_swapaudio; |
39 |
static int g_snd_rate; |
static int g_snd_rate; |
40 |
static BOOL g_swapaudio; |
static BOOL g_swapaudio; |
|
static short g_samplewidth; |
|
41 |
static int width = AL_SAMPLE_16; |
static int width = AL_SAMPLE_16; |
42 |
|
|
43 |
double min_volume, max_volume, volume_range; |
double min_volume, max_volume, volume_range; |
55 |
BOOL |
BOOL |
56 |
wave_out_open(void) |
wave_out_open(void) |
57 |
{ |
{ |
58 |
ALparamInfo pinfo; |
ALparamInfo pinfo; |
59 |
|
|
60 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
61 |
fprintf(stderr, "wave_out_open: begin\n"); |
fprintf(stderr, "wave_out_open: begin\n"); |
62 |
#endif |
#endif |
63 |
|
|
64 |
if ( alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0 ) |
if (alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0) |
65 |
{ |
{ |
66 |
fprintf(stderr, "wave_out_open: alGetParamInfo failed: %s\n", |
fprintf(stderr, "wave_out_open: alGetParamInfo failed: %s\n", |
67 |
alGetErrorString(oserror())); |
alGetErrorString(oserror())); |
68 |
} |
} |
69 |
min_volume = alFixedToDouble(pinfo.min.ll); |
min_volume = alFixedToDouble(pinfo.min.ll); |
70 |
max_volume = alFixedToDouble(pinfo.max.ll); |
max_volume = alFixedToDouble(pinfo.max.ll); |
71 |
volume_range = (max_volume - min_volume); |
volume_range = (max_volume - min_volume); |
72 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
73 |
fprintf(stderr, "wave_out_open: minvol = %lf, maxvol= %lf, range = %lf.\n", |
fprintf(stderr, "wave_out_open: minvol = %lf, maxvol= %lf, range = %lf.\n", |
74 |
min_volume, max_volume, volume_range); |
min_volume, max_volume, volume_range); |
75 |
#endif |
#endif |
76 |
|
|
77 |
queue_lo = queue_hi = 0; |
queue_lo = queue_hi = 0; |
78 |
|
|
79 |
audioconfig = alNewConfig(); |
audioconfig = alNewConfig(); |
80 |
if (audioconfig < 0) { |
if (audioconfig < 0) |
81 |
fprintf(stderr, "wave_out_open: alNewConfig failed: %s\n", |
{ |
82 |
alGetErrorString(oserror())); |
fprintf(stderr, "wave_out_open: alNewConfig failed: %s\n", |
83 |
|
alGetErrorString(oserror())); |
84 |
return False; |
return False; |
85 |
} |
} |
86 |
|
|
87 |
output_port = alOpenPort("rdpsnd", "w", 0); |
output_port = alOpenPort("rdpsnd", "w", 0); |
88 |
if (output_port == (ALport) 0) { |
if (output_port == (ALport) 0) |
89 |
fprintf(stderr, "wave_out_open: alOpenPort failed: %s\n", |
{ |
90 |
alGetErrorString(oserror())); |
fprintf(stderr, "wave_out_open: alOpenPort failed: %s\n", |
91 |
|
alGetErrorString(oserror())); |
92 |
return False; |
return False; |
93 |
} |
} |
94 |
|
|
95 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
96 |
fprintf(stderr, "wave_out_open: returning\n"); |
fprintf(stderr, "wave_out_open: returning\n"); |
97 |
#endif |
#endif |
98 |
return True; |
return True; |
99 |
} |
} |
103 |
{ |
{ |
104 |
/* Ack all remaining packets */ |
/* Ack all remaining packets */ |
105 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
106 |
fprintf(stderr, "wave_out_close: begin\n"); |
fprintf(stderr, "wave_out_close: begin\n"); |
107 |
#endif |
#endif |
108 |
|
|
109 |
while (queue_lo != queue_hi) |
while (queue_lo != queue_hi) |
110 |
{ |
{ |
111 |
rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index); |
rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index); |
112 |
free(packet_queue[queue_lo].s.data); |
free(packet_queue[queue_lo].s.data); |
113 |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
114 |
} |
} |
115 |
alDiscardFrames(output_port, 0); |
alDiscardFrames(output_port, 0); |
116 |
|
|
117 |
alClosePort(output_port); |
alClosePort(output_port); |
118 |
alFreeConfig(audioconfig); |
alFreeConfig(audioconfig); |
119 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
120 |
fprintf(stderr, "wave_out_close: returning\n"); |
fprintf(stderr, "wave_out_close: returning\n"); |
121 |
#endif |
#endif |
122 |
} |
} |
123 |
|
|
138 |
wave_out_set_format(WAVEFORMATEX * pwfx) |
wave_out_set_format(WAVEFORMATEX * pwfx) |
139 |
{ |
{ |
140 |
int channels; |
int channels; |
141 |
int frameSize, channelCount; |
int frameSize, channelCount; |
142 |
ALpv params; |
ALpv params; |
143 |
|
|
144 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
145 |
fprintf(stderr, "wave_out_set_format: init...\n"); |
fprintf(stderr, "wave_out_set_format: init...\n"); |
146 |
#endif |
#endif |
|
/* limited support to configure an opened audio port in IRIX */ |
|
|
/* have to reopen the audio port, using same config */ |
|
|
alClosePort(output_port); |
|
147 |
|
|
148 |
g_swapaudio = False; |
g_swapaudio = False; |
|
|
|
149 |
if (pwfx->wBitsPerSample == 8) |
if (pwfx->wBitsPerSample == 8) |
150 |
width = AL_SAMPLE_8; |
width = AL_SAMPLE_8; |
151 |
else if (pwfx->wBitsPerSample == 16) { |
else if (pwfx->wBitsPerSample == 16) |
152 |
|
{ |
153 |
width = AL_SAMPLE_16; |
width = AL_SAMPLE_16; |
154 |
/* Do we need to swap the 16bit values? (Are we BigEndian) */ |
/* Do we need to swap the 16bit values? (Are we BigEndian) */ |
155 |
#if (defined(IRIX_DEBUG)) |
#if (defined(B_ENDIAN)) |
156 |
g_swapaudio = 1; |
g_swapaudio = 1; |
157 |
#else |
#else |
158 |
g_swapaudio = 0; |
g_swapaudio = 0; |
159 |
#endif |
#endif |
160 |
} |
} |
161 |
|
|
162 |
g_samplewidth = pwfx->wBitsPerSample / 8; |
/* 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; |
channels = pwfx->nChannels; |
169 |
g_snd_rate = pwfx->nSamplesPerSec; |
g_snd_rate = pwfx->nSamplesPerSec; |
170 |
|
|
171 |
alSetSampFmt(audioconfig, AL_SAMPFMT_TWOSCOMP); |
alSetSampFmt(audioconfig, AL_SAMPFMT_TWOSCOMP); |
172 |
alSetWidth(audioconfig, width); |
alSetWidth(audioconfig, width); |
173 |
alSetChannels(audioconfig, channels); |
if (channels != alGetChannels(audioconfig)) |
174 |
|
{ |
175 |
|
alClosePort(output_port); |
176 |
|
alSetChannels(audioconfig, channels); |
177 |
|
output_port = alOpenPort("rdpsnd", "w", audioconfig); |
178 |
|
|
179 |
output_port = alOpenPort("rdpsnd", "w", audioconfig); |
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 |
|
|
|
if (output_port == (ALport) 0) { |
|
|
fprintf(stderr, "wave_out_set_format: alOpenPort failed: %s\n", |
|
|
alGetErrorString(oserror())); |
|
|
return False; |
|
186 |
} |
} |
187 |
|
|
188 |
resource = alGetResource(output_port); |
resource = alGetResource(output_port); |
189 |
maxFillable = alGetFillable(output_port); |
maxFillable = alGetFillable(output_port); |
190 |
channelCount = alGetChannels(audioconfig); |
channelCount = alGetChannels(audioconfig); |
191 |
frameSize = alGetWidth(audioconfig); |
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 (frameSize == 0 || channelCount == 0) |
if (alSetParams(resource, ¶ms, 1) < 0) |
204 |
{ |
{ |
205 |
fprintf(stderr, "wave_out_set_format: bad frameSize or channelCount\n"); |
fprintf(stderr, "wave_set_format: alSetParams failed: %s\n", |
206 |
return False; |
alGetErrorString(oserror())); |
207 |
} |
return False; |
208 |
combinedFrameSize = frameSize * channelCount; |
} |
209 |
|
if (params.sizeOut < 0) |
210 |
params.param = AL_RATE; |
{ |
211 |
params.value.ll = (long long) g_snd_rate << 32; |
fprintf(stderr, "wave_set_format: invalid rate %d\n", g_snd_rate); |
212 |
|
return False; |
213 |
if (alSetParams(resource, ¶ms, 1) < 0) |
} |
|
{ |
|
|
fprintf(stderr, "wave_set_format: alSetParams failed: %s\n", |
|
|
alGetErrorString(oserror())); |
|
|
return False; |
|
|
} |
|
|
if( params.sizeOut < 0 ) |
|
|
{ |
|
|
fprintf(stderr, "wave_set_format: invalid rate %d\n", g_snd_rate); |
|
|
return False; |
|
|
} |
|
214 |
|
|
215 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
216 |
fprintf(stderr, "wave_out_set_format: returning...\n"); |
fprintf(stderr, "wave_out_set_format: returning...\n"); |
217 |
#endif |
#endif |
218 |
return True; |
return True; |
219 |
} |
} |
221 |
void |
void |
222 |
wave_out_volume(uint16 left, uint16 right) |
wave_out_volume(uint16 left, uint16 right) |
223 |
{ |
{ |
224 |
double gainleft, gainright; |
double gainleft, gainright; |
225 |
ALpv pv[1]; |
ALpv pv[1]; |
226 |
ALfixed gain[8]; |
ALfixed gain[8]; |
227 |
|
|
228 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
229 |
fprintf(stderr, "wave_out_volume: begin\n"); |
fprintf(stderr, "wave_out_volume: begin\n"); |
230 |
fprintf(stderr, "left='%d', right='%d'\n", left, right); |
fprintf(stderr, "left='%d', right='%d'\n", left, right); |
231 |
#endif |
#endif |
232 |
|
|
233 |
gainleft = (double) left / IRIX_MAX_VOL; |
gainleft = (double) left / IRIX_MAX_VOL; |
234 |
gainright = (double) right / IRIX_MAX_VOL; |
gainright = (double) right / IRIX_MAX_VOL; |
235 |
|
|
236 |
gain[0] = alDoubleToFixed(min_volume + gainleft * volume_range); |
gain[0] = alDoubleToFixed(min_volume + gainleft * volume_range); |
237 |
gain[1] = alDoubleToFixed(min_volume + gainright * volume_range); |
gain[1] = alDoubleToFixed(min_volume + gainright * volume_range); |
238 |
|
|
239 |
pv[0].param = AL_GAIN; |
pv[0].param = AL_GAIN; |
240 |
pv[0].value.ptr = gain; |
pv[0].value.ptr = gain; |
241 |
pv[0].sizeIn = 8; |
pv[0].sizeIn = 8; |
242 |
if( alSetParams(AL_DEFAULT_OUTPUT, pv, 1) < 0) |
if (alSetParams(AL_DEFAULT_OUTPUT, pv, 1) < 0) |
243 |
{ |
{ |
244 |
fprintf(stderr, "wave_out_volume: alSetParams failed: %s\n", alGetErrorString(oserror())); |
fprintf(stderr, "wave_out_volume: alSetParams failed: %s\n", |
245 |
return; |
alGetErrorString(oserror())); |
246 |
} |
return; |
247 |
|
} |
248 |
|
|
249 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
250 |
fprintf(stderr, "wave_out_volume: returning\n"); |
fprintf(stderr, "wave_out_volume: returning\n"); |
251 |
#endif |
#endif |
252 |
} |
} |
253 |
|
|
285 |
unsigned int i; |
unsigned int i; |
286 |
uint8 swap; |
uint8 swap; |
287 |
STREAM out; |
STREAM out; |
|
static long startedat_us; |
|
|
static long startedat_s; |
|
|
static BOOL started = False; |
|
288 |
static BOOL swapped = False; |
static BOOL swapped = False; |
|
struct timeval tv; |
|
289 |
int gf; |
int gf; |
|
static long long temp; |
|
290 |
|
|
291 |
while (1) |
while (1) |
292 |
{ |
{ |
311 |
swapped = True; |
swapped = True; |
312 |
} |
} |
313 |
|
|
|
if (!started) |
|
|
{ |
|
|
gettimeofday(&tv, NULL); |
|
|
startedat_us = tv.tv_usec; |
|
|
startedat_s = tv.tv_sec; |
|
|
started = True; |
|
|
} |
|
|
|
|
314 |
len = out->end - out->p; |
len = out->end - out->p; |
|
gf = alGetFillable(output_port); |
|
|
if (len > gf) { |
|
|
//len = gf * combinedFrameSize; |
|
|
#if (defined(IRIX_DEBUG)) |
|
|
//fprintf(stderr,"Fillable...\n"); |
|
|
#endif |
|
|
} |
|
315 |
|
|
316 |
alWriteFrames(output_port, out->p, len/combinedFrameSize); |
alWriteFrames(output_port, out->p, len / combinedFrameSize); |
317 |
|
|
318 |
out->p += len; |
out->p += len; |
319 |
if (out->p == out->end) |
if (out->p == out->end) |
320 |
{ |
{ |
321 |
long long duration; |
gf = alGetFilled(output_port); |
322 |
long elapsed; |
if (gf < (4 * maxFillable / 10)) |
|
|
|
|
gettimeofday(&tv, NULL); |
|
|
duration = (out->size * (1000000 / (g_samplewidth * g_snd_rate))); |
|
|
elapsed = (tv.tv_sec - startedat_s) * 1000000 |
|
|
+ (tv.tv_usec - startedat_us); |
|
|
/* 7/10 is not good for IRIX audio port, 4x/100 is suitable */ |
|
|
if (elapsed >= (duration * 485) / 1000) |
|
323 |
{ |
{ |
324 |
rdpsnd_send_completion(packet->tick, packet->index); |
rdpsnd_send_completion(packet->tick, packet->index); |
325 |
free(out->data); |
free(out->data); |
326 |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
|
started = False; |
|
327 |
swapped = False; |
swapped = False; |
328 |
} |
} |
329 |
else |
else |
330 |
{ |
{ |
331 |
#if (defined(IRIX_DEBUG)) |
#if (defined(IRIX_DEBUG)) |
332 |
//fprintf(stderr,"Busy playing...\n"); |
/* fprintf(stderr,"Busy playing...\n"); */ |
333 |
#endif |
#endif |
334 |
g_dsp_busy = True; |
g_dsp_busy = True; |
335 |
return; |
return; |