--- uae/src/sd-uss/sound.c 2018/04/24 16:42:46 1.1.1.2 +++ uae/src/sd-uss/sound.c 2018/04/24 16:44:04 1.1.1.3 @@ -27,7 +27,7 @@ #endif int sound_fd; -static int have_sound; +static int have_sound = 0; static unsigned long formats; uae_u16 sndbuffer[44100]; @@ -48,21 +48,31 @@ void close_sound (void) close (sound_fd); } +/* Try to determine whether sound is available. This is only for GUI purposes. */ int setup_sound (void) { sound_fd = open ("/dev/dsp", O_WRONLY); - have_sound = !(sound_fd < 0); - if (! have_sound) + + sound_available = 0; + + if (sound_fd < 0) { + perror ("Can't open /dev/dsp"); + if (errno == EBUSY) { + /* We can hope, can't we ;) */ + sound_available = 1; + return 1; + } return 0; + } if (ioctl (sound_fd, SNDCTL_DSP_GETFMTS, &formats) == -1) { - fprintf (stderr, "ioctl failed - can't use sound.\n"); - close(sound_fd); - have_sound = 0; + perror ("ioctl failed - can't use sound"); + close (sound_fd); return 0; } sound_available = 1; + close (sound_fd); return 1; } @@ -72,6 +82,21 @@ int init_sound (void) int rate; int dspbits; + sound_fd = open ("/dev/dsp", O_WRONLY); + have_sound = !(sound_fd < 0); + if (! have_sound) { + perror ("Can't open /dev/dsp"); + if (errno != EBUSY) + sound_available = 0; + return 0; + } + if (ioctl (sound_fd, SNDCTL_DSP_GETFMTS, &formats) == -1) { + perror ("ioctl failed - can't use sound"); + close (sound_fd); + have_sound = 0; + return 0; + } + if (currprefs.sound_maxbsiz < 128 || currprefs.sound_maxbsiz > 16384) { fprintf (stderr, "Sound buffer size %d out of range.\n", currprefs.sound_maxbsiz); currprefs.sound_maxbsiz = 8192;