Mercurial > sdl-ios-xcode
annotate src/audio/esd/SDL_esdaudio.c @ 1312:c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
I batch edited these files, so please let me know if I've accidentally removed anybody's
credit here.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 01 Feb 2006 06:32:25 +0000 |
parents | 0c892e99b65b |
children | 3692456e7b0f |
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:
864
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:
864
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:
864
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:
864
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:
864
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
864
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
864
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 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 an ESD network stream mixing buffer */ | |
24 | |
25 #ifdef ESD_SUPPORT | |
26 | |
27 #include <stdlib.h> | |
28 #include <stdio.h> | |
29 #include <string.h> | |
30 #include <errno.h> | |
31 #include <signal.h> | |
32 #include <unistd.h> | |
33 | |
34 #include <esd.h> | |
35 | |
36 #include "SDL_audio.h" | |
37 #include "SDL_error.h" | |
38 #include "SDL_audiomem.h" | |
39 #include "SDL_audio_c.h" | |
40 #include "SDL_timer.h" | |
41 #include "SDL_audiodev_c.h" | |
42 #include "SDL_esdaudio.h" | |
43 | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
44 #ifdef ESD_DYNAMIC |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
45 #include "SDL_name.h" |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
46 #include "SDL_loadso.h" |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
47 #else |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
48 #define SDL_NAME(X) X |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
49 #endif |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
50 |
0 | 51 /* The tag name used by ESD audio */ |
52 #define ESD_DRIVER_NAME "esd" | |
53 | |
54 /* Audio driver functions */ | |
55 static int ESD_OpenAudio(_THIS, SDL_AudioSpec *spec); | |
56 static void ESD_WaitAudio(_THIS); | |
57 static void ESD_PlayAudio(_THIS); | |
58 static Uint8 *ESD_GetAudioBuf(_THIS); | |
59 static void ESD_CloseAudio(_THIS); | |
60 | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
61 #ifdef ESD_DYNAMIC |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
62 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
63 static const char *esd_library = ESD_DYNAMIC; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
64 static void *esd_handle = NULL; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
65 static int esd_loaded = 0; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
66 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
67 static int (*SDL_NAME(esd_open_sound))( const char *host ); |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
68 static int (*SDL_NAME(esd_close))( int esd ); |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
69 static int (*SDL_NAME(esd_play_stream))( esd_format_t format, int rate, |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
70 const char *host, const char *name ); |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
71 static struct { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
72 const char *name; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
73 void **func; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
74 } esd_functions[] = { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
75 { "esd_open_sound", (void **)&SDL_NAME(esd_open_sound) }, |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
76 { "esd_close", (void **)&SDL_NAME(esd_close) }, |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
77 { "esd_play_stream", (void **)&SDL_NAME(esd_play_stream) }, |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
78 }; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
79 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
80 static void UnloadESDLibrary() |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
81 { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
82 if ( esd_loaded ) { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
83 SDL_UnloadObject(esd_handle); |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
84 esd_handle = NULL; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
85 esd_loaded = 0; |
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 } |
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 static int LoadESDLibrary(void) |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
90 { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
91 int i, retval = -1; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
92 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
93 esd_handle = SDL_LoadObject(esd_library); |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
94 if ( esd_handle ) { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
95 esd_loaded = 1; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
96 retval = 0; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
97 for ( i=0; i<SDL_TABLESIZE(esd_functions); ++i ) { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
98 *esd_functions[i].func = SDL_LoadFunction(esd_handle, esd_functions[i].name); |
864
0c892e99b65b
Date: Sun, 29 Feb 2004 20:28:27 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
99 if ( !*esd_functions[i].func ) { |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
100 retval = -1; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
101 UnloadESDLibrary(); |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
102 break; |
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 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
106 return retval; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
107 } |
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 #else |
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 static void UnloadESDLibrary() |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
112 { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
113 return; |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
114 } |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
115 |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
116 static int LoadESDLibrary(void) |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
117 { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
118 return 0; |
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 #endif /* ESD_DYNAMIC */ |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
122 |
0 | 123 /* Audio driver bootstrap functions */ |
124 | |
125 static int Audio_Available(void) | |
126 { | |
127 int connection; | |
128 int available; | |
129 | |
130 available = 0; | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
131 if ( LoadESDLibrary() < 0 ) { |
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
132 return available; |
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 connection = SDL_NAME(esd_open_sound)(NULL); |
0 | 135 if ( connection >= 0 ) { |
136 available = 1; | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
137 SDL_NAME(esd_close)(connection); |
0 | 138 } |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
139 UnloadESDLibrary(); |
0 | 140 return(available); |
141 } | |
142 | |
143 static void Audio_DeleteDevice(SDL_AudioDevice *device) | |
144 { | |
145 free(device->hidden); | |
146 free(device); | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
147 UnloadESDLibrary(); |
0 | 148 } |
149 | |
150 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | |
151 { | |
152 SDL_AudioDevice *this; | |
153 | |
154 /* 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
|
155 LoadESDLibrary(); |
0 | 156 this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice)); |
157 if ( this ) { | |
158 memset(this, 0, (sizeof *this)); | |
159 this->hidden = (struct SDL_PrivateAudioData *) | |
160 malloc((sizeof *this->hidden)); | |
161 } | |
162 if ( (this == NULL) || (this->hidden == NULL) ) { | |
163 SDL_OutOfMemory(); | |
164 if ( this ) { | |
165 free(this); | |
166 } | |
167 return(0); | |
168 } | |
169 memset(this->hidden, 0, (sizeof *this->hidden)); | |
170 audio_fd = -1; | |
171 | |
172 /* Set the function pointers */ | |
173 this->OpenAudio = ESD_OpenAudio; | |
174 this->WaitAudio = ESD_WaitAudio; | |
175 this->PlayAudio = ESD_PlayAudio; | |
176 this->GetAudioBuf = ESD_GetAudioBuf; | |
177 this->CloseAudio = ESD_CloseAudio; | |
178 | |
179 this->free = Audio_DeleteDevice; | |
180 | |
181 return this; | |
182 } | |
183 | |
184 AudioBootStrap ESD_bootstrap = { | |
185 ESD_DRIVER_NAME, "Enlightened Sound Daemon", | |
186 Audio_Available, Audio_CreateDevice | |
187 }; | |
188 | |
189 /* This function waits until it is possible to write a full sound buffer */ | |
190 static void ESD_WaitAudio(_THIS) | |
191 { | |
192 Sint32 ticks; | |
193 | |
194 /* Check to see if the thread-parent process is still alive */ | |
195 { static int cnt = 0; | |
196 /* Note that this only works with thread implementations | |
197 that use a different process id for each thread. | |
198 */ | |
199 if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */ | |
200 if ( kill(parent, 0) < 0 ) { | |
201 this->enabled = 0; | |
202 } | |
203 } | |
204 } | |
205 | |
206 /* Use timer for general audio synchronization */ | |
207 ticks = ((Sint32)(next_frame - SDL_GetTicks()))-FUDGE_TICKS; | |
208 if ( ticks > 0 ) { | |
209 SDL_Delay(ticks); | |
210 } | |
211 } | |
212 | |
213 static void ESD_PlayAudio(_THIS) | |
214 { | |
215 int written; | |
216 | |
217 /* Write the audio data, checking for EAGAIN on broken audio drivers */ | |
218 do { | |
219 written = write(audio_fd, mixbuf, mixlen); | |
220 if ( (written < 0) && ((errno == 0) || (errno == EAGAIN)) ) { | |
221 SDL_Delay(1); /* Let a little CPU time go by */ | |
222 } | |
223 } while ( (written < 0) && | |
224 ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)) ); | |
225 | |
226 /* Set the next write frame */ | |
227 next_frame += frame_ticks; | |
228 | |
229 /* If we couldn't write, assume fatal error for now */ | |
230 if ( written < 0 ) { | |
231 this->enabled = 0; | |
232 } | |
233 } | |
234 | |
235 static Uint8 *ESD_GetAudioBuf(_THIS) | |
236 { | |
237 return(mixbuf); | |
238 } | |
239 | |
240 static void ESD_CloseAudio(_THIS) | |
241 { | |
242 if ( mixbuf != NULL ) { | |
243 SDL_FreeAudioMem(mixbuf); | |
244 mixbuf = NULL; | |
245 } | |
246 if ( audio_fd >= 0 ) { | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
247 SDL_NAME(esd_close)(audio_fd); |
0 | 248 audio_fd = -1; |
249 } | |
250 } | |
251 | |
252 /* Try to get the name of the program */ | |
253 static char *get_progname(void) | |
254 { | |
255 char *progname = NULL; | |
256 #ifdef linux | |
257 FILE *fp; | |
258 static char temp[BUFSIZ]; | |
259 | |
260 sprintf(temp, "/proc/%d/cmdline", getpid()); | |
261 fp = fopen(temp, "r"); | |
262 if ( fp != NULL ) { | |
263 if ( fgets(temp, sizeof(temp)-1, fp) ) { | |
264 progname = strrchr(temp, '/'); | |
265 if ( progname == NULL ) { | |
266 progname = temp; | |
267 } else { | |
268 progname = progname+1; | |
269 } | |
270 } | |
271 fclose(fp); | |
272 } | |
273 #endif | |
274 return(progname); | |
275 } | |
276 | |
277 static int ESD_OpenAudio(_THIS, SDL_AudioSpec *spec) | |
278 { | |
279 esd_format_t format; | |
280 | |
281 /* Convert audio spec to the ESD audio format */ | |
282 format = (ESD_STREAM | ESD_PLAY); | |
283 switch ( spec->format & 0xFF ) { | |
284 case 8: | |
285 format |= ESD_BITS8; | |
286 break; | |
287 case 16: | |
288 format |= ESD_BITS16; | |
289 break; | |
290 default: | |
291 SDL_SetError("Unsupported ESD audio format"); | |
292 return(-1); | |
293 } | |
294 if ( spec->channels == 1 ) { | |
295 format |= ESD_MONO; | |
296 } else { | |
297 format |= ESD_STEREO; | |
298 } | |
299 #if 0 | |
300 spec->samples = ESD_BUF_SIZE; /* Darn, no way to change this yet */ | |
301 #endif | |
302 | |
303 /* Open a connection to the ESD audio server */ | |
294
d2d48e10f370
Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
304 audio_fd = SDL_NAME(esd_play_stream)(format, spec->freq, NULL, get_progname()); |
0 | 305 if ( audio_fd < 0 ) { |
306 SDL_SetError("Couldn't open ESD connection"); | |
307 return(-1); | |
308 } | |
309 | |
310 /* Calculate the final parameters for this audio specification */ | |
311 SDL_CalculateAudioSpec(spec); | |
312 frame_ticks = (float)(spec->samples*1000)/spec->freq; | |
313 next_frame = SDL_GetTicks()+frame_ticks; | |
314 | |
315 /* Allocate mixing buffer */ | |
316 mixlen = spec->size; | |
317 mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen); | |
318 if ( mixbuf == NULL ) { | |
319 return(-1); | |
320 } | |
321 memset(mixbuf, spec->silence, spec->size); | |
322 | |
323 /* Get the parent process id (we're the parent of the audio thread) */ | |
324 parent = getpid(); | |
325 | |
326 /* We're ready to rock and roll. :-) */ | |
327 return(0); | |
328 } | |
329 | |
330 #endif /* ESD_SUPPORT */ |