--- 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 17:15:09 1.1.1.8 @@ -1,8 +1,8 @@ - /* + /* * UAE - The Un*x Amiga Emulator - * + * * Support for Linux/USS sound - * + * * Copyright 1997 Bernd Schmidt */ @@ -12,6 +12,7 @@ #include "config.h" #include "options.h" #include "memory.h" +#include "events.h" #include "custom.h" #include "gensound.h" #include "sounddep/sound.h" @@ -27,7 +28,7 @@ #endif int sound_fd; -static int have_sound; +static int have_sound = 0; static unsigned long formats; uae_u16 sndbuffer[44100]; @@ -48,21 +49,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 +83,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; @@ -89,7 +115,7 @@ int init_sound (void) return 0; } - tmp = currprefs.stereo; + tmp = currprefs.sound_stereo; ioctl (sound_fd, SNDCTL_DSP_STEREO, &tmp); rate = currprefs.sound_freq; @@ -101,28 +127,25 @@ int init_sound (void) return 0; } - sample_evtime = (long)maxhpos * maxvpos * 50 / rate; + scaled_sample_evtime = (unsigned long)MAXHPOS_PAL * MAXVPOS_PAL * VBLANK_HZ_PAL * CYCLE_UNIT / rate; + scaled_sample_evtime_ok = 1; if (dspbits == 16) { /* Will this break horribly on bigendian machines? Possible... */ if (!(formats & AFMT_S16_LE)) return 0; init_sound_table16 (); - sample_handler = currprefs.stereo ? sample16s_handler : sample16_handler; + sample_handler = currprefs.sound_stereo ? sample16s_handler : sample16_handler; } else { if (!(formats & AFMT_U8)) return 0; init_sound_table8 (); - sample_handler = currprefs.stereo ? sample8s_handler : sample8_handler; + sample_handler = currprefs.sound_stereo ? sample8s_handler : sample8_handler; } sound_available = 1; printf ("Sound driver found and configured for %d bits at %d Hz, buffer is %d bytes\n", dspbits, rate, sndbufsize); sndbufpt = sndbuffer; - -#ifdef FRAME_RATE_HACK - vsynctime = vsynctime * 9 / 10; -#endif return 1; }