void GetPlayerConfig()
{
- if (!sysinfo.audio_available)
+ if (!audio.sound_available)
setup.sound = FALSE;
- if (!sysinfo.audio_loops_available)
+ if (!audio.loops_available)
{
setup.sound_loops = FALSE;
setup.sound_music = FALSE;
setup.sound_music = FALSE;
FadeSound(background_loop[level_nr % num_bg_loops]);
}
- else if (sysinfo.audio_loops_available)
+ else if (audio.loops_available)
{
setup.sound = setup.sound_music = TRUE;
PlaySoundLoop(background_loop[level_nr % num_bg_loops]);
case SOUND_CTRL_ID_LOOPS:
if (setup.sound_loops)
setup.sound_loops = FALSE;
- else if (sysinfo.audio_loops_available)
+ else if (audio.loops_available)
setup.sound = setup.sound_loops = TRUE;
break;
case SOUND_CTRL_ID_SIMPLE:
if (setup.sound_simple)
setup.sound_simple = FALSE;
- else if (sysinfo.audio_available)
+ else if (audio.sound_available)
setup.sound = setup.sound_simple = TRUE;
break;
{
int i;
- /* REMOVE THIS! (gone to system.c:InitAudio) */
- if (!sysinfo.audio_available)
- return;
-
-#if defined(TARGET_SDL)
- if (InitAudio())
- {
- sysinfo.audio_available = TRUE;
- sysinfo.audio_loops_available = TRUE;
- }
- else
- {
- sysinfo.audio_available = FALSE;
- }
-#else /* !TARGET_SDL */
-
-#if defined(PLATFORM_UNIX)
- if (!(sysinfo.audio_available = CheckAudio(sound_device_name)))
- return;
-
-#ifdef VOXWARE
- sysinfo.audio_loops_available = TRUE;
-#endif
-
-#else /* !PLATFORM_UNIX */
- sysinfo.audio_loops_available = TRUE;
-
-#endif /* !PLATFORM_UNIX */
-#endif /* !TARGET_SDL */
+ audio = InitAudio();
for(i=0; i<NUM_SOUNDS; i++)
{
if (!LoadSound(&Sound[i]))
{
- sysinfo.audio_available = FALSE;
- sysinfo.audio_loops_available = FALSE;
+ audio.sound_available = FALSE;
+ audio.loops_available = FALSE;
return;
}
}
void InitSoundServer()
{
- if (!sysinfo.audio_available)
+ if (!audio.sound_available)
return;
#if !defined(TARGET_SDL)
#if defined(PLATFORM_UNIX)
- if (pipe(sysinfo.audio_process_pipe) < 0)
+ if (pipe(audio.soundserver_pipe) < 0)
{
Error(ERR_WARN, "cannot create pipe - no sounds");
- sysinfo.audio_available = FALSE;
+ audio.sound_available = FALSE;
return;
}
- if ((sysinfo.audio_process_id = fork()) < 0)
+ if ((audio.soundserver_pid = fork()) < 0)
{
Error(ERR_WARN, "cannot create sound server process - no sounds");
- sysinfo.audio_available = FALSE;
+ audio.sound_available = FALSE;
return;
}
- if (!sysinfo.audio_process_id) /* we are child */
+ if (audio.soundserver_pid == 0) /* we are child */
{
SoundServer();
exit(0);
}
else /* we are parent */
- close(sysinfo.audio_process_pipe[0]); /* no reading from pipe needed */
+ close(audio.soundserver_pipe[0]); /* no reading from pipe needed */
#else /* !PLATFORM_UNIX */
StopSounds();
FreeSounds(NUM_SOUNDS);
#else
- if (sysinfo.audio_process_id)
+ if (audio.soundserver_pid)
{
StopSounds();
- kill(sysinfo.audio_process_id, SIGTERM);
+ kill(audio.soundserver_pid, SIGTERM);
FreeSounds(NUM_SOUNDS);
}
#endif
struct OptionInfo options;
struct SetupInfo setup;
struct GameInfo game;
-struct SystemInfo sysinfo;
+struct AudioSystemInfo audio;
struct GlobalInfo global;
/* data needed for playing sounds */
extern struct OptionInfo options;
extern struct SetupInfo setup;
extern struct GameInfo game;
-extern struct SystemInfo sysinfo;
+extern struct AudioSystemInfo audio;
extern struct GlobalInfo global;
extern char *sound_name[];
static BITMAP *Read_PCX_to_AllegroBitmap(char *);
-static void allegro_drivers()
+static void allegro_init_drivers()
{
int i;
last_joystick_state = 0;
joystick_event = FALSE;
+}
- sysinfo.audio_available = TRUE;
+static boolean allegro_init_audio()
+{
reserve_voices(MAX_SOUNDS_PLAYING, 0);
+
if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) == -1)
if (install_sound(DIGI_SB, MIDI_NONE, NULL) == -1)
- sysinfo.audio_available = FALSE;
+ return FALSE;
+
+ return TRUE;
}
static boolean hide_mouse(Display *display, int x, int y,
display->mouse_ptr = mouse_bitmap;
allegro_init();
- allegro_drivers();
+ allegro_init_drivers();
set_color_depth(8);
/* force Windows 95 to switch to fullscreen mode */
keyboard_auto_repeat = FALSE;
}
+boolean MSDOSInitAudio(void)
+{
+ return allegro_init_audio();
+}
+
void NetworkServer(int port, int serveronly)
{
Error(ERR_WARN, "networking not supported in DOS version");
int *, int *, unsigned int *);
void XAutoRepeatOn(Display *);
void XAutoRepeatOff(Display *);
+
+boolean MSDOSInitAudio(void);
void NetworkServer(int, int);
#endif /* MSDOS_H */
{
int yy = y-1;
- if (y == 3 && sysinfo.audio_available)
+ if (y == 3 && audio.sound_available)
{
if (setup.sound)
{
DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
setup.sound = !setup.sound;
}
- else if (y == 4 && sysinfo.audio_loops_available)
+ else if (y == 4 && audio.loops_available)
{
if (setup.sound_loops)
DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
}
setup.sound_loops = !setup.sound_loops;
}
- else if (y == 5 && sysinfo.audio_loops_available)
+ else if (y == 5 && audio.loops_available)
{
if (setup.sound_music)
DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
return SOUND_AVAILABLE;
}
-boolean UnixInitAudio(void)
+void UnixInitAudio(struct AudioSystemInfo *audio)
{
- return TRUE;
+ if (!(audio->sound_available = CheckAudio(sound_device_name)))
+ return;
+
+#ifdef VOXWARE
+ audio->loops_available = TRUE;
+#endif
}
#endif /* PLATFORM_UNIX */
struct SoundControl snd_ctrl;
fd_set sound_fdset;
- close(sysinfo.audio_process_pipe[1]); /* no writing into pipe needed */
+ close(audio.soundserver_pipe[1]); /* no writing into pipe needed */
#endif
for(i=0;i<MAX_SOUNDS_PLAYING;i++)
#endif
FD_ZERO(&sound_fdset);
- FD_SET(sysinfo.audio_process_pipe[0], &sound_fdset);
+ FD_SET(audio.soundserver_pipe[0], &sound_fdset);
while(1) /* wait for sound playing commands from client */
{
- FD_SET(sysinfo.audio_process_pipe[0], &sound_fdset);
- select(sysinfo.audio_process_pipe[0] + 1, &sound_fdset, NULL, NULL, NULL);
- if (!FD_ISSET(sysinfo.audio_process_pipe[0], &sound_fdset))
+ FD_SET(audio.soundserver_pipe[0], &sound_fdset);
+ select(audio.soundserver_pipe[0] + 1, &sound_fdset, NULL, NULL, NULL);
+ if (!FD_ISSET(audio.soundserver_pipe[0], &sound_fdset))
continue;
- if (read(sysinfo.audio_process_pipe[0], &snd_ctrl, sizeof(snd_ctrl))
+ if (read(audio.soundserver_pipe[0], &snd_ctrl, sizeof(snd_ctrl))
!= sizeof(snd_ctrl))
Error(ERR_EXIT_SOUND_SERVER, "broken pipe - no sounds");
playlist[i]=emptySoundControl;
playing_sounds=0;
- close(sysinfo.audio_fd);
+ close(audio.device_fd);
}
else if (snd_ctrl.stop_sound)
{
}
if (!playing_sounds)
- close(sysinfo.audio_fd);
+ close(audio.device_fd);
}
if (playing_sounds || snd_ctrl.active)
#endif
if (playing_sounds ||
- (sysinfo.audio_fd = OpenAudio(sound_device_name)) >= 0)
+ (audio.device_fd = OpenAudio(sound_device_name)) >= 0)
{
if (!playing_sounds) /* we just opened the audio device */
{
/* (with stereo the effective buffer size will shrink to 256) */
fragment_size = 0x00020009;
- if (ioctl(sysinfo.audio_fd, SNDCTL_DSP_SETFRAGMENT, &fragment_size)
- < 0)
+ if (ioctl(audio.device_fd,SNDCTL_DSP_SETFRAGMENT,&fragment_size) < 0)
Error(ERR_EXIT_SOUND_SERVER,
"cannot set fragment size of /dev/dsp - no sounds");
/* try if we can use stereo sound */
- if (ioctl(sysinfo.audio_fd, SNDCTL_DSP_STEREO, &stereo) < 0)
+ if (ioctl(audio.device_fd, SNDCTL_DSP_STEREO, &stereo) < 0)
{
#ifdef DEBUG
static boolean reported = FALSE;
stereo = FALSE;
}
- if (ioctl(sysinfo.audio_fd, SNDCTL_DSP_SPEED, &sample_rate) < 0)
+ if (ioctl(audio.device_fd, SNDCTL_DSP_SPEED, &sample_rate) < 0)
Error(ERR_EXIT_SOUND_SERVER,
"cannot set sample rate of /dev/dsp - no sounds");
/* get the real fragmentation size; this should return 512 */
- if (ioctl(sysinfo.audio_fd, SNDCTL_DSP_GETBLKSIZE, &fragment_size)
- < 0)
+ if (ioctl(audio.device_fd, SNDCTL_DSP_GETBLKSIZE,&fragment_size) < 0)
Error(ERR_EXIT_SOUND_SERVER,
"cannot get fragment size of /dev/dsp - no sounds");
SoundServer_InsertNewSound(snd_ctrl);
while(playing_sounds &&
- select(sysinfo.audio_process_pipe[0] + 1,
+ select(audio.soundserver_pipe[0] + 1,
&sound_fdset, NULL, NULL, &delay) < 1)
{
- FD_SET(sysinfo.audio_process_pipe[0], &sound_fdset);
+ FD_SET(audio.soundserver_pipe[0], &sound_fdset);
/* first clear the last premixing buffer */
memset(premix_last_buffer,0,fragment_size*sizeof(int));
}
/* finally play the sound fragment */
- write(sysinfo.audio_fd, playing_buffer,fragment_size);
+ write(audio.device_fd, playing_buffer,fragment_size);
}
/* if no sounds playing, free device for other sound programs */
if (!playing_sounds)
- close(sysinfo.audio_fd);
+ close(audio.device_fd);
}
}
int wait_percent = 90; /* wait 90% of the real playing time */
int i;
- if ((sysinfo.audio_fd = OpenAudio(sound_device_name)) >= 0)
+ if ((audio.device_fd = OpenAudio(sound_device_name)) >= 0)
{
playing_sounds = 1;
while(playing_sounds &&
- select(sysinfo.audio_process_pipe[0] + 1,
+ select(audio.soundserver_pipe[0] + 1,
&sound_fdset, NULL, NULL, &delay) < 1)
{
- FD_SET(sysinfo.audio_process_pipe[0], &sound_fdset);
+ FD_SET(audio.soundserver_pipe[0], &sound_fdset);
/* get pointer and size of the actual sound sample */
sample_ptr = snd_ctrl.data_ptr + snd_ctrl.playingpos;
playing_sounds = 0;
/* finally play the sound fragment */
- write(sysinfo.audio_fd,playing_buffer,sample_size);
+ write(audio.device_fd,playing_buffer,sample_size);
delay.tv_sec = 0;
delay.tv_usec = ((sample_size*10*wait_percent)/(sample_rate))*1000;
}
- close(sysinfo.audio_fd);
+ close(audio.device_fd);
}
}
#if !defined(PLATFORM_MSDOS)
if (!playing_sounds)
- close(sysinfo.audio_fd);
+ close(audio.device_fd);
#endif
}
playing_sounds = 0;
#if !defined(PLATFORM_MSDOS)
- close(sysinfo.audio_fd);
+ close(audio.device_fd);
#endif
}
#endif /* PLATFORM_MSDOS */
{
struct SoundControl snd_ctrl = emptySoundControl;
- if (!sysinfo.audio_available || !setup.sound)
+ if (!audio.sound_available || !setup.sound)
return;
if (volume<PSND_MIN_VOLUME)
#else
#if !defined(PLATFORM_MSDOS)
- if (write(sysinfo.audio_process_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0)
+ if (write(audio.soundserver_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0)
{
Error(ERR_WARN, "cannot pipe to child process - no sounds");
- sysinfo.audio_available = FALSE;
+ audio.sound_available = FALSE;
return;
}
#else
{
struct SoundControl snd_ctrl = emptySoundControl;
- if (!sysinfo.audio_available)
+ if (!audio.sound_available)
return;
if (SSND_FADING(method))
#else
#if !defined(PLATFORM_MSDOS)
- if (write(sysinfo.audio_process_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0)
+ if (write(audio.soundserver_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0)
{
Error(ERR_WARN, "cannot pipe to child process - no sounds");
- sysinfo.audio_available = FALSE;
+ audio.sound_available = FALSE;
return;
}
#else
{
int i;
- if (!sysinfo.audio_available)
+ if (!audio.sound_available)
return;
for(i=0; i<num_sounds; i++)
/* general sound functions */
int OpenAudio(char *);
int CheckAudio(char *);
-boolean UnixInitAudio(void);
+void UnixInitAudio(struct AudioSystemInfo *);
/* sound server functions */
void SoundServer(void);
#include "main.h"
#include "misc.h"
+#include "sound.h"
/* ========================================================================= */
/* audio functions */
/* ========================================================================= */
-inline boolean InitAudio(void)
+inline struct AudioSystemInfo InitAudio(void)
{
- sysinfo.audio_available = TRUE;
- sysinfo.audio_loops_available = FALSE;
+ struct AudioSystemInfo audio;
- if (!sysinfo.audio_available)
- return FALSE;
+ 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;
-#ifdef TARGET_SDL
- return SDLInitAudio();
-#else
- return TRUE;
+#if defined(TARGET_SDL)
+ if (SDLInitAudio())
+ {
+ audio.sound_available = TRUE;
+ audio.loops_available = TRUE;
+ }
+#elif defined(PLATFORM_MSDOS)
+ if (MSDOSInitAudio())
+ {
+ audio.sound_available = TRUE;
+ audio.loops_available = TRUE;
+ }
+#elif defined(PLATFORM_UNIX)
+ UnixInitAudio(&audio);
#endif
+
+ return audio;
}
/* structure definitions */
-struct SystemInfo
+struct AudioSystemInfo
{
- boolean audio_available;
- boolean audio_loops_available;
- int audio_process_id;
- int audio_process_pipe[2];
- int audio_fd;
+ boolean sound_available;
+ boolean loops_available;
+ int soundserver_pipe[2];
+ int soundserver_pid;
+ int device_fd;
};
inline boolean SetVideoMode(void);
inline void ChangeVideoModeIfNeeded(void);
-inline boolean InitAudio(void);
+inline struct AudioSystemInfo InitAudio(void);
inline void InitEventFilter(EventFilter);
inline boolean PendingEvent(void);