From c431e727cdc0ecec3468ab4b89cae2e9708aa49a Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Wed, 8 May 2002 00:11:09 +0200 Subject: [PATCH] rnd-20020508-1-src --- src/libgame/msdos.c | 4 +- src/libgame/sdl.c | 6 +- src/libgame/sound.c | 229 ++++++++++++++++++++++++++++++++++++++------ src/libgame/sound.h | 10 +- 4 files changed, 212 insertions(+), 37 deletions(-) diff --git a/src/libgame/msdos.c b/src/libgame/msdos.c index 4c84010f..ea75479d 100644 --- a/src/libgame/msdos.c +++ b/src/libgame/msdos.c @@ -56,7 +56,7 @@ boolean wait_for_vsync; /* extern int playing_sounds; -extern struct SoundControl playlist[MAX_SOUNDS_PLAYING]; +extern struct SoundControl playlist[NUM_MIXER_CHANNELS]; extern struct SoundControl emptySoundControl; */ @@ -92,7 +92,7 @@ static void allegro_init_drivers() static boolean allegro_init_audio() { - reserve_voices(MAX_SOUNDS_PLAYING, 0); + reserve_voices(NUM_MIXER_CHANNELS, 0); if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) == -1) if (install_sound(DIGI_SB, MIDI_NONE, NULL) == -1) diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index f10dfd6d..ae4e41ea 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -873,7 +873,7 @@ inline void SDLOpenAudio(void) } if (Mix_OpenAudio(DEFAULT_AUDIO_SAMPLE_RATE, AUDIO_S16, - AUDIO_STEREO_CHANNELS, + AUDIO_NUM_CHANNELS_STEREO, DEFAULT_AUDIO_FRAGMENT_SIZE) < 0) { Error(ERR_WARN, "Mix_OpenAudio() failed: %s", SDL_GetError()); @@ -885,8 +885,8 @@ inline void SDLOpenAudio(void) audio.loops_available = TRUE; audio.sound_enabled = TRUE; - /* determine number of available channels */ - audio.channels = Mix_AllocateChannels(MIX_CHANNELS); + /* set number of available mixer channels */ + audio.channels = Mix_AllocateChannels(NUM_MIXER_CHANNELS); /* reserve first channel for music loops */ if (Mix_ReserveChannels(1) == 1) diff --git a/src/libgame/sound.c b/src/libgame/sound.c index f1a38d2c..84ca1984 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -55,7 +55,7 @@ static struct AudioFormatInfo afmt = }; static int playing_sounds = 0; -static struct SoundControl playlist[MAX_SOUNDS_PLAYING]; +static struct SoundControl playlist[NUM_MIXER_CHANNELS]; static struct SoundControl emptySoundControl = { -1,0,0, FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE, 0,0, 0,NULL @@ -196,11 +196,66 @@ void InitPlaylist(void) { int i; - for(i=0; i %d\n", playing_sounds); +#endif + + if (playing_sounds == NUM_MIXER_CHANNELS) + { + for (i=0; i= 1 && snd_ctrl.loop) { - for(i=0; idata_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 (snd_ctrl.music && i == audio.music_channel && playlist[i].active) + { + printf("THIS SHOULD NEVER HAPPEN! [adding music twice]\n"); + +#if 1 + playlist[i] = emptySoundControl; + playing_sounds--; +#endif + } +#endif + playlist[i] = snd_ctrl; playing_sounds++; @@ -793,7 +952,7 @@ void SoundServer_FadeSound(int nr) if (!playing_sounds) return; - for(i=0;isource_filename; -#if 1 +#if 0 printf("[decrementing reference counter of sound '%s']\n", filename); #endif if (--(*snd_info)->num_references <= 0) { -#if 1 +#if 0 printf("[deleting sound '%s']\n", filename); #endif @@ -1497,8 +1656,11 @@ void PlaySoundExt(int nr, int volume, int stereo, boolean loop_type) #endif #if defined(TARGET_SDL) - Mix_Volume(-1, SOUND_MAX_VOLUME); - Mix_PlayChannel(-1, Sound[nr]->data_ptr, (loop_type ? -1 : 0)); + if (Sound[nr]) + { + Mix_Volume(-1, SOUND_MAX_VOLUME); + Mix_PlayChannel(-1, Sound[nr]->data_ptr, (loop_type ? -1 : 0)); + } #elif defined(PLATFORM_UNIX) if (audio.soundserver_pid == 0) /* we are child process */ return; @@ -1616,7 +1778,7 @@ void StopSoundExt(int nr, int method) audio.sound_available = audio.sound_enabled = FALSE; return; } -#else +#else /* PLATFORM_MSDOS */ sound_handler(snd_ctrl); #endif } @@ -1646,12 +1808,16 @@ void deleteNodeFromList(ListNode **node_first, char *key, if (node_first == NULL || *node_first == NULL) return; +#if 0 printf("[CHECKING LIST KEY '%s' == '%s']\n", (*node_first)->key, key); +#endif if (strcmp((*node_first)->key, key) == 0) { +#if 0 printf("[DELETING LIST ENTRY]\n"); +#endif free((*node_first)->key); if (destructor_function) @@ -1780,9 +1946,9 @@ static void InitReloadSoundsOrMusic(char *set_name, int type) #if defined(TARGET_SDL) || defined(TARGET_ALLEGRO) if (type == SND_RELOAD_SOUNDS) - audio.func_reload_sounds(); + ReloadCustomSounds(); else - audio.func_reload_music(); + ReloadCustomMusic(); #elif defined(PLATFORM_UNIX) if (audio.soundserver_pid == 0) /* we are child process */ return; @@ -1885,8 +2051,17 @@ void FreeAllSounds() if (Sound == NULL) return; + printf("%s: FREEING SOUNDS ...\n", + audio.soundserver_pid == 0 ? "CHILD" : "PARENT"); + for(i=0; i