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; |
|
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; |
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 |
|
|
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 = rdpsnd_dsp_softvol_set; |
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 = description; |
libao_driver.description = description; |
197 |
libao_driver.need_byteswap_on_be = 0; |
libao_driver.need_byteswap_on_be = 0; |
198 |
|
libao_driver.need_resampling = 1; |
199 |
libao_driver.next = NULL; |
libao_driver.next = NULL; |
200 |
|
|
201 |
ao_initialize(); |
ao_initialize(); |
205 |
if (libao_info) |
if (libao_info) |
206 |
{ |
{ |
207 |
snprintf(description, 100, "libao output driver, default device: %s", |
snprintf(description, 100, "libao output driver, default device: %s", |
208 |
libao_info->short_name); |
libao_info->short_name); |
209 |
} |
} |
210 |
else |
else |
211 |
{ |
{ |