Mercurial > sdl-ios-xcode
annotate src/audio/macosx/SDL_coreaudio.c @ 3784:37c9c4590689 SDL-ryan-multiple-audio-device
First batch of heavy lifting on supporting multiple audio devices at once.
This has a long way to go yet, most of the drivers aren't updated for the
new interfaces, and it's still got some obvious bugs, FIXMEs, and wistlist
items.
Don't use yet.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 01 Oct 2006 05:24:03 +0000 |
parents | adf732f1f016 |
children | da2ea0694d11 |
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 |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
34 static int COREAUDIO_OpenAudio(_THIS, const char *devname, int iscapture); |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
35 static void COREAUDIO_WaitAudio(_THIS); |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
36 static void COREAUDIO_PlayAudio(_THIS); |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
37 static Uint8 *COREAUDIO_GetAudioBuf(_THIS); |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
38 static void COREAUDIO_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 |
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
|
42 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
|
43 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
|
44 { |
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
|
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 |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
48 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
|
49 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
|
50 { |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
51 /* Set the function pointers */ |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
52 impl->OpenAudio = COREAUDIO_OpenAudio; |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
53 impl->WaitAudio = COREAUDIO_WaitAudio; |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
54 impl->PlayAudio = COREAUDIO_PlayAudio; |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
55 impl->GetAudioBuf = COREAUDIO_GetAudioBuf; |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
56 impl->CloseAudio = COREAUDIO_CloseAudio; |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
58 return 1; |
935
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 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 AudioBootStrap COREAUDIO_bootstrap = { |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 "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
|
63 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
|
64 }; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 /* 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
|
67 static OSStatus |
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
|
68 audioCallback(void *inRefCon, |
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
|
69 AudioUnitRenderActionFlags inActionFlags, |
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
|
70 const AudioTimeStamp * inTimeStamp, |
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
|
71 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
|
72 { |
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
|
73 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
|
74 UInt32 remaining, len; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 void *ptr; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 /* 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
|
78 if (!this->enabled || this->paused) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
79 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
|
80 return 0; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 } |
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
|
82 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 /* 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
|
84 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
|
85 */ |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
86 /* |
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
|
87 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
|
88 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
|
89 */ |
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
|
90 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 remaining = ioData->mDataByteSize; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 ptr = ioData->mData; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 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
|
94 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
|
95 /* 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
|
96 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
|
97 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
|
98 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
|
99 (*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
|
100 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
|
101 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
|
102 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
|
103 } |
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
|
104 |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
105 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
|
106 if (len > remaining) |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 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
|
108 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
|
109 (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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 } |
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
|
115 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 return 0; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 } |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 /* Dummy functions -- we don't use thread-based audio */ |
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
|
120 void |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
121 COREAUDIO_WaitAudio(_THIS) |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 { |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 return; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 } |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 |
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
|
126 void |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
127 COREAUDIO_PlayAudio(_THIS) |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 { |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 return; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 } |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 |
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
|
132 Uint8 * |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
133 COREAUDIO_GetAudioBuf(_THIS) |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 { |
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
|
135 return (NULL); |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 } |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 |
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
|
138 void |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
139 COREAUDIO_CloseAudio(_THIS) |
935
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 OSStatus result; |
936
84f930aebaeb
CoreAudio driver works on Mac OSX 10.1
Sam Lantinga <slouken@libsdl.org>
parents:
935
diff
changeset
|
142 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
|
143 |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
144 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
|
145 return; |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
146 } |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
147 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 /* stop processing the audio unit */ |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
149 result = AudioOutputUnitStop(this->hidden->outputAudioUnit); |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 if (result != noErr) { |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
151 SDL_SetError("COREAUDIO_CloseAudio: AudioOutputUnitStop"); |
935
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 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 /* 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
|
156 callback.inputProc = 0; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 callback.inputProcRefCon = 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
|
158 result = AudioUnitSetProperty(this->hidden->outputAudioUnit, |
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
|
159 kAudioUnitProperty_SetInputCallback, |
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
|
160 kAudioUnitScope_Input, |
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
|
161 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
|
162 if (result != noErr) { |
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
|
163 SDL_SetError |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
164 ("COREAUDIO_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
|
165 return; |
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 |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
168 result = CloseComponent(this->hidden->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) { |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
170 SDL_SetError("COREAUDIO_CloseAudio: CloseComponent"); |
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 } |
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
|
173 |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
174 SDL_free(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
|
175 SDL_free(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
|
176 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
|
177 } |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 #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
|
180 if (result != noErr) { \ |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
181 COREAUDIO_CloseAudio(this); \ |
2017
df06e6eb65c6
Fixed macosx audio initialization (passed wrong struct to CoreAudio).
Ryan C. Gordon <icculus@icculus.org>
parents:
2016
diff
changeset
|
182 SDL_SetError("CoreAudio error (%s): %d", msg, (int) result); \ |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 return -1; \ |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 } |
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 |
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
|
187 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
|
188 COREAUDIO_OpenAudio(_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
|
189 { |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 OSStatus result = noErr; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 Component comp; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 ComponentDescription desc; |
936
84f930aebaeb
CoreAudio driver works on Mac OSX 10.1
Sam Lantinga <slouken@libsdl.org>
parents:
935
diff
changeset
|
193 struct AudioUnitInputCallback callback; |
2016 | 194 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
|
195 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
|
196 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
|
197 |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
198 /* 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
|
199 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
|
200 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
|
201 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
|
202 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
|
203 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
|
204 } |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
205 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
|
206 |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
207 /* !!! FIXME: check devname and iscapture... */ |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
208 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 /* Setup a AudioStreamBasicDescription with the requested format */ |
2043 | 210 memset(&strdesc, '\0', sizeof(AudioStreamBasicDescription)); |
2016 | 211 strdesc.mFormatID = kAudioFormatLinearPCM; |
212 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
|
213 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
|
214 strdesc.mSampleRate = this->spec.freq; |
2016 | 215 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
|
216 |
2003
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
217 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
|
218 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
|
219 /* 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
|
220 switch (test_format) { |
2043 | 221 case AUDIO_U8: |
222 case AUDIO_S8: | |
223 case AUDIO_U16LSB: | |
224 case AUDIO_S16LSB: | |
225 case AUDIO_U16MSB: | |
226 case AUDIO_S16MSB: | |
227 case AUDIO_S32LSB: | |
228 case AUDIO_S32MSB: | |
229 case AUDIO_F32LSB: | |
230 case AUDIO_F32MSB: | |
231 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
|
232 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
|
233 if (SDL_AUDIO_ISBIGENDIAN(this->spec.format)) |
2043 | 234 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
|
235 |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
236 if (SDL_AUDIO_ISFLOAT(this->spec.format)) |
2043 | 237 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
|
238 else if (SDL_AUDIO_ISSIGNED(this->spec.format)) |
2043 | 239 strdesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger; |
240 break; | |
2003
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
241 } |
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
242 } |
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
243 |
2043 | 244 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
|
245 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
|
246 return 0; |
2003
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
247 } |
506851d3efa4
Mac OS X audio backend now supports int32/float32.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
248 |
2016 | 249 strdesc.mBytesPerFrame = |
250 strdesc.mBitsPerChannel * strdesc.mChannelsPerFrame / 8; | |
251 strdesc.mBytesPerPacket = | |
252 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
|
253 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 /* Locate the default output audio unit */ |
2043 | 255 memset(&desc, '\0', sizeof(ComponentDescription)); |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 desc.componentType = kAudioUnitComponentType; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
257 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
|
258 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
|
259 desc.componentFlags = 0; |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
260 desc.componentFlagsMask = 0; |
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
|
261 |
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
|
262 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
|
263 if (comp == NULL) { |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
264 COREAUDIO_CloseAudio(this); |
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
|
265 SDL_SetError |
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
|
266 ("Failed to start CoreAudio: FindNextComponent returned NULL"); |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
267 return 0; |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 } |
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
|
269 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 /* Open & initialize the default output audio unit */ |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
271 result = OpenAComponent(comp, &this->hidden->outputAudioUnit); |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 CHECK_RESULT("OpenAComponent") |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
273 result = AudioUnitInitialize(this->hidden->outputAudioUnit); |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
274 CHECK_RESULT("AudioUnitInitialize") |
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
|
275 /* Set the input format of the audio unit. */ |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
276 result = AudioUnitSetProperty(this->hidden->outputAudioUnit, |
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
|
277 kAudioUnitProperty_StreamFormat, |
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
|
278 kAudioUnitScope_Input, |
2043 | 279 0, &strdesc, sizeof(strdesc)); |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)") |
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
|
281 /* Set the audio callback */ |
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
|
282 callback.inputProc = audioCallback; |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 callback.inputProcRefCon = this; |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
284 result = AudioUnitSetProperty(this->hidden->outputAudioUnit, |
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
|
285 kAudioUnitProperty_SetInputCallback, |
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 kAudioUnitScope_Input, |
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
|
287 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
|
288 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)") |
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
|
289 /* Calculate the final parameters for this audio specification */ |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
290 SDL_CalculateAudioSpec(&this->spec); |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 /* Allocate a sample buffer */ |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
293 this->hidden->bufferOffset = this->hidden->bufferSize = this->spec.size; |
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
294 this->hidden->buffer = SDL_malloc(this->hidden->bufferSize); |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
295 |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
296 /* Finally, start processing of the audio unit */ |
3784
37c9c4590689
First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
297 result = AudioOutputUnitStart(this->hidden->outputAudioUnit); |
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
|
298 CHECK_RESULT("AudioOutputUnitStart") |
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
|
299 /* We're running! */ |
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
|
300 return (1); |
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
|
301 } |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 |
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
|
303 /* vi: set ts=4 sw=4 expandtab: */ |