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