From 430aa8b71d2031eabc6341d4812363023105586e Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Fri, 10 May 2002 14:52:22 +0200 Subject: [PATCH] rnd-20020510-2-src --- src/libgame/msdos.c | 8 +- src/libgame/sdl.c | 6 +- src/libgame/sound.c | 325 +++++++++++++++++++++++++++++++++---------- src/libgame/system.c | 3 +- src/libgame/system.h | 3 +- 5 files changed, 268 insertions(+), 77 deletions(-) diff --git a/src/libgame/msdos.c b/src/libgame/msdos.c index ea75479d..61e1eaf2 100644 --- a/src/libgame/msdos.c +++ b/src/libgame/msdos.c @@ -931,9 +931,13 @@ void MSDOSOpenAudio(void) audio.music_available = TRUE; audio.loops_available = TRUE; audio.sound_enabled = TRUE; - } - InitPlaylist(); + audio.num_channels = NUM_MIXER_CHANNELS; + audio.music_channel = MUSIC_CHANNEL; + audio.first_sound_channel = FIRST_SOUND_CHANNEL; + + InitPlaylist(); + } } void MSDOSCloseAudio(void) diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index ae4e41ea..c7a7f567 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -886,7 +886,9 @@ inline void SDLOpenAudio(void) audio.sound_enabled = TRUE; /* set number of available mixer channels */ - audio.channels = Mix_AllocateChannels(NUM_MIXER_CHANNELS); + audio.num_channels = Mix_AllocateChannels(NUM_MIXER_CHANNELS); + audio.music_channel = MUSIC_CHANNEL; + audio.first_sound_channel = FIRST_SOUND_CHANNEL; /* reserve first channel for music loops */ if (Mix_ReserveChannels(1) == 1) @@ -896,6 +898,8 @@ inline void SDLOpenAudio(void) Mix_Volume(-1, SOUND_MAX_VOLUME); Mix_VolumeMusic(SOUND_MAX_VOLUME); + + InitPlaylist(); } inline void SDLCloseAudio(void) diff --git a/src/libgame/sound.c b/src/libgame/sound.c index fbdbd87d..20991570 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -56,6 +56,8 @@ static struct AudioFormatInfo afmt = static int playing_sounds = 0; static struct SoundControl playlist[NUM_MIXER_CHANNELS]; + +#if 0 static struct SoundControl emptySoundControl = { #if 1 @@ -64,6 +66,7 @@ static struct SoundControl emptySoundControl = -1,0,0, FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE, 0,0, 0,NULL #endif }; +#endif /* forward declaration of internal functions */ static void SoundServer_InsertNewSound(struct SoundControl); @@ -182,6 +185,10 @@ void UnixOpenAudio(void) audio.music_available = TRUE; audio.loops_available = TRUE; #endif + + audio.num_channels = NUM_MIXER_CHANNELS; + audio.music_channel = MUSIC_CHANNEL; + audio.first_sound_channel = FIRST_SOUND_CHANNEL; } void UnixCloseAudio(void) @@ -192,36 +199,17 @@ void UnixCloseAudio(void) if (audio.soundserver_pid > 0) /* we are parent process */ kill(audio.soundserver_pid, SIGTERM); } -#endif /* PLATFORM_UNIX */ - -void InitPlaylist(void) -{ - int i; - - for(i=0; ifullpath) + 1; unsigned long str_size2 = strlen(ti->basepath) + 1; unsigned long str_size3 = strlen(ti->fullpath) + 1; + snd_ctrl.active = FALSE; snd_ctrl.state = type; snd_ctrl.data_len = strlen(set_name) + 1; @@ -307,6 +295,208 @@ static void ReadReloadInfoFromPipe(struct SoundControl snd_ctrl) else artwork.music_set_current = set_name; } +#endif /* PLATFORM_UNIX */ + +void InitPlaylist(void) +{ + int i; + + for(i=0; i= num_sounds) + return; + + snd_info = (IS_MUSIC(snd_ctrl) ? Music[snd_ctrl.nr] : Sound[snd_ctrl.nr]); + if (snd_info == NULL) + { +#if 0 + printf("sound/music %d undefined\n", snd_ctrl.nr); +#endif + return; + } + +#if 0 + printf("-> %d\n", playing_sounds); +#endif + + if (playing_sounds == audio.num_channels) + { + for (i=0; i longest) + { + longest = actual; + longest_nr = i; + } + } +#if defined(PLATFORM_MSDOS) + voice_set_volume(playlist[longest_nr].voice, 0); + deallocate_voice(playlist[longest_nr].voice); +#endif + PlaylistRemoveSound(longest_nr); + } + + /* check if sound is already being played (and how often) */ + for (k=0, i=audio.first_sound_channel; i= 1 && IS_LOOP(snd_ctrl)) + { + for(i=audio.first_sound_channel; i= 2) + { + int longest = 0, longest_nr = 0; + + /* look for oldest equal sound */ + for(i=audio.first_sound_channel; i= longest) + { + longest = actual; + longest_nr = i; + } + } + +#if defined(PLATFORM_MSDOS) + voice_set_volume(playlist[longest_nr].voice, 0); + deallocate_voice(playlist[longest_nr].voice); +#endif + PlaylistRemoveSound(longest_nr); + } + + /* add new sound to playlist */ + for(i=0; idata_ptr; + snd_ctrl.data_len = snd_info->data_len; + snd_ctrl.format = snd_info->format; + +#if 1 + if (snd_info->data_len == 0) + { + printf("THIS SHOULD NEVER HAPPEN! [snd_info->data_len == 0]\n"); + } +#endif + +#if 1 + if (IS_MUSIC(snd_ctrl) && i == audio.music_channel && playlist[i].active) + { + printf("THIS SHOULD NEVER HAPPEN! [adding music twice]\n"); + +#if 1 + PlaylistRemoveSound(i); +#endif + } +#endif + + playlist[i] = snd_ctrl; + playing_sounds++; + +#if 0 + printf("NEW SOUND %d ADDED TO PLAYLIST\n", snd_ctrl.nr); +#endif + +#if defined(PLATFORM_MSDOS) + playlist[i].voice = allocate_voice((SAMPLE *)playlist[i].data_ptr); + + if (snd_ctrl.loop) + voice_set_playmode(playlist[i].voice, PLAYMODE_LOOP); + + voice_set_volume(playlist[i].voice, snd_ctrl.volume); + voice_set_pan(playlist[i].voice, snd_ctrl.stereo); + voice_start(playlist[i].voice); +#endif + break; + } + } +} static void HandleSoundRequest(struct SoundControl snd_ctrl) { @@ -330,11 +520,11 @@ static void HandleSoundRequest(struct SoundControl snd_ctrl) if (IS_MUSIC(snd_ctrl)) { - playlist[MUSIC_CHANNEL].state |= SND_CTRL_FADE; + playlist[audio.music_channel].state |= SND_CTRL_FADE; return; } - for(i=FIRST_SOUND_CHANNEL; i %d\n", playing_sounds); #endif - if (playing_sounds == NUM_MIXER_CHANNELS) + if (playing_sounds == audio.num_channels) { - for (i=0; i= 1 && IS_LOOP(snd_ctrl)) { - for(i=FIRST_SOUND_CHANNEL; idata_ptr; snd_ctrl.data_len = snd_info->data_len; snd_ctrl.format = snd_info->format; + snd_ctrl.playingpos = 0; + snd_ctrl.playingtime = 0; + #if 1 if (snd_info->data_len == 0) { @@ -912,13 +1100,12 @@ static void SoundServer_InsertNewSound(struct SoundControl snd_ctrl) #endif #if 1 - if (IS_MUSIC(snd_ctrl) && i == MUSIC_CHANNEL && playlist[i].active) + if (IS_MUSIC(snd_ctrl) && i == audio.music_channel && playlist[i].active) { printf("THIS SHOULD NEVER HAPPEN! [adding music twice]\n"); #if 1 - playlist[i] = emptySoundControl; - playing_sounds--; + PlaylistRemoveSound(i); #endif } #endif @@ -954,7 +1141,7 @@ void SoundServer_FadeSound(int nr) if (!playing_sounds) return; - for(i=0;ifullpath) + 1; - unsigned long str_size2 = strlen(ti->basepath) + 1; - unsigned long str_size3 = strlen(ti->fullpath) + 1; -#endif -#endif - if (!audio.sound_available) return; @@ -1953,6 +2133,7 @@ static void InitReloadSoundsOrMusic(char *set_name, int type) WriteReloadInfoToPipe(set_name, type); #else + snd_ctrl.active = FALSE; snd_ctrl.state = type; snd_ctrl.data_len = strlen(set_name) + 1; diff --git a/src/libgame/system.c b/src/libgame/system.c index bebc59ce..42c4a6ec 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -747,8 +747,9 @@ inline void OpenAudio(void) audio.device_name = NULL; audio.device_fd = -1; - audio.channels = 0; + audio.num_channels = 0; audio.music_channel = 0; + audio.first_sound_channel = 0; #if defined(TARGET_SDL) SDLOpenAudio(); diff --git a/src/libgame/system.h b/src/libgame/system.h index 316de68e..924b9060 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -241,8 +241,9 @@ struct AudioSystemInfo char *device_name; int device_fd; - int channels; + int num_channels; int music_channel; + int first_sound_channel; }; struct GfxInfo -- 2.34.1