31 |
|
#endif |
32 |
|
|
33 |
|
#ifdef __FreeBSD__ |
34 |
< |
#include <sys/soundcard.h> |
34 |
> |
#include <machine/soundcard.h> |
35 |
|
#endif |
36 |
|
|
37 |
|
#include "cpu_emulation.h" |
54 |
|
static int audio_sample_size_index = 0; |
55 |
|
static int audio_channel_count_index = 0; |
56 |
|
|
57 |
– |
// Constants |
58 |
– |
#define DSP_NAME "/dev/dsp" |
59 |
– |
|
57 |
|
// Global variables |
58 |
< |
static int audio_fd = -1; // fd of /dev/dsp or ESD |
59 |
< |
static int mixer_fd = -1; // fd of /dev/mixer |
58 |
> |
static int audio_fd = -1; // fd of dsp or ESD |
59 |
> |
static int mixer_fd = -1; // fd of mixer |
60 |
|
static sem_t audio_irq_done_sem; // Signal from interrupt to streaming thread: data block read |
61 |
|
static bool sem_inited = false; // Flag: audio_irq_done_sem initialized |
62 |
|
static int sound_buffer_size; // Size of sound buffer in bytes |
83 |
|
AudioStatus.channels = audio_channel_counts[audio_channel_count_index]; |
84 |
|
} |
85 |
|
|
86 |
< |
// Init using /dev/dsp, returns false on error |
86 |
> |
// Init using the dsp device, returns false on error |
87 |
|
static bool open_dsp(void) |
88 |
|
{ |
89 |
< |
// Open /dev/dsp |
90 |
< |
audio_fd = open(DSP_NAME, O_WRONLY); |
89 |
> |
// Open the device |
90 |
> |
const char *dsp = PrefsFindString("dsp"); |
91 |
> |
audio_fd = open(dsp, O_WRONLY); |
92 |
|
if (audio_fd < 0) { |
93 |
< |
fprintf(stderr, "WARNING: Cannot open %s (%s)\n", DSP_NAME, strerror(errno)); |
93 |
> |
fprintf(stderr, "WARNING: Cannot open %s (%s)\n", dsp, strerror(errno)); |
94 |
|
return false; |
95 |
|
} |
96 |
|
|
97 |
< |
printf("Using " DSP_NAME " audio output\n"); |
97 |
> |
printf("Using %s audio output\n", dsp); |
98 |
|
|
99 |
|
// Get supported sample formats |
100 |
|
if (audio_sample_sizes.empty()) { |
211 |
|
|
212 |
|
// The reason we do this here is that we don't want to add sample |
213 |
|
// rates etc. unless the ESD server connection could be opened |
214 |
< |
// (if ESD fails, /dev/dsp might be tried next) |
214 |
> |
// (if ESD fails, dsp might be tried next) |
215 |
|
audio_sample_rates.push_back(11025 << 16); |
216 |
|
audio_sample_rates.push_back(22050 << 16); |
217 |
|
audio_sample_rates.push_back(44100 << 16); |
244 |
|
goto dev_opened; |
245 |
|
#endif |
246 |
|
|
247 |
< |
// Try to open /dev/dsp |
247 |
> |
// Try to open dsp |
248 |
|
if (open_dsp()) |
249 |
|
goto dev_opened; |
250 |
|
|
251 |
|
#ifdef ENABLE_ESD |
252 |
< |
// Hm, /dev/dsp failed so we try ESD again if ESPEAKER wasn't set |
252 |
> |
// Hm, dsp failed so we try ESD again if ESPEAKER wasn't set |
253 |
|
if (!getenv("ESPEAKER")) |
254 |
|
if (open_esd()) |
255 |
|
goto dev_opened; |
292 |
|
return; |
293 |
|
sem_inited = true; |
294 |
|
|
295 |
< |
// Try to open /dev/mixer |
296 |
< |
mixer_fd = open("/dev/mixer", O_RDWR); |
295 |
> |
// Try to open the mixer device |
296 |
> |
const char *mixer = PrefsFindString("mixer"); |
297 |
> |
mixer_fd = open(mixer, O_RDWR); |
298 |
|
if (mixer_fd < 0) |
299 |
< |
printf("WARNING: Cannot open /dev/mixer (%s)", strerror(errno)); |
299 |
> |
printf("WARNING: Cannot open %s (%s)\n", mixer, strerror(errno)); |
300 |
|
|
301 |
|
// Open and initialize audio device |
302 |
|
open_audio(); |
319 |
|
stream_thread_active = false; |
320 |
|
} |
321 |
|
|
322 |
< |
// Close /dev/dsp or ESD socket |
322 |
> |
// Close dsp or ESD socket |
323 |
|
if (audio_fd >= 0) { |
324 |
|
close(audio_fd); |
325 |
|
audio_fd = -1; |
339 |
|
sem_inited = false; |
340 |
|
} |
341 |
|
|
342 |
< |
// Close /dev/mixer |
342 |
> |
// Close mixer device |
343 |
|
if (mixer_fd >= 0) { |
344 |
|
close(mixer_fd); |
345 |
|
mixer_fd = -1; |