annotate src/audio/arts/SDL_artsaudio.c @ 3846:66fb40445587 SDL-ryan-multiple-audio-device

Removed distinction between "available" and "init" in audio backends, since both had to be checked for success as a pair at the higher level and several of the Available methods were just always-succeed placeholders anyhow. Now the availability check is done in the init code, and the higher level tries all possible drivers until one manages to initialize successfully.
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 17 Oct 2006 09:09:21 +0000
parents 9d070c1a45fa
children
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: 956
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: 956
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: 956
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: 956
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: 956
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: 956
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: 956
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 a raw mixing buffer */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25
1358
c71e05b4dc2e More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
26 #include "SDL_timer.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27 #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
28 #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
29 #include "../SDL_audio_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 #include "SDL_artsaudio.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
32 #ifdef SDL_AUDIO_DRIVER_ARTS_DYNAMIC
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
33 #include "SDL_name.h"
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
34 #include "SDL_loadso.h"
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
35 #else
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
36 #define SDL_NAME(X) X
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
37 #endif
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
38
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 /* The tag name used by artsc audio */
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
40 #define ARTS_DRIVER_NAME "arts"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
42 #ifdef SDL_AUDIO_DRIVER_ARTS_DYNAMIC
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
43
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
44 static const char *arts_library = SDL_AUDIO_DRIVER_ARTS_DYNAMIC;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
45 static void *arts_handle = NULL;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
46
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
47 /* !!! FIXME: I hate this SDL_NAME clutter...it makes everything so messy! */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
48 static int (*SDL_NAME(arts_init)) (void);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
49 static void (*SDL_NAME(arts_free)) (void);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
50 static arts_stream_t(*SDL_NAME(arts_play_stream)) (int rate, int bits,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
51 int channels,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
52 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: 1402
diff changeset
53 static int (*SDL_NAME(arts_stream_set)) (arts_stream_t s,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
54 arts_parameter_t param, int value);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
55 static int (*SDL_NAME(arts_stream_get)) (arts_stream_t s,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
56 arts_parameter_t param);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
57 static int (*SDL_NAME(arts_write)) (arts_stream_t s, const void *buffer,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
58 int count);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
59 static void (*SDL_NAME(arts_close_stream)) (arts_stream_t s);
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
60 static void (*SDL_NAME(arts_close_stream)) (arts_stream_t s);
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
61 static const char *(*SDL_NAME(arts_error_text)) (int errorcode);
301
fb4c4c6a2773 Fixed dynamic arts support.
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
62
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
63 #define SDL_ARTS_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: 1402
diff changeset
64 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: 1402
diff changeset
65 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
66 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: 1402
diff changeset
67 void **func;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
68 } arts_functions[] = {
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
69 SDL_ARTS_SYM(arts_init),
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
70 SDL_ARTS_SYM(arts_free),
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
71 SDL_ARTS_SYM(arts_play_stream),
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
72 SDL_ARTS_SYM(arts_stream_set),
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
73 SDL_ARTS_SYM(arts_stream_get),
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
74 SDL_ARTS_SYM(arts_write),
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
75 SDL_ARTS_SYM(arts_close_stream),
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
76 SDL_ARTS_SYM(arts_error_text),
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
77 };
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
78 #undef SDL_ARTS_SYM
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
79
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
80 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: 1402
diff changeset
81 UnloadARTSLibrary()
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
82 {
3813
92f7304e50ff Removed duplicate state from arts driver.
Ryan C. Gordon <icculus@icculus.org>
parents: 3812
diff changeset
83 if (arts_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: 1402
diff changeset
84 SDL_UnloadObject(arts_handle);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
85 arts_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: 1402
diff changeset
86 }
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
87 }
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: 1402
diff changeset
89 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: 1402
diff changeset
90 LoadARTSLibrary(void)
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
91 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
92 int i, retval = -1;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
93
3813
92f7304e50ff Removed duplicate state from arts driver.
Ryan C. Gordon <icculus@icculus.org>
parents: 3812
diff changeset
94 if (arts_handle == NULL) {
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
95 arts_handle = SDL_LoadObject(arts_library);
3813
92f7304e50ff Removed duplicate state from arts driver.
Ryan C. Gordon <icculus@icculus.org>
parents: 3812
diff changeset
96 if (arts_handle != NULL) {
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
97 retval = 0;
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
98 for (i = 0; i < SDL_arraysize(arts_functions); ++i) {
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
99 *arts_functions[i].func =
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
100 SDL_LoadFunction(arts_handle, arts_functions[i].name);
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
101 if (!*arts_functions[i].func) {
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
102 retval = -1;
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
103 UnloadARTSLibrary();
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
104 break;
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
105 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
106 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
107 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
108 }
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
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: 1402
diff changeset
110 return retval;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
111 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
112
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
113 #else
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
114
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
115 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: 1402
diff changeset
116 UnloadARTSLibrary()
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: 1402
diff changeset
118 return;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
119 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
120
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
121 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: 1402
diff changeset
122 LoadARTSLibrary(void)
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
123 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
124 return 0;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
125 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
126
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
127 #endif /* SDL_AUDIO_DRIVER_ARTS_DYNAMIC */
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
128
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129 /* 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: 1402
diff changeset
130 static void
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
131 ARTS_WaitDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
132 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
133 Sint32 ticks;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
134
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
135 /* 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: 1402
diff changeset
136 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
137 static int cnt = 0;
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
138 /* Note that this only works with thread implementations
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
139 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: 1402
diff changeset
140 */
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
141 /* Check every 10 loops */
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
142 if (this->hidden->parent && (((++cnt) % 10) == 0)) {
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
143 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: 1402
diff changeset
144 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: 1402
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: 1402
diff changeset
146 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
147 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
148
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
149 /* Use timer for general audio synchronization */
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
150 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: 1402
diff changeset
151 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: 1402
diff changeset
152 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: 1402
diff changeset
153 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
154 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
155
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
156 static void
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
157 ARTS_PlayDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
158 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
159 /* Write the audio data */
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
160 int written = SDL_NAME(arts_write) (
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
161 this->hidden->stream,
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
162 this->hidden->mixbuf,
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
163 this->hidden->mixlen);
0
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: 1402
diff changeset
165 /* If timer synchronization is enabled, set the next write frame */
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
166 if (this->hidden->frame_ticks) {
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
167 this->hidden->next_frame += this->hidden->frame_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: 1402
diff changeset
168 }
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: 1402
diff changeset
170 /* 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: 1402
diff changeset
171 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: 1402
diff changeset
172 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: 1402
diff changeset
173 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
174 #ifdef DEBUG_AUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
175 fprintf(stderr, "Wrote %d bytes of audio data\n", written);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
176 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
177 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
178
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
179 static void
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
180 ARTS_WaitDone(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
181 {
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
182 /* !!! FIXME: camp here until buffer drains... SDL_Delay(???); */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
183 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
184
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
185
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
186 static Uint8 *
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
187 ARTS_GetDeviceBuf(_THIS)
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
188 {
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
189 return (this->hidden->mixbuf);
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
190 }
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
191
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
192
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
193 static void
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
194 ARTS_CloseDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 {
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
196 if (this->hidden != NULL) {
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
197 if (this->hidden->mixbuf != NULL) {
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
198 SDL_FreeAudioMem(this->hidden->mixbuf);
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
199 this->hidden->mixbuf = NULL;
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
200 }
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
201 if (this->hidden->stream) {
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
202 SDL_NAME(arts_close_stream) (this->hidden->stream);
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
203 this->hidden->stream = 0;
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
204 }
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
205 SDL_NAME(arts_free) ();
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
206 SDL_free(this->hidden);
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
207 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: 1402
diff changeset
208 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
209 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
210
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
211
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
212 static int
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
213 ARTS_OpenDevice(_THIS, const char *devname, int iscapture)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
214 {
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
215 int rc = 0;
3814
8e1af9ff0e1f One more minor cleanup in arts driver.
Ryan C. Gordon <icculus@icculus.org>
parents: 3813
diff changeset
216 int bits = 0, frag_spec = 0;
8e1af9ff0e1f One more minor cleanup in arts driver.
Ryan C. Gordon <icculus@icculus.org>
parents: 3813
diff changeset
217 SDL_AudioFormat test_format = 0, format = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
219 /* Initialize all variables that we clean on shutdown */
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
220 this->hidden = (struct SDL_PrivateAudioData *)
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
221 SDL_malloc((sizeof *this->hidden));
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
222 if (this->hidden == NULL) {
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
223 SDL_OutOfMemory();
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
224 return 0;
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
225 }
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
226 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
228 /* Try for a closest match on audio format */
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
229 for (test_format = SDL_FirstAudioFormat(this->spec.format);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
230 !format && test_format;) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231 #ifdef DEBUG_AUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
232 fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
233 #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: 1402
diff changeset
234 switch (test_format) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
235 case AUDIO_U8:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
236 bits = 8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
237 format = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
238 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
239 case AUDIO_S16LSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
240 bits = 16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
241 format = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
242 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
243 default:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
244 format = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
245 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
246 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
247 if (!format) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
248 test_format = SDL_NextAudioFormat();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
249 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
250 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
251 if (format == 0) {
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
252 ARTS_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: 1402
diff changeset
253 SDL_SetError("Couldn't find any hardware audio formats");
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
254 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: 1402
diff changeset
255 }
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
256 this->spec.format = test_format;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
257
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
258 if ((rc = SDL_NAME(arts_init) ()) != 0) {
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
259 ARTS_CloseDevice(this);
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
260 SDL_SetError( "Unable to initialize ARTS: %s",
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
261 SDL_NAME(arts_error_text)(rc) );
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
262 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: 1402
diff changeset
263 }
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
264 this->hidden->stream = SDL_NAME(arts_play_stream) (
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
265 this->spec.freq,
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
266 bits, this->spec.channels,
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
267 "SDL");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
268
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
269 /* Calculate the final parameters for this audio specification */
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
270 SDL_CalculateAudioSpec(&this->spec);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
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: 1402
diff changeset
272 /* Determine the power of two of the fragment size */
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
273 for (frag_spec = 0; (0x01 << frag_spec) < this->spec.size; ++frag_spec);
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
274 if ((0x01 << frag_spec) != this->spec.size) {
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
275 ARTS_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: 1402
diff changeset
276 SDL_SetError("Fragment size must be a power of two");
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
277 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: 1402
diff changeset
278 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
279 frag_spec |= 0x00020000; /* two fragments, for low latency */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
280
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
281 #ifdef ARTS_P_PACKET_SETTINGS
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
282 SDL_NAME(arts_stream_set) (this->hidden->stream,
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
283 ARTS_P_PACKET_SETTINGS, frag_spec);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
284 #else
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
285 SDL_NAME(arts_stream_set) (this->hidden->stream, ARTS_P_PACKET_SIZE,
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
286 frag_spec & 0xffff);
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
287 SDL_NAME(arts_stream_set) (this->hidden->stream, ARTS_P_PACKET_COUNT,
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
288 frag_spec >> 16);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
289 #endif
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
290 this->spec.size = SDL_NAME(arts_stream_get) (this->hidden->stream,
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
291 ARTS_P_PACKET_SIZE);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
292
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
293 /* Allocate mixing buffer */
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
294 this->hidden->mixlen = this->spec.size;
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
295 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
296 if (this->hidden->mixbuf == NULL) {
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
297 ARTS_CloseDevice(this);
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
298 SDL_OutOfMemory();
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
299 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: 1402
diff changeset
300 }
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
301 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
302
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
303 /* Get the parent process id (we're the parent of the audio thread) */
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
304 this->hidden->parent = getpid();
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
305
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
306 /* We're ready to rock and roll. :-) */
3812
35d1367020a3 Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
307 return 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
308 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
309
3816
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
310
3846
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
311 static void
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
312 ARTS_Deinitialize(void)
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
313 {
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
314 UnloadARTSLibrary();
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
315 }
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
316
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
317
3816
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
318 static int
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
319 ARTS_Init(SDL_AudioDriverImpl *impl)
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
320 {
3846
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
321 if (LoadARTSLibrary() < 0) {
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
322 return 0;
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
323 } else {
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
324 if (SDL_NAME(arts_init) () != 0) {
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
325 UnloadARTSLibrary();
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
326 SDL_SetError("ARTS: arts_init failed (no audio server?)");
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
327 return 0;
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
328 }
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
329
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
330 /* Play a stream so aRts doesn't crash */
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
331 arts_stream_t stream;
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
332 stream = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL");
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
333 SDL_NAME(arts_write) (stream, "", 0);
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
334 SDL_NAME(arts_close_stream) (stream);
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
335 SDL_NAME(arts_free) ();
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
336 }
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
337
3816
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
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: 3814
diff changeset
339 impl->OpenDevice = ARTS_OpenDevice;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
340 impl->PlayDevice = ARTS_PlayDevice;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
341 impl->WaitDevice = ARTS_WaitDevice;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
342 impl->GetDeviceBuf = ARTS_GetDeviceBuf;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
343 impl->CloseDevice = ARTS_CloseDevice;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
344 impl->WaitDone = ARTS_WaitDone;
3846
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
345 impl->Deinitialize = ARTS_Deinitialize;
3816
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
346 impl->OnlyHasDefaultOutputDevice = 1;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
347
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
348 return 1;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
349 }
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
350
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
351
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
352 AudioBootStrap ARTS_bootstrap = {
3846
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
353 ARTS_DRIVER_NAME, "Analog RealTime Synthesizer", ARTS_Init, 0
3816
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
diff changeset
354 };
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3814
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: 1402
diff changeset
356 /* vi: set ts=4 sw=4 expandtab: */