Mercurial > sdl-ios-xcode
annotate src/audio/macrom/SDL_romaudio.c @ 1133:609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
To: SDL Developers <sdl@libsdl.org>
From: =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb@algonet.se>
Date: Mon, 30 May 2005 23:29:04 +0200
Subject: [SDL] Mac OS X Video Drivers [patch]
I've updated/added the Carbon and X11 video drivers
to the Mac OS X port of SDL 1.2 (the CVS version),
and made the Cocoa driver and runtime *optional*.
The default is still Cocoa, and the "Quartz" driver.
But you can now also use "toolbox" for Carbon, and
"x11" for running with Apple's (or other) X11 server:
export SDL_VIDEODRIVER=x11
export SDL_VIDEO_GL_DRIVER=/usr/X11R6/lib/libGL.dylib
It also checks if the frameworks are available, by a:
#include <Carbon/Carbon.h> or #import <Cocoa/Cocoa.h>
(this should make it configure on plain Darwin as well?)
Here are the new configure targets:
--enable-video-cocoa use Cocoa/Quartz video driver default=yes
--enable-video-carbon use Carbon/QuickDraw video driver default=yes
--enable-video-x11 use X11 video driver default=no
./configure --enable-video-cocoa --enable-video-carbon
--enable-video-x11 \
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib
The Carbon version is just an updated version of the old
SDL driver for Mac OS 9, and could probably be improved...
(but it does work, including the Carbon version of SDLmain)
If you disable cocoa, you can run with -framework Carbon only,
and the C version of SDL_main.c. And if you disable carbon too,
you can still use the X11 version which doesn't require SDLmain.
I updated the DrawSprocket version, but did not include it.
(no blitters or VRAM GWorlds etc. available on OS X anyway)
Besides for Mac OS 9, I don't think there's any use for it ?
And note that any performance on Mac OS X equals OpenGL anyway...
You can get "fair" software SDL results on captured CG displays,
but for decent frame rates you need to be using GL for rendering.
Finally, here is the patch itself:
http://www.algonet.se/~afb/SDL-12CVS-macvideo.patch
--anders
PS. It says "video", but as usual it applies to mouse/keyboard too.
------
To: A list for developers using the SDL library <sdl@libsdl.org>
From: =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb@algonet.se>
Date: Sun, 4 Sep 2005 10:02:15 +0200
Subject: [SDL] Updated Mac patch
Updated the previous Mac patch to disable Carbon by default.
Also "fixed" the SDL.spec again, so that it builds on Darwin.
http://www.algonet.se/~afb/SDL-1.2.9-mac.patch
Also applied fine to SDL12 CVS, when I tried it.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 08 Sep 2005 06:16:14 +0000 |
parents | b8d311d90021 |
children | cf6133247d34 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
348
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
47
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
28 #if defined(__APPLE__) && defined(__MACH__) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
29 # include <Carbon/Carbon.h> |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
30 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) |
0 | 31 # include <Carbon.h> |
32 #else | |
33 # include <Sound.h> /* SoundManager interface */ | |
34 # include <Gestalt.h> | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
35 # include <DriverServices.h> |
0 | 36 #endif |
37 | |
38 #include <stdlib.h> | |
39 #include <stdio.h> | |
40 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
41 #if !defined(NewSndCallBackUPP) && (UNIVERSAL_INTERFACES_VERSION < 0x0335) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
42 #if !defined(NewSndCallBackProc) /* avoid circular redefinition... */ |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
43 #define NewSndCallBackUPP NewSndCallBackProc |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
44 #endif |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
45 #endif |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
46 |
0 | 47 #include "SDL_endian.h" |
48 #include "SDL_audio.h" | |
49 #include "SDL_audio_c.h" | |
50 #include "SDL_audiomem.h" | |
51 #include "SDL_sysaudio.h" | |
52 #include "SDL_romaudio.h" | |
53 | |
54 /* Audio driver functions */ | |
55 | |
56 static void Mac_CloseAudio(_THIS); | |
57 static int Mac_OpenAudio(_THIS, SDL_AudioSpec *spec); | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
58 static void Mac_LockAudio(_THIS); |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
59 static void Mac_UnlockAudio(_THIS); |
0 | 60 |
61 /* Audio driver bootstrap functions */ | |
62 | |
63 | |
64 static int Audio_Available(void) | |
65 { | |
66 return(1); | |
67 } | |
68 | |
69 static void Audio_DeleteDevice(SDL_AudioDevice *device) | |
70 { | |
71 free(device->hidden); | |
72 free(device); | |
73 } | |
74 | |
75 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | |
76 { | |
77 SDL_AudioDevice *this; | |
78 | |
79 /* Initialize all variables that we clean on shutdown */ | |
80 this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice)); | |
81 if ( this ) { | |
82 memset(this, 0, (sizeof *this)); | |
83 this->hidden = (struct SDL_PrivateAudioData *) | |
84 malloc((sizeof *this->hidden)); | |
85 } | |
86 if ( (this == NULL) || (this->hidden == NULL) ) { | |
87 SDL_OutOfMemory(); | |
88 if ( this ) { | |
89 free(this); | |
90 } | |
91 return(0); | |
92 } | |
93 memset(this->hidden, 0, (sizeof *this->hidden)); | |
94 | |
95 /* Set the function pointers */ | |
96 this->OpenAudio = Mac_OpenAudio; | |
97 this->CloseAudio = Mac_CloseAudio; | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
98 this->LockAudio = Mac_LockAudio; |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
99 this->UnlockAudio = Mac_UnlockAudio; |
0 | 100 this->free = Audio_DeleteDevice; |
101 | |
348
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
102 #ifdef MACOSX /* MacOS X uses threaded audio, so normal thread code is okay */ |
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
103 this->LockAudio = NULL; |
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
104 this->UnlockAudio = NULL; |
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
105 #endif |
0 | 106 return this; |
107 } | |
108 | |
109 AudioBootStrap SNDMGR_bootstrap = { | |
110 "sndmgr", "MacOS SoundManager 3.0", | |
111 Audio_Available, Audio_CreateDevice | |
112 }; | |
113 | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
114 #if defined(TARGET_API_MAC_CARBON) || defined(USE_RYANS_SOUNDCODE) |
348
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
115 /* This works correctly on MacOS X */ |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
116 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
117 #pragma options align=power |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
118 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
119 static volatile SInt32 audio_is_locked = 0; |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
120 static volatile SInt32 need_to_mix = 0; |
0 | 121 |
122 static UInt8 *buffer[2]; | |
123 static volatile UInt32 running = 0; | |
124 static CmpSoundHeader header; | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
125 static volatile Uint32 fill_me = 0; |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
126 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
127 static void mix_buffer(SDL_AudioDevice *audio, UInt8 *buffer) |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
128 { |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
129 if ( ! audio->paused ) { |
348
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
130 #ifdef MACOSX |
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
131 SDL_mutexP(audio->mixer_lock); |
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
132 #endif |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
133 if ( audio->convert.needed ) { |
348
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
134 audio->spec.callback(audio->spec.userdata, |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
135 (Uint8 *)audio->convert.buf,audio->convert.len); |
348
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
136 SDL_ConvertAudio(&audio->convert); |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
137 if ( audio->convert.len_cvt != audio->spec.size ) { |
348
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
138 /* Uh oh... probably crashes here */; |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
139 } |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
140 memcpy(buffer, audio->convert.buf, audio->convert.len_cvt); |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
141 } else { |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
142 audio->spec.callback(audio->spec.userdata, buffer, audio->spec.size); |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
143 } |
348
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
144 #ifdef MACOSX |
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
145 SDL_mutexV(audio->mixer_lock); |
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
146 #endif |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
147 } |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
148 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
149 DecrementAtomic((SInt32 *) &need_to_mix); |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
150 } |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
151 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
152 static void Mac_LockAudio(_THIS) |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
153 { |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
154 IncrementAtomic((SInt32 *) &audio_is_locked); |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
155 } |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
156 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
157 static void Mac_UnlockAudio(_THIS) |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
158 { |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
159 SInt32 oldval; |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
160 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
161 oldval = DecrementAtomic((SInt32 *) &audio_is_locked); |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
162 if ( oldval != 1 ) /* != 1 means audio is still locked. */ |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
163 return; |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
164 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
165 /* Did we miss the chance to mix in an interrupt? Do it now. */ |
324
f25f666d609a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
323
diff
changeset
|
166 if ( BitAndAtomic (0xFFFFFFFF, (UInt32 *) &need_to_mix) ) { |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
167 /* |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
168 * Note that this could be a problem if you missed an interrupt |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
169 * while the audio was locked, and get preempted by a second |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
170 * interrupt here, but that means you locked for way too long anyhow. |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
171 */ |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
172 mix_buffer (this, buffer[fill_me]); |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
173 } |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
174 } |
0 | 175 |
176 static void callBackProc (SndChannel *chan, SndCommand *cmd_passed ) { | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
177 UInt32 play_me; |
0 | 178 SndCommand cmd; |
179 SDL_AudioDevice *audio = (SDL_AudioDevice *)chan->userInfo; | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
180 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
181 IncrementAtomic((SInt32 *) &need_to_mix); |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
182 |
47
45b1c4303f87
Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
183 fill_me = cmd_passed->param2; /* buffer that has just finished playing, so fill it */ |
0 | 184 play_me = ! fill_me; /* filled buffer to play _now_ */ |
185 | |
186 if ( ! audio->enabled ) { | |
187 return; | |
188 } | |
189 | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
190 /* queue previously mixed buffer for playback. */ |
0 | 191 header.samplePtr = (Ptr)buffer[play_me]; |
192 cmd.cmd = bufferCmd; | |
193 cmd.param1 = 0; | |
194 cmd.param2 = (long)&header; | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
195 SndDoCommand (chan, &cmd, 0); |
47
45b1c4303f87
Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
196 |
0 | 197 memset (buffer[fill_me], 0, audio->spec.size); |
47
45b1c4303f87
Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
198 |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
199 /* |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
200 * if audio device isn't locked, mix the next buffer to be queued in |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
201 * the memory block that just finished playing. |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
202 */ |
324
f25f666d609a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
323
diff
changeset
|
203 if ( ! BitAndAtomic(0xFFFFFFFF, (UInt32 *) &audio_is_locked) ) { |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
204 mix_buffer (audio, buffer[fill_me]); |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
205 } |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
206 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
207 /* set this callback to run again when current buffer drains. */ |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
208 if ( running ) { |
0 | 209 cmd.cmd = callBackCmd; |
210 cmd.param1 = 0; | |
211 cmd.param2 = play_me; | |
212 | |
213 SndDoCommand (chan, &cmd, 0); | |
214 } | |
215 } | |
216 | |
217 static int Mac_OpenAudio(_THIS, SDL_AudioSpec *spec) { | |
218 | |
219 SndCallBackUPP callback; | |
220 int sample_bits; | |
221 int i; | |
222 long initOptions; | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
223 |
0 | 224 /* Very few conversions are required, but... */ |
225 switch (spec->format) { | |
226 case AUDIO_S8: | |
227 spec->format = AUDIO_U8; | |
228 break; | |
229 case AUDIO_U16LSB: | |
230 spec->format = AUDIO_S16LSB; | |
231 break; | |
232 case AUDIO_U16MSB: | |
233 spec->format = AUDIO_S16MSB; | |
234 break; | |
235 } | |
236 SDL_CalculateAudioSpec(spec); | |
237 | |
238 /* initialize bufferCmd header */ | |
239 memset (&header, 0, sizeof(header)); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
240 callback = (SndCallBackUPP) NewSndCallBackUPP (callBackProc); |
0 | 241 sample_bits = spec->size / spec->samples / spec->channels * 8; |
242 | |
243 #ifdef DEBUG_AUDIO | |
244 fprintf(stderr, | |
245 "Audio format 0x%x, channels = %d, sample_bits = %d, frequency = %d\n", | |
246 spec->format, spec->channels, sample_bits, spec->freq); | |
247 #endif /* DEBUG_AUDIO */ | |
248 | |
249 header.numChannels = spec->channels; | |
250 header.sampleSize = sample_bits; | |
251 header.sampleRate = spec->freq << 16; | |
252 header.numFrames = spec->samples; | |
253 header.encode = cmpSH; | |
254 | |
255 /* Note that we install the 16bitLittleEndian Converter if needed. */ | |
256 if ( spec->format == 0x8010 ) { | |
257 header.compressionID = fixedCompression; | |
258 header.format = k16BitLittleEndianFormat; | |
259 } | |
260 | |
261 /* allocate 2 buffers */ | |
262 for (i=0; i<2; i++) { | |
263 buffer[i] = (UInt8*)malloc (sizeof(UInt8) * spec->size); | |
264 if (buffer[i] == NULL) { | |
265 SDL_OutOfMemory(); | |
266 return (-1); | |
267 } | |
268 memset (buffer[i], 0, spec->size); | |
269 } | |
270 | |
271 /* Create the sound manager channel */ | |
272 channel = (SndChannelPtr)malloc(sizeof(*channel)); | |
273 if ( channel == NULL ) { | |
274 SDL_OutOfMemory(); | |
275 return(-1); | |
276 } | |
277 if ( spec->channels >= 2 ) { | |
278 initOptions = initStereo; | |
279 } else { | |
280 initOptions = initMono; | |
281 } | |
282 channel->userInfo = (long)this; | |
283 channel->qLength = 128; | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
284 if ( SndNewChannel(&channel, sampledSynth, initOptions, callback) != noErr ) { |
0 | 285 SDL_SetError("Unable to create audio channel"); |
286 free(channel); | |
287 channel = NULL; | |
288 return(-1); | |
289 } | |
290 | |
291 /* start playback */ | |
292 { | |
293 SndCommand cmd; | |
294 cmd.cmd = callBackCmd; | |
295 cmd.param2 = 0; | |
296 running = 1; | |
297 SndDoCommand (channel, &cmd, 0); | |
298 } | |
299 | |
300 return 1; | |
301 } | |
302 | |
303 static void Mac_CloseAudio(_THIS) { | |
304 | |
305 int i; | |
306 | |
307 running = 0; | |
308 | |
309 if (channel) { | |
310 SndDisposeChannel (channel, true); | |
311 channel = NULL; | |
312 } | |
313 | |
314 for ( i=0; i<2; ++i ) { | |
315 if ( buffer[i] ) { | |
316 free(buffer[i]); | |
317 buffer[i] = NULL; | |
318 } | |
319 } | |
320 } | |
321 | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
322 #else /* !TARGET_API_MAC_CARBON && !USE_RYANS_SOUNDCODE */ |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
323 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
324 static void Mac_LockAudio(_THIS) |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
325 { |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
326 /* no-op. */ |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
327 } |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
328 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
329 static void Mac_UnlockAudio(_THIS) |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
330 { |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
331 /* no-op. */ |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
332 } |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
333 |
0 | 334 |
335 /* This function is called by Sound Manager when it has exhausted one of | |
336 the buffers, so we'll zero it to silence and fill it with audio if | |
337 we're not paused. | |
338 */ | |
339 static pascal | |
340 void sndDoubleBackProc (SndChannelPtr chan, SndDoubleBufferPtr newbuf) | |
341 { | |
342 SDL_AudioDevice *audio = (SDL_AudioDevice *)newbuf->dbUserInfo[0]; | |
343 | |
344 /* If audio is quitting, don't do anything */ | |
345 if ( ! audio->enabled ) { | |
346 return; | |
347 } | |
348 memset (newbuf->dbSoundData, 0, audio->spec.size); | |
349 newbuf->dbNumFrames = audio->spec.samples; | |
350 if ( ! audio->paused ) { | |
351 if ( audio->convert.needed ) { | |
352 audio->spec.callback(audio->spec.userdata, | |
353 (Uint8 *)audio->convert.buf,audio->convert.len); | |
354 SDL_ConvertAudio(&audio->convert); | |
355 #if 0 | |
356 if ( audio->convert.len_cvt != audio->spec.size ) { | |
357 /* Uh oh... probably crashes here */; | |
358 } | |
359 #endif | |
360 memcpy(newbuf->dbSoundData, audio->convert.buf, | |
361 audio->convert.len_cvt); | |
362 } else { | |
363 audio->spec.callback(audio->spec.userdata, | |
364 (Uint8 *)newbuf->dbSoundData, audio->spec.size); | |
365 } | |
366 } | |
367 newbuf->dbFlags |= dbBufferReady; | |
368 } | |
369 | |
370 static int DoubleBufferAudio_Available(void) | |
371 { | |
372 int available; | |
373 NumVersion sndversion; | |
374 long response; | |
375 | |
376 available = 0; | |
377 sndversion = SndSoundManagerVersion(); | |
378 if ( sndversion.majorRev >= 3 ) { | |
379 if ( Gestalt(gestaltSoundAttr, &response) == noErr ) { | |
380 if ( (response & (1 << gestaltSndPlayDoubleBuffer)) ) { | |
381 available = 1; | |
382 } | |
383 } | |
384 } else { | |
385 if ( Gestalt(gestaltSoundAttr, &response) == noErr ) { | |
386 if ( (response & (1 << gestaltHasASC)) ) { | |
387 available = 1; | |
388 } | |
389 } | |
390 } | |
391 return(available); | |
392 } | |
393 | |
394 static void Mac_CloseAudio(_THIS) | |
395 { | |
396 int i; | |
397 | |
398 if ( channel != NULL ) { | |
399 /* Clean up the audio channel */ | |
400 SndDisposeChannel(channel, true); | |
401 channel = NULL; | |
402 } | |
403 for ( i=0; i<2; ++i ) { | |
404 if ( audio_buf[i] ) { | |
405 free(audio_buf[i]); | |
406 audio_buf[i] = NULL; | |
407 } | |
408 } | |
409 } | |
410 | |
411 static int Mac_OpenAudio(_THIS, SDL_AudioSpec *spec) | |
412 { | |
413 SndDoubleBufferHeader2 audio_dbh; | |
414 int i; | |
415 long initOptions; | |
416 int sample_bits; | |
417 SndDoubleBackUPP doubleBackProc; | |
418 | |
419 /* Check to make sure double-buffered audio is available */ | |
420 if ( ! DoubleBufferAudio_Available() ) { | |
421 SDL_SetError("Sound manager doesn't support double-buffering"); | |
422 return(-1); | |
423 } | |
424 | |
425 /* Very few conversions are required, but... */ | |
426 switch (spec->format) { | |
427 case AUDIO_S8: | |
428 spec->format = AUDIO_U8; | |
429 break; | |
430 case AUDIO_U16LSB: | |
431 spec->format = AUDIO_S16LSB; | |
432 break; | |
433 case AUDIO_U16MSB: | |
434 spec->format = AUDIO_S16MSB; | |
435 break; | |
436 } | |
437 SDL_CalculateAudioSpec(spec); | |
438 | |
439 /* initialize the double-back header */ | |
440 memset(&audio_dbh, 0, sizeof(audio_dbh)); | |
441 doubleBackProc = NewSndDoubleBackProc (sndDoubleBackProc); | |
442 sample_bits = spec->size / spec->samples / spec->channels * 8; | |
443 | |
444 audio_dbh.dbhNumChannels = spec->channels; | |
445 audio_dbh.dbhSampleSize = sample_bits; | |
446 audio_dbh.dbhCompressionID = 0; | |
447 audio_dbh.dbhPacketSize = 0; | |
448 audio_dbh.dbhSampleRate = spec->freq << 16; | |
449 audio_dbh.dbhDoubleBack = doubleBackProc; | |
450 audio_dbh.dbhFormat = 0; | |
451 | |
452 /* Note that we install the 16bitLittleEndian Converter if needed. */ | |
453 if ( spec->format == 0x8010 ) { | |
454 audio_dbh.dbhCompressionID = fixedCompression; | |
455 audio_dbh.dbhFormat = k16BitLittleEndianFormat; | |
456 } | |
457 | |
458 /* allocate the 2 double-back buffers */ | |
459 for ( i=0; i<2; ++i ) { | |
460 audio_buf[i] = calloc(1, sizeof(SndDoubleBuffer)+spec->size); | |
461 if ( audio_buf[i] == NULL ) { | |
462 SDL_OutOfMemory(); | |
463 return(-1); | |
464 } | |
465 audio_buf[i]->dbNumFrames = spec->samples; | |
466 audio_buf[i]->dbFlags = dbBufferReady; | |
467 audio_buf[i]->dbUserInfo[0] = (long)this; | |
468 audio_dbh.dbhBufferPtr[i] = audio_buf[i]; | |
469 } | |
470 | |
471 /* Create the sound manager channel */ | |
472 channel = (SndChannelPtr)malloc(sizeof(*channel)); | |
473 if ( channel == NULL ) { | |
474 SDL_OutOfMemory(); | |
475 return(-1); | |
476 } | |
477 if ( spec->channels >= 2 ) { | |
478 initOptions = initStereo; | |
479 } else { | |
480 initOptions = initMono; | |
481 } | |
482 channel->userInfo = 0; | |
483 channel->qLength = 128; | |
484 if ( SndNewChannel(&channel, sampledSynth, initOptions, 0L) != noErr ) { | |
485 SDL_SetError("Unable to create audio channel"); | |
486 free(channel); | |
487 channel = NULL; | |
488 return(-1); | |
489 } | |
490 | |
491 /* Start playback */ | |
492 if ( SndPlayDoubleBuffer(channel, (SndDoubleBufferHeaderPtr)&audio_dbh) | |
493 != noErr ) { | |
494 SDL_SetError("Unable to play double buffered audio"); | |
495 return(-1); | |
496 } | |
497 | |
498 return 1; | |
499 } | |
500 | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
501 #endif /* TARGET_API_MAC_CARBON || USE_RYANS_SOUNDCODE */ |
0 | 502 |