Mercurial > sdl-ios-xcode
annotate src/audio/macosx/SDL_coreaudio.c @ 3796:b19680c84cdf SDL-ryan-multiple-audio-device
Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
the core and into the drivers where it belongs, and push generic
responsibilities out of the drivers and into the core where they belong.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 04 Oct 2006 19:54:23 +0000 |
parents | 589bc3d060cd |
children | c8b3d3d13ed1 |
rev | line source |
---|---|
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
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:
936
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
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:
936
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
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:
936
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
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:
936
diff
changeset
|
13 Lesser General Public License for more details. |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
936
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:
936
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:
936
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
24 #include <CoreAudio/CoreAudio.h> |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 #include <AudioUnit/AudioUnit.h> |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
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_audio_c.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_sysaudio.h" |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 #include "SDL_coreaudio.h" |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
3790
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
32 #define DEBUG_COREAUDIO 0 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
34 typedef struct COREAUDIO_DeviceList |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
35 { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
36 AudioDeviceID id; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
37 const char *name; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
38 } COREAUDIO_DeviceList; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
39 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
40 static COREAUDIO_DeviceList *inputDevices = NULL; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
41 static int inputDeviceCount = 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
42 static COREAUDIO_DeviceList *outputDevices = NULL; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
43 static int outputDeviceCount = 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
44 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
45 static void |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
46 free_device_list(COREAUDIO_DeviceList **devices, int *devCount) |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
47 { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
48 if (*devices) { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
49 int i = *devCount; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
50 while (i--) |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
51 SDL_free((void *) (*devices)[i].name); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
52 SDL_free(*devices); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
53 *devices = NULL; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
54 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
55 *devCount = 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
56 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
57 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
58 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
59 static void |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
60 build_device_list(int iscapture, COREAUDIO_DeviceList **devices, int *devCount) |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
61 { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
62 Boolean outWritable = 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
63 OSStatus result = noErr; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
64 UInt32 size = 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
65 AudioDeviceID *devs = NULL; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
66 UInt32 i = 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
67 UInt32 max = 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
68 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
69 free_device_list(devices, devCount); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
70 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
71 result = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
72 &size, &outWritable); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
73 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
74 if (result != kAudioHardwareNoError) |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
75 return; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
76 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
77 devs = (AudioDeviceID *) alloca(size); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
78 if (devs == NULL) |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
79 return; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
80 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
81 max = size / sizeof (AudioDeviceID); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
82 *devices = (COREAUDIO_DeviceList *) SDL_malloc(max * sizeof (**devices)); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
83 if (*devices == NULL) |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
84 return; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
85 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
86 result = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
87 &size, devs); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
88 if (result != kAudioHardwareNoError) |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
89 return; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
90 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
91 for (i = 0; i < max; i++) { |
3788
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
92 CFStringRef cfstr = NULL; |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
93 char *ptr = NULL; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
94 AudioDeviceID dev = devs[i]; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
95 AudioBufferList *buflist = NULL; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
96 int usable = 0; |
3788
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
97 CFIndex len = 0; |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
98 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
99 result = AudioDeviceGetPropertyInfo(dev, 0, iscapture, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
100 kAudioDevicePropertyStreamConfiguration, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
101 &size, &outWritable); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
102 if (result != noErr) |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
103 continue; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
104 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
105 buflist = (AudioBufferList *) SDL_malloc(size); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
106 if (buflist == NULL) |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
107 continue; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
108 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
109 result = AudioDeviceGetProperty(dev, 0, iscapture, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
110 kAudioDevicePropertyStreamConfiguration, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
111 &size, buflist); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
112 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
113 if (result == noErr) { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
114 UInt32 j; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
115 for (j = 0; j < buflist->mNumberBuffers; j++) { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
116 if (buflist->mBuffers[j].mNumberChannels > 0) { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
117 usable = 1; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
118 break; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
119 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
120 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
121 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
122 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
123 SDL_free(buflist); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
124 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
125 if (!usable) |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
126 continue; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
127 |
3788
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
128 size = sizeof (CFStringRef); |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
129 result = AudioDeviceGetProperty(dev, 0, iscapture, |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
130 kAudioObjectPropertyName, |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
131 &size, &cfstr); |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
132 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
133 if (result != kAudioHardwareNoError) |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
134 continue; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
135 |
3788
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
136 len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstr), |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
137 kCFStringEncodingUTF8); |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
138 |
3788
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
139 ptr = (char *) SDL_malloc(len + 1); |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
140 usable = ( (ptr != NULL) && |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
141 (CFStringGetCString(cfstr,ptr,len+1,kCFStringEncodingUTF8)) ); |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
142 |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
143 CFRelease(cfstr); |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
144 |
3788
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
145 if (usable) { |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
146 len = strlen(ptr); |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
147 /* Some devices have whitespace at the end...trim it. */ |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
148 while ((len > 0) && (ptr[len-1] == ' ')) { |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
149 len--; |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
150 } |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
151 usable = (len > 0); |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
152 } |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
153 |
3788
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
154 if (!usable) { |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
155 SDL_free(ptr); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
156 } else { |
3788
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
157 ptr[len] = '\0'; |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
158 |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
159 #if DEBUG_COREAUDIO |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
160 printf("COREAUDIO: Found %s device #%d: '%s' (devid %d)\n", |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
161 ((iscapture) ? "capture" : "output"), |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
162 (int) *devCount, ptr, (int) dev); |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
163 #endif |
7006b176ef4f
More work on the 1.3 CoreAudio code.
Ryan C. Gordon <icculus@icculus.org>
parents:
3787
diff
changeset
|
164 |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
165 (*devices)[*devCount].id = dev; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
166 (*devices)[*devCount].name = ptr; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
167 (*devCount)++; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
168 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
169 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
170 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
171 |
3790
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
172 static inline void |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
173 build_device_lists(void) |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
174 { |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
175 build_device_list(0, &outputDevices, &outputDeviceCount); |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
176 build_device_list(1, &inputDevices, &inputDeviceCount); |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
177 } |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
178 |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
179 |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
180 static inline void |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
181 free_device_lists(void) |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
182 { |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
183 free_device_list(&outputDevices, &outputDeviceCount); |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
184 free_device_list(&inputDevices, &inputDeviceCount); |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
185 } |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
186 |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
187 |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
188 static int |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
189 find_device_id(const char *devname, int iscapture, AudioDeviceID *id) |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
190 { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
191 int i = ((iscapture) ? inputDeviceCount : outputDeviceCount); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
192 COREAUDIO_DeviceList *devs = ((iscapture) ? inputDevices : outputDevices); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
193 while (i--) { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
194 if (SDL_strcmp(devname, devs->name) == 0) { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
195 *id = devs->id; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
196 return 1; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
197 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
198 devs++; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
199 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
200 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
201 return 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
202 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
203 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
204 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 /* Audio driver functions */ |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 |
3790
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
207 static int COREAUDIO_DetectDevices(int iscapture); |
3792
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
208 static const char *COREAUDIO_GetDeviceName(int index, int iscapture); |
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
209 static int COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture); |
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
210 static void COREAUDIO_WaitDevice(_THIS); |
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
211 static void COREAUDIO_PlayDevice(_THIS); |
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
212 static Uint8 *COREAUDIO_GetDeviceBuf(_THIS); |
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
213 static void COREAUDIO_CloseDevice(_THIS); |
3787
8d74a4721ca9
Added deinitialize hook.
Ryan C. Gordon <icculus@icculus.org>
parents:
3786
diff
changeset
|
214 static void COREAUDIO_Deinitialize(void); |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 /* Audio driver bootstrap functions */ |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
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:
1487
diff
changeset
|
218 static int |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
219 COREAUDIO_Available(void) |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
221 return (1); |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 } |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
224 static int |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
225 COREAUDIO_Init(SDL_AudioDriverImpl *impl) |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 { |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
227 /* Set the function pointers */ |
3790
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
228 impl->DetectDevices = COREAUDIO_DetectDevices; |
3792
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
229 impl->GetDeviceName = COREAUDIO_GetDeviceName; |
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
230 impl->OpenDevice = COREAUDIO_OpenDevice; |
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
231 impl->WaitDevice = COREAUDIO_WaitDevice; |
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
232 impl->PlayDevice = COREAUDIO_PlayDevice; |
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
233 impl->GetDeviceBuf = COREAUDIO_GetDeviceBuf; |
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
234 impl->CloseDevice = COREAUDIO_CloseDevice; |
3787
8d74a4721ca9
Added deinitialize hook.
Ryan C. Gordon <icculus@icculus.org>
parents:
3786
diff
changeset
|
235 impl->Deinitialize = COREAUDIO_Deinitialize; |
3796
b19680c84cdf
Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents:
3795
diff
changeset
|
236 impl->ProvidesOwnCallbackThread = 1; |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
237 return 1; |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 } |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 AudioBootStrap COREAUDIO_bootstrap = { |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 "coreaudio", "Mac OS X CoreAudio", |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
242 COREAUDIO_Available, COREAUDIO_Init |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 }; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 |
3787
8d74a4721ca9
Added deinitialize hook.
Ryan C. Gordon <icculus@icculus.org>
parents:
3786
diff
changeset
|
245 |
3790
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
246 static int |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
247 COREAUDIO_DetectDevices(int iscapture) |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
248 { |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
249 if (iscapture) { |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
250 build_device_list(1, &inputDevices, &inputDeviceCount); |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
251 return inputDeviceCount; |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
252 } else { |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
253 build_device_list(0, &outputDevices, &outputDeviceCount); |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
254 return outputDeviceCount; |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
255 } |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
256 |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
257 return 0; /* shouldn't ever hit this. */ |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
258 } |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
259 |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
260 |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
261 static const char * |
3792
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
262 COREAUDIO_GetDeviceName(int index, int iscapture) |
3790
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
263 { |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
264 if ((iscapture) && (index < inputDeviceCount)) { |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
265 return inputDevices[index].name; |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
266 } else if ((!iscapture) && (index < outputDeviceCount)) { |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
267 return outputDevices[index].name; |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
268 } |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
269 |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
270 SDL_SetError("No such device"); |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
271 return NULL; |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
272 } |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
273 |
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
274 |
3787
8d74a4721ca9
Added deinitialize hook.
Ryan C. Gordon <icculus@icculus.org>
parents:
3786
diff
changeset
|
275 static void |
8d74a4721ca9
Added deinitialize hook.
Ryan C. Gordon <icculus@icculus.org>
parents:
3786
diff
changeset
|
276 COREAUDIO_Deinitialize(void) |
8d74a4721ca9
Added deinitialize hook.
Ryan C. Gordon <icculus@icculus.org>
parents:
3786
diff
changeset
|
277 { |
3790
8f8209f8da6d
Added audio device enumeration for 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
3788
diff
changeset
|
278 free_device_lists(); |
3787
8d74a4721ca9
Added deinitialize hook.
Ryan C. Gordon <icculus@icculus.org>
parents:
3786
diff
changeset
|
279 } |
8d74a4721ca9
Added deinitialize hook.
Ryan C. Gordon <icculus@icculus.org>
parents:
3786
diff
changeset
|
280 |
8d74a4721ca9
Added deinitialize hook.
Ryan C. Gordon <icculus@icculus.org>
parents:
3786
diff
changeset
|
281 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 /* The CoreAudio callback */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
283 static OSStatus |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
284 outputCallback(void *inRefCon, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
285 AudioUnitRenderActionFlags *ioActionFlags, |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
286 const AudioTimeStamp * inTimeStamp, |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
287 UInt32 inBusNumber, UInt32 inNumberFrames, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
288 AudioBufferList *ioDataList) |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
290 SDL_AudioDevice *this = (SDL_AudioDevice *) inRefCon; |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
291 AudioBuffer *ioData = &ioDataList->mBuffers[0]; |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 UInt32 remaining, len; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 void *ptr; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 |
3786
b70f4e9291bb
High level now lets user select a specific audio device with an environment
Ryan C. Gordon <icculus@icculus.org>
parents:
3785
diff
changeset
|
295 /* |
b70f4e9291bb
High level now lets user select a specific audio device with an environment
Ryan C. Gordon <icculus@icculus.org>
parents:
3785
diff
changeset
|
296 * !!! FIXME: I'm not sure if you can ever have more than one |
b70f4e9291bb
High level now lets user select a specific audio device with an environment
Ryan C. Gordon <icculus@icculus.org>
parents:
3785
diff
changeset
|
297 * buffer, or what this signifies, or what to do with it... |
b70f4e9291bb
High level now lets user select a specific audio device with an environment
Ryan C. Gordon <icculus@icculus.org>
parents:
3785
diff
changeset
|
298 */ |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
299 if (ioDataList->mNumberBuffers != 1) { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
300 return noErr; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
301 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
302 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 /* Only do anything if audio is enabled and not paused */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
304 if (!this->enabled || this->paused) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
305 SDL_memset(ioData->mData, this->spec.silence, ioData->mDataByteSize); |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 return 0; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
308 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 /* No SDL conversion should be needed here, ever, since we accept |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 any input format in OpenAudio, and leave the conversion to CoreAudio. |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 */ |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
312 /* |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
313 assert(!this->convert.needed); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
314 assert(this->spec.channels == ioData->mNumberChannels); |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
315 */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
316 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 remaining = ioData->mDataByteSize; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 ptr = ioData->mData; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
319 while (remaining > 0) { |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
320 if (this->hidden->bufferOffset >= this->hidden->bufferSize) { |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
321 /* Generate the data */ |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
322 SDL_memset(this->hidden->buffer, this->spec.silence, |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
323 this->hidden->bufferSize); |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
324 SDL_mutexP(this->mixer_lock); |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
325 (*this->spec.callback) (this->spec.userdata, this->hidden->buffer, |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
326 this->hidden->bufferSize); |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 SDL_mutexV(this->mixer_lock); |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
328 this->hidden->bufferOffset = 0; |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
330 |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
331 len = this->hidden->bufferSize - this->hidden->bufferOffset; |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
332 if (len > remaining) |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 len = remaining; |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
334 SDL_memcpy(ptr, |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
335 (char *) this->hidden->buffer + this->hidden->bufferOffset, |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
336 len); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
337 ptr = (char *) ptr + len; |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 remaining -= len; |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
339 this->hidden->bufferOffset += len; |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
341 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 return 0; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 } |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
345 static OSStatus |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
346 inputCallback(void *inRefCon, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
347 AudioUnitRenderActionFlags *ioActionFlags, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
348 const AudioTimeStamp * inTimeStamp, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
349 UInt32 inBusNumber, UInt32 inNumberFrames, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
350 AudioBufferList *ioData) |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
351 { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
352 //err = AudioUnitRender(afr->fAudioUnit, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, afr->fAudioBuffer); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
353 // !!! FIXME: write me! |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
354 return noErr; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
355 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
356 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
357 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 /* Dummy functions -- we don't use thread-based audio */ |
3795
589bc3d060cd
More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents:
3792
diff
changeset
|
359 static void |
3792
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
360 COREAUDIO_WaitDevice(_THIS) |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
361 { |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
362 return; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 } |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
364 |
3795
589bc3d060cd
More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents:
3792
diff
changeset
|
365 static void |
3792
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
366 COREAUDIO_PlayDevice(_THIS) |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
367 { |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
368 return; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
369 } |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
370 |
3795
589bc3d060cd
More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents:
3792
diff
changeset
|
371 static Uint8 * |
3792
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
372 COREAUDIO_GetDeviceBuf(_THIS) |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
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:
1487
diff
changeset
|
374 return (NULL); |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 } |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
376 |
3795
589bc3d060cd
More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents:
3792
diff
changeset
|
377 static void |
3792
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
378 COREAUDIO_CloseDevice(_THIS) |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
379 { |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
380 if (this->hidden != NULL) { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
381 OSStatus result = noErr; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
382 AURenderCallbackStruct callback; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
383 const AudioUnitElement output_bus = 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
384 const AudioUnitElement input_bus = 1; |
3796
b19680c84cdf
Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents:
3795
diff
changeset
|
385 const int iscapture = this->iscapture; |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
386 const AudioUnitElement bus = ((iscapture) ? input_bus : output_bus); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
387 const AudioUnitScope scope = ((iscapture) ? kAudioUnitScope_Output : |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
388 kAudioUnitScope_Input); |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
389 |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
390 /* stop processing the audio unit */ |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
391 result = AudioOutputUnitStop(this->hidden->audioUnit); |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
392 |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
393 /* Remove the input callback */ |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
394 memset(&callback, '\0', sizeof (AURenderCallbackStruct)); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
395 result = AudioUnitSetProperty(this->hidden->audioUnit, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
396 kAudioUnitProperty_SetRenderCallback, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
397 scope, bus, &callback, sizeof (callback)); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
398 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
399 CloseComponent(this->hidden->audioUnit); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
400 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
401 SDL_free(this->hidden->buffer); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
402 SDL_free(this->hidden); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
403 this->hidden = NULL; |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
404 } |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
405 } |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
406 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
407 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
408 #define CHECK_RESULT(msg) \ |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
409 if (result != noErr) { \ |
3792
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
410 COREAUDIO_CloseDevice(this); \ |
2017
df06e6eb65c6
Fixed macosx audio initialization (passed wrong struct to CoreAudio).
Ryan C. Gordon <icculus@icculus.org>
parents:
2016
diff
changeset
|
411 SDL_SetError("CoreAudio error (%s): %d", msg, (int) result); \ |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
412 return 0; \ |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
413 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
414 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
415 static int |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
416 find_device_by_name(_THIS, const char *devname, int iscapture) |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
417 { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
418 AudioDeviceID devid = 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
419 OSStatus result = noErr; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
420 UInt32 size = 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
421 UInt32 alive = 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
422 pid_t pid = 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
423 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
424 if (devname == NULL) { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
425 size = sizeof (AudioDeviceID); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
426 const AudioHardwarePropertyID propid = |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
427 ((iscapture) ? kAudioHardwarePropertyDefaultInputDevice : |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
428 kAudioHardwarePropertyDefaultOutputDevice); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
429 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
430 result = AudioHardwareGetProperty(propid, &size, &devid); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
431 CHECK_RESULT("AudioHardwareGetProperty (default device)"); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
432 } else { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
433 if (!find_device_id(devname, iscapture, &devid)) { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
434 SDL_SetError("CoreAudio: No such audio device."); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
435 return 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
436 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
437 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
438 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
439 size = sizeof (alive); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
440 result = AudioDeviceGetProperty(devid, 0, iscapture, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
441 kAudioDevicePropertyDeviceIsAlive, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
442 &size, &alive); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
443 CHECK_RESULT("AudioDeviceGetProperty (kAudioDevicePropertyDeviceIsAlive)"); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
444 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
445 if (!alive) { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
446 SDL_SetError("CoreAudio: requested device exists, but isn't alive."); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
447 return 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
448 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
449 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
450 size = sizeof (pid); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
451 result = AudioDeviceGetProperty(devid, 0, iscapture, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
452 kAudioDevicePropertyHogMode, &size, &pid); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
453 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
454 /* some devices don't support this property, so errors are fine here. */ |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
455 if ((result == noErr) && (pid != -1)) { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
456 SDL_SetError("CoreAudio: requested device is being hogged."); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
457 return 0; |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
458 } |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
459 |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
460 this->hidden->deviceID = devid; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
461 return 1; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
462 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
463 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
464 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
465 static int |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
466 prepare_audiounit(_THIS, const char *devname, int iscapture, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
467 const AudioStreamBasicDescription *strdesc) |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
468 { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
469 OSStatus result = noErr; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
470 AURenderCallbackStruct callback; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
471 ComponentDescription desc; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
472 Component comp = NULL; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
473 int use_system_device = 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
474 UInt32 enableIO = 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
475 const AudioUnitElement output_bus = 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
476 const AudioUnitElement input_bus = 1; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
477 const AudioUnitElement bus = ((iscapture) ? input_bus : output_bus); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
478 const AudioUnitScope scope = ((iscapture) ? kAudioUnitScope_Output : |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
479 kAudioUnitScope_Input); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
480 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
481 if (!find_device_by_name(this, devname, iscapture)) { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
482 SDL_SetError("Couldn't find requested CoreAudio device"); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
483 return 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
484 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
485 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
486 memset(&desc, '\0', sizeof(ComponentDescription)); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
487 desc.componentType = kAudioUnitType_Output; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
488 desc.componentSubType = kAudioUnitSubType_HALOutput; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
489 desc.componentManufacturer = kAudioUnitManufacturer_Apple; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
490 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
491 comp = FindNextComponent(NULL, &desc); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
492 if (comp == NULL) { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
493 SDL_SetError("Couldn't find requested CoreAudio component"); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
494 return 0; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
495 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
496 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
497 /* Open & initialize the audio unit */ |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
498 result = OpenAComponent(comp, &this->hidden->audioUnit); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
499 CHECK_RESULT("OpenAComponent"); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
500 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
501 // !!! FIXME: this is wrong? |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
502 enableIO = ((iscapture) ? 1 : 0); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
503 result = AudioUnitSetProperty(this->hidden->audioUnit, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
504 kAudioOutputUnitProperty_EnableIO, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
505 kAudioUnitScope_Input, input_bus, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
506 &enableIO, sizeof (enableIO)); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
507 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_EnableIO input)"); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
508 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
509 // !!! FIXME: this is wrong? |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
510 enableIO = ((iscapture) ? 0 : 1); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
511 result = AudioUnitSetProperty(this->hidden->audioUnit, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
512 kAudioOutputUnitProperty_EnableIO, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
513 kAudioUnitScope_Output, output_bus, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
514 &enableIO, sizeof (enableIO)); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
515 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_EnableIO output)"); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
516 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
517 result = AudioUnitSetProperty(this->hidden->audioUnit, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
518 kAudioOutputUnitProperty_CurrentDevice, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
519 kAudioUnitScope_Global, 0, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
520 &this->hidden->deviceID, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
521 sizeof (AudioDeviceID)); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
522 CHECK_RESULT("AudioUnitSetProperty (kAudioOutputUnitProperty_CurrentDevice)"); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
523 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
524 /* Set the data format of the audio unit. */ |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
525 result = AudioUnitSetProperty(this->hidden->audioUnit, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
526 kAudioUnitProperty_StreamFormat, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
527 scope, bus, strdesc, sizeof (*strdesc)); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
528 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)"); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
529 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
530 /* Set the audio callback */ |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
531 memset(&callback, '\0', sizeof (AURenderCallbackStruct)); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
532 callback.inputProc = ((iscapture) ? inputCallback : outputCallback); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
533 callback.inputProcRefCon = this; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
534 result = AudioUnitSetProperty(this->hidden->audioUnit, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
535 kAudioUnitProperty_SetRenderCallback, |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
536 scope, bus, &callback, sizeof (callback)); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
537 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)"); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
538 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
539 /* Calculate the final parameters for this audio specification */ |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
540 SDL_CalculateAudioSpec(&this->spec); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
541 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
542 /* Allocate a sample buffer */ |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
543 this->hidden->bufferOffset = this->hidden->bufferSize = this->spec.size; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
544 this->hidden->buffer = SDL_malloc(this->hidden->bufferSize); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
545 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
546 result = AudioUnitInitialize(this->hidden->audioUnit); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
547 CHECK_RESULT("AudioUnitInitialize"); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
548 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
549 /* Finally, start processing of the audio unit */ |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
550 result = AudioOutputUnitStart(this->hidden->audioUnit); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
551 CHECK_RESULT("AudioOutputUnitStart"); |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
552 |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
553 /* We're running! */ |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
554 return 1; |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
555 } |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
556 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
557 |
3795
589bc3d060cd
More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents:
3792
diff
changeset
|
558 static int |
3792
866c310e2cb5
Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents:
3790
diff
changeset
|
559 COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
560 { |
2016 | 561 AudioStreamBasicDescription strdesc; |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
562 SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format); |
2003
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
563 int valid_datatype = 0; |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
564 |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
565 /* Initialize all variables that we clean on shutdown */ |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
566 this->hidden = (struct SDL_PrivateAudioData *) |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
567 SDL_malloc((sizeof *this->hidden)); |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
568 if (this->hidden == NULL) { |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
569 SDL_OutOfMemory(); |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
570 return (0); |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
571 } |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
572 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
573 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
574 /* Setup a AudioStreamBasicDescription with the requested format */ |
2043 | 575 memset(&strdesc, '\0', sizeof(AudioStreamBasicDescription)); |
2016 | 576 strdesc.mFormatID = kAudioFormatLinearPCM; |
577 strdesc.mFormatFlags = kLinearPCMFormatFlagIsPacked; | |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
578 strdesc.mChannelsPerFrame = this->spec.channels; |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
579 strdesc.mSampleRate = this->spec.freq; |
2016 | 580 strdesc.mFramesPerPacket = 1; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
581 |
2003
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
582 while ((!valid_datatype) && (test_format)) { |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
583 this->spec.format = test_format; |
2003
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
584 /* Just a list of valid SDL formats, so people don't pass junk here. */ |
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
585 switch (test_format) { |
2043 | 586 case AUDIO_U8: |
587 case AUDIO_S8: | |
588 case AUDIO_U16LSB: | |
589 case AUDIO_S16LSB: | |
590 case AUDIO_U16MSB: | |
591 case AUDIO_S16MSB: | |
592 case AUDIO_S32LSB: | |
593 case AUDIO_S32MSB: | |
594 case AUDIO_F32LSB: | |
595 case AUDIO_F32MSB: | |
596 valid_datatype = 1; | |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
597 strdesc.mBitsPerChannel = SDL_AUDIO_BITSIZE(this->spec.format); |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
598 if (SDL_AUDIO_ISBIGENDIAN(this->spec.format)) |
2043 | 599 strdesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian; |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
600 |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
601 if (SDL_AUDIO_ISFLOAT(this->spec.format)) |
2043 | 602 strdesc.mFormatFlags |= kLinearPCMFormatFlagIsFloat; |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
603 else if (SDL_AUDIO_ISSIGNED(this->spec.format)) |
2043 | 604 strdesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger; |
605 break; | |
2003
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
606 } |
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
607 } |
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
608 |
2043 | 609 if (!valid_datatype) { /* shouldn't happen, but just in case... */ |
2003
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
610 SDL_SetError("Unsupported audio format"); |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
611 return 0; |
2003
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
612 } |
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
613 |
2016 | 614 strdesc.mBytesPerFrame = |
615 strdesc.mBitsPerChannel * strdesc.mChannelsPerFrame / 8; | |
616 strdesc.mBytesPerPacket = | |
617 strdesc.mBytesPerFrame * strdesc.mFramesPerPacket; | |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
618 |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
619 if (!prepare_audiounit(this, devname, iscapture, &strdesc)) { |
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
620 return 0; /* prepare_audiounit() will call SDL_SetError()... */ |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
621 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
622 |
3785
da2ea0694d11
Ton of work on CoreAudio driver for new 1.3 features...most of the
Ryan C. Gordon <icculus@icculus.org>
parents:
3784
diff
changeset
|
623 return 1; /* good to go. */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
624 } |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
625 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1487
diff
changeset
|
626 /* vi: set ts=4 sw=4 expandtab: */ |