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