Index: client/audio.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/audio.c,v retrieving revision 1.13 diff -u -r1.13 audio.c --- client/audio.c 2002/08/15 20:24:08 1.13 +++ client/audio.c 2002/09/30 12:34:18 @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include "audio.h" #include "support.h" @@ -58,6 +60,10 @@ static int num_plugins_used = 0; static int selected_plugin = -1; +static long sec_last_path = 0; +static long usec_last_path = 0; +static char last_path[200]; + /********************************************************************** Returns a static, NULL-terminated list of all sound plugins available on the system. This function is unfortunately similar to @@ -154,6 +160,7 @@ audio_none_init(); assert(num_plugins_used == 1); selected_plugin = 0; + last_path[0] = '\0'; #ifdef ESD audio_esd_init(); @@ -299,6 +306,8 @@ static bool audio_play_tag(const char *tag, bool repeat) { char *soundfile, *fullpath = NULL; + struct timeval tv; + struct timezone tz; if (!tag || strcmp(tag, "-") == 0) { return FALSE; @@ -315,6 +324,20 @@ freelog(LOG_ERROR, _("Cannot find audio file %s"), soundfile); } } + } + + if (fullpath && strlen(fullpath) > 0) { + /* see if we should skip this one to avoid too many sounds at once */ + (void) gettimeofday(&tv, &tz); /* error unthinkable */ + if ((tv.tv_sec - sec_last_path) * 1000000 + + (tv.tv_usec - usec_last_path) < 75000 + && strcmp(last_path, fullpath) == 0) { + /* Too fast, ignore it */ + return TRUE; + } + sec_last_path = tv.tv_sec; + usec_last_path = tv.tv_usec; + sz_strlcpy(last_path, fullpath); } return plugins[selected_plugin].play(tag, fullpath, repeat);