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> |
|
#include <stropts.h> |
|
29 |
|
|
30 |
#define MAX_QUEUE 10 |
#define MAX_QUEUE 10 |
31 |
|
|
32 |
int g_dsp_fd; |
int g_dsp_fd; |
33 |
BOOL g_dsp_busy; |
BOOL g_dsp_busy = False; |
34 |
static BOOL reopened; |
static BOOL g_reopened; |
35 |
static BOOL swapaudio; |
static BOOL g_swapaudio; |
36 |
static short samplewidth; |
static short g_samplewidth; |
37 |
|
|
38 |
static struct audio_packet |
static struct audio_packet |
39 |
{ |
{ |
63 |
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); |
64 |
|
|
65 |
queue_lo = queue_hi = 0; |
queue_lo = queue_hi = 0; |
66 |
reopened = True; |
g_reopened = True; |
67 |
|
|
68 |
return True; |
return True; |
69 |
} |
} |
79 |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
80 |
} |
} |
81 |
|
|
82 |
|
#if defined I_FLUSH && defined FLUSHW |
83 |
/* Flush the audiobuffer */ |
/* Flush the audiobuffer */ |
84 |
ioctl(g_dsp_fd, I_FLUSH, FLUSHW); |
ioctl(g_dsp_fd, I_FLUSH, FLUSHW); |
85 |
|
#endif |
86 |
close(g_dsp_fd); |
close(g_dsp_fd); |
87 |
} |
} |
88 |
|
|
106 |
int test = 1; |
int test = 1; |
107 |
|
|
108 |
ioctl(g_dsp_fd, AUDIO_DRAIN, 0); |
ioctl(g_dsp_fd, AUDIO_DRAIN, 0); |
109 |
swapaudio = False; |
g_swapaudio = False; |
110 |
AUDIO_INITINFO(&info); |
AUDIO_INITINFO(&info); |
111 |
|
|
112 |
|
|
118 |
{ |
{ |
119 |
info.play.encoding = AUDIO_ENCODING_LINEAR; |
info.play.encoding = AUDIO_ENCODING_LINEAR; |
120 |
/* Do we need to swap the 16bit values? (Are we BigEndian) */ |
/* Do we need to swap the 16bit values? (Are we BigEndian) */ |
121 |
swapaudio = !(*(uint8 *) (&test)); |
g_swapaudio = !(*(uint8 *) (&test)); |
122 |
} |
} |
123 |
|
|
124 |
samplewidth = pwfx->wBitsPerSample / 8; |
g_samplewidth = pwfx->wBitsPerSample / 8; |
125 |
|
|
126 |
if (pwfx->nChannels == 1) |
if (pwfx->nChannels == 1) |
127 |
{ |
{ |
128 |
info.play.channels = AUDIO_CHANNELS_MONO; |
info.play.channels = 1; |
129 |
} |
} |
130 |
else if (pwfx->nChannels == 2) |
else if (pwfx->nChannels == 2) |
131 |
{ |
{ |
132 |
info.play.channels = AUDIO_CHANNELS_STEREO; |
info.play.channels = 2; |
133 |
samplewidth *= 2; |
g_samplewidth *= 2; |
134 |
} |
} |
135 |
|
|
136 |
info.play.sample_rate = pwfx->nSamplesPerSec; |
info.play.sample_rate = pwfx->nSamplesPerSec; |
138 |
info.play.samples = 0; |
info.play.samples = 0; |
139 |
info.play.eof = 0; |
info.play.eof = 0; |
140 |
info.play.error = 0; |
info.play.error = 0; |
141 |
reopened = True; |
g_reopened = True; |
142 |
|
|
143 |
if (ioctl(g_dsp_fd, AUDIO_SETINFO, &info) == -1) |
if (ioctl(g_dsp_fd, AUDIO_SETINFO, &info) == -1) |
144 |
{ |
{ |
228 |
|
|
229 |
while (1) |
while (1) |
230 |
{ |
{ |
231 |
if (reopened) |
if (g_reopened) |
232 |
{ |
{ |
233 |
/* Device was just (re)openend */ |
/* Device was just (re)openend */ |
234 |
samplecnt = 0; |
samplecnt = 0; |
235 |
swapped = False; |
swapped = False; |
236 |
sentcompletion = True; |
sentcompletion = True; |
237 |
reopened = False; |
g_reopened = False; |
238 |
} |
} |
239 |
|
|
240 |
if (queue_lo == queue_hi) |
if (queue_lo == queue_hi) |
247 |
out = &packet->s; |
out = &packet->s; |
248 |
|
|
249 |
/* Swap the current packet, but only once */ |
/* Swap the current packet, but only once */ |
250 |
if (swapaudio && !swapped) |
if (g_swapaudio && !swapped) |
251 |
{ |
{ |
252 |
for (i = 0; i < out->end - out->p; i += 2) |
for (i = 0; i < out->end - out->p; i += 2) |
253 |
{ |
{ |
261 |
if (sentcompletion) |
if (sentcompletion) |
262 |
{ |
{ |
263 |
sentcompletion = False; |
sentcompletion = False; |
264 |
numsamples = (out->end - out->p) / samplewidth; |
numsamples = (out->end - out->p) / g_samplewidth; |
265 |
} |
} |
266 |
|
|
267 |
len = 0; |
len = 0; |