23 #if SDL_AUDIO_DRIVER_ESD
35 #include "../SDL_audiomem.h"
36 #include "../SDL_audio_c.h"
39 #ifdef SDL_AUDIO_DRIVER_ESD_DYNAMIC
46 #ifdef SDL_AUDIO_DRIVER_ESD_DYNAMIC
48 static const char *esd_library = SDL_AUDIO_DRIVER_ESD_DYNAMIC;
49 static void *esd_handle =
NULL;
51 static int (*
SDL_NAME(esd_open_sound)) (
const char *host);
54 const char *host,
const char *
name);
56 #define SDL_ESD_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) }
61 }
const esd_functions[] = {
62 SDL_ESD_SYM(esd_open_sound),
63 SDL_ESD_SYM(esd_close), SDL_ESD_SYM(esd_play_stream),
71 if (esd_handle !=
NULL) {
82 if (esd_handle ==
NULL) {
87 *esd_functions[
i].func =
89 if (!*esd_functions[i].
func) {
119 ESD_WaitDevice(
_THIS)
130 if (this->hidden->parent && (((++cnt) % 10) == 0)) {
131 if (kill(this->hidden->parent, 0) < 0 && errno == ESRCH) {
146 ESD_PlayDevice(
_THIS)
152 written = write(this->hidden->audio_fd,
153 this->hidden->mixbuf, this->hidden->mixlen);
154 if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
157 }
while ((written < 0) &&
158 ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
161 this->hidden->next_frame += this->hidden->frame_ticks;
170 ESD_GetDeviceBuf(
_THIS)
172 return (this->hidden->mixbuf);
176 ESD_CloseDevice(
_THIS)
178 if (this->hidden !=
NULL) {
180 this->hidden->mixbuf =
NULL;
181 if (this->hidden->audio_fd >= 0) {
182 SDL_NAME(esd_close) (this->hidden->audio_fd);
183 this->hidden->audio_fd = -1;
195 char *progname =
NULL;
198 static char temp[BUFSIZ];
201 fp = fopen(temp,
"r");
203 if (fgets(temp,
sizeof(temp) - 1, fp)) {
205 if (progname ==
NULL) {
208 progname = progname + 1;
219 ESD_OpenDevice(
_THIS,
const char *devname,
int iscapture)
221 esd_format_t format = (ESD_STREAM | ESD_PLAY);
228 if (this->hidden ==
NULL) {
231 SDL_memset(this->hidden, 0, (
sizeof *this->hidden));
232 this->hidden->audio_fd = -1;
239 fprintf(stderr,
"Trying format 0x%4.4x\n", test_format);
242 switch (test_format) {
247 format |= ESD_BITS16;
256 ESD_CloseDevice(
this);
257 return SDL_SetError(
"Couldn't find any hardware audio formats");
260 if (this->spec.channels == 1) {
263 format |= ESD_STEREO;
266 this->spec.samples = ESD_BUF_SIZE;
270 this->hidden->audio_fd =
274 if (this->hidden->audio_fd < 0) {
275 ESD_CloseDevice(
this);
281 this->hidden->frame_ticks =
282 (float) (this->spec.samples * 1000) / this->spec.freq;
283 this->hidden->next_frame =
SDL_GetTicks() + this->hidden->frame_ticks;
286 this->hidden->mixlen = this->spec.size;
288 if (this->hidden->mixbuf ==
NULL) {
289 ESD_CloseDevice(
this);
292 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
295 this->hidden->parent = getpid();
302 ESD_Deinitialize(
void)
310 if (LoadESDLibrary() < 0) {
319 if (connection < 0) {
321 SDL_SetError(
"ESD: esd_open_sound failed (no audio server?)");
341 "esd",
"Enlightened Sound Daemon", ESD_Init, 0
void(* CloseDevice)(_THIS)
SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format)
int32_t Sint32
A signed 32-bit integer type.
void(* WaitDevice)(_THIS)
DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt,...)
GLenum GLsizei const GLuint GLboolean enabled
Uint8 *(* GetDeviceBuf)(_THIS)
DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c)
DECLSPEC void SDLCALL SDL_free(void *mem)
EGLImageKHR EGLint * name
Uint16 SDL_AudioFormat
Audio format flags.
int(* OpenDevice)(_THIS, const char *devname, int iscapture)
SDL_AudioFormat SDL_NextAudioFormat(void)
void(* PlayDevice)(_THIS)
DECLSPEC Uint32 SDLCALL SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
int OnlyHasDefaultOutputDevice
DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile)
DECLSPEC void SDLCALL SDL_Delay(Uint32 ms)
Wait a specified number of milliseconds before returning.
DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len)
DECLSPEC void SDLCALL SDL_UnloadObject(void *handle)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
void SDL_CalculateAudioSpec(SDL_AudioSpec *spec)
void(* Deinitialize)(void)
#define SDL_AllocAudioMem
#define SDL_OutOfMemory()
#define SDL_arraysize(array)
uint8_t Uint8
An unsigned 8-bit integer type.
AudioBootStrap ESD_bootstrap
DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite)
DECLSPEC void *SDLCALL SDL_LoadFunction(void *handle, const char *name)