tESD sound files added to CVS. - vaccinewars - be a doctor and try to vaccinate the world
(HTM) git clone git://src.adamsgaard.dk/vaccinewars
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit ec0940c899eac626c94d0729c87b26cb7ba3be30
(DIR) parent 48c28f70d792074ca402cb9dcc8c0e2ff3c0c285
(HTM) Author: Ben Webb <ben@salilab.org>
Date: Sat, 4 May 2002 17:53:14 +0000
ESD sound files added to CVS.
Diffstat:
A src/sound_esd.c | 102 +++++++++++++++++++++++++++++++
A src/sound_esd.h | 36 +++++++++++++++++++++++++++++++
2 files changed, 138 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/src/sound_esd.c b/src/sound_esd.c
t@@ -0,0 +1,102 @@
+/************************************************************************
+ * sound_esd.c dopewars sound system (ESD/esound driver) *
+ * Copyright (C) 1998-2002 Ben Webb *
+ * Email: ben@bellatrix.pcl.ox.ac.uk *
+ * WWW: http://dopewars.sourceforge.net/ *
+ * *
+ * 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 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software *
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, *
+ * MA 02111-1307, USA. *
+ ************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_ESD
+#include <stdio.h>
+#include <string.h>
+#include <esd.h>
+#include <glib.h>
+#include "sound.h"
+
+#define MAXCACHE 6
+
+struct SoundCache {
+ int esdid;
+ gchar *name;
+} cache[MAXCACHE];
+
+
+static int sock, nextcache;
+
+static gboolean SoundOpen_ESD(void)
+{
+ int i;
+
+ sock = esd_open_sound(NULL);
+ for (i = 0; i < MAXCACHE; i++) {
+ cache[i].esdid = -1;
+ cache[i].name = NULL;
+ }
+ nextcache = 0;
+ return TRUE;
+}
+
+static void SoundClose_ESD(void)
+{
+ int i;
+
+ for (i = 0; i < MAXCACHE; i++) {
+ g_free(cache[i].name);
+ if (cache[i].esdid != -1) {
+ esd_sample_free(sock, cache[i].esdid);
+ }
+ }
+ esd_close(sock);
+}
+
+static void SoundPlay_ESD(const gchar *snd)
+{
+ int i;
+
+ for (i = 0; i < MAXCACHE; i++) {
+ if (cache[i].name && strcmp(cache[i].name, snd) == 0) {
+ esd_sample_play(sock, cache[i].esdid);
+ return;
+ }
+ }
+
+ if (cache[nextcache].esdid != -1) {
+ esd_sample_free(sock, cache[nextcache].esdid);
+ g_free(cache[nextcache].name);
+ }
+ cache[nextcache].esdid = esd_file_cache(sock, "", snd);
+ cache[nextcache].name = g_strdup(snd);
+ esd_sample_play(sock, cache[nextcache].esdid);
+ nextcache = (nextcache + 1) % MAXCACHE;
+}
+
+SoundDriver *SoundInit_ESD(void)
+{
+ static SoundDriver driver;
+
+ driver.name = "esd";
+ driver.open = SoundOpen_ESD;
+ driver.close = SoundClose_ESD;
+ driver.play = SoundPlay_ESD;
+ return &driver;
+}
+
+#endif /* HAVE_ESD */
(DIR) diff --git a/src/sound_esd.h b/src/sound_esd.h
t@@ -0,0 +1,36 @@
+/************************************************************************
+ * sound_esd.h Header file for dopewars sound system (ESD driver) *
+ * Copyright (C) 1998-2002 Ben Webb *
+ * Email: ben@bellatrix.pcl.ox.ac.uk *
+ * WWW: http://dopewars.sourceforge.net/ *
+ * *
+ * 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 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software *
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, *
+ * MA 02111-1307, USA. *
+ ************************************************************************/
+
+#ifndef __DP_SOUND_ESD_H__
+#define __DP_SOUND_ESD_H__
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "sound.h"
+
+#ifdef HAVE_ESD
+SoundDriver *SoundInit_ESD(void);
+#endif /* HAVE_ESD */
+
+#endif /* __DP_SOUND_ESD_H__ */