Mercurial > sdl-ios-xcode
comparison src/audio/macosx/SDL_coreaudio.c @ 3790:8f8209f8da6d SDL-ryan-multiple-audio-device
Added audio device enumeration for 1.3.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 03 Oct 2006 20:07:50 +0000 |
parents | 7006b176ef4f |
children | 866c310e2cb5 |
comparison
equal
deleted
inserted
replaced
3789:e2f68b579a01 | 3790:8f8209f8da6d |
---|---|
27 #include "SDL_audio.h" | 27 #include "SDL_audio.h" |
28 #include "../SDL_audio_c.h" | 28 #include "../SDL_audio_c.h" |
29 #include "../SDL_sysaudio.h" | 29 #include "../SDL_sysaudio.h" |
30 #include "SDL_coreaudio.h" | 30 #include "SDL_coreaudio.h" |
31 | 31 |
32 #define DEBUG_COREAUDIO 1 | 32 #define DEBUG_COREAUDIO 0 |
33 | 33 |
34 typedef struct COREAUDIO_DeviceList | 34 typedef struct COREAUDIO_DeviceList |
35 { | 35 { |
36 AudioDeviceID id; | 36 AudioDeviceID id; |
37 const char *name; | 37 const char *name; |
167 (*devCount)++; | 167 (*devCount)++; |
168 } | 168 } |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 static inline void | |
173 build_device_lists(void) | |
174 { | |
175 build_device_list(0, &outputDevices, &outputDeviceCount); | |
176 build_device_list(1, &inputDevices, &inputDeviceCount); | |
177 } | |
178 | |
179 | |
180 static inline void | |
181 free_device_lists(void) | |
182 { | |
183 free_device_list(&outputDevices, &outputDeviceCount); | |
184 free_device_list(&inputDevices, &inputDeviceCount); | |
185 } | |
186 | |
187 | |
172 static int | 188 static int |
173 find_device_id(const char *devname, int iscapture, AudioDeviceID *id) | 189 find_device_id(const char *devname, int iscapture, AudioDeviceID *id) |
174 { | 190 { |
175 int i = ((iscapture) ? inputDeviceCount : outputDeviceCount); | 191 int i = ((iscapture) ? inputDeviceCount : outputDeviceCount); |
176 COREAUDIO_DeviceList *devs = ((iscapture) ? inputDevices : outputDevices); | 192 COREAUDIO_DeviceList *devs = ((iscapture) ? inputDevices : outputDevices); |
186 } | 202 } |
187 | 203 |
188 | 204 |
189 /* Audio driver functions */ | 205 /* Audio driver functions */ |
190 | 206 |
207 static int COREAUDIO_DetectDevices(int iscapture); | |
208 static const char *COREAUDIO_GetAudioDevice(int index, int iscapture); | |
191 static int COREAUDIO_OpenAudio(_THIS, const char *devname, int iscapture); | 209 static int COREAUDIO_OpenAudio(_THIS, const char *devname, int iscapture); |
192 static void COREAUDIO_WaitAudio(_THIS); | 210 static void COREAUDIO_WaitAudio(_THIS); |
193 static void COREAUDIO_PlayAudio(_THIS); | 211 static void COREAUDIO_PlayAudio(_THIS); |
194 static Uint8 *COREAUDIO_GetAudioBuf(_THIS); | 212 static Uint8 *COREAUDIO_GetAudioBuf(_THIS); |
195 static void COREAUDIO_CloseAudio(_THIS); | 213 static void COREAUDIO_CloseAudio(_THIS); |
204 } | 222 } |
205 | 223 |
206 static int | 224 static int |
207 COREAUDIO_Init(SDL_AudioDriverImpl *impl) | 225 COREAUDIO_Init(SDL_AudioDriverImpl *impl) |
208 { | 226 { |
209 /* !!! FIXME: should these _really_ be static? */ | |
210 build_device_list(0, &outputDevices, &outputDeviceCount); | |
211 build_device_list(1, &inputDevices, &inputDeviceCount); | |
212 | |
213 /* Set the function pointers */ | 227 /* Set the function pointers */ |
228 impl->DetectDevices = COREAUDIO_DetectDevices; | |
229 impl->GetAudioDevice = COREAUDIO_GetAudioDevice; | |
214 impl->OpenAudio = COREAUDIO_OpenAudio; | 230 impl->OpenAudio = COREAUDIO_OpenAudio; |
215 impl->WaitAudio = COREAUDIO_WaitAudio; | 231 impl->WaitAudio = COREAUDIO_WaitAudio; |
216 impl->PlayAudio = COREAUDIO_PlayAudio; | 232 impl->PlayAudio = COREAUDIO_PlayAudio; |
217 impl->GetAudioBuf = COREAUDIO_GetAudioBuf; | 233 impl->GetAudioBuf = COREAUDIO_GetAudioBuf; |
218 impl->CloseAudio = COREAUDIO_CloseAudio; | 234 impl->CloseAudio = COREAUDIO_CloseAudio; |
225 "coreaudio", "Mac OS X CoreAudio", | 241 "coreaudio", "Mac OS X CoreAudio", |
226 COREAUDIO_Available, COREAUDIO_Init | 242 COREAUDIO_Available, COREAUDIO_Init |
227 }; | 243 }; |
228 | 244 |
229 | 245 |
246 static int | |
247 COREAUDIO_DetectDevices(int iscapture) | |
248 { | |
249 if (iscapture) { | |
250 build_device_list(1, &inputDevices, &inputDeviceCount); | |
251 return inputDeviceCount; | |
252 } else { | |
253 build_device_list(0, &outputDevices, &outputDeviceCount); | |
254 return outputDeviceCount; | |
255 } | |
256 | |
257 return 0; /* shouldn't ever hit this. */ | |
258 } | |
259 | |
260 | |
261 static const char * | |
262 COREAUDIO_GetAudioDevice(int index, int iscapture) | |
263 { | |
264 if ((iscapture) && (index < inputDeviceCount)) { | |
265 return inputDevices[index].name; | |
266 } else if ((!iscapture) && (index < outputDeviceCount)) { | |
267 return outputDevices[index].name; | |
268 } | |
269 | |
270 SDL_SetError("No such device"); | |
271 return NULL; | |
272 } | |
273 | |
274 | |
230 static void | 275 static void |
231 COREAUDIO_Deinitialize(void) | 276 COREAUDIO_Deinitialize(void) |
232 { | 277 { |
233 free_device_list(&outputDevices, &outputDeviceCount); | 278 free_device_lists(); |
234 free_device_list(&inputDevices, &inputDeviceCount); | |
235 } | 279 } |
236 | 280 |
237 | 281 |
238 /* The CoreAudio callback */ | 282 /* The CoreAudio callback */ |
239 static OSStatus | 283 static OSStatus |