Optionally play sounds using audio player
This commit is contained in:
parent
0ef79b8771
commit
1ea08c2075
15
configure.ac
15
configure.ac
|
@ -92,6 +92,9 @@ xyes)
|
||||||
enable_sound=pulseaudio;;
|
enable_sound=pulseaudio;;
|
||||||
xpulseaudio|xesound|xsndio)
|
xpulseaudio|xesound|xsndio)
|
||||||
;;
|
;;
|
||||||
|
xplayer)
|
||||||
|
with_sndldr=none
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
enable_sound=no;;
|
enable_sound=no;;
|
||||||
esac
|
esac
|
||||||
|
@ -141,6 +144,15 @@ if test "x$enable_sound" = "xsndio"; then
|
||||||
fi
|
fi
|
||||||
AM_CONDITIONAL(USE_LIBSNDIO, test "x$enable_sound" = "xsndio")
|
AM_CONDITIONAL(USE_LIBSNDIO, test "x$enable_sound" = "xsndio")
|
||||||
|
|
||||||
|
if test "x$enable_sound" = "xplayer"; then
|
||||||
|
AC_DEFINE(USE_SOUND_PLAYER, 1, [Play sounds using audio player])
|
||||||
|
AC_ARG_WITH(sndplayer,
|
||||||
|
AC_HELP_STRING([--with-sndplayer],
|
||||||
|
[select sound player @<:@default="/usr/bin/aplay -q %s"@:>@]),,
|
||||||
|
with_sndplayer="/usr/bin/aplay -q %s")
|
||||||
|
AC_DEFINE_UNQUOTED(SOUND_PLAYER_FMT, "$with_sndplayer", [Audio player]),
|
||||||
|
fi
|
||||||
|
|
||||||
case x$enable_sound in
|
case x$enable_sound in
|
||||||
xpulseaudio|xesound|xsndio)
|
xpulseaudio|xesound|xsndio)
|
||||||
if test "x$with_sndldr" = "xnone"; then
|
if test "x$with_sndldr" = "xnone"; then
|
||||||
|
@ -148,6 +160,9 @@ xpulseaudio|xesound|xsndio)
|
||||||
fi
|
fi
|
||||||
AC_DEFINE(ENABLE_SOUND, 1, [Sound support])
|
AC_DEFINE(ENABLE_SOUND, 1, [Sound support])
|
||||||
;;
|
;;
|
||||||
|
xplayer)
|
||||||
|
AC_DEFINE(ENABLE_SOUND, 1, [Sound support])
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Save CPPFLAGS/LDFLAGS and add X_... to each
|
# Save CPPFLAGS/LDFLAGS and add X_... to each
|
||||||
|
|
39
src/sound.c
39
src/sound.c
|
@ -30,12 +30,16 @@
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
#include "sounds.h"
|
#include "sounds.h"
|
||||||
|
|
||||||
|
#define HAVE_SOUND_OPS 1
|
||||||
|
|
||||||
#if USE_SOUND_ESD
|
#if USE_SOUND_ESD
|
||||||
#define SOUND_SERVER_NAME "esd"
|
#define SOUND_SERVER_NAME "esd"
|
||||||
#elif USE_SOUND_PULSE
|
#elif USE_SOUND_PULSE
|
||||||
#define SOUND_SERVER_NAME "pulseaudio"
|
#define SOUND_SERVER_NAME "pulseaudio"
|
||||||
#elif USE_SOUND_SNDIO
|
#elif USE_SOUND_SNDIO
|
||||||
#define SOUND_SERVER_NAME "sndio"
|
#define SOUND_SERVER_NAME "sndio"
|
||||||
|
#elif USE_SOUND_PLAYER
|
||||||
|
#undef HAVE_SOUND_OPS
|
||||||
#else
|
#else
|
||||||
#error Invalid sound configuration
|
#error Invalid sound configuration
|
||||||
#endif
|
#endif
|
||||||
|
@ -153,8 +157,10 @@ _SclassSampleDestroy(void *data, void *user_data __UNUSED__)
|
||||||
if (!sclass || !sclass->sample)
|
if (!sclass || !sclass->sample)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#if HAVE_SOUND_OPS
|
||||||
if (ops)
|
if (ops)
|
||||||
ops->SampleDestroy(sclass->sample);
|
ops->SampleDestroy(sclass->sample);
|
||||||
|
#endif
|
||||||
sclass->sample = NULL;
|
sclass->sample = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,12 +202,29 @@ _SclassDestroy(void *data, void *user_data __UNUSED__)
|
||||||
SclassDestroy((SoundClass *) data);
|
SclassDestroy((SoundClass *) data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_SOUND_PLAYER
|
||||||
|
static void
|
||||||
|
_SclassPlayAplay(SoundClass * sclass)
|
||||||
|
{
|
||||||
|
char *file;
|
||||||
|
|
||||||
|
file = FindFile(sclass->file, SOUND_THEME_PATH, FILE_TYPE_SOUND);
|
||||||
|
if (!file)
|
||||||
|
return;
|
||||||
|
Espawn(SOUND_PLAYER_FMT, file);
|
||||||
|
Efree(file);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
SclassApply(SoundClass * sclass)
|
SclassApply(SoundClass * sclass)
|
||||||
{
|
{
|
||||||
if (!sclass || !Conf_sound.enable)
|
if (!sclass || !Conf_sound.enable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#if USE_SOUND_PLAYER
|
||||||
|
_SclassPlayAplay(sclass);
|
||||||
|
#else
|
||||||
if (!sclass->sample)
|
if (!sclass->sample)
|
||||||
{
|
{
|
||||||
char *file;
|
char *file;
|
||||||
|
@ -226,6 +249,7 @@ SclassApply(SoundClass * sclass)
|
||||||
}
|
}
|
||||||
|
|
||||||
ops->SamplePlay(sclass->sample);
|
ops->SamplePlay(sclass->sample);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -291,12 +315,11 @@ SoundFree(const char *name)
|
||||||
static void
|
static void
|
||||||
SoundInit(void)
|
SoundInit(void)
|
||||||
{
|
{
|
||||||
int err;
|
|
||||||
|
|
||||||
if (!Conf_sound.enable)
|
if (!Conf_sound.enable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
err = -1;
|
#if HAVE_SOUND_OPS
|
||||||
|
|
||||||
#if USE_MODULES
|
#if USE_MODULES
|
||||||
if (!ops)
|
if (!ops)
|
||||||
#if USE_SOUND_ESD
|
#if USE_SOUND_ESD
|
||||||
|
@ -304,11 +327,9 @@ SoundInit(void)
|
||||||
#elif USE_SOUND_PULSE
|
#elif USE_SOUND_PULSE
|
||||||
ops = ModLoadSym("sound", "SoundOps", "pa");
|
ops = ModLoadSym("sound", "SoundOps", "pa");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif /* USE_MODULES */
|
||||||
if (ops && ops->Init)
|
|
||||||
err = ops->Init();
|
|
||||||
|
|
||||||
if (err)
|
if (!ops || ops->Init())
|
||||||
{
|
{
|
||||||
Conf_sound.enable = 0;
|
Conf_sound.enable = 0;
|
||||||
AlertX(_("Error initialising sound"), _("OK"), NULL, NULL,
|
AlertX(_("Error initialising sound"), _("OK"), NULL, NULL,
|
||||||
|
@ -317,6 +338,8 @@ SoundInit(void)
|
||||||
"Audio will now be disabled.\n"), SOUND_SERVER_NAME);
|
"Audio will now be disabled.\n"), SOUND_SERVER_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* HAVE_SOUND_OPS */
|
||||||
|
|
||||||
_SoundConfigLoad();
|
_SoundConfigLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,8 +350,10 @@ SoundExit(void)
|
||||||
|
|
||||||
LIST_FOR_EACH(SoundClass, &sound_list, sc) _SclassSampleDestroy(sc, NULL);
|
LIST_FOR_EACH(SoundClass, &sound_list, sc) _SclassSampleDestroy(sc, NULL);
|
||||||
|
|
||||||
|
#if HAVE_SOUND_OPS
|
||||||
if (ops)
|
if (ops)
|
||||||
ops->Exit();
|
ops->Exit();
|
||||||
|
#endif
|
||||||
|
|
||||||
Conf_sound.enable = 0;
|
Conf_sound.enable = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue