26 |
#include <errno.h> |
#include <errno.h> |
27 |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
28 |
#include <sys/audioio.h> |
#include <sys/audioio.h> |
29 |
|
|
30 |
|
#if (defined(sun) && (defined(__svr4__) || defined(__SVR4))) |
31 |
#include <stropts.h> |
#include <stropts.h> |
32 |
|
#endif |
33 |
|
|
34 |
#define MAX_QUEUE 10 |
#define MAX_QUEUE 10 |
35 |
|
|
36 |
int g_dsp_fd; |
int g_dsp_fd; |
37 |
BOOL g_dsp_busy = False; |
BOOL g_dsp_busy = False; |
38 |
static BOOL reopened; |
static BOOL g_reopened; |
39 |
static BOOL swapaudio; |
static BOOL g_swapaudio; |
40 |
static short samplewidth; |
static short g_samplewidth; |
41 |
|
|
42 |
static struct audio_packet |
static struct audio_packet |
43 |
{ |
{ |
67 |
fcntl(g_dsp_fd, F_SETFL, fcntl(g_dsp_fd, F_GETFL) | O_NONBLOCK); |
fcntl(g_dsp_fd, F_SETFL, fcntl(g_dsp_fd, F_GETFL) | O_NONBLOCK); |
68 |
|
|
69 |
queue_lo = queue_hi = 0; |
queue_lo = queue_hi = 0; |
70 |
reopened = True; |
g_reopened = True; |
71 |
|
|
72 |
return True; |
return True; |
73 |
} |
} |
83 |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
84 |
} |
} |
85 |
|
|
86 |
|
#if defined I_FLUSH && defined FLUSHW |
87 |
/* Flush the audiobuffer */ |
/* Flush the audiobuffer */ |
88 |
ioctl(g_dsp_fd, I_FLUSH, FLUSHW); |
ioctl(g_dsp_fd, I_FLUSH, FLUSHW); |
89 |
|
#endif |
90 |
close(g_dsp_fd); |
close(g_dsp_fd); |
91 |
} |
} |
92 |
|
|
110 |
int test = 1; |
int test = 1; |
111 |
|
|
112 |
ioctl(g_dsp_fd, AUDIO_DRAIN, 0); |
ioctl(g_dsp_fd, AUDIO_DRAIN, 0); |
113 |
swapaudio = False; |
g_swapaudio = False; |
114 |
AUDIO_INITINFO(&info); |
AUDIO_INITINFO(&info); |
115 |
|
|
116 |
|
|
122 |
{ |
{ |
123 |
info.play.encoding = AUDIO_ENCODING_LINEAR; |
info.play.encoding = AUDIO_ENCODING_LINEAR; |
124 |
/* Do we need to swap the 16bit values? (Are we BigEndian) */ |
/* Do we need to swap the 16bit values? (Are we BigEndian) */ |
125 |
swapaudio = !(*(uint8 *) (&test)); |
g_swapaudio = !(*(uint8 *) (&test)); |
126 |
} |
} |
127 |
|
|
128 |
samplewidth = pwfx->wBitsPerSample / 8; |
g_samplewidth = pwfx->wBitsPerSample / 8; |
129 |
|
|
130 |
if (pwfx->nChannels == 1) |
if (pwfx->nChannels == 1) |
131 |
{ |
{ |
132 |
info.play.channels = AUDIO_CHANNELS_MONO; |
info.play.channels = 1; |
133 |
} |
} |
134 |
else if (pwfx->nChannels == 2) |
else if (pwfx->nChannels == 2) |
135 |
{ |
{ |
136 |
info.play.channels = AUDIO_CHANNELS_STEREO; |
info.play.channels = 2; |
137 |
samplewidth *= 2; |
g_samplewidth *= 2; |
138 |
} |
} |
139 |
|
|
140 |
info.play.sample_rate = pwfx->nSamplesPerSec; |
info.play.sample_rate = pwfx->nSamplesPerSec; |
142 |
info.play.samples = 0; |
info.play.samples = 0; |
143 |
info.play.eof = 0; |
info.play.eof = 0; |
144 |
info.play.error = 0; |
info.play.error = 0; |
145 |
reopened = True; |
g_reopened = True; |
146 |
|
|
147 |
if (ioctl(g_dsp_fd, AUDIO_SETINFO, &info) == -1) |
if (ioctl(g_dsp_fd, AUDIO_SETINFO, &info) == -1) |
148 |
{ |
{ |
232 |
|
|
233 |
while (1) |
while (1) |
234 |
{ |
{ |
235 |
if (reopened) |
if (g_reopened) |
236 |
{ |
{ |
237 |
/* Device was just (re)openend */ |
/* Device was just (re)openend */ |
238 |
samplecnt = 0; |
samplecnt = 0; |
239 |
swapped = False; |
swapped = False; |
240 |
sentcompletion = True; |
sentcompletion = True; |
241 |
reopened = False; |
g_reopened = False; |
242 |
} |
} |
243 |
|
|
244 |
if (queue_lo == queue_hi) |
if (queue_lo == queue_hi) |
251 |
out = &packet->s; |
out = &packet->s; |
252 |
|
|
253 |
/* Swap the current packet, but only once */ |
/* Swap the current packet, but only once */ |
254 |
if (swapaudio && !swapped) |
if (g_swapaudio && !swapped) |
255 |
{ |
{ |
256 |
for (i = 0; i < out->end - out->p; i += 2) |
for (i = 0; i < out->end - out->p; i += 2) |
257 |
{ |
{ |
265 |
if (sentcompletion) |
if (sentcompletion) |
266 |
{ |
{ |
267 |
sentcompletion = False; |
sentcompletion = False; |
268 |
numsamples = (out->end - out->p) / samplewidth; |
numsamples = (out->end - out->p) / g_samplewidth; |
269 |
} |
} |
270 |
|
|
271 |
len = 0; |
len = 0; |