29 |
#define MAX_QUEUE 10 |
#define MAX_QUEUE 10 |
30 |
|
|
31 |
int g_dsp_fd; |
int g_dsp_fd; |
32 |
BOOL g_dsp_busy; |
BOOL g_dsp_busy = False; |
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 |
|
static BOOL use_dev_mixer = False; |
120 |
|
uint32 volume; |
121 |
|
int fd_mix = -1; |
122 |
|
|
123 |
|
volume = left / (65536 / 100); |
124 |
|
volume |= right / (65536 / 100) << 8; |
125 |
|
|
126 |
|
if (use_dev_mixer) |
127 |
|
{ |
128 |
|
if ((fd_mix = open( "/dev/mixer", O_RDWR|O_NONBLOCK )) == -1 ) |
129 |
|
{ |
130 |
|
perror("open /dev/mixer"); |
131 |
|
return; |
132 |
|
} |
133 |
|
|
134 |
|
if (ioctl(fd_mix, MIXER_WRITE(SOUND_MIXER_PCM), &volume) == -1) |
135 |
|
{ |
136 |
|
perror("MIXER_WRITE(SOUND_MIXER_PCM)"); |
137 |
|
return; |
138 |
|
} |
139 |
|
|
140 |
|
close(fd_mix); |
141 |
|
} |
142 |
|
|
143 |
|
if (ioctl(g_dsp_fd, MIXER_WRITE(SOUND_MIXER_PCM), &volume) == -1) |
144 |
|
{ |
145 |
|
perror("MIXER_WRITE(SOUND_MIXER_PCM)"); |
146 |
|
use_dev_mixer = True; |
147 |
|
return; |
148 |
|
} |
149 |
|
} |
150 |
|
|
151 |
|
void |
152 |
wave_out_write(STREAM s, uint16 tick, uint8 index) |
wave_out_write(STREAM s, uint16 tick, uint8 index) |
153 |
{ |
{ |
154 |
struct audio_packet *packet = &packet_queue[queue_hi]; |
struct audio_packet *packet = &packet_queue[queue_hi]; |
165 |
packet->s = *s; |
packet->s = *s; |
166 |
packet->tick = tick; |
packet->tick = tick; |
167 |
packet->index = index; |
packet->index = index; |
168 |
|
packet->s.p += 4; |
169 |
|
|
170 |
/* we steal the data buffer from s, give it a new one */ |
/* we steal the data buffer from s, give it a new one */ |
171 |
s->data = malloc(s->size); |
s->data = malloc(s->size); |
192 |
packet = &packet_queue[queue_lo]; |
packet = &packet_queue[queue_lo]; |
193 |
out = &packet->s; |
out = &packet->s; |
194 |
|
|
195 |
len = write(g_dsp_fd, out->p, out->end-out->p); |
len = write(g_dsp_fd, out->p, out->end - out->p); |
196 |
if (len == -1) |
if (len == -1) |
197 |
{ |
{ |
198 |
if (errno != EWOULDBLOCK) |
if (errno != EWOULDBLOCK) |