31 |
#define WAVEOUTBUF 16 |
#define WAVEOUTBUF 16 |
32 |
|
|
33 |
int g_dsp_fd; |
int g_dsp_fd; |
|
ao_device *o_device = NULL; |
|
|
int default_driver; |
|
|
int g_samplerate; |
|
|
int g_channels; |
|
34 |
BOOL g_dsp_busy = False; |
BOOL g_dsp_busy = False; |
35 |
static BOOL g_reopened; |
static ao_device *o_device = NULL; |
36 |
static short g_samplewidth; |
static int default_driver; |
37 |
|
static int samplerate; |
38 |
|
static int audiochannels; |
39 |
|
static BOOL reopened; |
40 |
|
static short samplewidth; |
41 |
|
|
42 |
static struct audio_packet |
static struct audio_packet |
43 |
{ |
{ |
57 |
|
|
58 |
format.bits = 16; |
format.bits = 16; |
59 |
format.channels = 2; |
format.channels = 2; |
60 |
g_channels = 2; |
audiochannels = 2; |
61 |
format.rate = 44100; |
format.rate = 44100; |
62 |
g_samplerate = 44100; |
samplerate = 44100; |
63 |
format.byte_format = AO_FMT_LITTLE; |
format.byte_format = AO_FMT_LITTLE; |
64 |
|
|
65 |
o_device = ao_open_live(default_driver, &format, NULL); |
o_device = ao_open_live(default_driver, &format, NULL); |
71 |
g_dsp_fd = 0; |
g_dsp_fd = 0; |
72 |
queue_lo = queue_hi = 0; |
queue_lo = queue_hi = 0; |
73 |
|
|
74 |
g_reopened = True; |
reopened = True; |
75 |
|
|
76 |
return True; |
return True; |
77 |
} |
} |
117 |
|
|
118 |
format.bits = pwfx->wBitsPerSample; |
format.bits = pwfx->wBitsPerSample; |
119 |
format.channels = pwfx->nChannels; |
format.channels = pwfx->nChannels; |
120 |
g_channels = pwfx->nChannels; |
audiochannels = pwfx->nChannels; |
121 |
format.rate = 44100; |
format.rate = 44100; |
122 |
g_samplerate = pwfx->nSamplesPerSec; |
samplerate = pwfx->nSamplesPerSec; |
123 |
format.byte_format = AO_FMT_LITTLE; |
format.byte_format = AO_FMT_LITTLE; |
124 |
|
|
125 |
g_samplewidth = pwfx->wBitsPerSample / 8; |
samplewidth = pwfx->wBitsPerSample / 8; |
126 |
|
|
127 |
if (o_device != NULL) |
if (o_device != NULL) |
128 |
ao_close(o_device); |
ao_close(o_device); |
133 |
return False; |
return False; |
134 |
} |
} |
135 |
|
|
136 |
g_reopened = True; |
reopened = True; |
137 |
|
|
138 |
return True; |
return True; |
139 |
} |
} |
182 |
struct timeval tv; |
struct timeval tv; |
183 |
int next_tick; |
int next_tick; |
184 |
|
|
185 |
if (g_reopened) |
if (reopened) |
186 |
{ |
{ |
187 |
g_reopened = False; |
reopened = False; |
188 |
gettimeofday(&tv, NULL); |
gettimeofday(&tv, NULL); |
189 |
prev_s = tv.tv_sec; |
prev_s = tv.tv_sec; |
190 |
prev_us = tv.tv_usec; |
prev_us = tv.tv_usec; |
210 |
|
|
211 |
len = 0; |
len = 0; |
212 |
|
|
213 |
if (g_samplerate == 22050) |
if (samplerate == 22050) |
214 |
{ |
{ |
215 |
/* Resample to 44100 */ |
/* Resample to 44100 */ |
216 |
for (i = 0; (i < ((WAVEOUTBUF / 4) * (3 - g_samplewidth))) && (out->p < out->end); |
for (i = 0; (i < ((WAVEOUTBUF / 4) * (3 - samplewidth))) && (out->p < out->end); |
217 |
i++) |
i++) |
218 |
{ |
{ |
219 |
/* On a stereo-channel we must make sure that left and right |
/* On a stereo-channel we must make sure that left and right |
221 |
data with channels in mind: 1234 -> 12123434 |
data with channels in mind: 1234 -> 12123434 |
222 |
If we have a mono-channel, we can expand the data by simply |
If we have a mono-channel, we can expand the data by simply |
223 |
doubling the sample-data: 1234 -> 11223344 */ |
doubling the sample-data: 1234 -> 11223344 */ |
224 |
if (g_channels == 2) |
if (audiochannels == 2) |
225 |
offset = ((i * 2) - (i & 1)) * g_samplewidth; |
offset = ((i * 2) - (i & 1)) * samplewidth; |
226 |
else |
else |
227 |
offset = (i * 2) * g_samplewidth; |
offset = (i * 2) * samplewidth; |
228 |
|
|
229 |
memcpy(&outbuf[offset], out->p, g_samplewidth); |
memcpy(&outbuf[offset], out->p, samplewidth); |
230 |
memcpy(&outbuf[g_channels * g_samplewidth + offset], out->p, g_samplewidth); |
memcpy(&outbuf[audiochannels * samplewidth + offset], out->p, samplewidth); |
231 |
|
|
232 |
out->p += g_samplewidth; |
out->p += samplewidth; |
233 |
len += 2 * g_samplewidth; |
len += 2 * samplewidth; |
234 |
} |
} |
235 |
} |
} |
236 |
else |
else |