Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2005:
[Freeciv-Dev] (PR#12972) Audio cleanup
Home

[Freeciv-Dev] (PR#12972) Audio cleanup

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12972) Audio cleanup
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Tue, 3 May 2005 11:22:13 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12972 >

This patch removes support for all but SDL_mixer plugin (since they do not
support .ogg) and adds a volume control API.

  - Per

Index: client/audio.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/audio.c,v
retrieving revision 1.21
diff -u -r1.21 audio.c
--- client/audio.c      13 Apr 2005 02:21:51 -0000      1.21
+++ client/audio.c      3 May 2005 18:20:28 -0000
@@ -1,5 +1,5 @@
 /********************************************************************** 
- Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+ Freeciv - Copyright (C) 2005 - The Freeciv Team
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2, or (at your option)
@@ -28,26 +28,14 @@
 #include "shared.h"
 #include "support.h"
 
-#ifdef AMIGA
-#include "audio_amiga.h"
-#endif
-#ifdef ESD
-#include "audio_esd.h"
-#endif
 #include "audio_none.h"
 #ifdef SDL
 #include "audio_sdl.h"
 #endif
-#ifdef WINMM
-#include "audio_winmm.h"
-#endif
-#ifdef ALSA
-#include "audio_alsa.h"
-#endif
 
 #include "audio.h"
 
-#define MAX_NUM_PLUGINS                4
+#define MAX_NUM_PLUGINS                1
 #define SNDSPEC_SUFFIX         ".soundspec"
 
 /* keep it open throughout */
@@ -154,21 +142,9 @@
   assert(num_plugins_used == 1);
   selected_plugin = 0;
 
-#ifdef ESD
-  audio_esd_init();
-#endif
 #ifdef SDL
   audio_sdl_init();
 #endif
-#ifdef ALSA
-  audio_alsa_init();
-#endif
-#ifdef WINMM
-  audio_winmm_init();
-#endif
-#ifdef AMIGA
-  audio_amiga_init();
-#endif
 }
 
 /**************************************************************************
@@ -221,10 +197,8 @@
     freelog(LOG_NORMAL, _("No real audio plugin present, "
       "proceeding with sound support disabled"));
     freelog(LOG_NORMAL,
-      _("For sound support, install either esound or SDL_mixer"));
-    freelog(LOG_NORMAL, 
-      _("Esound: http://www.tux.org/~ricdude/EsounD.html";));
-    freelog(LOG_NORMAL, _("SDL_mixer: http://www.libsdl.org/";
+      _("For sound support, install SDL_mixer"));
+    freelog(LOG_NORMAL, _("http://www.libsdl.org/";
       "projects/SDL_mixer/index.html"));
     tagfile = NULL;
     return;
@@ -279,18 +253,6 @@
 #ifdef SDL
   if (audio_select_plugin("sdl")) return; 
 #endif
-#ifdef ESD
-  if (audio_select_plugin("esd")) return; 
-#endif
-#ifdef ALSA
-  if (audio_select_plugin("alsa")) return;
-#endif
-#ifdef WINMM
-  if (audio_select_plugin("winmm")) return;
-#endif
-#ifdef AMIGA
-  if (audio_select_plugin("amiga")) return;
-#endif
   freelog(LOG_ERROR,
     _("No real audio subsystem managed to initialize!"));
   freelog(LOG_ERROR,
@@ -370,6 +332,22 @@
 }
 
 /**************************************************************************
+  Stop looping sound. Music should die down in a few seconds.
+**************************************************************************/
+double audio_get_volume()
+{
+  return plugins[selected_plugin].get_volume();
+}
+
+/**************************************************************************
+  Stop looping sound. Music should die down in a few seconds.
+**************************************************************************/
+void audio_set_volume(double volume)
+{
+  plugins[selected_plugin].set_volume(volume);
+}
+
+/**************************************************************************
   Call this at end of program only.
 **************************************************************************/
 void audio_shutdown()
Index: client/audio.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/audio.h,v
retrieving revision 1.4
diff -u -r1.4 audio.h
--- client/audio.h      1 Nov 2002 18:11:42 -0000       1.4
+++ client/audio.h      3 May 2005 18:20:28 -0000
@@ -25,6 +25,8 @@
   void (*shutdown) (void);
   void (*stop) (void);
   void (*wait) (void);
+  double (*get_volume) (void);
+  void (*set_volume) (double volume);
   bool (*play) (const char *const tag, const char *const path, bool repeat);
 };
 
@@ -41,6 +43,9 @@
 void audio_play_sound(const char *const tag, char *const alt_tag);
 void audio_play_music(const char *const tag, char *const alt_tag);
 
+double audio_get_volume(void);
+void audio_set_volume(double volume);
+
 bool audio_select_plugin(const char *const name);
 const char *audio_get_all_plugin_names(void);
 
Index: client/audio_sdl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/audio_sdl.c,v
retrieving revision 1.8
diff -u -r1.8 audio_sdl.c
--- client/audio_sdl.c  3 Feb 2005 23:56:43 -0000       1.8
+++ client/audio_sdl.c  3 May 2005 18:20:28 -0000
@@ -34,6 +34,25 @@
 
 static Mix_Music *mus = NULL;
 static struct sample samples[MIX_CHANNELS];
+static double my_volume;
+
+/**************************************************************************
+  Set the volume.
+**************************************************************************/
+static void my_set_volume(double volume)
+{
+  Mix_VolumeMusic(volume * MIX_MAX_VOLUME);
+  Mix_Volume(-1, volume * MIX_MAX_VOLUME);
+  my_volume = volume;
+}
+
+/**************************************************************************
+  Get the volume.
+**************************************************************************/
+static double my_get_volume(void)
+{
+  return my_volume;
+}
 
 /**************************************************************************
   Play sound
@@ -206,7 +225,7 @@
     samples[i].wave = NULL;
   }
   /* sanity check, for now; add volume controls later */
-  Mix_Volume(-1, MIX_MAX_VOLUME);
+  my_set_volume(my_volume);
   return TRUE;
 }
 
@@ -225,5 +244,8 @@
   self.stop = my_stop;
   self.wait = my_wait;
   self.play = my_play;
+  self.set_volume = my_set_volume;
+  self.get_volume = my_get_volume;
   audio_add_plugin(&self);
+  my_volume = 1.0;
 }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12972) Audio cleanup, Per I. Mathisen <=