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;
{
int i;
+#if defined(PLATFORM_MSDOS)
+ for (i=0; i<audio.num_channels; i++)
+ {
+ if (!mixer[i].active || IS_LOOP(mixer[i]))
+ continue;
+
+ mixer[i].playingpos = voice_get_position(mixer[i].voice);
+ mixer[i].volume = voice_get_volume(mixer[i].voice);
+
+ if (mixer[i].playingpos == -1 || mixer[i].volume == 0)
+ Mixer_RemoveSound(i);
+ }
+#endif /* PLATFORM_MSDOS */
+
if (IS_RELOADING(snd_ctrl)) /* load new sound or music files */
{
ReadReloadInfoFromPipe(snd_ctrl);
select(audio.mixer_pipe[0] + 1, &mixer_fdset, NULL, NULL, NULL);
if (!FD_ISSET(audio.mixer_pipe[0], &mixer_fdset))
continue;
- if (read(audio.mixer_pipe[0], &snd_ctrl, sizeof(snd_ctrl))
- != sizeof(snd_ctrl))
- Error(ERR_EXIT_SOUND_SERVER, "broken pipe -- no sounds");
+
+ ReadSoundControlFromPipe(&snd_ctrl);
HandleSoundRequest(snd_ctrl);
}
#endif /* PLATFORM_UNIX */
-#if defined(PLATFORM_MSDOS)
-static void sound_handler(struct SoundControl snd_ctrl)
-{
- for (i=0; i<audio.num_channels; i++)
- {
- if (!mixer[i].active || mixer[i].loop)
- continue;
-
- mixer[i].playingpos = voice_get_position(mixer[i].voice);
- mixer[i].volume = voice_get_volume(mixer[i].voice);
- if (mixer[i].playingpos == -1 || !mixer[i].volume)
- {
- deallocate_voice(mixer[i].voice);
- Mixer_RemoveSound(i);
- }
- }
-
- HandleSoundRequest(snd_ctrl);
-}
-#endif /* PLATFORM_MSDOS */
-
/* ------------------------------------------------------------------------- */
/* platform dependant audio initialization code */
Mix_PlayChannel(-1, Sound[nr]->data_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
}
#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
}