annotate src/audio/esd/SDL_esdaudio.c @ 3815:3234d6eee011 SDL-ryan-multiple-audio-device

Updated esd audio driver for 1.3 API.
author Ryan C. Gordon <icculus@icculus.org>
date Fri, 06 Oct 2006 04:16:11 +0000
parents 7852b5b78af5
children 9d070c1a45fa
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 864
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 864
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 864
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 864
diff changeset
13 Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 864
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 864
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 864
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1379
diff changeset
22 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 /* Allow access to an ESD network stream mixing buffer */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25
1616
9f836cec0521 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
26 #include <sys/types.h>
9f836cec0521 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
27 #include <unistd.h>
9f836cec0521 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
28 #include <signal.h>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 #include <errno.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 #include <esd.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31
1358
c71e05b4dc2e More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
32 #include "SDL_timer.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #include "SDL_audio.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
34 #include "../SDL_audiomem.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
35 #include "../SDL_audio_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 #include "SDL_esdaudio.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
38 #ifdef SDL_AUDIO_DRIVER_ESD_DYNAMIC
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
39 #include "SDL_name.h"
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
40 #include "SDL_loadso.h"
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
41 #else
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
42 #define SDL_NAME(X) X
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
43 #endif
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
44
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 /* The tag name used by ESD audio */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 #define ESD_DRIVER_NAME "esd"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 /* Audio driver functions */
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
49 static int ESD_OpenDevice(_THIS, const char *devname, int iscapture);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
50 static void ESD_WaitDevice(_THIS);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
51 static void ESD_PlayDevice(_THIS);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
52 static Uint8 *ESD_GetDeviceBuf(_THIS);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
53 static void ESD_CloseDevice(_THIS);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
55 #ifdef SDL_AUDIO_DRIVER_ESD_DYNAMIC
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
56
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
57 static const char *esd_library = SDL_AUDIO_DRIVER_ESD_DYNAMIC;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
58 static void *esd_handle = NULL;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
59
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
60 static int (*SDL_NAME(esd_open_sound)) (const char *host);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
61 static int (*SDL_NAME(esd_close)) (int esd);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
62 static int (*SDL_NAME(esd_play_stream)) (esd_format_t format, int rate,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
63 const char *host, const char *name);
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
64
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
65 #define SDL_ESD_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
66 static struct
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
67 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
68 const char *name;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
69 void **func;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
70 } esd_functions[] = {
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
71 SDL_ESD_SYM(esd_open_sound),
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
72 SDL_ESD_SYM(esd_close),
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
73 SDL_ESD_SYM(esd_play_stream),
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
74 };
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
75 #undef SDL_ESD_SYM
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
76
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
77 static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
78 UnloadESDLibrary()
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
79 {
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
80 if (esd_handle != NULL) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
81 SDL_UnloadObject(esd_handle);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
82 esd_handle = NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
83 }
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
84 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
85
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
86 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
87 LoadESDLibrary(void)
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
88 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
89 int i, retval = -1;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
90
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
91 if (esd_handle == NULL) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
92 esd_handle = SDL_LoadObject(esd_library);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
93 if (esd_handle) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
94 retval = 0;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
95 for (i = 0; i < SDL_arraysize(esd_functions); ++i) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
96 *esd_functions[i].func =
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
97 SDL_LoadFunction(esd_handle, esd_functions[i].name);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
98 if (!*esd_functions[i].func) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
99 retval = -1;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
100 UnloadESDLibrary();
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
101 break;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
102 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
103 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
104 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
105 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
106 return retval;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
107 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
108
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
109 #else
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
110
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
111 static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
112 UnloadESDLibrary()
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
113 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
114 return;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
115 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
116
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
117 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
118 LoadESDLibrary(void)
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
119 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
120 return 0;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
121 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
122
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
123 #endif /* SDL_AUDIO_DRIVER_ESD_DYNAMIC */
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
124
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
125 /* Audio driver bootstrap functions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
126
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
127 static int
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
128 ESD_Available(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129 {
3803
3decf9cdeb63 Removed ESD cruft from the core...now the driver will use esound if there's
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
130 int available = 0;
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
131 if (LoadESDLibrary() == 0) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
132 int connection;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
133 if (SDL_getenv("ESD_NO_SPAWN") == NULL) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
134 SDL_putenv("ESD_NO_SPAWN=1"); /* Don't start ESD if it's not running */
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
135 }
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
136 connection = SDL_NAME(esd_open_sound) (NULL);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
137 if (connection >= 0) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
138 available = 1;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
139 SDL_NAME(esd_close) (connection);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
140 }
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
141 UnloadESDLibrary();
3803
3decf9cdeb63 Removed ESD cruft from the core...now the driver will use esound if there's
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
142 }
3decf9cdeb63 Removed ESD cruft from the core...now the driver will use esound if there's
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
143 return available;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
144 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
146
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
147 static int
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
148 ESD_Init(SDL_AudioDriverImpl *impl)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 {
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
150 /* Set the function pointers */
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
151 impl->OpenDevice = ESD_OpenDevice;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
152 impl->PlayDevice = ESD_PlayDevice;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
153 impl->WaitDevice = ESD_WaitDevice;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
154 impl->GetDeviceBuf = ESD_GetDeviceBuf;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
155 impl->CloseDevice = ESD_CloseDevice;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
156 impl->OnlyHasDefaultOutputDevice = 1;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
157
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
158 return 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
159 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
161
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
162 AudioBootStrap ESD_bootstrap = {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
163 ESD_DRIVER_NAME, "Enlightened Sound Daemon",
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
164 ESD_Available, ESD_Init, 0
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165 };
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
166
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
167 /* This function waits until it is possible to write a full sound buffer */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
168 static void
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
169 ESD_WaitDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
170 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
171 Sint32 ticks;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
173 /* Check to see if the thread-parent process is still alive */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
174 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
175 static int cnt = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
176 /* Note that this only works with thread implementations
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
177 that use a different process id for each thread.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
178 */
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
179 /* Check every 10 loops */
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
180 if (this->hidden->parent && (((++cnt) % 10) == 0)) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
181 if (kill(this->hidden->parent, 0) < 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
182 this->enabled = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
183 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
184 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
185 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
186
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
187 /* Use timer for general audio synchronization */
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
188 ticks = ((Sint32) (this->hidden->next_frame-SDL_GetTicks())) - FUDGE_TICKS;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
189 if (ticks > 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
190 SDL_Delay(ticks);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
191 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
192 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
193
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
194 static void
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
195 ESD_PlayDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196 {
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
197 int written = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
198
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
199 /* Write the audio data, checking for EAGAIN on broken audio drivers */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
200 do {
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
201 written = write(this->hidden->audio_fd,
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
202 this->hidden->mixbuf,
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
203 this->hidden->mixlen);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
204 if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
205 SDL_Delay(1); /* Let a little CPU time go by */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
206 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
207 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
208 while ((written < 0) &&
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
209 ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
210
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
211 /* Set the next write frame */
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
212 this->hidden->next_frame += this->hidden->frame_ticks;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
213
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
214 /* If we couldn't write, assume fatal error for now */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
215 if (written < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
216 this->enabled = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
217 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
220 static Uint8 *
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
221 ESD_GetDeviceBuf(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
222 {
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
223 return (this->hidden->mixbuf);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
226 static void
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
227 ESD_CloseDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
228 {
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
229 if (this->hidden != NULL) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
230 if (this->hidden->mixbuf != NULL) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
231 SDL_FreeAudioMem(this->hidden->mixbuf);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
232 this->hidden->mixbuf = NULL;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
233 }
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
234 if (this->hidden->audio_fd >= 0) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
235 SDL_NAME(esd_close) (this->hidden->audio_fd);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
236 this->hidden->audio_fd = -1;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
237 }
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
238
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
239 SDL_free(this->hidden);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
240 this->hidden = NULL;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
241 }
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
242 UnloadESDLibrary();
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
243 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
244
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
245 /* Try to get the name of the program */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
246 static char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
247 get_progname(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
248 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
249 char *progname = NULL;
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1379
diff changeset
250 #ifdef __LINUX__
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
251 FILE *fp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
252 static char temp[BUFSIZ];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
253
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
254 SDL_snprintf(temp, SDL_arraysize(temp), "/proc/%d/cmdline", getpid());
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
255 fp = fopen(temp, "r");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
256 if (fp != NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
257 if (fgets(temp, sizeof(temp) - 1, fp)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
258 progname = SDL_strrchr(temp, '/');
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
259 if (progname == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
260 progname = temp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
261 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
262 progname = progname + 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
263 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
264 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
265 fclose(fp);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
266 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
267 #endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
268 return (progname);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
269 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
270
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
271
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
272 static int
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
273 ESD_OpenDevice(_THIS, const char *devname, int iscapture)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
274 {
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
275 esd_format_t format = (ESD_STREAM | ESD_PLAY);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
276 SDL_AudioFormat test_format = 0;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
277 int found = 0;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
278
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
279 /* Initialize all variables that we clean on shutdown */
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
280 this->hidden = (struct SDL_PrivateAudioData *)
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
281 SDL_malloc((sizeof *this->hidden));
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
282 if (this->hidden == NULL) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
283 SDL_OutOfMemory();
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
284 return 0;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
285 }
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
286 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
287 this->hidden->audio_fd = -1;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
288
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
289 if (LoadESDLibrary() < 0) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
290 ESD_CloseDevice(this);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
291 SDL_SetError("ESD: failed to load library: %s", SDL_GetError());
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
292 return 0;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
293 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
294
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
295 /* Convert audio spec to the ESD audio format */
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
296 /* Try for a closest match on audio format */
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
297 for (test_format = SDL_FirstAudioFormat(this->spec.format);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
298 !found && test_format; test_format = SDL_NextAudioFormat()) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
299 #ifdef DEBUG_AUDIO
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
300 fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
301 #endif
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
302 found = 1;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
303 switch (test_format) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
304 case AUDIO_U8:
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
305 format |= ESD_BITS8;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
306 break;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
307 case AUDIO_S16SYS:
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
308 format |= ESD_BITS16;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
309 break;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
310 default:
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
311 found = 0;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
312 break;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
313 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
314 }
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
315
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
316 if (!found) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
317 ESD_CloseDevice(this);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
318 SDL_SetError("Couldn't find any hardware audio formats");
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
319 return 0;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
320 }
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
321
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
322 if (this->spec.channels == 1) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
323 format |= ESD_MONO;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
324 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
325 format |= ESD_STEREO;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
326 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 #if 0
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
328 this->spec.samples = ESD_BUF_SIZE; /* Darn, no way to change this yet */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
330
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
331 /* Open a connection to the ESD audio server */
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
332 this->hidden->audio_fd =
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
333 SDL_NAME(esd_play_stream)(format,this->spec.freq,NULL,get_progname());
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
334
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
335 if (this->hidden->audio_fd < 0) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
336 ESD_CloseDevice(this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
337 SDL_SetError("Couldn't open ESD connection");
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
338 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
339 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
340
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
341 /* Calculate the final parameters for this audio specification */
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
342 SDL_CalculateAudioSpec(&this->spec);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
343 this->hidden->frame_ticks = (float) (this->spec.samples*1000) / this->spec.freq;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
344 this->hidden->next_frame = SDL_GetTicks() + this->hidden->frame_ticks;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
345
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
346 /* Allocate mixing buffer */
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
347 this->hidden->mixlen = this->spec.size;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
348 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
349 if (this->hidden->mixbuf == NULL) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
350 ESD_CloseDevice(this);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
351 SDL_OutOfMemory();
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
352 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
353 }
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
354 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
355
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
356 /* Get the parent process id (we're the parent of the audio thread) */
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
357 this->hidden->parent = getpid();
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
358
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
359 /* We're ready to rock and roll. :-) */
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
360 return 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
361 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
362
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1616
diff changeset
363 /* vi: set ts=4 sw=4 expandtab: */