29 |
#include <ao/ao.h> |
#include <ao/ao.h> |
30 |
#include <sys/time.h> |
#include <sys/time.h> |
31 |
|
|
32 |
#define WAVEOUTBUF 16 |
#define WAVEOUTLEN 16 |
33 |
|
|
34 |
static ao_device *o_device = NULL; |
static ao_device *o_device = NULL; |
35 |
static int default_driver; |
static int default_driver; |
|
static int samplerate; |
|
|
static int audiochannels; |
|
36 |
static BOOL reopened; |
static BOOL reopened; |
|
static short samplewidth; |
|
37 |
static char *libao_device = NULL; |
static char *libao_device = NULL; |
38 |
|
|
39 |
BOOL |
BOOL |
54 |
|
|
55 |
format.bits = 16; |
format.bits = 16; |
56 |
format.channels = 2; |
format.channels = 2; |
|
audiochannels = 2; |
|
57 |
format.rate = 44100; |
format.rate = 44100; |
58 |
samplerate = 44100; |
format.byte_format = AO_FMT_NATIVE; |
59 |
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); |
62 |
if (o_device == NULL) |
if (o_device == NULL) |
65 |
} |
} |
66 |
|
|
67 |
g_dsp_fd = 0; |
g_dsp_fd = 0; |
|
rdpsnd_queue_init(); |
|
68 |
|
|
69 |
reopened = True; |
reopened = True; |
70 |
|
|
77 |
/* Ack all remaining packets */ |
/* Ack all remaining packets */ |
78 |
while (!rdpsnd_queue_empty()) |
while (!rdpsnd_queue_empty()) |
79 |
{ |
{ |
80 |
rdpsnd_send_completion(rdpsnd_queue_current_packet()->tick, |
rdpsnd_queue_next(0); |
|
rdpsnd_queue_current_packet()->index); |
|
|
rdpsnd_queue_next(); |
|
81 |
} |
} |
82 |
|
|
83 |
if (o_device != NULL) |
if (o_device != NULL) |
87 |
} |
} |
88 |
|
|
89 |
BOOL |
BOOL |
|
libao_format_supported(WAVEFORMATEX * pwfx) |
|
|
{ |
|
|
if (pwfx->wFormatTag != WAVE_FORMAT_PCM) |
|
|
return False; |
|
|
if ((pwfx->nChannels != 1) && (pwfx->nChannels != 2)) |
|
|
return False; |
|
|
if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16)) |
|
|
return False; |
|
|
/* The only common denominator between libao output drivers is a sample-rate of |
|
|
44100, we need to upsample 22050 to it */ |
|
|
if ((pwfx->nSamplesPerSec != 44100) && (pwfx->nSamplesPerSec != 22050)) |
|
|
return False; |
|
|
|
|
|
return True; |
|
|
} |
|
|
|
|
|
BOOL |
|
90 |
libao_set_format(WAVEFORMATEX * pwfx) |
libao_set_format(WAVEFORMATEX * pwfx) |
91 |
{ |
{ |
92 |
ao_sample_format format; |
ao_sample_format format; |
93 |
|
|
94 |
format.bits = pwfx->wBitsPerSample; |
format.bits = pwfx->wBitsPerSample; |
95 |
format.channels = pwfx->nChannels; |
format.channels = pwfx->nChannels; |
|
audiochannels = pwfx->nChannels; |
|
96 |
format.rate = 44100; |
format.rate = 44100; |
97 |
samplerate = pwfx->nSamplesPerSec; |
format.byte_format = AO_FMT_NATIVE; |
|
format.byte_format = AO_FMT_LITTLE; |
|
|
|
|
|
samplewidth = pwfx->wBitsPerSample / 8; |
|
98 |
|
|
99 |
if (o_device != NULL) |
if (o_device != NULL) |
100 |
ao_close(o_device); |
ao_close(o_device); |
105 |
return False; |
return False; |
106 |
} |
} |
107 |
|
|
108 |
|
if (rdpsnd_dsp_resample_set(44100, pwfx->wBitsPerSample, pwfx->nChannels) == False) |
109 |
|
{ |
110 |
|
return False; |
111 |
|
} |
112 |
|
|
113 |
reopened = True; |
reopened = True; |
114 |
|
|
115 |
return True; |
return True; |
120 |
{ |
{ |
121 |
struct audio_packet *packet; |
struct audio_packet *packet; |
122 |
STREAM out; |
STREAM out; |
123 |
char outbuf[WAVEOUTBUF]; |
int len; |
|
int offset, len, i; |
|
124 |
static long prev_s, prev_us; |
static long prev_s, prev_us; |
125 |
unsigned int duration; |
unsigned int duration; |
126 |
struct timeval tv; |
struct timeval tv; |
145 |
|
|
146 |
next_tick = rdpsnd_queue_next_tick(); |
next_tick = rdpsnd_queue_next_tick(); |
147 |
|
|
148 |
len = 0; |
len = (WAVEOUTLEN > (out->end - out->p)) ? (out->end - out->p) : WAVEOUTLEN; |
149 |
|
ao_play(o_device, (char *) out->p, len); |
150 |
if (samplerate == 22050) |
out->p += len; |
|
{ |
|
|
/* Resample to 44100 */ |
|
|
for (i = 0; (i < ((WAVEOUTBUF / 4) * (3 - samplewidth))) && (out->p < out->end); |
|
|
i++) |
|
|
{ |
|
|
/* On a stereo-channel we must make sure that left and right |
|
|
does not get mixed up, so we need to expand the sample- |
|
|
data with channels in mind: 1234 -> 12123434 |
|
|
If we have a mono-channel, we can expand the data by simply |
|
|
doubling the sample-data: 1234 -> 11223344 */ |
|
|
if (audiochannels == 2) |
|
|
offset = ((i * 2) - (i & 1)) * samplewidth; |
|
|
else |
|
|
offset = (i * 2) * samplewidth; |
|
|
|
|
|
memcpy(&outbuf[offset], out->p, samplewidth); |
|
|
memcpy(&outbuf[audiochannels * samplewidth + offset], out->p, samplewidth); |
|
|
|
|
|
out->p += samplewidth; |
|
|
len += 2 * samplewidth; |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
len = (WAVEOUTBUF > (out->end - out->p)) ? (out->end - out->p) : WAVEOUTBUF; |
|
|
memcpy(outbuf, out->p, len); |
|
|
out->p += len; |
|
|
} |
|
|
|
|
|
ao_play(o_device, outbuf, len); |
|
151 |
|
|
152 |
gettimeofday(&tv, NULL); |
gettimeofday(&tv, NULL); |
153 |
|
|
168 |
(packet->tick + duration) % 65536, next_tick % 65536)); |
(packet->tick + duration) % 65536, next_tick % 65536)); |
169 |
} |
} |
170 |
|
|
171 |
rdpsnd_send_completion(((packet->tick + duration) % 65536), packet->index); |
rdpsnd_queue_next(duration); |
|
rdpsnd_queue_next(); |
|
172 |
} |
} |
173 |
|
|
174 |
g_dsp_busy = 1; |
g_dsp_busy = 1; |
182 |
struct ao_info *libao_info; |
struct ao_info *libao_info; |
183 |
static char description[101]; |
static char description[101]; |
184 |
|
|
|
libao_driver.wave_out_write = rdpsnd_queue_write; |
|
185 |
libao_driver.wave_out_open = libao_open; |
libao_driver.wave_out_open = libao_open; |
186 |
libao_driver.wave_out_close = libao_close; |
libao_driver.wave_out_close = libao_close; |
187 |
libao_driver.wave_out_format_supported = libao_format_supported; |
libao_driver.wave_out_format_supported = rdpsnd_dsp_resample_supported; |
188 |
libao_driver.wave_out_set_format = libao_set_format; |
libao_driver.wave_out_set_format = libao_set_format; |
189 |
libao_driver.wave_out_volume = rdpsnd_dsp_softvol_set; |
libao_driver.wave_out_volume = rdpsnd_dsp_softvol_set; |
190 |
libao_driver.wave_out_play = libao_play; |
libao_driver.wave_out_play = libao_play; |
191 |
libao_driver.name = xstrdup("libao"); |
libao_driver.name = xstrdup("libao"); |
192 |
libao_driver.description = description; |
libao_driver.description = description; |
193 |
libao_driver.need_byteswap_on_be = 0; |
libao_driver.need_byteswap_on_be = 1; |
194 |
|
libao_driver.need_resampling = 1; |
195 |
libao_driver.next = NULL; |
libao_driver.next = NULL; |
196 |
|
|
197 |
ao_initialize(); |
ao_initialize(); |
201 |
if (libao_info) |
if (libao_info) |
202 |
{ |
{ |
203 |
snprintf(description, 100, "libao output driver, default device: %s", |
snprintf(description, 100, "libao output driver, default device: %s", |
204 |
libao_info->short_name); |
libao_info->short_name); |
205 |
} |
} |
206 |
else |
else |
207 |
{ |
{ |