Mercurial > sdl-ios-xcode
annotate src/audio/macrom/SDL_romaudio.c @ 1336:3692456e7b0f
Use SDL_ prefixed versions of C library functions.
FIXME:
Change #include <stdlib.h> to #include "SDL_stdlib.h"
Change #include <string.h> to #include "SDL_string.h"
Make sure nothing else broke because of this...
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 06:59:48 +0000 |
parents | c9b51268668f |
children | 604d73db6802 |
rev | line source |
---|---|
0 | 1 /* |
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:
1135
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
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:
1135
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 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:
1135
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1135
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1135
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:
1135
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:
1135
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 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 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
23 #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
|
24 # 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
|
25 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) |
0 | 26 # include <Carbon.h> |
27 #else | |
28 # include <Sound.h> /* SoundManager interface */ | |
29 # 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
|
30 # include <DriverServices.h> |
0 | 31 #endif |
32 | |
33 #include <stdlib.h> | |
34 #include <stdio.h> | |
35 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
36 #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
|
37 #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
|
38 #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
|
39 #endif |
1135
cf6133247d34
Mac Classic and CodeWarrior patches.
Ryan C. Gordon <icculus@icculus.org>
parents:
1133
diff
changeset
|
40 #if !defined(NewSndCallBackUPP) |
cf6133247d34
Mac Classic and CodeWarrior patches.
Ryan C. Gordon <icculus@icculus.org>
parents:
1133
diff
changeset
|
41 #define NewSndCallBackUPP NewSndCallBackProc |
cf6133247d34
Mac Classic and CodeWarrior patches.
Ryan C. Gordon <icculus@icculus.org>
parents:
1133
diff
changeset
|
42 #endif |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
43 #endif |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
44 |
0 | 45 #include "SDL_endian.h" |
46 #include "SDL_audio.h" | |
47 #include "SDL_audio_c.h" | |
48 #include "SDL_audiomem.h" | |
49 #include "SDL_sysaudio.h" | |
50 #include "SDL_romaudio.h" | |
51 | |
52 /* Audio driver functions */ | |
53 | |
54 static void Mac_CloseAudio(_THIS); | |
55 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
|
56 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
|
57 static void Mac_UnlockAudio(_THIS); |
0 | 58 |
59 /* Audio driver bootstrap functions */ | |
60 | |
61 | |
62 static int Audio_Available(void) | |
63 { | |
64 return(1); | |
65 } | |
66 | |
67 static void Audio_DeleteDevice(SDL_AudioDevice *device) | |
68 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
69 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
70 SDL_free(device); |
0 | 71 } |
72 | |
73 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | |
74 { | |
75 SDL_AudioDevice *this; | |
76 | |
77 /* Initialize all variables that we clean on shutdown */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
78 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); |
0 | 79 if ( this ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
80 SDL_memset(this, 0, (sizeof *this)); |
0 | 81 this->hidden = (struct SDL_PrivateAudioData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
82 SDL_malloc((sizeof *this->hidden)); |
0 | 83 } |
84 if ( (this == NULL) || (this->hidden == NULL) ) { | |
85 SDL_OutOfMemory(); | |
86 if ( this ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
87 SDL_free(this); |
0 | 88 } |
89 return(0); | |
90 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
91 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
0 | 92 |
93 /* Set the function pointers */ | |
94 this->OpenAudio = Mac_OpenAudio; | |
95 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
|
96 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
|
97 this->UnlockAudio = Mac_UnlockAudio; |
0 | 98 this->free = Audio_DeleteDevice; |
99 | |
348
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
100 #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
|
101 this->LockAudio = NULL; |
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
102 this->UnlockAudio = NULL; |
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
103 #endif |
0 | 104 return this; |
105 } | |
106 | |
107 AudioBootStrap SNDMGR_bootstrap = { | |
108 "sndmgr", "MacOS SoundManager 3.0", | |
109 Audio_Available, Audio_CreateDevice | |
110 }; | |
111 | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
112 #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
|
113 /* 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
|
114 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
115 #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
|
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 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
|
118 static volatile SInt32 need_to_mix = 0; |
0 | 119 |
120 static UInt8 *buffer[2]; | |
121 static volatile UInt32 running = 0; | |
122 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
|
123 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
|
124 |
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 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
|
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 if ( ! audio->paused ) { |
348
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
128 #ifdef MACOSX |
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
129 SDL_mutexP(audio->mixer_lock); |
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
130 #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
|
131 if ( audio->convert.needed ) { |
348
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
132 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
|
133 (Uint8 *)audio->convert.buf,audio->convert.len); |
348
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
134 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
|
135 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
|
136 /* 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
|
137 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
138 SDL_memcpy(buffer, audio->convert.buf, audio->convert.len_cvt); |
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 } else { |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
140 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
|
141 } |
348
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
142 #ifdef MACOSX |
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
143 SDL_mutexV(audio->mixer_lock); |
25809353f877
Re-added MacOS X audio locking
Sam Lantinga <slouken@libsdl.org>
parents:
324
diff
changeset
|
144 #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
|
145 } |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
146 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
147 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
|
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 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
150 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
|
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 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
|
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 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
155 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
|
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 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
|
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 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
|
160 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
|
161 return; |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
162 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
163 /* 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
|
164 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
|
165 /* |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
166 * 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
|
167 * 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
|
168 * 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
|
169 */ |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
170 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
|
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 } |
0 | 173 |
174 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
|
175 UInt32 play_me; |
0 | 176 SndCommand cmd; |
177 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
|
178 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
179 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
|
180 |
47
45b1c4303f87
Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
181 fill_me = cmd_passed->param2; /* buffer that has just finished playing, so fill it */ |
0 | 182 play_me = ! fill_me; /* filled buffer to play _now_ */ |
183 | |
184 if ( ! audio->enabled ) { | |
185 return; | |
186 } | |
187 | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
188 /* queue previously mixed buffer for playback. */ |
0 | 189 header.samplePtr = (Ptr)buffer[play_me]; |
190 cmd.cmd = bufferCmd; | |
191 cmd.param1 = 0; | |
192 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
|
193 SndDoCommand (chan, &cmd, 0); |
47
45b1c4303f87
Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
194 |
0 | 195 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
|
196 |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
197 /* |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
198 * 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
|
199 * 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
|
200 */ |
324
f25f666d609a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
323
diff
changeset
|
201 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
|
202 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
|
203 } |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
204 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
205 /* 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
|
206 if ( running ) { |
0 | 207 cmd.cmd = callBackCmd; |
208 cmd.param1 = 0; | |
209 cmd.param2 = play_me; | |
210 | |
211 SndDoCommand (chan, &cmd, 0); | |
212 } | |
213 } | |
214 | |
215 static int Mac_OpenAudio(_THIS, SDL_AudioSpec *spec) { | |
216 | |
217 SndCallBackUPP callback; | |
218 int sample_bits; | |
219 int i; | |
220 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
|
221 |
0 | 222 /* Very few conversions are required, but... */ |
223 switch (spec->format) { | |
224 case AUDIO_S8: | |
225 spec->format = AUDIO_U8; | |
226 break; | |
227 case AUDIO_U16LSB: | |
228 spec->format = AUDIO_S16LSB; | |
229 break; | |
230 case AUDIO_U16MSB: | |
231 spec->format = AUDIO_S16MSB; | |
232 break; | |
233 } | |
234 SDL_CalculateAudioSpec(spec); | |
235 | |
236 /* initialize bufferCmd header */ | |
237 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
|
238 callback = (SndCallBackUPP) NewSndCallBackUPP (callBackProc); |
0 | 239 sample_bits = spec->size / spec->samples / spec->channels * 8; |
240 | |
241 #ifdef DEBUG_AUDIO | |
242 fprintf(stderr, | |
243 "Audio format 0x%x, channels = %d, sample_bits = %d, frequency = %d\n", | |
244 spec->format, spec->channels, sample_bits, spec->freq); | |
245 #endif /* DEBUG_AUDIO */ | |
246 | |
247 header.numChannels = spec->channels; | |
248 header.sampleSize = sample_bits; | |
249 header.sampleRate = spec->freq << 16; | |
250 header.numFrames = spec->samples; | |
251 header.encode = cmpSH; | |
252 | |
253 /* Note that we install the 16bitLittleEndian Converter if needed. */ | |
254 if ( spec->format == 0x8010 ) { | |
255 header.compressionID = fixedCompression; | |
256 header.format = k16BitLittleEndianFormat; | |
257 } | |
258 | |
259 /* allocate 2 buffers */ | |
260 for (i=0; i<2; i++) { | |
261 buffer[i] = (UInt8*)malloc (sizeof(UInt8) * spec->size); | |
262 if (buffer[i] == NULL) { | |
263 SDL_OutOfMemory(); | |
264 return (-1); | |
265 } | |
266 memset (buffer[i], 0, spec->size); | |
267 } | |
268 | |
269 /* Create the sound manager channel */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
270 channel = (SndChannelPtr)SDL_malloc(sizeof(*channel)); |
0 | 271 if ( channel == NULL ) { |
272 SDL_OutOfMemory(); | |
273 return(-1); | |
274 } | |
275 if ( spec->channels >= 2 ) { | |
276 initOptions = initStereo; | |
277 } else { | |
278 initOptions = initMono; | |
279 } | |
280 channel->userInfo = (long)this; | |
281 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
|
282 if ( SndNewChannel(&channel, sampledSynth, initOptions, callback) != noErr ) { |
0 | 283 SDL_SetError("Unable to create audio channel"); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
284 SDL_free(channel); |
0 | 285 channel = NULL; |
286 return(-1); | |
287 } | |
288 | |
289 /* start playback */ | |
290 { | |
291 SndCommand cmd; | |
292 cmd.cmd = callBackCmd; | |
293 cmd.param2 = 0; | |
294 running = 1; | |
295 SndDoCommand (channel, &cmd, 0); | |
296 } | |
297 | |
298 return 1; | |
299 } | |
300 | |
301 static void Mac_CloseAudio(_THIS) { | |
302 | |
303 int i; | |
304 | |
305 running = 0; | |
306 | |
307 if (channel) { | |
308 SndDisposeChannel (channel, true); | |
309 channel = NULL; | |
310 } | |
311 | |
312 for ( i=0; i<2; ++i ) { | |
313 if ( buffer[i] ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
314 SDL_free(buffer[i]); |
0 | 315 buffer[i] = NULL; |
316 } | |
317 } | |
318 } | |
319 | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
320 #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
|
321 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
322 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
|
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 /* 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
|
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 |
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
327 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
|
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 /* 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
|
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 |
0 | 332 |
333 /* This function is called by Sound Manager when it has exhausted one of | |
334 the buffers, so we'll zero it to silence and fill it with audio if | |
335 we're not paused. | |
336 */ | |
337 static pascal | |
338 void sndDoubleBackProc (SndChannelPtr chan, SndDoubleBufferPtr newbuf) | |
339 { | |
340 SDL_AudioDevice *audio = (SDL_AudioDevice *)newbuf->dbUserInfo[0]; | |
341 | |
342 /* If audio is quitting, don't do anything */ | |
343 if ( ! audio->enabled ) { | |
344 return; | |
345 } | |
346 memset (newbuf->dbSoundData, 0, audio->spec.size); | |
347 newbuf->dbNumFrames = audio->spec.samples; | |
348 if ( ! audio->paused ) { | |
349 if ( audio->convert.needed ) { | |
350 audio->spec.callback(audio->spec.userdata, | |
351 (Uint8 *)audio->convert.buf,audio->convert.len); | |
352 SDL_ConvertAudio(&audio->convert); | |
353 #if 0 | |
354 if ( audio->convert.len_cvt != audio->spec.size ) { | |
355 /* Uh oh... probably crashes here */; | |
356 } | |
357 #endif | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
358 SDL_memcpy(newbuf->dbSoundData, audio->convert.buf, |
0 | 359 audio->convert.len_cvt); |
360 } else { | |
361 audio->spec.callback(audio->spec.userdata, | |
362 (Uint8 *)newbuf->dbSoundData, audio->spec.size); | |
363 } | |
364 } | |
365 newbuf->dbFlags |= dbBufferReady; | |
366 } | |
367 | |
368 static int DoubleBufferAudio_Available(void) | |
369 { | |
370 int available; | |
371 NumVersion sndversion; | |
372 long response; | |
373 | |
374 available = 0; | |
375 sndversion = SndSoundManagerVersion(); | |
376 if ( sndversion.majorRev >= 3 ) { | |
377 if ( Gestalt(gestaltSoundAttr, &response) == noErr ) { | |
378 if ( (response & (1 << gestaltSndPlayDoubleBuffer)) ) { | |
379 available = 1; | |
380 } | |
381 } | |
382 } else { | |
383 if ( Gestalt(gestaltSoundAttr, &response) == noErr ) { | |
384 if ( (response & (1 << gestaltHasASC)) ) { | |
385 available = 1; | |
386 } | |
387 } | |
388 } | |
389 return(available); | |
390 } | |
391 | |
392 static void Mac_CloseAudio(_THIS) | |
393 { | |
394 int i; | |
395 | |
396 if ( channel != NULL ) { | |
397 /* Clean up the audio channel */ | |
398 SndDisposeChannel(channel, true); | |
399 channel = NULL; | |
400 } | |
401 for ( i=0; i<2; ++i ) { | |
402 if ( audio_buf[i] ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
403 SDL_free(audio_buf[i]); |
0 | 404 audio_buf[i] = NULL; |
405 } | |
406 } | |
407 } | |
408 | |
409 static int Mac_OpenAudio(_THIS, SDL_AudioSpec *spec) | |
410 { | |
411 SndDoubleBufferHeader2 audio_dbh; | |
412 int i; | |
413 long initOptions; | |
414 int sample_bits; | |
415 SndDoubleBackUPP doubleBackProc; | |
416 | |
417 /* Check to make sure double-buffered audio is available */ | |
418 if ( ! DoubleBufferAudio_Available() ) { | |
419 SDL_SetError("Sound manager doesn't support double-buffering"); | |
420 return(-1); | |
421 } | |
422 | |
423 /* Very few conversions are required, but... */ | |
424 switch (spec->format) { | |
425 case AUDIO_S8: | |
426 spec->format = AUDIO_U8; | |
427 break; | |
428 case AUDIO_U16LSB: | |
429 spec->format = AUDIO_S16LSB; | |
430 break; | |
431 case AUDIO_U16MSB: | |
432 spec->format = AUDIO_S16MSB; | |
433 break; | |
434 } | |
435 SDL_CalculateAudioSpec(spec); | |
436 | |
437 /* initialize the double-back header */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
438 SDL_memset(&audio_dbh, 0, sizeof(audio_dbh)); |
0 | 439 doubleBackProc = NewSndDoubleBackProc (sndDoubleBackProc); |
440 sample_bits = spec->size / spec->samples / spec->channels * 8; | |
441 | |
442 audio_dbh.dbhNumChannels = spec->channels; | |
443 audio_dbh.dbhSampleSize = sample_bits; | |
444 audio_dbh.dbhCompressionID = 0; | |
445 audio_dbh.dbhPacketSize = 0; | |
446 audio_dbh.dbhSampleRate = spec->freq << 16; | |
447 audio_dbh.dbhDoubleBack = doubleBackProc; | |
448 audio_dbh.dbhFormat = 0; | |
449 | |
450 /* Note that we install the 16bitLittleEndian Converter if needed. */ | |
451 if ( spec->format == 0x8010 ) { | |
452 audio_dbh.dbhCompressionID = fixedCompression; | |
453 audio_dbh.dbhFormat = k16BitLittleEndianFormat; | |
454 } | |
455 | |
456 /* allocate the 2 double-back buffers */ | |
457 for ( i=0; i<2; ++i ) { | |
458 audio_buf[i] = calloc(1, sizeof(SndDoubleBuffer)+spec->size); | |
459 if ( audio_buf[i] == NULL ) { | |
460 SDL_OutOfMemory(); | |
461 return(-1); | |
462 } | |
463 audio_buf[i]->dbNumFrames = spec->samples; | |
464 audio_buf[i]->dbFlags = dbBufferReady; | |
465 audio_buf[i]->dbUserInfo[0] = (long)this; | |
466 audio_dbh.dbhBufferPtr[i] = audio_buf[i]; | |
467 } | |
468 | |
469 /* Create the sound manager channel */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
470 channel = (SndChannelPtr)SDL_malloc(sizeof(*channel)); |
0 | 471 if ( channel == NULL ) { |
472 SDL_OutOfMemory(); | |
473 return(-1); | |
474 } | |
475 if ( spec->channels >= 2 ) { | |
476 initOptions = initStereo; | |
477 } else { | |
478 initOptions = initMono; | |
479 } | |
480 channel->userInfo = 0; | |
481 channel->qLength = 128; | |
482 if ( SndNewChannel(&channel, sampledSynth, initOptions, 0L) != noErr ) { | |
483 SDL_SetError("Unable to create audio channel"); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
484 SDL_free(channel); |
0 | 485 channel = NULL; |
486 return(-1); | |
487 } | |
488 | |
489 /* Start playback */ | |
490 if ( SndPlayDoubleBuffer(channel, (SndDoubleBufferHeaderPtr)&audio_dbh) | |
491 != noErr ) { | |
492 SDL_SetError("Unable to play double buffered audio"); | |
493 return(-1); | |
494 } | |
495 | |
496 return 1; | |
497 } | |
498 | |
323
b7e8038e40ae
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
499 #endif /* TARGET_API_MAC_CARBON || USE_RYANS_SOUNDCODE */ |
0 | 500 |