Index: client/audio_esd.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/audio_esd.c,v retrieving revision 1.3 diff -u -r1.3 audio_esd.c --- client/audio_esd.c 2002/09/02 02:19:53 1.3 +++ client/audio_esd.c 2002/09/25 10:11:31 @@ -19,6 +19,8 @@ #include #include /* close */ #include +#include +#include #include "log.h" #include "fcintl.h" @@ -34,9 +36,12 @@ const char *tag; }; +static long time_last_path = 0; +static char last_path[200]; + static struct sample samples[MAX_SAMPLES]; static int music_id = -1; -static int last_sample = 0; +static int last_cached_sample = 0; static int sock = -1; /* @@ -123,6 +128,18 @@ esd_sample_loop(sock, music_id); } else { + /* see if we should skip this one to avoid too many sounds at once */ + struct timeval tv; + struct timezone tz; + (void) gettimeofday(&tv, &tz); /* error unthinkable */ + if (abs(tv.tv_usec - time_last_path) < 45000 + && strcmp(last_path, fullpath) == 0) { + /* Too fast, ignore it */ + return TRUE; + } + time_last_path = tv.tv_usec; + sz_strlcpy(last_path, fullpath); + /* see if we can cache on this one */ for (i = 0; i < MAX_SAMPLES; i++) { if (samples[i].tag && (strcmp(samples[i].tag, tag) == 0)) { @@ -134,24 +151,24 @@ } /* not in cache, so let's create an open sample slot */ - if (samples[last_sample].id != -1) { - freelog(LOG_DEBUG, "Opening sample slot %d", last_sample); - esd_sample_free(sock, samples[last_sample].id); + if (samples[last_cached_sample].id != -1) { + freelog(LOG_DEBUG, "Opening sample slot %d", last_cached_sample); + esd_sample_free(sock, samples[last_cached_sample].id); } freelog(LOG_DEBUG, "Playing file %s in slot %d", fullpath, - last_sample); - samples[last_sample].id = esd_file_cache(sock, program_name, fullpath); - samples[last_sample].tag = tag; - if (samples[last_sample].id < 0) { + last_cached_sample); + samples[last_cached_sample].id = esd_file_cache(sock, program_name, fullpath); + samples[last_cached_sample].tag = tag; + if (samples[last_cached_sample].id < 0) { freelog(LOG_ERROR, _("Error while caching sample <%d>: " "confirm value != samples[].id\n"), - samples[last_sample].id); + samples[last_cached_sample].id); } - esd_sample_play(sock, samples[last_sample].id); + esd_sample_play(sock, samples[last_cached_sample].id); - last_sample = (last_sample + 1) % MAX_SAMPLES; + last_cached_sample = (last_cached_sample + 1) % MAX_SAMPLES; } return TRUE; } @@ -162,6 +179,7 @@ static bool my_init(void) { sock = esd_open_sound(NULL); + last_path[0] = '\0'; if (sock >= 0) { int i;