annotate src/audio/macosx/SDL_coreaudio.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
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
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #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
25
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #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
27 #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
28 #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
29 #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
30
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 /* Audio driver functions */
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
34 static int Core_OpenAudio(_THIS, SDL_AudioSpec * spec);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
35 static void Core_WaitAudio(_THIS);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
36 static void Core_PlayAudio(_THIS);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
37 static Uint8 *Core_GetAudioBuf(_THIS);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
38 static void Core_CloseAudio(_THIS);
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 /* 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
41
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
42 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
43 Audio_Available(void)
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
45 return (1);
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 }
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
48 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
49 Audio_DeleteDevice(SDL_AudioDevice * device)
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
51 SDL_free(device->hidden);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
52 SDL_free(device);
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 }
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
55 static SDL_AudioDevice *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
56 Audio_CreateDevice(int devindex)
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 {
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 SDL_AudioDevice *this;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 /* Initialize all variables that we clean on shutdown */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
61 this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
62 if (this) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
63 SDL_memset(this, 0, (sizeof *this));
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 this->hidden = (struct SDL_PrivateAudioData *)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
65 SDL_malloc((sizeof *this->hidden));
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
67 if ((this == NULL) || (this->hidden == NULL)) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
68 SDL_OutOfMemory();
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
69 if (this) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
70 SDL_free(this);
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
72 return (0);
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
74 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 /* Set the function pointers */
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 this->OpenAudio = Core_OpenAudio;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 this->WaitAudio = Core_WaitAudio;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 this->PlayAudio = Core_PlayAudio;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 this->GetAudioBuf = Core_GetAudioBuf;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 this->CloseAudio = Core_CloseAudio;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 this->free = Audio_DeleteDevice;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 return this;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 }
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 AudioBootStrap COREAUDIO_bootstrap = {
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 "coreaudio", "Mac OS X CoreAudio",
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 Audio_Available, Audio_CreateDevice
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 };
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 /* The CoreAudio callback */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
94 static OSStatus
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
95 audioCallback(void *inRefCon,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
96 AudioUnitRenderActionFlags inActionFlags,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
97 const AudioTimeStamp * inTimeStamp,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
98 UInt32 inBusNumber, AudioBuffer * ioData)
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
100 SDL_AudioDevice *this = (SDL_AudioDevice *) inRefCon;
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 UInt32 remaining, len;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 void *ptr;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 /* Only do anything if audio is enabled and not paused */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
105 if (!this->enabled || this->paused) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
106 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
107 return 0;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
109
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 /* 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
111 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
112 */
1338
604d73db6802 Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents: 1336
diff changeset
113 /*
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
114 assert(!this->convert.needed);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
115 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
116 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
117
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 remaining = ioData->mDataByteSize;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 ptr = ioData->mData;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 while (remaining > 0) {
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 if (bufferOffset >= bufferSize) {
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 /* Generate the data */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
123 SDL_memset(buffer, this->spec.silence, bufferSize);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
124 SDL_mutexP(this->mixer_lock);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
125 (*this->spec.callback) (this->spec.userdata, buffer, bufferSize);
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
126 SDL_mutexV(this->mixer_lock);
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 bufferOffset = 0;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
129
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 len = bufferSize - bufferOffset;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 if (len > remaining)
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 len = remaining;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
133 SDL_memcpy(ptr, (char *) buffer + bufferOffset, len);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
134 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
135 remaining -= len;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 bufferOffset += len;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
138
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 return 0;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 }
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 /* Dummy functions -- we don't use thread-based audio */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
143 void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
144 Core_WaitAudio(_THIS)
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 {
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 return;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 }
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
149 void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
150 Core_PlayAudio(_THIS)
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 {
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 return;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 }
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
155 Uint8 *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
156 Core_GetAudioBuf(_THIS)
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
158 return (NULL);
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 }
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
161 void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
162 Core_CloseAudio(_THIS)
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 {
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 OSStatus result;
936
84f930aebaeb CoreAudio driver works on Mac OSX 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 935
diff changeset
165 struct AudioUnitInputCallback callback;
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 /* stop processing the audio unit */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
168 result = AudioOutputUnitStop(outputAudioUnit);
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 if (result != noErr) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
170 SDL_SetError("Core_CloseAudio: AudioOutputUnitStop");
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 return;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 }
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 /* Remove the input callback */
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 callback.inputProc = 0;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 callback.inputProcRefCon = 0;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
177 result = AudioUnitSetProperty(outputAudioUnit,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
178 kAudioUnitProperty_SetInputCallback,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
179 kAudioUnitScope_Input,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
180 0, &callback, sizeof(callback));
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 if (result != noErr) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
182 SDL_SetError
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
183 ("Core_CloseAudio: AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)");
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 return;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 }
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
187 result = CloseComponent(outputAudioUnit);
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 if (result != noErr) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
189 SDL_SetError("Core_CloseAudio: CloseComponent");
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 return;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
192
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
193 SDL_free(buffer);
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 }
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 #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
197 if (result != noErr) { \
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 SDL_SetError("Failed to start CoreAudio: " msg); \
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 return -1; \
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 }
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
203 int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
204 Core_OpenAudio(_THIS, SDL_AudioSpec * spec)
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 {
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 OSStatus result = noErr;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 Component comp;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 ComponentDescription desc;
936
84f930aebaeb CoreAudio driver works on Mac OSX 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 935
diff changeset
209 struct AudioUnitInputCallback callback;
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 AudioStreamBasicDescription requestedDesc;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 /* Setup a AudioStreamBasicDescription with the requested format */
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 requestedDesc.mFormatID = kAudioFormatLinearPCM;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 requestedDesc.mFormatFlags = kLinearPCMFormatFlagIsPacked;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 requestedDesc.mChannelsPerFrame = spec->channels;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 requestedDesc.mSampleRate = spec->freq;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
217
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 requestedDesc.mBitsPerChannel = spec->format & 0xFF;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 if (spec->format & 0x8000)
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 if (spec->format & 0x1000)
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 requestedDesc.mFramesPerPacket = 1;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
225 requestedDesc.mBytesPerFrame =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
226 requestedDesc.mBitsPerChannel * requestedDesc.mChannelsPerFrame / 8;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
227 requestedDesc.mBytesPerPacket =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
228 requestedDesc.mBytesPerFrame * requestedDesc.mFramesPerPacket;
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 /* Locate the default output audio unit */
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 desc.componentType = kAudioUnitComponentType;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 desc.componentSubType = kAudioUnitSubType_Output;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 desc.componentManufacturer = kAudioUnitID_DefaultOutput;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 desc.componentFlags = 0;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 desc.componentFlagsMask = 0;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
237
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
238 comp = FindNextComponent(NULL, &desc);
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 if (comp == NULL) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
240 SDL_SetError
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
241 ("Failed to start CoreAudio: FindNextComponent returned NULL");
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 return -1;
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
244
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 /* Open & initialize the default output audio unit */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
246 result = OpenAComponent(comp, &outputAudioUnit);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
247 CHECK_RESULT("OpenAComponent")
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
248 result = AudioUnitInitialize(outputAudioUnit);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
249 CHECK_RESULT("AudioUnitInitialize")
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
250 /* Set the input format of the audio unit. */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
251 result = AudioUnitSetProperty(outputAudioUnit,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
252 kAudioUnitProperty_StreamFormat,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
253 kAudioUnitScope_Input,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
254 0,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
255 &requestedDesc, sizeof(requestedDesc));
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
256 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)")
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
257 /* Set the audio callback */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
258 callback.inputProc = audioCallback;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
259 callback.inputProcRefCon = this;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
260 result = AudioUnitSetProperty(outputAudioUnit,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
261 kAudioUnitProperty_SetInputCallback,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
262 kAudioUnitScope_Input,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
263 0, &callback, sizeof(callback));
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
264 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)")
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
265 /* Calculate the final parameters for this audio specification */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
266 SDL_CalculateAudioSpec(spec);
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 /* Allocate a sample buffer */
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 bufferOffset = bufferSize = this->spec.size;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
270 buffer = SDL_malloc(bufferSize);
1338
604d73db6802 Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents: 1336
diff changeset
271
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 /* Finally, start processing of the audio unit */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
273 result = AudioOutputUnitStart(outputAudioUnit);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
274 CHECK_RESULT("AudioOutputUnitStart")
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
275 /* We're running! */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
276 return (1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
277 }
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
279 /* vi: set ts=4 sw=4 expandtab: */