Mercurial > sdl-ios-xcode
annotate src/audio/arts/SDL_artsaudio.c @ 1358:c71e05b4dc2e
More header massaging... works great on Windows. ;-)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 10 Feb 2006 06:48:43 +0000 |
parents | 604d73db6802 |
children | 19418e4422cb |
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 */ |
22 | |
23 /* Allow access to a raw mixing buffer */ | |
24 | |
1358
c71e05b4dc2e
More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
25 #include "SDL_timer.h" |
0 | 26 #include "SDL_audio.h" |
27 #include "SDL_audiomem.h" | |
28 #include "SDL_audio_c.h" | |
29 #include "SDL_audiodev_c.h" | |
30 #include "SDL_artsaudio.h" | |
31 | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
32 #ifdef ARTSC_DYNAMIC |
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 */ |
956
4263beff9e38
Date: Mon, 30 Aug 2004 18:20:25 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
929
diff
changeset
|
40 #define ARTSC_DRIVER_NAME "arts" |
0 | 41 |
42 /* Audio driver functions */ | |
43 static int ARTSC_OpenAudio(_THIS, SDL_AudioSpec *spec); | |
44 static void ARTSC_WaitAudio(_THIS); | |
45 static void ARTSC_PlayAudio(_THIS); | |
46 static Uint8 *ARTSC_GetAudioBuf(_THIS); | |
47 static void ARTSC_CloseAudio(_THIS); | |
48 | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
49 #ifdef ARTSC_DYNAMIC |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
50 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
51 static const char *arts_library = ARTSC_DYNAMIC; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
52 static void *arts_handle = NULL; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
53 static int arts_loaded = 0; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
54 |
301
fb4c4c6a2773
Fixed dynamic arts support.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
55 static int (*SDL_NAME(arts_init))(void); |
fb4c4c6a2773
Fixed dynamic arts support.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
56 static void (*SDL_NAME(arts_free))(void); |
fb4c4c6a2773
Fixed dynamic arts support.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
57 static arts_stream_t (*SDL_NAME(arts_play_stream))(int rate, int bits, int channels, const char *name); |
fb4c4c6a2773
Fixed dynamic arts support.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
58 static int (*SDL_NAME(arts_stream_set))(arts_stream_t s, arts_parameter_t param, int value); |
fb4c4c6a2773
Fixed dynamic arts support.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
59 static int (*SDL_NAME(arts_stream_get))(arts_stream_t s, arts_parameter_t param); |
fb4c4c6a2773
Fixed dynamic arts support.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
60 static int (*SDL_NAME(arts_write))(arts_stream_t s, const void *buffer, int count); |
fb4c4c6a2773
Fixed dynamic arts support.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
61 static void (*SDL_NAME(arts_close_stream))(arts_stream_t s); |
fb4c4c6a2773
Fixed dynamic arts support.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
62 |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
63 static struct { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
64 const char *name; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
65 void **func; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
66 } arts_functions[] = { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
67 { "arts_init", (void **)&SDL_NAME(arts_init) }, |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
68 { "arts_free", (void **)&SDL_NAME(arts_free) }, |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
69 { "arts_play_stream", (void **)&SDL_NAME(arts_play_stream) }, |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
70 { "arts_stream_set", (void **)&SDL_NAME(arts_stream_set) }, |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
71 { "arts_stream_get", (void **)&SDL_NAME(arts_stream_get) }, |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
72 { "arts_write", (void **)&SDL_NAME(arts_write) }, |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
73 { "arts_close_stream", (void **)&SDL_NAME(arts_close_stream) }, |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
74 }; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
75 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
76 static void UnloadARTSLibrary() |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
77 { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
78 if ( arts_loaded ) { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
79 SDL_UnloadObject(arts_handle); |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
80 arts_handle = NULL; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
81 arts_loaded = 0; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
82 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
83 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
84 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
85 static int LoadARTSLibrary(void) |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
86 { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
87 int i, retval = -1; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
88 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
89 arts_handle = SDL_LoadObject(arts_library); |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
90 if ( arts_handle ) { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
91 arts_loaded = 1; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
92 retval = 0; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
93 for ( i=0; i<SDL_TABLESIZE(arts_functions); ++i ) { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
94 *arts_functions[i].func = SDL_LoadFunction(arts_handle, arts_functions[i].name); |
864
0c892e99b65b
Date: Sun, 29 Feb 2004 20:28:27 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
95 if ( !*arts_functions[i].func ) { |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
96 retval = -1; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
97 UnloadARTSLibrary(); |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
98 break; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
99 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
100 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
101 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
102 return retval; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
103 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
104 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
105 #else |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
106 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
107 static void UnloadARTSLibrary() |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
108 { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
109 return; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
110 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
111 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
112 static int LoadARTSLibrary(void) |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
113 { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
114 return 0; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
115 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
116 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
117 #endif /* ARTSC_DYNAMIC */ |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
118 |
0 | 119 /* Audio driver bootstrap functions */ |
120 | |
121 static int Audio_Available(void) | |
122 { | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
123 int available = 0; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
124 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
125 if ( LoadARTSLibrary() < 0 ) { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
126 return available; |
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 if ( SDL_NAME(arts_init)() == 0 ) { |
929
03fb90fc135e
Date: Mon, 05 Jul 2004 14:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
864
diff
changeset
|
129 #define ARTS_CRASH_HACK /* Play a stream so aRts doesn't crash */ |
03fb90fc135e
Date: Mon, 05 Jul 2004 14:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
864
diff
changeset
|
130 #ifdef ARTS_CRASH_HACK |
03fb90fc135e
Date: Mon, 05 Jul 2004 14:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
864
diff
changeset
|
131 arts_stream_t stream2; |
03fb90fc135e
Date: Mon, 05 Jul 2004 14:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
864
diff
changeset
|
132 stream2=SDL_NAME(arts_play_stream)(44100, 16, 2, "SDL"); |
03fb90fc135e
Date: Mon, 05 Jul 2004 14:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
864
diff
changeset
|
133 SDL_NAME(arts_write)(stream2, "", 0); |
03fb90fc135e
Date: Mon, 05 Jul 2004 14:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
864
diff
changeset
|
134 SDL_NAME(arts_close_stream)(stream2); |
03fb90fc135e
Date: Mon, 05 Jul 2004 14:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
864
diff
changeset
|
135 #endif |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
136 available = 1; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
137 SDL_NAME(arts_free)(); |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
138 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
139 UnloadARTSLibrary(); |
474
583a07ab5444
Doh! Patch by Joel Ray Holveck
Sam Lantinga <slouken@libsdl.org>
parents:
301
diff
changeset
|
140 |
583a07ab5444
Doh! Patch by Joel Ray Holveck
Sam Lantinga <slouken@libsdl.org>
parents:
301
diff
changeset
|
141 return available; |
0 | 142 } |
143 | |
144 static void Audio_DeleteDevice(SDL_AudioDevice *device) | |
145 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
146 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
147 SDL_free(device); |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
148 UnloadARTSLibrary(); |
0 | 149 } |
150 | |
151 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | |
152 { | |
153 SDL_AudioDevice *this; | |
154 | |
155 /* Initialize all variables that we clean on shutdown */ | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
156 LoadARTSLibrary(); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
157 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); |
0 | 158 if ( this ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
159 SDL_memset(this, 0, (sizeof *this)); |
0 | 160 this->hidden = (struct SDL_PrivateAudioData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
161 SDL_malloc((sizeof *this->hidden)); |
0 | 162 } |
163 if ( (this == NULL) || (this->hidden == NULL) ) { | |
164 SDL_OutOfMemory(); | |
165 if ( this ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
166 SDL_free(this); |
0 | 167 } |
168 return(0); | |
169 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
170 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
0 | 171 stream = 0; |
172 | |
173 /* Set the function pointers */ | |
174 this->OpenAudio = ARTSC_OpenAudio; | |
175 this->WaitAudio = ARTSC_WaitAudio; | |
176 this->PlayAudio = ARTSC_PlayAudio; | |
177 this->GetAudioBuf = ARTSC_GetAudioBuf; | |
178 this->CloseAudio = ARTSC_CloseAudio; | |
179 | |
180 this->free = Audio_DeleteDevice; | |
181 | |
182 return this; | |
183 } | |
184 | |
185 AudioBootStrap ARTSC_bootstrap = { | |
186 ARTSC_DRIVER_NAME, "Analog Realtime Synthesizer", | |
187 Audio_Available, Audio_CreateDevice | |
188 }; | |
189 | |
190 /* This function waits until it is possible to write a full sound buffer */ | |
191 static void ARTSC_WaitAudio(_THIS) | |
192 { | |
193 Sint32 ticks; | |
194 | |
195 /* Check to see if the thread-parent process is still alive */ | |
196 { static int cnt = 0; | |
197 /* Note that this only works with thread implementations | |
198 that use a different process id for each thread. | |
199 */ | |
200 if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */ | |
201 if ( kill(parent, 0) < 0 ) { | |
202 this->enabled = 0; | |
203 } | |
204 } | |
205 } | |
206 | |
207 /* Use timer for general audio synchronization */ | |
208 ticks = ((Sint32)(next_frame - SDL_GetTicks()))-FUDGE_TICKS; | |
209 if ( ticks > 0 ) { | |
210 SDL_Delay(ticks); | |
211 } | |
212 } | |
213 | |
214 static void ARTSC_PlayAudio(_THIS) | |
215 { | |
216 int written; | |
217 | |
218 /* Write the audio data */ | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
219 written = SDL_NAME(arts_write)(stream, mixbuf, mixlen); |
0 | 220 |
221 /* If timer synchronization is enabled, set the next write frame */ | |
222 if ( frame_ticks ) { | |
223 next_frame += frame_ticks; | |
224 } | |
225 | |
226 /* If we couldn't write, assume fatal error for now */ | |
227 if ( written < 0 ) { | |
228 this->enabled = 0; | |
229 } | |
230 #ifdef DEBUG_AUDIO | |
231 fprintf(stderr, "Wrote %d bytes of audio data\n", written); | |
232 #endif | |
233 } | |
234 | |
235 static Uint8 *ARTSC_GetAudioBuf(_THIS) | |
236 { | |
237 return(mixbuf); | |
238 } | |
239 | |
240 static void ARTSC_CloseAudio(_THIS) | |
241 { | |
242 if ( mixbuf != NULL ) { | |
243 SDL_FreeAudioMem(mixbuf); | |
244 mixbuf = NULL; | |
245 } | |
246 if ( stream ) { | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
247 SDL_NAME(arts_close_stream)(stream); |
0 | 248 stream = 0; |
249 } | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
250 SDL_NAME(arts_free)(); |
0 | 251 } |
252 | |
253 static int ARTSC_OpenAudio(_THIS, SDL_AudioSpec *spec) | |
254 { | |
255 int bits, frag_spec; | |
256 Uint16 test_format, format; | |
257 | |
258 /* Reset the timer synchronization flag */ | |
259 frame_ticks = 0.0; | |
260 | |
261 mixbuf = NULL; | |
262 | |
263 /* Try for a closest match on audio format */ | |
264 format = 0; | |
265 bits = 0; | |
266 for ( test_format = SDL_FirstAudioFormat(spec->format); | |
267 ! format && test_format; ) { | |
268 #ifdef DEBUG_AUDIO | |
269 fprintf(stderr, "Trying format 0x%4.4x\n", test_format); | |
270 #endif | |
271 switch ( test_format ) { | |
272 case AUDIO_U8: | |
273 bits = 8; | |
274 format = 1; | |
275 break; | |
276 case AUDIO_S16LSB: | |
277 bits = 16; | |
278 format = 1; | |
279 break; | |
280 default: | |
281 format = 0; | |
282 break; | |
283 } | |
284 if ( ! format ) { | |
285 test_format = SDL_NextAudioFormat(); | |
286 } | |
287 } | |
288 if ( format == 0 ) { | |
289 SDL_SetError("Couldn't find any hardware audio formats"); | |
290 return(-1); | |
291 } | |
292 spec->format = test_format; | |
293 | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
294 if ( SDL_NAME(arts_init)() != 0 ) { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
295 SDL_SetError("Unable to initialize ARTS"); |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
296 return(-1); |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
297 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
298 stream = SDL_NAME(arts_play_stream)(spec->freq, bits, spec->channels, "SDL"); |
0 | 299 |
300 /* Calculate the final parameters for this audio specification */ | |
301 SDL_CalculateAudioSpec(spec); | |
302 | |
303 /* Determine the power of two of the fragment size */ | |
304 for ( frag_spec = 0; (0x01<<frag_spec) < spec->size; ++frag_spec ); | |
305 if ( (0x01<<frag_spec) != spec->size ) { | |
306 SDL_SetError("Fragment size must be a power of two"); | |
307 return(-1); | |
308 } | |
309 frag_spec |= 0x00020000; /* two fragments, for low latency */ | |
310 | |
311 #ifdef ARTS_P_PACKET_SETTINGS | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
312 SDL_NAME(arts_stream_set)(stream, ARTS_P_PACKET_SETTINGS, frag_spec); |
0 | 313 #else |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
314 SDL_NAME(arts_stream_set)(stream, ARTS_P_PACKET_SIZE, frag_spec&0xffff); |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
315 SDL_NAME(arts_stream_set)(stream, ARTS_P_PACKET_COUNT, frag_spec>>16); |
0 | 316 #endif |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
317 spec->size = SDL_NAME(arts_stream_get)(stream, ARTS_P_PACKET_SIZE); |
0 | 318 |
319 /* Allocate mixing buffer */ | |
320 mixlen = spec->size; | |
321 mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen); | |
322 if ( mixbuf == NULL ) { | |
323 return(-1); | |
324 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
325 SDL_memset(mixbuf, spec->silence, spec->size); |
0 | 326 |
327 /* Get the parent process id (we're the parent of the audio thread) */ | |
328 parent = getpid(); | |
329 | |
330 /* We're ready to rock and roll. :-) */ | |
331 return(0); | |
332 } |