29 |
#include <ao/ao.h> |
#include <ao/ao.h> |
30 |
#include <sys/time.h> |
#include <sys/time.h> |
31 |
|
|
32 |
#define WAVEOUTBUF 16 |
#define WAVEOUTBUF 512 |
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) |
90 |
} |
} |
91 |
|
|
92 |
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 |
|
93 |
libao_set_format(WAVEFORMATEX * pwfx) |
libao_set_format(WAVEFORMATEX * pwfx) |
94 |
{ |
{ |
95 |
ao_sample_format format; |
ao_sample_format format; |
96 |
|
|
97 |
format.bits = pwfx->wBitsPerSample; |
format.bits = pwfx->wBitsPerSample; |
98 |
format.channels = pwfx->nChannels; |
format.channels = pwfx->nChannels; |
|
audiochannels = pwfx->nChannels; |
|
99 |
format.rate = 44100; |
format.rate = 44100; |
100 |
samplerate = pwfx->nSamplesPerSec; |
format.byte_format = AO_FMT_NATIVE; |
|
format.byte_format = AO_FMT_LITTLE; |
|
|
|
|
|
samplewidth = pwfx->wBitsPerSample / 8; |
|
101 |
|
|
102 |
if (o_device != NULL) |
if (o_device != NULL) |
103 |
ao_close(o_device); |
ao_close(o_device); |
108 |
return False; |
return False; |
109 |
} |
} |
110 |
|
|
111 |
|
if (rdpsnd_dsp_resample_set(44100, pwfx->wBitsPerSample, pwfx->nChannels) == False) |
112 |
|
{ |
113 |
|
return False; |
114 |
|
} |
115 |
|
|
116 |
reopened = True; |
reopened = True; |
117 |
|
|
118 |
return True; |
return True; |
123 |
{ |
{ |
124 |
struct audio_packet *packet; |
struct audio_packet *packet; |
125 |
STREAM out; |
STREAM out; |
126 |
char outbuf[WAVEOUTBUF]; |
int len; |
|
int offset, len, i; |
|
127 |
static long prev_s, prev_us; |
static long prev_s, prev_us; |
128 |
unsigned int duration; |
unsigned int duration; |
129 |
struct timeval tv; |
struct timeval tv; |
148 |
|
|
149 |
next_tick = rdpsnd_queue_next_tick(); |
next_tick = rdpsnd_queue_next_tick(); |
150 |
|
|
151 |
len = 0; |
len = (WAVEOUTBUF > (out->end - out->p)) ? (out->end - out->p) : WAVEOUTBUF; |
152 |
|
ao_play(o_device, (char *) out->p, len); |
153 |
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); |
|
154 |
|
|
155 |
gettimeofday(&tv, NULL); |
gettimeofday(&tv, NULL); |
156 |
|
|
183 |
libao_register(char *options) |
libao_register(char *options) |
184 |
{ |
{ |
185 |
static struct audio_driver libao_driver; |
static struct audio_driver libao_driver; |
186 |
|
struct ao_info *libao_info; |
187 |
static char description[101]; |
static char description[101]; |
188 |
|
|
189 |
libao_driver.wave_out_write = rdpsnd_queue_write; |
libao_driver.wave_out_write = rdpsnd_queue_write; |
190 |
libao_driver.wave_out_open = libao_open; |
libao_driver.wave_out_open = libao_open; |
191 |
libao_driver.wave_out_close = libao_close; |
libao_driver.wave_out_close = libao_close; |
192 |
libao_driver.wave_out_format_supported = libao_format_supported; |
libao_driver.wave_out_format_supported = rdpsnd_dsp_resample_supported; |
193 |
libao_driver.wave_out_set_format = libao_set_format; |
libao_driver.wave_out_set_format = libao_set_format; |
194 |
libao_driver.wave_out_volume = rdpsnd_dsp_softvol_set; |
libao_driver.wave_out_volume = rdpsnd_dsp_softvol_set; |
195 |
libao_driver.wave_out_play = libao_play; |
libao_driver.wave_out_play = libao_play; |
196 |
libao_driver.name = xstrdup("libao"); |
libao_driver.name = xstrdup("libao"); |
197 |
libao_driver.description = description; |
libao_driver.description = description; |
198 |
libao_driver.need_byteswap_on_be = 0; |
libao_driver.need_byteswap_on_be = 1; |
199 |
|
libao_driver.need_resampling = 1; |
200 |
libao_driver.next = NULL; |
libao_driver.next = NULL; |
201 |
|
|
202 |
ao_initialize(); |
ao_initialize(); |
203 |
snprintf(description, 100, "libao output driver, default device: %s", ao_driver_info(ao_default_driver_id())->short_name); |
|
204 |
|
libao_info = ao_driver_info(ao_default_driver_id()); |
205 |
|
|
206 |
|
if (libao_info) |
207 |
|
{ |
208 |
|
snprintf(description, 100, "libao output driver, default device: %s", |
209 |
|
libao_info->short_name); |
210 |
|
} |
211 |
|
else |
212 |
|
{ |
213 |
|
snprintf(description, 100, "libao output driver, default device: none"); |
214 |
|
} |
215 |
|
|
216 |
ao_shutdown(); |
ao_shutdown(); |
217 |
|
|
218 |
if (options) |
if (options) |