27 |
#include <ao/ao.h> |
#include <ao/ao.h> |
28 |
|
|
29 |
#define MAX_QUEUE 10 |
#define MAX_QUEUE 10 |
30 |
|
#define WAVEOUTBUF 32 |
31 |
|
|
32 |
int g_dsp_fd; |
int g_dsp_fd; |
33 |
ao_device *o_device = NULL; |
ao_device *o_device = NULL; |
34 |
int default_driver; |
int default_driver; |
35 |
|
int g_samplerate; |
36 |
BOOL g_dsp_busy = False; |
BOOL g_dsp_busy = False; |
37 |
static short g_samplewidth; |
static short g_samplewidth; |
38 |
|
|
55 |
format.bits = 16; |
format.bits = 16; |
56 |
format.channels = 2; |
format.channels = 2; |
57 |
format.rate = 44100; |
format.rate = 44100; |
58 |
|
g_samplerate = 44100; |
59 |
format.byte_format = AO_FMT_LITTLE; |
format.byte_format = AO_FMT_LITTLE; |
60 |
|
|
61 |
o_device = ao_open_live(default_driver, &format, NULL); |
o_device = ao_open_live(default_driver, &format, NULL); |
96 |
if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16)) |
if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16)) |
97 |
return False; |
return False; |
98 |
/* The only common denominator between libao output drivers is a sample-rate of |
/* The only common denominator between libao output drivers is a sample-rate of |
99 |
44100, windows gives a max of 22050. we need to upsample that... |
44100, we need to upsample 22050 to it */ |
100 |
TODO: support 11025, too */ |
if ((pwfx->nSamplesPerSec != 44100) && (pwfx->nSamplesPerSec != 22050)) |
|
if (pwfx->nSamplesPerSec != 22050) |
|
101 |
return False; |
return False; |
102 |
|
|
103 |
return True; |
return True; |
108 |
{ |
{ |
109 |
ao_sample_format format; |
ao_sample_format format; |
110 |
|
|
|
printf("%d\n",pwfx->wBitsPerSample); |
|
111 |
format.bits = pwfx->wBitsPerSample; |
format.bits = pwfx->wBitsPerSample; |
112 |
format.channels = pwfx->nChannels; |
format.channels = pwfx->nChannels; |
113 |
format.rate = 44100; |
format.rate = 44100; |
114 |
|
g_samplerate = pwfx->nSamplesPerSec; |
115 |
format.byte_format = AO_FMT_LITTLE; |
format.byte_format = AO_FMT_LITTLE; |
116 |
|
|
117 |
g_samplewidth = pwfx->wBitsPerSample / 8; |
g_samplewidth = pwfx->wBitsPerSample / 8; |
118 |
|
|
119 |
if(o_device != NULL) |
if (o_device != NULL) |
120 |
ao_close(o_device); |
ao_close(o_device); |
121 |
|
|
122 |
o_device = ao_open_live(default_driver, &format, NULL); |
o_device = ao_open_live(default_driver, &format, NULL); |
165 |
{ |
{ |
166 |
struct audio_packet *packet; |
struct audio_packet *packet; |
167 |
STREAM out; |
STREAM out; |
168 |
unsigned char expanded[8]; |
unsigned char outbuf[WAVEOUTBUF]; |
169 |
|
int offset, len, i; |
170 |
|
|
171 |
while (1) |
if (queue_lo == queue_hi) |
172 |
{ |
{ |
173 |
if (queue_lo == queue_hi) |
g_dsp_busy = 0; |
174 |
{ |
return; |
175 |
g_dsp_busy = 0; |
} |
|
return; |
|
|
} |
|
|
|
|
|
packet = &packet_queue[queue_lo]; |
|
|
out = &packet->s; |
|
176 |
|
|
177 |
/* Resample 22050 -> 44100 */ |
packet = &packet_queue[queue_lo]; |
178 |
/* TODO: Do this for 11025, too... */ |
out = &packet->s; |
|
memcpy(&expanded[0],out->p,g_samplewidth); |
|
|
memcpy(&expanded[2*g_samplewidth],out->p,g_samplewidth); |
|
|
out->p += 2; |
|
|
memcpy(&expanded[1*g_samplewidth],out->p,g_samplewidth); |
|
|
memcpy(&expanded[3*g_samplewidth],out->p,g_samplewidth); |
|
|
out->p += 2; |
|
179 |
|
|
180 |
ao_play(o_device, expanded, g_samplewidth*4); |
len = 0; |
181 |
|
|
182 |
if (out->p == out->end) |
if (g_samplerate == 22050) |
183 |
|
{ |
184 |
|
/* Resample to 44100 */ |
185 |
|
for (i = 0; (i < ((WAVEOUTBUF / 8) * (3 - g_samplewidth))) && (out->p < out->end); |
186 |
|
i++) |
187 |
{ |
{ |
188 |
rdpsnd_send_completion(packet->tick, packet->index); |
offset = i * 4 * g_samplewidth; |
189 |
free(out->data); |
memcpy(&outbuf[0 * g_samplewidth + offset], out->p, g_samplewidth); |
190 |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
memcpy(&outbuf[2 * g_samplewidth + offset], out->p, g_samplewidth); |
191 |
} else { |
out->p += 2; |
192 |
g_dsp_busy = 1; |
|
193 |
return; |
memcpy(&outbuf[1 * g_samplewidth + offset], out->p, g_samplewidth); |
194 |
|
memcpy(&outbuf[3 * g_samplewidth + offset], out->p, g_samplewidth); |
195 |
|
out->p += 2; |
196 |
|
len += 4 * g_samplewidth; |
197 |
} |
} |
198 |
} |
} |
199 |
|
else |
200 |
|
{ |
201 |
|
len = (WAVEOUTBUF > (out->end - out->p)) ? (out->end - out->p) : WAVEOUTBUF; |
202 |
|
memcpy(outbuf, out->p, len); |
203 |
|
out->p += len; |
204 |
|
} |
205 |
|
|
206 |
|
ao_play(o_device, outbuf, len); |
207 |
|
|
208 |
|
if (out->p == out->end) |
209 |
|
{ |
210 |
|
rdpsnd_send_completion(packet->tick, packet->index); |
211 |
|
free(out->data); |
212 |
|
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
213 |
|
} |
214 |
|
|
215 |
|
g_dsp_busy = 1; |
216 |
|
return; |
217 |
} |
} |