{
int i;
- audio = InitAudio();
+ OpenAudio(&audio);
for(i=0; i<NUM_SOUNDS; i++)
{
keyboard_auto_repeat = FALSE;
}
-boolean MSDOSInitAudio(void)
+boolean MSDOSOpenAudio(void)
{
return allegro_init_audio();
}
+boolean MSDOSCloseAudio(void)
+{
+ /* nothing to be done here */
+}
+
void NetworkServer(int port, int serveronly)
{
Error(ERR_WARN, "networking not supported in DOS version");
void XAutoRepeatOn(Display *);
void XAutoRepeatOff(Display *);
-boolean MSDOSInitAudio(void);
+boolean MSDOSOpenAudio(void);
+boolean MSDOSCloseAudio(void);
+
void NetworkServer(int, int);
#endif /* MSDOS_H */
SDL_MapRGB(surface->format, color_r, color_g, color_b));
}
-inline boolean SDLInitAudio(void)
+inline boolean SDLOpenAudio(void)
{
if (SDL_Init(SDL_INIT_AUDIO) < 0)
{
return TRUE;
}
+inline void SDLCloseAudio(void)
+{
+ Mix_HaltMusic();
+ Mix_HaltChannel(-1);
+
+ Mix_CloseAudio();
+}
+
#endif /* TARGET_SDL */
inline void SDLFillRectangle(SDL_Surface *, int, int, int, int, unsigned int);
inline void SDLDrawSimpleLine(SDL_Surface *, int, int, int, int, unsigned int);
-inline boolean SDLInitAudio(void);
+inline boolean SDLOpenAudio(void);
+inline void SDLCloseAudio(void);
#endif /* SDL_H */
#endif
#if defined(PLATFORM_UNIX)
-int OpenAudio(char *audio_device_name)
+int OpenAudioDevice(char *audio_device_name)
{
int audio_fd;
+ /* check if desired audio device is accessible */
+ if (access(sound_device_name, W_OK) != 0)
+ return -1;
+
/* try to open audio device in non-blocking mode */
if ((audio_fd = open(audio_device_name, O_WRONLY | O_NONBLOCK)) < 0)
return audio_fd;
return audio_fd;
}
-int CheckAudio(char *audio_device_name)
+void UnixOpenAudio(struct AudioSystemInfo *audio)
{
+ static char *audio_device_name[] =
+ {
+ DEV_DSP,
+ DEV_AUDIO
+ };
int audio_fd;
+ int i;
- if (access(audio_device_name, W_OK) != 0)
- {
- Error(ERR_WARN, "cannot access audio device - no sound");
- return SOUND_OFF;
- }
+ /* look for available audio devices, starting with preferred ones */
+ for (i=0; i<sizeof(audio_device_name)/sizeof(char *); i++)
+ if ((audio_fd = OpenAudioDevice(sound_device_name)) >= 0)
+ break;
- if ((audio_fd = OpenAudio(sound_device_name)) < 0)
+ if (audio_fd < 0)
{
Error(ERR_WARN, "cannot open audio device - no sound");
- return SOUND_OFF;
+ return;
}
close(audio_fd);
- return SOUND_AVAILABLE;
-}
-
-void UnixInitAudio(struct AudioSystemInfo *audio)
-{
- if (!(audio->sound_available = CheckAudio(sound_device_name)))
- return;
+ audio->sound_available = TRUE;
#ifdef VOXWARE
audio->loops_available = TRUE;
#endif
}
+
+void UnixCloseAudio(struct AudioSystemInfo *audio)
+{
+ if (audio->device_fd)
+ close(audio->device_fd);
+}
+
#endif /* PLATFORM_UNIX */
void SoundServer()
#endif
if (playing_sounds ||
- (audio.device_fd = OpenAudio(sound_device_name)) >= 0)
+ (audio.device_fd = OpenAudioDevice(sound_device_name)) >= 0)
{
if (!playing_sounds) /* we just opened the audio device */
{
int wait_percent = 90; /* wait 90% of the real playing time */
int i;
- if ((audio.device_fd = OpenAudio(sound_device_name)) >= 0)
+ if ((audio.device_fd = OpenAudioDevice(sound_device_name)) >= 0)
{
playing_sounds = 1;
#define SND_PATH "./sounds"
#endif
-#define DEV_AUDIO "/dev/audio"
#define DEV_DSP "/dev/dsp"
+#define DEV_AUDIO "/dev/audio"
+#define DEV_AUDIOCTL "/dev/audioCtl"
#ifdef VOXWARE
#define SOUND_DEVICE DEV_DSP
#define SOUND_DEVICE DEV_AUDIO
#endif
-#define SOUND_OFF 0
-#define SOUND_AVAILABLE 1
-
-#ifdef NO_SOUNDS
-#define SOUND_STATUS SOUND_OFF
-#else
-#define SOUND_STATUS SOUND_AVAILABLE
-#endif
-
struct SoundHeader_SUN
{
unsigned long magic;
};
/* general sound functions */
-int OpenAudio(char *);
-int CheckAudio(char *);
-void UnixInitAudio(struct AudioSystemInfo *);
+void UnixOpenAudio(struct AudioSystemInfo *);
+void UnixCloseAudio(struct AudioSystemInfo *);
/* sound server functions */
void SoundServer(void);
/* audio functions */
/* ========================================================================= */
-inline struct AudioSystemInfo InitAudio(void)
+inline boolean OpenAudio(struct AudioSystemInfo *audio)
{
- struct AudioSystemInfo audio;
-
- audio.sound_available = FALSE;
- audio.loops_available = FALSE;
- audio.soundserver_pipe[0] = audio.soundserver_pipe[1] = 0;
- audio.soundserver_pid = 0;
- audio.device_fd = 0;
+ audio->sound_available = FALSE;
+ audio->loops_available = FALSE;
+ audio->soundserver_pipe[0] = audio->soundserver_pipe[1] = 0;
+ audio->soundserver_pid = 0;
+ audio->device_fd = 0;
#if defined(TARGET_SDL)
- if (SDLInitAudio())
+ if (SDLOpenAudio())
{
- audio.sound_available = TRUE;
- audio.loops_available = TRUE;
+ audio->sound_available = TRUE;
+ audio->loops_available = TRUE;
}
#elif defined(PLATFORM_MSDOS)
- if (MSDOSInitAudio())
+ if (MSDOSOpenAudio())
{
- audio.sound_available = TRUE;
- audio.loops_available = TRUE;
+ audio->sound_available = TRUE;
+ audio->loops_available = TRUE;
}
#elif defined(PLATFORM_UNIX)
- UnixInitAudio(&audio);
+ UnixOpenAudio(audio);
+#endif
+
+ return audio->sound_available;
+}
+
+inline void CloseAudio(struct AudioSystemInfo *audio)
+{
+#if defined(TARGET_SDL)
+ SDLCloseAudio();
+#elif defined(PLATFORM_MSDOS)
+ MSDOSCloseAudio();
+#elif defined(PLATFORM_UNIX)
+ UnixCloseAudio(audio);
#endif
- return audio;
+ audio->sound_available = FALSE;
+ audio->loops_available = FALSE;
}
inline boolean SetVideoMode(void);
inline void ChangeVideoModeIfNeeded(void);
-inline struct AudioSystemInfo InitAudio(void);
+inline boolean OpenAudio(struct AudioSystemInfo *);
+inline void CloseAudio(struct AudioSystemInfo *);
inline void InitEventFilter(EventFilter);
inline boolean PendingEvent(void);