Mercurial > sdl-ios-xcode
annotate src/audio/arts/SDL_artsaudio.c @ 3813:92f7304e50ff SDL-ryan-multiple-audio-device
Removed duplicate state from arts driver.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 06 Oct 2006 03:32:48 +0000 |
parents | 35d1367020a3 |
children | 8e1af9ff0e1f |
rev | line source |
---|---|
0 | 1 /* |
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 | 4 |
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 | 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 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
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 | 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 | 18 |
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 | 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 | 23 |
24 /* Allow access to a raw mixing buffer */ | |
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 | 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 | 30 #include "SDL_artsaudio.h" |
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 | 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 | 41 |
42 /* Audio driver functions */ | |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
43 static int ARTS_OpenDevice(_THIS, const char *devname, int iscapture); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
44 static void ARTS_WaitDevice(_THIS); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
45 static void ARTS_PlayDevice(_THIS); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
46 static Uint8 *ARTS_GetDeviceBuf(_THIS); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
47 static void ARTS_CloseDevice(_THIS); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
48 static void ARTS_WaitDone(_THIS); |
0 | 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 #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
|
51 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
52 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
|
53 static void *arts_handle = NULL; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
54 |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
55 /* !!! 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
71 #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
|
72 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
|
73 { |
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
|
74 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
|
75 void **func; |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
76 } arts_functions[] = { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
77 SDL_ARTS_SYM(arts_init), |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
78 SDL_ARTS_SYM(arts_free), |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
79 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
|
80 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
|
81 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
|
82 SDL_ARTS_SYM(arts_write), |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
83 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
|
84 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
|
85 }; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
86 #undef SDL_ARTS_SYM |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
87 |
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
|
88 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
|
89 UnloadARTSLibrary() |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
90 { |
3813
92f7304e50ff
Removed duplicate state from arts driver.
Ryan C. Gordon <icculus@icculus.org>
parents:
3812
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 } |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
95 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
96 |
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
|
97 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
|
98 LoadARTSLibrary(void) |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
99 { |
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
|
100 int i, retval = -1; |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
101 |
3813
92f7304e50ff
Removed duplicate state from arts driver.
Ryan C. Gordon <icculus@icculus.org>
parents:
3812
diff
changeset
|
102 if (arts_handle == NULL) { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
103 arts_handle = SDL_LoadObject(arts_library); |
3813
92f7304e50ff
Removed duplicate state from arts driver.
Ryan C. Gordon <icculus@icculus.org>
parents:
3812
diff
changeset
|
104 if (arts_handle != NULL) { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
105 retval = 0; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
106 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
|
107 *arts_functions[i].func = |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
108 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
|
109 if (!*arts_functions[i].func) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
110 retval = -1; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
111 UnloadARTSLibrary(); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
112 break; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
113 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
114 } |
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 } |
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 } |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
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 retval; |
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 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
121 #else |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
122 |
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
|
123 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
|
124 UnloadARTSLibrary() |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
125 { |
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
|
126 return; |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
127 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
128 |
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
|
129 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
|
130 LoadARTSLibrary(void) |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
131 { |
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
|
132 return 0; |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
133 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
134 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
135 #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
|
136 |
0 | 137 /* Audio driver bootstrap functions */ |
138 | |
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 static int |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
140 ARTS_Available(void) |
0 | 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:
1402
diff
changeset
|
142 int available = 0; |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
143 |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
144 if (LoadARTSLibrary() == 0) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
145 if (SDL_NAME(arts_init) () == 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
|
146 #define ARTS_CRASH_HACK /* Play a stream so aRts doesn't crash */ |
929
03fb90fc135e
Date: Mon, 05 Jul 2004 14:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
864
diff
changeset
|
147 #ifdef ARTS_CRASH_HACK |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
148 arts_stream_t stream; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
149 stream = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL"); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
150 SDL_NAME(arts_write) (stream, "", 0); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
151 SDL_NAME(arts_close_stream) (stream); |
929
03fb90fc135e
Date: Mon, 05 Jul 2004 14:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
864
diff
changeset
|
152 #endif |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
153 available = 1; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
154 SDL_NAME(arts_free) (); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
155 } |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
156 UnloadARTSLibrary(); |
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
|
157 } |
474
583a07ab5444
Doh! Patch by Joel Ray Holveck
Sam Lantinga <slouken@libsdl.org>
parents:
301
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 return available; |
0 | 160 } |
161 | |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
162 |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
163 static int |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
164 ARTS_Init(SDL_AudioDriverImpl *impl) |
0 | 165 { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
166 /* Set the function pointers */ |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
167 impl->OpenDevice = ARTS_OpenDevice; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
168 impl->PlayDevice = ARTS_PlayDevice; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
169 impl->WaitDevice = ARTS_WaitDevice; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
170 impl->GetDeviceBuf = ARTS_GetDeviceBuf; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
171 impl->CloseDevice = ARTS_CloseDevice; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
172 impl->WaitDone = ARTS_WaitDone; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
173 impl->OnlyHasDefaultOutputDevice = 1; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
174 |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
175 return 1; |
0 | 176 } |
177 | |
178 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
179 AudioBootStrap ARTS_bootstrap = { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
180 ARTS_DRIVER_NAME, "Analog RealTime Synthesizer", |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
181 ARTS_Available, ARTS_Init, 0 |
0 | 182 }; |
183 | |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
184 |
0 | 185 /* 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
|
186 static void |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
187 ARTS_WaitDevice(_THIS) |
0 | 188 { |
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
|
189 Sint32 ticks; |
0 | 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:
1402
diff
changeset
|
191 /* 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
|
192 { |
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 int cnt = 0; |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
194 /* 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
|
195 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
|
196 */ |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
197 /* Check every 10 loops */ |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
198 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
|
199 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
|
200 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
|
201 } |
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
|
202 } |
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
|
203 } |
0 | 204 |
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
|
205 /* 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
|
206 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
|
207 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
|
208 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
|
209 } |
0 | 210 } |
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 void |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
213 ARTS_PlayDevice(_THIS) |
0 | 214 { |
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
|
215 /* Write the audio data */ |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
216 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
|
217 this->hidden->stream, |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
218 this->hidden->mixbuf, |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
219 this->hidden->mixlen); |
0 | 220 |
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
|
221 /* 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
|
222 if (this->hidden->frame_ticks) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
223 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
|
224 } |
0 | 225 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
226 /* 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
|
227 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
|
228 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
|
229 } |
0 | 230 #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
|
231 fprintf(stderr, "Wrote %d bytes of audio data\n", written); |
0 | 232 #endif |
233 } | |
234 | |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
235 static void |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
236 ARTS_WaitDone(_THIS) |
0 | 237 { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
238 /* !!! FIXME: camp here until buffer drains... SDL_Delay(???); */ |
0 | 239 } |
240 | |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
241 |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
242 static Uint8 * |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
243 ARTS_GetDeviceBuf(_THIS) |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
244 { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
245 return (this->hidden->mixbuf); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
246 } |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
247 |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
248 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
249 static void |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
250 ARTS_CloseDevice(_THIS) |
0 | 251 { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
252 if (this->hidden != NULL) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
253 if (this->hidden->mixbuf != NULL) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
254 SDL_FreeAudioMem(this->hidden->mixbuf); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
255 this->hidden->mixbuf = NULL; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
256 } |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
257 if (this->hidden->stream) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
258 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
|
259 this->hidden->stream = 0; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
260 } |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
261 SDL_NAME(arts_free) (); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
262 SDL_free(this->hidden); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
263 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
|
264 } |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
265 UnloadARTSLibrary(); |
0 | 266 } |
267 | |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
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 static int |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
270 ARTS_OpenDevice(_THIS, const char *devname, int iscapture) |
0 | 271 { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
272 int rc = 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
|
273 int bits, frag_spec; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
274 SDL_AudioFormat test_format, format; |
0 | 275 |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
276 /* 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
|
277 this->hidden = (struct SDL_PrivateAudioData *) |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
278 SDL_malloc((sizeof *this->hidden)); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
279 if (this->hidden == NULL) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
280 SDL_OutOfMemory(); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
281 return 0; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
282 } |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
283 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
0 | 284 |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
285 if (LoadARTSLibrary() < 0) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
286 ARTS_CloseDevice(this); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
287 SDL_SetError("ARTS: failed to load library: %s", SDL_GetError()); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
288 return 0; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
289 } |
0 | 290 |
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
|
291 /* Try for a closest match on audio 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
|
292 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
|
293 bits = 0; |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
294 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
|
295 !format && test_format;) { |
0 | 296 #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
|
297 fprintf(stderr, "Trying format 0x%4.4x\n", test_format); |
0 | 298 #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
|
299 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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 } |
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
|
312 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
|
313 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
|
314 } |
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
|
315 } |
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
|
316 if (format == 0) { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 } |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
321 this->spec.format = test_format; |
0 | 322 |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
323 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
|
324 ARTS_CloseDevice(this); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
325 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
|
326 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
|
327 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
|
328 } |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
329 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
|
330 this->spec.freq, |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
331 bits, this->spec.channels, |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
332 "SDL"); |
0 | 333 |
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
|
334 /* 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
|
335 SDL_CalculateAudioSpec(&this->spec); |
0 | 336 |
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
|
337 /* 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 } |
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
|
344 frag_spec |= 0x00020000; /* two fragments, for low latency */ |
0 | 345 |
346 #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
|
347 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
|
348 ARTS_P_PACKET_SETTINGS, frag_spec); |
0 | 349 #else |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
350 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
|
351 frag_spec & 0xffff); |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
352 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
|
353 frag_spec >> 16); |
0 | 354 #endif |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
355 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
|
356 ARTS_P_PACKET_SIZE); |
0 | 357 |
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
|
358 /* Allocate mixing buffer */ |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
359 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
|
360 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
|
361 if (this->hidden->mixbuf == NULL) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
362 ARTS_CloseDevice(this); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
363 SDL_OutOfMemory(); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
364 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
|
365 } |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
366 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); |
0 | 367 |
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
|
368 /* 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
|
369 this->hidden->parent = getpid(); |
0 | 370 |
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
|
371 /* 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
|
372 return 1; |
0 | 373 } |
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
|
374 |
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
|
375 /* vi: set ts=4 sw=4 expandtab: */ |