gnome-games r7112 - in trunk: . libgames-support m4
- From: andreasr svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r7112 - in trunk: . libgames-support m4
- Date: Sun, 6 Jan 2008 20:40:06 +0000 (GMT)
Author: andreasr
Date: Sun Jan 6 20:40:05 2008
New Revision: 7112
URL: http://svn.gnome.org/viewvc/gnome-games?rev=7112&view=rev
Log:
Add support for playing sounds using SDL_mixer.
Added:
trunk/m4/sound.m4
Modified:
trunk/ChangeLog
trunk/README
trunk/configure.in
trunk/libgames-support/Makefile.am
trunk/libgames-support/games-sound.c
trunk/libgames-support/games-sound.h
Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog (original)
+++ trunk/ChangeLog Sun Jan 6 20:40:05 2008
@@ -1,3 +1,12 @@
+2008-01-06 Andreas RÃsdal <andreasr gnome org>
+
+ * m4/sound.m4:
+ * libgames-support/games-sound.c:
+ * libgames-support/games-sound.h:
+ * libgames-support/Makefile.am:
+ * configure.in:
+ * README: Add support for playing sounds using SDL_mixer.
+
2008-01-03 Andreas RÃsdal <andreasr gnome org>
* glchess/help/C/glchess.xml
Modified: trunk/README
==============================================================================
--- trunk/README (original)
+++ trunk/README Sun Jan 6 20:40:05 2008
@@ -235,14 +235,17 @@
These packages are optional, but highly recommended:
- - gtkglext 1.2.0 , pygtkglext 1.1.0 and pyopengl 2.0
- - ggz-server 0.0.14
+ - SDL_Mixer 1.2.0 or later for sound support using SDL.
+ - gtkglext 1.2.0 , pygtkglext 1.1.0 and pyopengl 2.0 for 3D support in Chess.
+ - ggz-server 0.0.14 for hosting GGZ servers.
+
To compile these packages, we recommend using the baseline GNOME 2.18.x
development packages. While gnome-games may compile with older versions,
we will not accept bug reports for games used under those conditions.
GStreamer 0.10 is required by gnome-games, and is used to play sounds.
+SDL_Mixer is also supported for playing sounds.
CVS checkouts will require the latest intltool.
Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in (original)
+++ trunk/configure.in Sun Jan 6 20:40:05 2008
@@ -249,7 +249,7 @@
if test "$want_gstreamer" = "yes"; then
AC_MSG_CHECKING([whether to enable sound support])
AC_ARG_ENABLE([sound],
- [AS_HELP_STRING([--enable-sound],[Enable sound with GStreamer])],
+ [AS_HELP_STRING([--enable-sound],[Enable sound with GStreamer or SDL_Mixer.])],
[],[case "$with_platform" in
gnome|gtk-only) enable_sound=yes ;;
hildon) enable_sound=no ;;
@@ -414,19 +414,29 @@
AM_CONDITIONAL([WITH_GTHREAD],[test "$need_gthread" = "yes"])
-# GStreamer
+# Sound support: GStreamer and SDL_mixer
have_gstreamer=no
if test "$enable_sound" = "yes"; then
- PKG_CHECK_MODULES([GSTREAMER],
- [gstreamer-0.10 >= $GSTREAMER_REQUIRED],
- [have_gstreamer=yes],[have_gstreamer=no])
-fi
-if test "$enable_sound" = "yes" -a "$have_gstreamer" = "no"; then
- AC_MSG_ERROR([sound enabled but GStreamer not found])
+ # Check for SDL_Mixer sound support, sets SDL_MIXER_CFLAGS, SDL_MIXER_LIBS, AUDIO_SDL
+ GAMES_CHECK_SOUND()
+
+ if test "x$SDL_mixer" != "xyes"; then
+ # Check for GStreamer
+ PKG_CHECK_MODULES([GSTREAMER],
+ [gstreamer-0.10 >= $GSTREAMER_REQUIRED],
+ [have_gstreamer=yes],[have_gstreamer=no])
+
+ # SDL_mixer is default, while GStreamer is a required dependency if SDL_mixer isn't found.
+ if test "$enable_sound" = "yes" -a "$have_gstreamer" = "no"; then
+ AC_MSG_ERROR([Sound enabled but GStreamer not found])
+ fi
+ fi
+
fi
+
if test "$have_gstreamer" = "yes"; then
AC_SUBST([GSTREAMER_CFLAGS])
AC_SUBST([GSTREAMER_LIBS])
@@ -434,12 +444,21 @@
AC_DEFINE([HAVE_GSTREAMER],[1],[Define if GStreamer is available])
fi
+if test "x$SDL_mixer" = "xyes"; then
+ AC_SUBST(SDL_MIXER_CFLAGS)
+ AC_SUBST(SDL_MIXER_LIBS)
+
+ AC_DEFINE([HAVE_SDL_MIXER],[1],[Define if SDL_Mixer is available])
+fi
+
+
AM_CONDITIONAL([HAVE_GSTREAMER],[test "$have_gstreamer" = "yes"])
+AM_CONDITIONAL([HAVE_SDL_MIXER],[test "x$SDL_mixer" = "xyes"])
# Compat defines (FIXMEchpe: update all games to only use those flags they require!)
-GNOME_GAMES_CFLAGS="$GTK_CFLAGS $GCONF_CFLAGS $GNOME_CFLAGS $PYGTK_CFLAGS $RSVG_CFLAGS $GSTREAMER_CFLAGS"
-GNOME_GAMES_LIBS="$GTK_LIBS $GCONF_LIBS $GNOME_LIBS $PYGTK_LIBS $RSVG_LIBS $GSTREAMER_LIBS"
+GNOME_GAMES_CFLAGS="$GTK_CFLAGS $GCONF_CFLAGS $GNOME_CFLAGS $PYGTK_CFLAGS $RSVG_CFLAGS $GSTREAMER_CFLAGS $SDL_MIXER_CFLAGS"
+GNOME_GAMES_LIBS="$GTK_LIBS $GCONF_LIBS $GNOME_LIBS $PYGTK_LIBS $RSVG_LIBS $GSTREAMER_LIBS $SDL_MIXER_LIBS"
# *************
@@ -877,7 +896,8 @@
Games to be compiled: ${gamelist}
Using RSVG: ${have_rsvg}
- Using GStreamer: ${have_gstreamer}
+ SDL_Mixer support: ${SDL_mixer}
+ GStreamer support: ${have_gstreamer}
Use setgid binaries: ${setgid}
Scores user: ${scores_user}
Scores & setgid group: ${scores_group}
Modified: trunk/libgames-support/Makefile.am
==============================================================================
--- trunk/libgames-support/Makefile.am (original)
+++ trunk/libgames-support/Makefile.am Sun Jan 6 20:40:05 2008
@@ -132,6 +132,11 @@
libgames_support_la_LIBADD += $(GSTREAMER_LIBS)
endif
+if HAVE_SDL_MIXER
+libgames_support_la_CFLAGS += $(SDL_MIXER_CFLAGS)
+libgames_support_la_LIBADD += $(SDL_MIXER_LIBS)
+endif
+
# Auxiliary programme to prerender card images
if HAVE_RSVG
Modified: trunk/libgames-support/games-sound.c
==============================================================================
--- trunk/libgames-support/games-sound.c (original)
+++ trunk/libgames-support/games-sound.c Sun Jan 6 20:40:05 2008
@@ -1,7 +1,7 @@
/*
* games-sound.c: common sound player for gnome-games
*
- * Copyright  2007 Andreas RÃsdal
+ * Copyright  2007-2008 Andreas RÃsdal
*
* 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
@@ -25,16 +25,32 @@
#include <glib/gi18n.h>
#ifdef HAVE_GSTREAMER
-#include <gst/gst.h>
-#endif /* HAVE_GSTREAMER */
+ #include <gst/gst.h>
+#elif HAVE_SDL_MIXER
+ #include "SDL.h"
+ #include "SDL_mixer.h"
+#endif
#include "games-sound.h"
-#ifdef HAVE_GSTREAMER
-
-static GstElement *pipeline;
static gboolean sound_enabled = FALSE;
static gboolean sound_init = FALSE;
+
+
+#ifdef HAVE_SDL_MIXER
+/* Sounds don't sound good on Windows unless the buffer size is 4k,
+ * but this seems to cause strange behaviour on other systems,
+ * such as a delay before playing the sound. */
+#ifdef WIN32_NATIVE
+const size_t buf_size = 4096;
+#else
+const size_t buf_size = 1024;
+#endif
+#endif /* HAVE_SDL_MIXER */
+
+
+#ifdef HAVE_GSTREAMER
+static GstElement *pipeline;
static GThreadPool *threads;
/* This function is called as a separate thread, playing the sound. */
@@ -86,10 +102,33 @@
g_free (fullname);
}
-/* Initializes the games-sound support, GStreamer and threads. */
+#endif /* HAVE_GSTREAMER */
+
+
+#if HAVE_SDL_MIXER
+static void
+games_sound_sdl_play (gchar *filename)
+{
+ Mix_Chunk *wave = NULL;
+ gchar *fullpath = NULL;
+
+ fullpath = g_strdup_printf ("%s/%s.ogg", SOUNDDIR, (char *) filename);
+
+ wave = Mix_LoadWAV(fullpath);
+ if (wave == NULL) {
+ g_print (_("Error playing sound: %s\n"), Mix_GetError());
+ }
+
+ Mix_PlayChannel(-1, wave, 0);
+
+}
+#endif /* HAVE_SDL_MIXER */
+
+/* Initializes the games-sound support */
static void
games_sound_init (void)
{
+#ifdef HAVE_GSTREAMER
GError *err = NULL;
g_assert (g_thread_supported ());
@@ -100,9 +139,23 @@
NULL, 10, FALSE, &err);
sound_init = TRUE;
-}
+#elif HAVE_SDL_MIXER
+ const int audio_rate = MIX_DEFAULT_FREQUENCY;
+ const int audio_format = MIX_DEFAULT_FORMAT;
+ const int audio_channels = 2;
-#endif /* HAVE_GSTREAMER */
+ SDL_Init(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
+
+ if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, buf_size) < 0) {
+ g_print ("Error calling Mix_OpenAudio");
+ return;
+ }
+
+ //Mix_AllocateChannels(MIX_CHANNELS);
+
+#endif /* HAVE_SDL_MIXER */
+
+}
/**
* games_sound_add_option_group:
@@ -137,6 +190,16 @@
games_sound_init ();
g_thread_pool_push (threads, (gchar *) filename, &err);
+#elif HAVE_SDL_MIXER
+
+
+ if (!sound_enabled)
+ return;
+ if (!sound_init)
+ games_sound_init ();
+
+ games_sound_sdl_play (filename);
+
#endif /* HAVE_GSTREAMER */
}
@@ -151,6 +214,8 @@
{
#ifdef HAVE_GSTREAMER
sound_enabled = enabled;
+#elif HAVE_SDL_MIXER
+ sound_enabled = enabled;
#endif /* HAVE_GSTREAMER */
}
@@ -164,6 +229,8 @@
{
#ifdef HAVE_GSTREAMER
return sound_enabled;
+#elif HAVE_SDL_MIXER
+ return sound_enabled;
#else
return FALSE;
#endif /* HAVE_GSTREAMER */
@@ -179,6 +246,8 @@
{
#ifdef HAVE_GSTREAMER
return TRUE;
+#elif HAVE_SDL_MIXER
+ return TRUE;
#else
return FALSE;
#endif /* HAVE_GSTREAMER */
Modified: trunk/libgames-support/games-sound.h
==============================================================================
--- trunk/libgames-support/games-sound.h (original)
+++ trunk/libgames-support/games-sound.h Sun Jan 6 20:40:05 2008
@@ -1,7 +1,7 @@
/*
* games-sound.h: common sound player for gnome-games
*
- * Copyright  2007 Andreas RÃsdal
+ * Copyright  2007-2008 Andreas RÃsdal
*
* 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
Added: trunk/m4/sound.m4
==============================================================================
--- (empty file)
+++ trunk/m4/sound.m4 Sun Jan 6 20:40:05 2008
@@ -0,0 +1,30 @@
+AC_DEFUN([GAMES_CHECK_SOUND],[
+ AC_ARG_ENABLE(sdl-mixer,
+ [ --disable-sdl-mixer Do not try to use the SDL mixer],
+ USE_SOUND=no, USE_SOUND_SDL=yes)
+
+ if test "x$USE_SOUND_SDL" = "xyes"; then
+ dnl Add SDL support to client
+ SDL_VERSION=1.2.0
+ AM_PATH_SDL($SDL_VERSION, SDL=yes, SDL=no)
+ if test "x$SDL" != "xno"; then
+ AC_CHECK_HEADER(SDL/SDL_mixer.h, SDL_mixer_h=1, SDL_mixer_h=0)
+ AC_CHECK_LIB(SDL_mixer, Mix_OpenAudio, SDL_mixer=yes)
+ AC_MSG_CHECKING(building SDL_mixer support)
+ if test "x$SDL_mixer_h" = "x1"; then
+ if test "x$SDL_mixer" = "xyes"; then
+ SDL_MIXER_CFLAGS="$SDL_MIXER_CFLAGS $SDL_CFLAGS"
+ SDL_MIXER_LIBS="$SDL_MIXER_LIBS $SDL_LIBS -lSDL_mixer"
+ AC_DEFINE(AUDIO_SDL, 1, [SDL_Mixer support])
+ AC_DEFINE(SDL, 1, [SDL is used])
+ AC_MSG_RESULT(yes)
+ else
+ AC_MSG_RESULT([no, found header but not library!])
+ fi
+ else
+ AC_MSG_RESULT([no, install SDL_mixer first: http://www.libsdl.org/projects/SDL_mixer/index.html])
+ SDL_mixer="no"
+ fi
+ fi
+ fi
+])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]