31 |
int g_dsp_fd; |
int g_dsp_fd; |
32 |
BOOL g_dsp_busy; |
BOOL g_dsp_busy; |
33 |
|
|
34 |
static struct audio_packet { |
static struct audio_packet |
35 |
|
{ |
36 |
struct stream s; |
struct stream s; |
37 |
uint16 tick; |
uint16 tick; |
38 |
uint8 index; |
uint8 index; |
44 |
{ |
{ |
45 |
char *dsp_dev = "/dev/dsp"; |
char *dsp_dev = "/dev/dsp"; |
46 |
|
|
47 |
if ((g_dsp_fd = open(dsp_dev, O_WRONLY)) == -1) |
if ((g_dsp_fd = open(dsp_dev, O_WRONLY | O_NONBLOCK)) == -1) |
48 |
{ |
{ |
49 |
perror(dsp_dev); |
perror(dsp_dev); |
50 |
return False; |
return False; |
51 |
} |
} |
52 |
|
|
53 |
/* Non-blocking so that user interface is responsive */ |
/* Non-blocking so that user interface is responsive */ |
54 |
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); |
55 |
return True; |
return True; |
56 |
} |
} |
57 |
|
|
62 |
} |
} |
63 |
|
|
64 |
BOOL |
BOOL |
65 |
wave_out_format_supported(WAVEFORMATEX *pwfx) |
wave_out_format_supported(WAVEFORMATEX * pwfx) |
66 |
{ |
{ |
67 |
if (pwfx->wFormatTag != WAVE_FORMAT_PCM) |
if (pwfx->wFormatTag != WAVE_FORMAT_PCM) |
68 |
return False; |
return False; |
75 |
} |
} |
76 |
|
|
77 |
BOOL |
BOOL |
78 |
wave_out_set_format(WAVEFORMATEX *pwfx) |
wave_out_set_format(WAVEFORMATEX * pwfx) |
79 |
{ |
{ |
80 |
int speed, channels, format; |
int speed, channels, format; |
81 |
|
|
114 |
} |
} |
115 |
|
|
116 |
void |
void |
117 |
|
wave_out_volume(uint16 left, uint16 right) |
118 |
|
{ |
119 |
|
uint32 volume; |
120 |
|
|
121 |
|
volume = left / (65536 / 100); |
122 |
|
volume |= right / (65536 / 100) << 8; |
123 |
|
if (ioctl(g_dsp_fd, MIXER_WRITE(SOUND_MIXER_PCM), &volume) == -1) |
124 |
|
{ |
125 |
|
perror("MIXER_WRITE(SOUND_MIXER_PCM)"); |
126 |
|
return; |
127 |
|
} |
128 |
|
} |
129 |
|
|
130 |
|
void |
131 |
wave_out_write(STREAM s, uint16 tick, uint8 index) |
wave_out_write(STREAM s, uint16 tick, uint8 index) |
132 |
{ |
{ |
133 |
struct audio_packet *packet = &packet_queue[queue_hi]; |
struct audio_packet *packet = &packet_queue[queue_hi]; |
144 |
packet->s = *s; |
packet->s = *s; |
145 |
packet->tick = tick; |
packet->tick = tick; |
146 |
packet->index = index; |
packet->index = index; |
147 |
|
packet->s.p += 4; |
148 |
|
|
149 |
/* we steal the data buffer from s, give it a new one */ |
/* we steal the data buffer from s, give it a new one */ |
150 |
s->data = malloc(s->size); |
s->data = malloc(s->size); |
171 |
packet = &packet_queue[queue_lo]; |
packet = &packet_queue[queue_lo]; |
172 |
out = &packet->s; |
out = &packet->s; |
173 |
|
|
174 |
len = write(g_dsp_fd, out->p, out->end-out->p); |
len = write(g_dsp_fd, out->p, out->end - out->p); |
175 |
if (len == -1) |
if (len == -1) |
176 |
{ |
{ |
177 |
if (errno != EWOULDBLOCK) |
if (errno != EWOULDBLOCK) |