22 |
|
|
23 |
#include "rdesktop.h" |
#include "rdesktop.h" |
24 |
#include "rdpsnd.h" |
#include "rdpsnd.h" |
25 |
|
#include "rdpsnd_dsp.h" |
26 |
#include <unistd.h> |
#include <unistd.h> |
27 |
#include <fcntl.h> |
#include <fcntl.h> |
28 |
#include <errno.h> |
#include <errno.h> |
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 |
40 |
libao_open(void) |
libao_open(void) |
41 |
{ |
{ |
42 |
ao_sample_format format; |
ao_sample_format format; |
|
static int warned = 0; |
|
43 |
|
|
44 |
if (!warned && libao_device) |
ao_initialize(); |
45 |
|
|
46 |
|
if (libao_device) |
47 |
{ |
{ |
48 |
warning("device-options not supported for libao-driver\n"); |
default_driver = ao_driver_id(libao_device); |
49 |
warned = 1; |
} |
50 |
|
else |
51 |
|
{ |
52 |
|
default_driver = ao_default_driver_id(); |
53 |
} |
} |
|
|
|
|
ao_initialize(); |
|
|
default_driver = ao_default_driver_id(); |
|
54 |
|
|
55 |
format.bits = 16; |
format.bits = 16; |
56 |
format.channels = 2; |
format.channels = 2; |
|
audiochannels = 2; |
|
57 |
format.rate = 44100; |
format.rate = 44100; |
|
samplerate = 44100; |
|
58 |
format.byte_format = AO_FMT_LITTLE; |
format.byte_format = AO_FMT_LITTLE; |
59 |
|
|
60 |
o_device = ao_open_live(default_driver, &format, NULL); |
o_device = ao_open_live(default_driver, &format, NULL); |
89 |
} |
} |
90 |
|
|
91 |
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 |
|
92 |
libao_set_format(WAVEFORMATEX * pwfx) |
libao_set_format(WAVEFORMATEX * pwfx) |
93 |
{ |
{ |
94 |
ao_sample_format format; |
ao_sample_format format; |
95 |
|
|
96 |
format.bits = pwfx->wBitsPerSample; |
format.bits = pwfx->wBitsPerSample; |
97 |
format.channels = pwfx->nChannels; |
format.channels = pwfx->nChannels; |
|
audiochannels = pwfx->nChannels; |
|
98 |
format.rate = 44100; |
format.rate = 44100; |
|
samplerate = pwfx->nSamplesPerSec; |
|
99 |
format.byte_format = AO_FMT_LITTLE; |
format.byte_format = AO_FMT_LITTLE; |
100 |
|
|
|
samplewidth = pwfx->wBitsPerSample / 8; |
|
|
|
|
101 |
if (o_device != NULL) |
if (o_device != NULL) |
102 |
ao_close(o_device); |
ao_close(o_device); |
103 |
|
|
107 |
return False; |
return False; |
108 |
} |
} |
109 |
|
|
110 |
|
if (rdpsnd_dsp_resample_set(44100, pwfx->wBitsPerSample, pwfx->nChannels) == False) |
111 |
|
{ |
112 |
|
return False; |
113 |
|
} |
114 |
|
|
115 |
reopened = True; |
reopened = True; |
116 |
|
|
117 |
return True; |
return True; |
118 |
} |
} |
119 |
|
|
120 |
void |
void |
|
libao_volume(uint16 left, uint16 right) |
|
|
{ |
|
|
warning("volume changes not supported with libao-output\n"); |
|
|
} |
|
|
|
|
|
void |
|
121 |
libao_play(void) |
libao_play(void) |
122 |
{ |
{ |
123 |
struct audio_packet *packet; |
struct audio_packet *packet; |
124 |
STREAM out; |
STREAM out; |
125 |
char outbuf[WAVEOUTBUF]; |
int len; |
|
int offset, len, i; |
|
126 |
static long prev_s, prev_us; |
static long prev_s, prev_us; |
127 |
unsigned int duration; |
unsigned int duration; |
128 |
struct timeval tv; |
struct timeval tv; |
147 |
|
|
148 |
next_tick = rdpsnd_queue_next_tick(); |
next_tick = rdpsnd_queue_next_tick(); |
149 |
|
|
150 |
len = 0; |
len = (WAVEOUTBUF > (out->end - out->p)) ? (out->end - out->p) : WAVEOUTBUF; |
151 |
|
ao_play(o_device, (char *) out->p, len); |
152 |
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); |
|
153 |
|
|
154 |
gettimeofday(&tv, NULL); |
gettimeofday(&tv, NULL); |
155 |
|
|
182 |
libao_register(char *options) |
libao_register(char *options) |
183 |
{ |
{ |
184 |
static struct audio_driver libao_driver; |
static struct audio_driver libao_driver; |
185 |
|
struct ao_info *libao_info; |
186 |
|
static char description[101]; |
187 |
|
|
188 |
libao_driver.wave_out_write = rdpsnd_queue_write; |
libao_driver.wave_out_write = rdpsnd_queue_write; |
189 |
libao_driver.wave_out_open = libao_open; |
libao_driver.wave_out_open = libao_open; |
190 |
libao_driver.wave_out_close = libao_close; |
libao_driver.wave_out_close = libao_close; |
191 |
libao_driver.wave_out_format_supported = libao_format_supported; |
libao_driver.wave_out_format_supported = rdpsnd_dsp_resample_supported; |
192 |
libao_driver.wave_out_set_format = libao_set_format; |
libao_driver.wave_out_set_format = libao_set_format; |
193 |
libao_driver.wave_out_volume = libao_volume; |
libao_driver.wave_out_volume = rdpsnd_dsp_softvol_set; |
194 |
libao_driver.wave_out_play = libao_play; |
libao_driver.wave_out_play = libao_play; |
195 |
libao_driver.name = xstrdup("libao"); |
libao_driver.name = xstrdup("libao"); |
196 |
libao_driver.description = xstrdup("libao output driver"); |
libao_driver.description = description; |
197 |
|
libao_driver.need_byteswap_on_be = 0; |
198 |
libao_driver.next = NULL; |
libao_driver.next = NULL; |
199 |
|
|
200 |
|
ao_initialize(); |
201 |
|
|
202 |
|
libao_info = ao_driver_info(ao_default_driver_id()); |
203 |
|
|
204 |
|
if (libao_info) |
205 |
|
{ |
206 |
|
snprintf(description, 100, "libao output driver, default device: %s", |
207 |
|
libao_info->short_name); |
208 |
|
} |
209 |
|
else |
210 |
|
{ |
211 |
|
snprintf(description, 100, "libao output driver, default device: none"); |
212 |
|
} |
213 |
|
|
214 |
|
ao_shutdown(); |
215 |
|
|
216 |
if (options) |
if (options) |
217 |
{ |
{ |
218 |
libao_device = xstrdup(options); |
libao_device = xstrdup(options); |