Mercurial > sdl-ios-xcode
comparison src/audio/macosx/SDL_coreaudio.c @ 3788:7006b176ef4f SDL-ryan-multiple-audio-device
More work on the 1.3 CoreAudio code.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 03 Oct 2006 18:32:34 +0000 |
parents | 8d74a4721ca9 |
children | 8f8209f8da6d |
comparison
equal
deleted
inserted
replaced
3787:8d74a4721ca9 | 3788:7006b176ef4f |
---|---|
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 | 33 |
33 typedef struct COREAUDIO_DeviceList | 34 typedef struct COREAUDIO_DeviceList |
34 { | 35 { |
35 AudioDeviceID id; | 36 AudioDeviceID id; |
36 const char *name; | 37 const char *name; |
86 &size, devs); | 87 &size, devs); |
87 if (result != kAudioHardwareNoError) | 88 if (result != kAudioHardwareNoError) |
88 return; | 89 return; |
89 | 90 |
90 for (i = 0; i < max; i++) { | 91 for (i = 0; i < max; i++) { |
92 CFStringRef cfstr = NULL; | |
91 char *ptr = NULL; | 93 char *ptr = NULL; |
92 AudioDeviceID dev = devs[i]; | 94 AudioDeviceID dev = devs[i]; |
93 AudioBufferList *buflist = NULL; | 95 AudioBufferList *buflist = NULL; |
94 int usable = 0; | 96 int usable = 0; |
97 CFIndex len = 0; | |
95 | 98 |
96 result = AudioDeviceGetPropertyInfo(dev, 0, iscapture, | 99 result = AudioDeviceGetPropertyInfo(dev, 0, iscapture, |
97 kAudioDevicePropertyStreamConfiguration, | 100 kAudioDevicePropertyStreamConfiguration, |
98 &size, &outWritable); | 101 &size, &outWritable); |
99 if (result != noErr) | 102 if (result != noErr) |
120 SDL_free(buflist); | 123 SDL_free(buflist); |
121 | 124 |
122 if (!usable) | 125 if (!usable) |
123 continue; | 126 continue; |
124 | 127 |
125 /* !!! FIXME: use CFStrings, instead, and convert to UTF-8. */ | 128 size = sizeof (CFStringRef); |
126 result = AudioDeviceGetPropertyInfo(dev, 0, iscapture, | 129 result = AudioDeviceGetProperty(dev, 0, iscapture, |
127 kAudioDevicePropertyDeviceName, | 130 kAudioObjectPropertyName, |
128 &size, &outWritable); | 131 &size, &cfstr); |
129 | 132 |
130 if (result != kAudioHardwareNoError) | 133 if (result != kAudioHardwareNoError) |
131 continue; | 134 continue; |
132 | 135 |
133 ptr = (char *) SDL_malloc(size + 1); | 136 len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstr), |
134 if (ptr == NULL) | 137 kCFStringEncodingUTF8); |
135 continue; | 138 |
136 | 139 ptr = (char *) SDL_malloc(len + 1); |
137 result = AudioDeviceGetProperty(dev, 0, iscapture, | 140 usable = ( (ptr != NULL) && |
138 kAudioDevicePropertyDeviceName, | 141 (CFStringGetCString(cfstr,ptr,len+1,kCFStringEncodingUTF8)) ); |
139 &size, ptr); | 142 |
140 | 143 CFRelease(cfstr); |
141 if (result != kAudioHardwareNoError) | 144 |
142 continue; | 145 if (usable) { |
143 | 146 len = strlen(ptr); |
144 while ((size > 0) && (ptr[size-1] == ' ')) | 147 /* Some devices have whitespace at the end...trim it. */ |
145 size--; /* I have a USB device with whitespace at the end... */ | 148 while ((len > 0) && (ptr[len-1] == ' ')) { |
146 | 149 len--; |
147 if (size == 0) { | 150 } |
151 usable = (len > 0); | |
152 } | |
153 | |
154 if (!usable) { | |
148 SDL_free(ptr); | 155 SDL_free(ptr); |
149 } else { | 156 } else { |
150 ptr[size] = '\0'; | 157 ptr[len] = '\0'; |
158 | |
159 #if DEBUG_COREAUDIO | |
160 printf("COREAUDIO: Found %s device #%d: '%s' (devid %d)\n", | |
161 ((iscapture) ? "capture" : "output"), | |
162 (int) *devCount, ptr, (int) dev); | |
163 #endif | |
164 | |
151 (*devices)[*devCount].id = dev; | 165 (*devices)[*devCount].id = dev; |
152 (*devices)[*devCount].name = ptr; | 166 (*devices)[*devCount].name = ptr; |
153 (*devCount)++; | 167 (*devCount)++; |
154 } | 168 } |
155 } | 169 } |
214 | 228 |
215 | 229 |
216 static void | 230 static void |
217 COREAUDIO_Deinitialize(void) | 231 COREAUDIO_Deinitialize(void) |
218 { | 232 { |
219 free_device_list(0, &outputDevices, &outputDeviceCount); | 233 free_device_list(&outputDevices, &outputDeviceCount); |
220 free_device_list(1, &inputDevices, &inputDeviceCount); | 234 free_device_list(&inputDevices, &inputDeviceCount); |
221 } | 235 } |
222 | 236 |
223 | 237 |
224 /* The CoreAudio callback */ | 238 /* The CoreAudio callback */ |
225 static OSStatus | 239 static OSStatus |