tsound_esd.c - 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
---
tsound_esd.c (3032B)
---
1 /************************************************************************
2 * sound_esd.c dopewars sound system (ESD/esound driver) *
3 * Copyright (C) 1998-2021 Ben Webb *
4 * Email: benwebb@users.sf.net *
5 * WWW: https://dopewars.sourceforge.io/ *
6 * *
7 * This program is free software; you can redistribute it and/or *
8 * modify it under the terms of the GNU General Public License *
9 * as published by the Free Software Foundation; either version 2 *
10 * of the License, or (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, *
20 * MA 02111-1307, USA. *
21 ************************************************************************/
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #ifdef HAVE_ESD
28 #include <stdio.h>
29 #include <string.h>
30 #include <esd.h>
31 #include <glib.h>
32 #include "../sound.h"
33
34 #define MAXCACHE 6
35
36 struct SoundCache {
37 int esdid;
38 gchar *name;
39 } cache[MAXCACHE];
40
41
42 static int sock, nextcache;
43
44 static gboolean SoundOpen_ESD(void)
45 {
46 int i;
47
48 sock = esd_open_sound(NULL);
49 for (i = 0; i < MAXCACHE; i++) {
50 cache[i].esdid = -1;
51 cache[i].name = NULL;
52 }
53 nextcache = 0;
54 return TRUE;
55 }
56
57 static void SoundClose_ESD(void)
58 {
59 int i;
60
61 for (i = 0; i < MAXCACHE; i++) {
62 g_free(cache[i].name);
63 if (cache[i].esdid != -1) {
64 esd_sample_free(sock, cache[i].esdid);
65 }
66 }
67 esd_close(sock);
68 }
69
70 static void SoundPlay_ESD(const gchar *snd)
71 {
72 int i;
73
74 for (i = 0; i < MAXCACHE; i++) {
75 if (cache[i].name && strcmp(cache[i].name, snd) == 0) {
76 esd_sample_play(sock, cache[i].esdid);
77 return;
78 }
79 }
80
81 if (cache[nextcache].esdid != -1) {
82 esd_sample_free(sock, cache[nextcache].esdid);
83 g_free(cache[nextcache].name);
84 }
85 cache[nextcache].esdid = esd_file_cache(sock, PACKAGE, snd);
86 cache[nextcache].name = g_strdup(snd);
87 esd_sample_play(sock, cache[nextcache].esdid);
88 nextcache = (nextcache + 1) % MAXCACHE;
89 }
90
91 SoundDriver *sound_esd_init(void)
92 {
93 static SoundDriver driver;
94
95 driver.name = "esd";
96 driver.open = SoundOpen_ESD;
97 driver.close = SoundClose_ESD;
98 driver.play = SoundPlay_ESD;
99 return &driver;
100 }
101
102 #endif /* HAVE_ESD */