annotate src/audio/esd/SDL_esdaudio.c @ 3816:9d070c1a45fa SDL-ryan-multiple-audio-device

Moved AudioBootstrap section in converted drivers to bottom of source, so I could delete the predeclarations (one more thing to forget to update when changing the API, otherwise). There're a few other cleanups that snuck into this commit, too.
author Ryan C. Gordon <icculus@icculus.org>
date Fri, 06 Oct 2006 04:46:58 +0000
parents 3234d6eee011
children 66fb40445587
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
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
48 #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
49
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
50 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
51 static void *esd_handle = NULL;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
52
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
53 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
54 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
55 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
56 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
57
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
58 #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
59 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
60 {
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 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
62 void **func;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
63 } esd_functions[] = {
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
64 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
65 SDL_ESD_SYM(esd_close),
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
66 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
67 };
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
68 #undef SDL_ESD_SYM
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
69
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
70 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
71 UnloadESDLibrary()
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
72 {
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
73 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
74 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
75 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
76 }
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
77 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
78
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
79 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
80 LoadESDLibrary(void)
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
81 {
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
82 int i, retval = -1;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
83
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
84 if (esd_handle == NULL) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
85 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
86 if (esd_handle) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
87 retval = 0;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
88 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
89 *esd_functions[i].func =
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
90 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
91 if (!*esd_functions[i].func) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
92 retval = -1;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
93 UnloadESDLibrary();
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
94 break;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
95 }
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
96 }
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
97 }
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
98 }
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
99 return retval;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
100 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
101
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
102 #else
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
103
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
104 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
105 UnloadESDLibrary()
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
106 {
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
107 return;
294
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
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
110 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
111 LoadESDLibrary(void)
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
112 {
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
113 return 0;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
114 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
115
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
116 #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
117
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
118 static int
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
119 ESD_Available(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
120 {
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
121 int available = 0;
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
122 if (LoadESDLibrary() == 0) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
123 int connection;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
124 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
125 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
126 }
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
127 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
128 if (connection >= 0) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
129 available = 1;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
130 SDL_NAME(esd_close) (connection);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
131 }
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
132 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
133 }
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
134 return available;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
135 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
136
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
137
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
138 /* 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
139 static void
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
140 ESD_WaitDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
141 {
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
142 Sint32 ticks;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143
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
144 /* 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
145 {
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
146 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
147 /* 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
148 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
149 */
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
150 /* Check every 10 loops */
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
151 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
152 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
153 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
154 }
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
155 }
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
156 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
157
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
158 /* 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
159 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
160 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
161 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
162 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164
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
165 static void
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
166 ESD_PlayDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
167 {
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
168 int written = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
169
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
170 /* 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
171 do {
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
172 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
173 this->hidden->mixbuf,
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
174 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
175 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
176 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
177 }
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 }
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
179 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
180 ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
181
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 /* 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
183 this->hidden->next_frame += this->hidden->frame_ticks;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
184
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
185 /* 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
186 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
187 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
188 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
189 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
190
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
191 static Uint8 *
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
192 ESD_GetDeviceBuf(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
193 {
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
194 return (this->hidden->mixbuf);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196
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
197 static void
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
198 ESD_CloseDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
199 {
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
200 if (this->hidden != NULL) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
201 if (this->hidden->mixbuf != NULL) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
202 SDL_FreeAudioMem(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->mixbuf = NULL;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
204 }
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
205 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
206 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
207 this->hidden->audio_fd = -1;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
208 }
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
209
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
210 SDL_free(this->hidden);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
211 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
212 }
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
213 UnloadESDLibrary();
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
214 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
215
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
216 /* 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
217 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
218 get_progname(void)
0
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 char *progname = NULL;
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1379
diff changeset
221 #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
222 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
223 static char temp[BUFSIZ];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224
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
225 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
226 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
227 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
228 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
229 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
230 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
231 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
232 } 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
233 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
234 }
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
235 }
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
236 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
237 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238 #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
239 return (progname);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
241
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
242
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
243 static int
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
244 ESD_OpenDevice(_THIS, const char *devname, int iscapture)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
245 {
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
246 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
247 SDL_AudioFormat test_format = 0;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
248 int found = 0;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
249
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
250 /* 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
251 this->hidden = (struct SDL_PrivateAudioData *)
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
252 SDL_malloc((sizeof *this->hidden));
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
253 if (this->hidden == NULL) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
254 SDL_OutOfMemory();
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
255 return 0;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
256 }
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
257 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
258 this->hidden->audio_fd = -1;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
259
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
260 if (LoadESDLibrary() < 0) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
261 ESD_CloseDevice(this);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
262 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
263 return 0;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
264 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
265
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
266 /* 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
267 /* 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
268 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
269 !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
270 #ifdef DEBUG_AUDIO
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
271 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
272 #endif
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
273 found = 1;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
274 switch (test_format) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
275 case AUDIO_U8:
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
276 format |= ESD_BITS8;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
277 break;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
278 case AUDIO_S16SYS:
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
279 format |= ESD_BITS16;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
280 break;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
281 default:
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
282 found = 0;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
283 break;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
284 }
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
285 }
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
286
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
287 if (!found) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
288 ESD_CloseDevice(this);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
289 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
290 return 0;
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
291 }
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
292
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
293 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
294 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
295 } 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
296 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
297 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
298 #if 0
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
299 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
300 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
301
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
302 /* 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
303 this->hidden->audio_fd =
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
304 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
305
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
306 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
307 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
308 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
309 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
310 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
311
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
312 /* 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
313 SDL_CalculateAudioSpec(&this->spec);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
314 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
315 this->hidden->next_frame = SDL_GetTicks() + this->hidden->frame_ticks;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
316
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
317 /* Allocate mixing buffer */
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
318 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
319 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
320 if (this->hidden->mixbuf == NULL) {
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
321 ESD_CloseDevice(this);
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
322 SDL_OutOfMemory();
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
323 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
324 }
3815
3234d6eee011 Updated esd audio driver for 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
325 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326
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
327 /* 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
328 this->hidden->parent = getpid();
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329
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
330 /* 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
331 return 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332 }
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
333
3816
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
334
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
335 static int
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
336 ESD_Init(SDL_AudioDriverImpl *impl)
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
337 {
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
338 /* Set the function pointers */
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
339 impl->OpenDevice = ESD_OpenDevice;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
340 impl->PlayDevice = ESD_PlayDevice;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
341 impl->WaitDevice = ESD_WaitDevice;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
342 impl->GetDeviceBuf = ESD_GetDeviceBuf;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
343 impl->CloseDevice = ESD_CloseDevice;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
344 impl->OnlyHasDefaultOutputDevice = 1;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
345
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
346 return 1;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
347 }
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
348
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
349
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
350 AudioBootStrap ESD_bootstrap = {
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
351 ESD_DRIVER_NAME, "Enlightened Sound Daemon",
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
352 ESD_Available, ESD_Init, 0
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
353 };
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3815
diff changeset
354
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
355 /* vi: set ts=4 sw=4 expandtab: */