- if (mixer[i].playingpos >= mixer[i].data_len)
- Mixer_RemoveSound(i);
-
- for(i=0; i<sample_size; i++)
- playing_buffer[i] = (premix_first_buffer[i] >> 8) ^ 0x80;
-
- /* finally play the sound fragment */
- write(audio.device_fd, playing_buffer, sample_size);
-
- return sample_size;
-}
-#endif /* !AUDIO_STREAMING_DSP */
-
-void Mixer_Main()
-{
- struct SoundControl snd_ctrl;
- fd_set mixer_fdset;
-
- close(audio.mixer_pipe[1]); /* no writing into pipe needed */
-
- Mixer_InitChannels();
-
-#if defined(PLATFORM_HPUX)
- InitAudioDevice(&afmt);
-#endif
-
- FD_ZERO(&mixer_fdset);
- FD_SET(audio.mixer_pipe[0], &mixer_fdset);
-
- while(1) /* wait for sound playing commands from client */
- {
- struct timeval delay = { 0, 0 };
-
- FD_SET(audio.mixer_pipe[0], &mixer_fdset);
- 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");
-
- HandleSoundRequest(snd_ctrl);
-
-#if defined(AUDIO_STREAMING_DSP)
-
- while (mixer_active_channels &&
- select(audio.mixer_pipe[0] + 1,
- &mixer_fdset, NULL, NULL, &delay) < 1)
- {
- FD_SET(audio.mixer_pipe[0], &mixer_fdset);
-
- Mixer_Main_DSP();
- }
-
-#else /* !AUDIO_STREAMING_DSP */
-
- if (!snd_ctrl.active || IS_LOOP(snd_ctrl) ||
- (audio.device_fd = OpenAudioDevice(audio.device_name)) < 0)
- continue;
-
- InitAudioDevice(&afmt);
-
- delay.tv_sec = 0;
- delay.tv_usec = 0;
-
- while (mixer_active_channels &&
- select(audio.mixer_pipe[0] + 1,
- &mixer_fdset, NULL, NULL, &delay) < 1)
- {
- int wait_percent = 90; /* wait 90% of the real playing time */
- int sample_size;
-
- FD_SET(audio.mixer_pipe[0], &mixer_fdset);
-
- sample_size = Mixer_Main_SimpleAudio(snd_ctrl);
-
- delay.tv_sec = 0;
- delay.tv_usec =
- ((sample_size * 10 * wait_percent) / afmt.sample_rate) * 1000;
- }
-
- CloseAudioDevice(&audio.device_fd);
-
- Mixer_InitChannels(); /* remove all sounds from mixer */
-
-#endif /* !AUDIO_STREAMING_DSP */
- }
-}
-#endif /* PLATFORM_UNIX */
-
-#if defined(PLATFORM_MSDOS)
-static void sound_handler(struct SoundControl snd_ctrl)
-{
- int i;
-
- if (snd_ctrl.fade_sound)
- {
- if (!mixer_active_channels)
- return;
-
- for (i=0; i<audio.num_channels; i++)
- if ((snd_ctrl.stop_all_sounds ||
- (i != audio.music_channel && mixer[i].nr == snd_ctrl.nr) ||
- (i == audio.music_channel && snd_ctrl.music)) &&
- !mixer[i].fade_sound)
- {
- mixer[i].fade_sound = TRUE;
- if (voice_check(mixer[i].voice))
- voice_ramp_volume(mixer[i].voice, 1000, 0);
- mixer[i].state &= ~SND_CTRL_IS_LOOP;
- }
- }
- else if (snd_ctrl.stop_all_sounds)
- {
- if (!mixer_active_channels)
- return;
- Mixer_StopAllSounds();
- }
- else if (snd_ctrl.stop_sound)
- {
- if (!mixer_active_channels)
- return;
- Mixer_StopSound(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);
- }
- }
-
- if (snd_ctrl.active)
- Mixer_InsertNewSound(snd_ctrl);
-}
-#endif /* PLATFORM_MSDOS */
-
-#if 0
-#if defined(TARGET_SDL)
-static void sound_handler_SDL(struct SoundControl snd_ctrl)
-{
- /* copy sound_handler() here ... */
-}
-#endif /* TARGET_SDL */
-#endif
-
-#if !defined(PLATFORM_WIN32)
-static void Mixer_InsertNewSound(struct SoundControl snd_ctrl)
-{
- Mixer_InsertSound(snd_ctrl);
-}
-#endif /* !PLATFORM_WIN32 */
-
-/*
-void Mixer_FadeSound(int nr)
-{
- int i;
-
- if (!mixer_active_channels)
- return;
-
- for(i=0;i<audio.num_channels;i++)
- if (snd_ctrl.stop_all_sounds || mixer[i].nr == snd_ctrl.nr)
- mixer[i].fade_sound = TRUE;
-}
-*/
-
-#if !defined(PLATFORM_WIN32)
-#if defined(PLATFORM_MSDOS)
-static void Mixer_StopSound(struct SoundControl snd_ctrl)
-{
- int nr = snd_ctrl.nr;
- int i;
-
- if (!mixer_active_channels)
- return;
-
- for(i=0; i<audio.num_channels; i++)
- {
- if ((i == audio.music_channel && snd_ctrl.music) ||
- (i != audio.music_channel && mixer[i].nr == nr))
- {
-#if defined(PLATFORM_MSDOS)
- voice_set_volume(mixer[i].voice, 0);
- deallocate_voice(mixer[i].voice);
-#endif
- Mixer_RemoveSound(i);
- }
- }
-
-#if !defined(PLATFORM_MSDOS)
- if (!mixer_active_channels)
- close(audio.device_fd);
-#endif
-}
-
-static void Mixer_StopAllSounds()
-{
- int i;
-
- for(i=0; i<audio.num_channels; i++)
- {
-#if defined(PLATFORM_MSDOS)
- voice_set_volume(mixer[i].voice, 0);
- deallocate_voice(mixer[i].voice);
-#endif
- Mixer_RemoveSound(i);
- }
- mixer_active_channels = 0;
-
-#if !defined(PLATFORM_MSDOS)
- close(audio.device_fd);
-#endif
-}
-#endif /* PLATFORM_MSDOS */
-#endif /* !PLATFORM_WIN32 */