From 71a1616f11627ab005c19fc6fc06ba23f6b4b633 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Fri, 10 May 2002 17:17:50 +0200 Subject: [PATCH] rnd-20020510-7-src --- src/libgame/sound.c | 90 ++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 5e93bd7a..ac814e90 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -179,6 +179,29 @@ void UnixCloseAudio(void) kill(audio.mixer_pid, SIGTERM); } +static void WriteSoundControlToPipe(struct SoundControl snd_ctrl) +{ + if (audio.mixer_pid == 0) /* we are child process */ + return; + + if (write(audio.mixer_pipe[1], &snd_ctrl, sizeof(struct SoundControl)) < 0) + { + Error(ERR_WARN, "cannot pipe to child process -- no sounds"); + audio.sound_available = audio.sound_enabled = FALSE; + return; + } +} + +static void ReadSoundControlFromPipe(struct SoundControl *snd_ctrl) +{ + if (audio.mixer_pid != 0) /* we are parent process */ + return; + + if (read(audio.mixer_pipe[0], snd_ctrl, sizeof(struct SoundControl)) + != sizeof(struct SoundControl)) + Error(ERR_EXIT_SOUND_SERVER, "broken pipe -- no sounds"); +} + static void WriteReloadInfoToPipe(char *set_name, int type) { struct SoundControl snd_ctrl; @@ -517,6 +540,20 @@ static void HandleSoundRequest(struct SoundControl snd_ctrl) { int i; +#if defined(PLATFORM_MSDOS) + for (i=0; idata_ptr, (state & SND_CTRL_LOOP ? -1 : 0)); } #elif defined(PLATFORM_UNIX) - if (audio.mixer_pid == 0) /* we are child process */ - return; - if (write(audio.mixer_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0) - { - Error(ERR_WARN, "cannot pipe to child process -- no sounds"); - audio.sound_available = audio.sound_enabled = FALSE; - return; - } + WriteSoundControlToPipe(snd_ctrl); + #elif defined(PLATFORM_MSDOS) - sound_handler(snd_ctrl); + + HandleSoundRequest(snd_ctrl); + #endif } @@ -1677,17 +1688,12 @@ void StopSoundExt(int nr, int state) #elif !defined(PLATFORM_MSDOS) - if (audio.mixer_pid == 0) /* we are child process */ - return; + WriteSoundControlToPipe(snd_ctrl); - if (write(audio.mixer_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0) - { - Error(ERR_WARN, "cannot pipe to child process -- no sounds"); - audio.sound_available = audio.sound_enabled = FALSE; - return; - } #else /* PLATFORM_MSDOS */ - sound_handler(snd_ctrl); + + HandleSoundRequest(snd_ctrl); + #endif } -- 2.34.1