27 |
#include <ao/ao.h> |
#include <ao/ao.h> |
28 |
|
|
29 |
#define MAX_QUEUE 10 |
#define MAX_QUEUE 10 |
30 |
#define WAVEOUTBUF 32 |
#define WAVEOUTBUF 64 |
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; |
int g_samplerate; |
36 |
|
int g_channels; |
37 |
BOOL g_dsp_busy = False; |
BOOL g_dsp_busy = False; |
38 |
static short g_samplewidth; |
static short g_samplewidth; |
39 |
|
|
55 |
|
|
56 |
format.bits = 16; |
format.bits = 16; |
57 |
format.channels = 2; |
format.channels = 2; |
58 |
|
g_channels = 2; |
59 |
format.rate = 44100; |
format.rate = 44100; |
60 |
g_samplerate = 44100; |
g_samplerate = 44100; |
61 |
format.byte_format = AO_FMT_LITTLE; |
format.byte_format = AO_FMT_LITTLE; |
85 |
|
|
86 |
if (o_device != NULL) |
if (o_device != NULL) |
87 |
ao_close(o_device); |
ao_close(o_device); |
88 |
|
|
89 |
ao_shutdown(); |
ao_shutdown(); |
90 |
} |
} |
91 |
|
|
113 |
|
|
114 |
format.bits = pwfx->wBitsPerSample; |
format.bits = pwfx->wBitsPerSample; |
115 |
format.channels = pwfx->nChannels; |
format.channels = pwfx->nChannels; |
116 |
|
g_channels = pwfx->nChannels; |
117 |
format.rate = 44100; |
format.rate = 44100; |
118 |
g_samplerate = pwfx->nSamplesPerSec; |
g_samplerate = pwfx->nSamplesPerSec; |
119 |
format.byte_format = AO_FMT_LITTLE; |
format.byte_format = AO_FMT_LITTLE; |
120 |
|
|
121 |
g_samplewidth = pwfx->wBitsPerSample / 8; |
g_samplewidth = pwfx->wBitsPerSample / 8; |
122 |
|
|
123 |
if(o_device != NULL) |
if (o_device != NULL) |
124 |
ao_close(o_device); |
ao_close(o_device); |
125 |
|
|
126 |
o_device = ao_open_live(default_driver, &format, NULL); |
o_device = ao_open_live(default_driver, &format, NULL); |
136 |
void |
void |
137 |
wave_out_volume(uint16 left, uint16 right) |
wave_out_volume(uint16 left, uint16 right) |
138 |
{ |
{ |
139 |
|
warning("volume changes not supported with libao-output\n"); |
140 |
} |
} |
141 |
|
|
142 |
void |
void |
170 |
{ |
{ |
171 |
struct audio_packet *packet; |
struct audio_packet *packet; |
172 |
STREAM out; |
STREAM out; |
173 |
unsigned char expanded[WAVEOUTBUF]; |
unsigned char outbuf[WAVEOUTBUF]; |
174 |
int offset,len,i; |
int offset, len, i; |
175 |
|
|
176 |
if (queue_lo == queue_hi) |
if (queue_lo == queue_hi) |
177 |
{ |
{ |
184 |
|
|
185 |
len = 0; |
len = 0; |
186 |
|
|
187 |
if (g_samplerate == 22050 ) |
if (g_samplerate == 22050) |
188 |
{ |
{ |
189 |
/* Resample to 44100 */ |
/* Resample to 44100 */ |
190 |
for(i=0; (i<((WAVEOUTBUF/8)*(3-g_samplewidth))) && (out->p < out->end); i++) |
for (i = 0; (i < ((WAVEOUTBUF / 4) * (3 - g_samplewidth))) && (out->p < out->end); |
191 |
|
i++) |
192 |
{ |
{ |
193 |
offset=i*4*g_samplewidth; |
/* On a stereo-channel we must make sure that left and right |
194 |
memcpy(&expanded[0*g_samplewidth+offset],out->p,g_samplewidth); |
does not get mixed up, so we need to expand the sample- |
195 |
memcpy(&expanded[2*g_samplewidth+offset],out->p,g_samplewidth); |
data with channels in mind: 1234 -> 12123434 |
196 |
out->p += 2; |
If we have a mono-channel, we can expand the data by simply |
197 |
|
doubling the sample-data: 1234 -> 11223344 */ |
198 |
memcpy(&expanded[1*g_samplewidth+offset],out->p,g_samplewidth); |
if (g_channels == 2) |
199 |
memcpy(&expanded[3*g_samplewidth+offset],out->p,g_samplewidth); |
offset = ((i * 2) - (i & 1)) * g_samplewidth; |
200 |
out->p += 2; |
else |
201 |
len += 4*g_samplewidth; |
offset = (i * 2) * g_samplewidth; |
202 |
|
|
203 |
|
memcpy(&outbuf[offset], out->p, g_samplewidth); |
204 |
|
memcpy(&outbuf[g_channels * g_samplewidth + offset], out->p, g_samplewidth); |
205 |
|
|
206 |
|
out->p += g_samplewidth; |
207 |
|
len += 2 * g_samplewidth; |
208 |
} |
} |
209 |
} |
} |
210 |
else |
else |
211 |
{ |
{ |
212 |
len = (WAVEOUTBUF > (out->end - out->p)) ? (out->end - out->p) : WAVEOUTBUF; |
len = (WAVEOUTBUF > (out->end - out->p)) ? (out->end - out->p) : WAVEOUTBUF; |
213 |
memcpy(expanded,out->p,len); |
memcpy(outbuf, out->p, len); |
214 |
out->p += len; |
out->p += len; |
215 |
} |
} |
216 |
|
|
217 |
ao_play(o_device, expanded, len); |
ao_play(o_device, outbuf, len); |
218 |
|
|
219 |
if (out->p == out->end) |
if (out->p == out->end) |
220 |
{ |
{ |