2 * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3 * Copyright (C) 2004-2008 Kim Woelders
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies of the Software, its documentation and marketing & publicity
14 * materials, and acknowledgment shall be given in the documentation, materials
15 * and software packages that this Software was used.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #if defined(HAVE_SOUND) && defined(HAVE_SOUND_ESD)
30 #define Estrdup strdup
38 static int sound_fd = -1;
41 _sound_esd_Load(const char *file)
49 s = ECALLOC(Sample, 1);
53 err = SoundSampleGetData(file, &s->ssd);
60 format = ESD_STREAM | ESD_PLAY;
61 if (s->ssd.bit_per_sample == 8)
63 else if (s->ssd.bit_per_sample == 16)
65 if (s->ssd.channels == 1)
67 else if (s->ssd.channels == 2)
70 s->id = esd_sample_getid(sound_fd, file);
75 s->id = esd_sample_cache(sound_fd, format, s->ssd.rate, s->ssd.size,
77 write(sound_fd, s->ssd.data, s->ssd.size);
78 confirm = esd_confirm_sample_cache(sound_fd);
91 _sound_esd_Destroy(Sample * s)
96 if (s->id && sound_fd >= 0)
98 /* Why the hell is this symbol not in esd? */
99 /* it's in esd.h - evil evil evil */
100 /* esd_sample_kill(sound_fd,s->id); */
101 esd_sample_free(sound_fd, s->id);
108 _sound_esd_Play(Sample * s)
110 if (sound_fd < 0 || !s)
114 esd_sample_play(sound_fd, s->id);
118 _sound_esd_Init(void)
123 sound_fd = esd_open_sound(NULL);
129 _sound_esd_Exit(void)
138 __EXPORT__ extern const SoundOps SoundOps_esd;
139 const SoundOps SoundOps_esd = {
140 _sound_esd_Init, _sound_esd_Exit, _sound_esd_Load, _sound_esd_Destroy,
144 #endif /* HAVE_SOUND && HAVE_SOUND_ESD */