Mercurial > sdl-ios-xcode
annotate src/audio/arts/SDL_artsaudio.c @ 3812:35d1367020a3 SDL-ryan-multiple-audio-device
Updated arts driver for 1.3 audio API.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 06 Oct 2006 02:40:02 +0000 |
parents | 7852b5b78af5 |
children | 92f7304e50ff |
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 static int arts_loaded = 0; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
55 |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
56 /* !!! 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 const char *name); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
72 #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
|
73 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
|
74 { |
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 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
|
76 void **func; |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
77 } arts_functions[] = { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
78 SDL_ARTS_SYM(arts_init), |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
79 SDL_ARTS_SYM(arts_free), |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 SDL_ARTS_SYM(arts_write), |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
84 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
|
85 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
|
86 }; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
87 #undef SDL_ARTS_SYM |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
88 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
89 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
|
90 UnloadARTSLibrary() |
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 if (arts_loaded) { |
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 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
|
94 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
|
95 arts_loaded = 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
|
96 } |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
97 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
98 |
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
|
99 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
|
100 LoadARTSLibrary(void) |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
101 { |
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
|
102 int i, retval = -1; |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
103 |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
104 if (!arts_loaded) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
105 arts_handle = SDL_LoadObject(arts_library); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
106 if (arts_handle) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
107 arts_loaded = 1; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
108 retval = 0; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
109 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
|
110 *arts_functions[i].func = |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
111 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
|
112 if (!*arts_functions[i].func) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
113 retval = -1; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
114 UnloadARTSLibrary(); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
115 break; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
116 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
117 } |
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 } |
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
|
119 } |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
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 return retval; |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
122 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
123 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
124 #else |
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 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
|
127 UnloadARTSLibrary() |
294
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 return; |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
130 } |
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 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
|
133 LoadARTSLibrary(void) |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
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 return 0; |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
136 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
137 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
138 #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
|
139 |
0 | 140 /* Audio driver bootstrap functions */ |
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 static int |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
143 ARTS_Available(void) |
0 | 144 { |
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
|
145 int available = 0; |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
146 |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
147 if (LoadARTSLibrary() == 0) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
148 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
|
149 #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
|
150 #ifdef ARTS_CRASH_HACK |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
151 arts_stream_t stream; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 #endif |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
156 available = 1; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
157 SDL_NAME(arts_free) (); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
158 } |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
159 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
|
160 } |
474
583a07ab5444
Doh! Patch by Joel Ray Holveck
Sam Lantinga <slouken@libsdl.org>
parents:
301
diff
changeset
|
161 |
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
|
162 return available; |
0 | 163 } |
164 | |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
165 |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
166 static int |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
167 ARTS_Init(SDL_AudioDriverImpl *impl) |
0 | 168 { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
169 /* Set the function pointers */ |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
170 impl->OpenDevice = ARTS_OpenDevice; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
171 impl->PlayDevice = ARTS_PlayDevice; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
172 impl->WaitDevice = ARTS_WaitDevice; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
173 impl->GetDeviceBuf = ARTS_GetDeviceBuf; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
174 impl->CloseDevice = ARTS_CloseDevice; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
175 impl->WaitDone = ARTS_WaitDone; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
176 impl->OnlyHasDefaultOutputDevice = 1; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
177 |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
178 return 1; |
0 | 179 } |
180 | |
181 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
182 AudioBootStrap ARTS_bootstrap = { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
183 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
|
184 ARTS_Available, ARTS_Init, 0 |
0 | 185 }; |
186 | |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
187 |
0 | 188 /* 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
|
189 static void |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
190 ARTS_WaitDevice(_THIS) |
0 | 191 { |
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
|
192 Sint32 ticks; |
0 | 193 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
194 /* 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
|
195 { |
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 static int cnt = 0; |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
197 /* 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
|
198 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
|
199 */ |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
200 /* Check every 10 loops */ |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
201 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
|
202 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
|
203 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
|
204 } |
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 } |
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
|
206 } |
0 | 207 |
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 /* 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
|
209 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
|
210 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
|
211 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
|
212 } |
0 | 213 } |
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 static void |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
216 ARTS_PlayDevice(_THIS) |
0 | 217 { |
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
|
218 /* Write the audio data */ |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
219 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
|
220 this->hidden->stream, |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
221 this->hidden->mixbuf, |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
222 this->hidden->mixlen); |
0 | 223 |
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 /* 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
|
225 if (this->hidden->frame_ticks) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
226 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
|
227 } |
0 | 228 |
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
|
229 /* 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
|
230 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
|
231 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
|
232 } |
0 | 233 #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
|
234 fprintf(stderr, "Wrote %d bytes of audio data\n", written); |
0 | 235 #endif |
236 } | |
237 | |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
238 static void |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
239 ARTS_WaitDone(_THIS) |
0 | 240 { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
241 /* !!! FIXME: camp here until buffer drains... SDL_Delay(???); */ |
0 | 242 } |
243 | |
3812
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 static Uint8 * |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
246 ARTS_GetDeviceBuf(_THIS) |
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 return (this->hidden->mixbuf); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
249 } |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
250 |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
251 |
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
|
252 static void |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
253 ARTS_CloseDevice(_THIS) |
0 | 254 { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
255 if (this->hidden != NULL) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
256 if (this->hidden->mixbuf != NULL) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
257 SDL_FreeAudioMem(this->hidden->mixbuf); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
258 this->hidden->mixbuf = NULL; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
259 } |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
260 if (this->hidden->stream) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
261 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
|
262 this->hidden->stream = 0; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
263 } |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
264 SDL_NAME(arts_free) (); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
265 SDL_free(this->hidden); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
266 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
|
267 } |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
268 UnloadARTSLibrary(); |
0 | 269 } |
270 | |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
271 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
272 static int |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
273 ARTS_OpenDevice(_THIS, const char *devname, int iscapture) |
0 | 274 { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
275 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
|
276 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
|
277 SDL_AudioFormat test_format, format; |
0 | 278 |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
279 /* 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
|
280 this->hidden = (struct SDL_PrivateAudioData *) |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
281 SDL_malloc((sizeof *this->hidden)); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
282 if (this->hidden == NULL) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
283 SDL_OutOfMemory(); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
284 return 0; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
285 } |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
286 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
0 | 287 |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
288 if (LoadARTSLibrary() < 0) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
289 ARTS_CloseDevice(this); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
290 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
|
291 return 0; |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
292 } |
0 | 293 |
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
|
294 /* 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
|
295 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
|
296 bits = 0; |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
297 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
|
298 !format && test_format;) { |
0 | 299 #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
|
300 fprintf(stderr, "Trying format 0x%4.4x\n", test_format); |
0 | 301 #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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
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 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
|
312 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
|
313 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
|
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 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
|
316 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
|
317 } |
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 } |
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
|
319 if (format == 0) { |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
320 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
|
321 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
|
322 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
|
323 } |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
324 this->spec.format = test_format; |
0 | 325 |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
326 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
|
327 ARTS_CloseDevice(this); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
328 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
|
329 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
|
330 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
|
331 } |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
332 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
|
333 this->spec.freq, |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
334 bits, this->spec.channels, |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
335 "SDL"); |
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 /* 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
|
338 SDL_CalculateAudioSpec(&this->spec); |
0 | 339 |
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
|
340 /* 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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 } |
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
|
347 frag_spec |= 0x00020000; /* two fragments, for low latency */ |
0 | 348 |
349 #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
|
350 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
|
351 ARTS_P_PACKET_SETTINGS, frag_spec); |
0 | 352 #else |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
353 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
|
354 frag_spec & 0xffff); |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
355 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
|
356 frag_spec >> 16); |
0 | 357 #endif |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
358 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
|
359 ARTS_P_PACKET_SIZE); |
0 | 360 |
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
|
361 /* Allocate mixing buffer */ |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
362 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
|
363 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
|
364 if (this->hidden->mixbuf == NULL) { |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
365 ARTS_CloseDevice(this); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
366 SDL_OutOfMemory(); |
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
367 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
|
368 } |
3812
35d1367020a3
Updated arts driver for 1.3 audio API.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
369 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); |
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 /* 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
|
372 this->hidden->parent = getpid(); |
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 /* 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
|
375 return 1; |
0 | 376 } |
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
|
377 |
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
|
378 /* vi: set ts=4 sw=4 expandtab: */ |