Mercurial > sdl-ios-xcode
annotate src/audio/SDL_audio.c @ 1330:450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
using Visual C++ 2005
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 06 Feb 2006 08:28:51 +0000 |
parents | c9b51268668f |
children | 3692456e7b0f |
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:
1204
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:
1204
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:
1204
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:
1204
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:
1204
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:
1204
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:
1204
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:
148
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 /* Allow access to a raw mixing buffer */ | |
24 | |
25 #include "SDL.h" | |
26 #include "SDL_audio.h" | |
27 #include "SDL_timer.h" | |
28 #include "SDL_error.h" | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
29 #include "SDL_string.h" |
0 | 30 #include "SDL_audio_c.h" |
31 #include "SDL_audiomem.h" | |
32 #include "SDL_sysaudio.h" | |
33 | |
1190 | 34 #ifdef __OS2__ |
35 // We'll need the DosSetPriority() API! | |
36 #define INCL_DOSPROCESS | |
37 #include <os2.h> | |
38 #endif | |
39 | |
0 | 40 /* Available audio drivers */ |
41 static AudioBootStrap *bootstrap[] = { | |
121
43febd46d49d
Name changed from OBSD to OPENBSD_AUDIO
Sam Lantinga <slouken@libsdl.org>
parents:
94
diff
changeset
|
42 #ifdef OPENBSD_AUDIO_SUPPORT |
43febd46d49d
Name changed from OBSD to OPENBSD_AUDIO
Sam Lantinga <slouken@libsdl.org>
parents:
94
diff
changeset
|
43 &OPENBSD_AUDIO_bootstrap, |
94
ae6e6b73333f
Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
44 #endif |
0 | 45 #ifdef OSS_SUPPORT |
46 &DSP_bootstrap, | |
47 &DMA_bootstrap, | |
48 #endif | |
49 #ifdef ALSA_SUPPORT | |
50 &ALSA_bootstrap, | |
51 #endif | |
663
8bedd6d61642
Date: Sat, 2 Aug 2003 16:22:51 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
654
diff
changeset
|
52 #ifdef QNXNTOAUDIO_SUPPORT |
8bedd6d61642
Date: Sat, 2 Aug 2003 16:22:51 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
654
diff
changeset
|
53 &QNXNTOAUDIO_bootstrap, |
8bedd6d61642
Date: Sat, 2 Aug 2003 16:22:51 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
654
diff
changeset
|
54 #endif |
148
8758b8d42cd9
Audio subsystem no longer assumes sun audio API on UNIX systems
Sam Lantinga <slouken@libsdl.org>
parents:
121
diff
changeset
|
55 #ifdef SUNAUDIO_SUPPORT |
8758b8d42cd9
Audio subsystem no longer assumes sun audio API on UNIX systems
Sam Lantinga <slouken@libsdl.org>
parents:
121
diff
changeset
|
56 &SUNAUDIO_bootstrap, |
8758b8d42cd9
Audio subsystem no longer assumes sun audio API on UNIX systems
Sam Lantinga <slouken@libsdl.org>
parents:
121
diff
changeset
|
57 #endif |
8758b8d42cd9
Audio subsystem no longer assumes sun audio API on UNIX systems
Sam Lantinga <slouken@libsdl.org>
parents:
121
diff
changeset
|
58 #ifdef DMEDIA_SUPPORT |
8758b8d42cd9
Audio subsystem no longer assumes sun audio API on UNIX systems
Sam Lantinga <slouken@libsdl.org>
parents:
121
diff
changeset
|
59 &DMEDIA_bootstrap, |
35
d3bc792e136d
Added detection of Open Sound System on Solaris x86
Sam Lantinga <slouken@lokigames.com>
parents:
21
diff
changeset
|
60 #endif |
0 | 61 #ifdef ARTSC_SUPPORT |
62 &ARTSC_bootstrap, | |
63 #endif | |
64 #ifdef ESD_SUPPORT | |
65 &ESD_bootstrap, | |
66 #endif | |
67 #ifdef NAS_SUPPORT | |
68 &NAS_bootstrap, | |
69 #endif | |
70 #ifdef ENABLE_DIRECTX | |
71 &DSOUND_bootstrap, | |
72 #endif | |
73 #ifdef ENABLE_WINDIB | |
74 &WAVEOUT_bootstrap, | |
75 #endif | |
76 #ifdef __BEOS__ | |
77 &BAUDIO_bootstrap, | |
78 #endif | |
936
84f930aebaeb
CoreAudio driver works on Mac OSX 10.1
Sam Lantinga <slouken@libsdl.org>
parents:
935
diff
changeset
|
79 #ifdef MACOSX |
935
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
808
diff
changeset
|
80 &COREAUDIO_bootstrap, |
f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents:
808
diff
changeset
|
81 #endif |
0 | 82 #if defined(macintosh) || TARGET_API_MAC_CARBON |
83 &SNDMGR_bootstrap, | |
84 #endif | |
85 #ifdef _AIX | |
86 &Paud_bootstrap, | |
87 #endif | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
88 #ifdef ENABLE_AHI |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
89 &AHI_bootstrap, |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
90 #endif |
654
e92bcf2573cb
Added audio and CD-ROM support for OSF/Tru64 (thanks Hayashi!)
Sam Lantinga <slouken@libsdl.org>
parents:
644
diff
changeset
|
91 #ifdef MMEAUDIO_SUPPORT |
e92bcf2573cb
Added audio and CD-ROM support for OSF/Tru64 (thanks Hayashi!)
Sam Lantinga <slouken@libsdl.org>
parents:
644
diff
changeset
|
92 &MMEAUDIO_bootstrap, |
e92bcf2573cb
Added audio and CD-ROM support for OSF/Tru64 (thanks Hayashi!)
Sam Lantinga <slouken@libsdl.org>
parents:
644
diff
changeset
|
93 #endif |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
322
diff
changeset
|
94 #ifdef MINTAUDIO_SUPPORT |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
630
diff
changeset
|
95 &MINTAUDIO_GSXB_bootstrap, |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
630
diff
changeset
|
96 &MINTAUDIO_MCSN_bootstrap, |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
630
diff
changeset
|
97 &MINTAUDIO_STFA_bootstrap, |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
630
diff
changeset
|
98 &MINTAUDIO_XBIOS_bootstrap, |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
630
diff
changeset
|
99 &MINTAUDIO_DMA8_bootstrap, |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
322
diff
changeset
|
100 #endif |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
38
diff
changeset
|
101 #ifdef DISKAUD_SUPPORT |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
38
diff
changeset
|
102 &DISKAUD_bootstrap, |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
38
diff
changeset
|
103 #endif |
509
dad72daf44b3
Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
398
diff
changeset
|
104 #ifdef ENABLE_DC |
dad72daf44b3
Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
398
diff
changeset
|
105 &DCAUD_bootstrap, |
dad72daf44b3
Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
398
diff
changeset
|
106 #endif |
630
550bccdf04bd
Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
509
diff
changeset
|
107 #ifdef DRENDERER_SUPPORT |
550bccdf04bd
Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
509
diff
changeset
|
108 &DRENDERER_bootstrap, |
550bccdf04bd
Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
509
diff
changeset
|
109 #endif |
1190 | 110 #ifdef __OS2__ |
111 &DART_bootstrap, | |
112 #endif | |
0 | 113 NULL |
114 }; | |
115 SDL_AudioDevice *current_audio = NULL; | |
116 | |
117 /* Various local functions */ | |
118 int SDL_AudioInit(const char *driver_name); | |
119 void SDL_AudioQuit(void); | |
120 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
121 #ifdef ENABLE_AHI |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
122 static int audio_configured = 0; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
123 #endif |
0 | 124 |
125 /* The general mixing thread function */ | |
126 int SDL_RunAudio(void *audiop) | |
127 { | |
128 SDL_AudioDevice *audio = (SDL_AudioDevice *)audiop; | |
129 Uint8 *stream; | |
130 int stream_len; | |
131 void *udata; | |
132 void (*fill)(void *userdata,Uint8 *stream, int len); | |
133 int silence; | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
134 #ifdef ENABLE_AHI |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
135 int started = 0; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
136 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
137 /* AmigaOS NEEDS that the audio driver is opened in the thread that uses it! */ |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
138 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
139 D(bug("Task audio started audio struct:<%lx>...\n",audiop)); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
140 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
141 D(bug("Before Openaudio...")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
142 if(audio->OpenAudio(audio, &audio->spec)==-1) |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
143 { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
144 D(bug("Open audio failed...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
145 return(-1); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
146 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
147 D(bug("OpenAudio...OK\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
148 #endif |
0 | 149 |
150 /* Perform any thread setup */ | |
151 if ( audio->ThreadInit ) { | |
152 audio->ThreadInit(audio); | |
153 } | |
154 audio->threadid = SDL_ThreadID(); | |
155 | |
156 /* Set up the mixing function */ | |
157 fill = audio->spec.callback; | |
158 udata = audio->spec.userdata; | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
159 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
160 #ifdef ENABLE_AHI |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
161 audio_configured = 1; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
162 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
163 D(bug("Audio configured... Checking for conversion\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
164 SDL_mutexP(audio->mixer_lock); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
165 D(bug("Semaphore obtained...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
166 #endif |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
167 |
0 | 168 if ( audio->convert.needed ) { |
169 if ( audio->convert.src_format == AUDIO_U8 ) { | |
170 silence = 0x80; | |
171 } else { | |
172 silence = 0; | |
173 } | |
174 stream_len = audio->convert.len; | |
175 } else { | |
176 silence = audio->spec.silence; | |
177 stream_len = audio->spec.size; | |
178 } | |
179 stream = audio->fake_stream; | |
180 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
181 #ifdef ENABLE_AHI |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
182 SDL_mutexV(audio->mixer_lock); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
183 D(bug("Entering audio loop...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
184 #endif |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
185 |
1190 | 186 #ifdef __OS2__ |
187 // Increase the priority of this thread to make sure that | |
188 // the audio will be continuous all the time! | |
189 #ifdef USE_DOSSETPRIORITY | |
190 #ifdef DEBUG_BUILD | |
191 printf("[SDL_RunAudio] : Setting priority to ForegroundServer+0! (TID%d)\n", SDL_ThreadID()); | |
192 #endif | |
193 DosSetPriority(PRTYS_THREAD, PRTYC_FOREGROUNDSERVER, 0, 0); | |
194 #endif | |
195 #endif | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
196 |
0 | 197 /* Loop, filling the audio buffers */ |
198 while ( audio->enabled ) { | |
199 | |
200 /* Wait for new current buffer to finish playing */ | |
201 if ( stream == audio->fake_stream ) { | |
202 SDL_Delay((audio->spec.samples*1000)/audio->spec.freq); | |
203 } else { | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
204 #ifdef ENABLE_AHI |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
205 if ( started > 1 ) |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
206 #endif |
0 | 207 audio->WaitAudio(audio); |
208 } | |
209 | |
210 /* Fill the current buffer with sound */ | |
211 if ( audio->convert.needed ) { | |
212 if ( audio->convert.buf ) { | |
213 stream = audio->convert.buf; | |
214 } else { | |
215 continue; | |
216 } | |
217 } else { | |
218 stream = audio->GetAudioBuf(audio); | |
219 if ( stream == NULL ) { | |
220 stream = audio->fake_stream; | |
221 } | |
222 } | |
223 memset(stream, silence, stream_len); | |
224 | |
225 if ( ! audio->paused ) { | |
226 SDL_mutexP(audio->mixer_lock); | |
227 (*fill)(udata, stream, stream_len); | |
228 SDL_mutexV(audio->mixer_lock); | |
229 } | |
230 | |
231 /* Convert the audio if necessary */ | |
232 if ( audio->convert.needed ) { | |
233 SDL_ConvertAudio(&audio->convert); | |
234 stream = audio->GetAudioBuf(audio); | |
235 if ( stream == NULL ) { | |
236 stream = audio->fake_stream; | |
237 } | |
238 memcpy(stream, audio->convert.buf, | |
239 audio->convert.len_cvt); | |
240 } | |
241 | |
242 /* Ready current buffer for play and change current buffer */ | |
243 if ( stream != audio->fake_stream ) { | |
244 audio->PlayAudio(audio); | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
245 #ifdef ENABLE_AHI |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
246 /* AmigaOS don't have to wait the first time audio is played! */ |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
247 started++; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
248 #endif |
0 | 249 } |
250 } | |
251 /* Wait for the audio to drain.. */ | |
252 if ( audio->WaitDone ) { | |
253 audio->WaitDone(audio); | |
254 } | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
255 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
256 #ifdef ENABLE_AHI |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
257 D(bug("WaitAudio...Done\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
258 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
259 audio->CloseAudio(audio); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
260 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
261 D(bug("CloseAudio..Done, subtask exiting...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
262 audio_configured = 0; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
263 #endif |
1190 | 264 #ifdef __OS2__ |
265 #ifdef DEBUG_BUILD | |
266 printf("[SDL_RunAudio] : Task exiting. (TID%d)\n", SDL_ThreadID()); | |
267 #endif | |
268 #endif | |
0 | 269 return(0); |
270 } | |
271 | |
322
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
272 static void SDL_LockAudio_Default(SDL_AudioDevice *audio) |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
273 { |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
274 if ( audio->thread && (SDL_ThreadID() == audio->threadid) ) { |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
275 return; |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
276 } |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
277 SDL_mutexP(audio->mixer_lock); |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
278 } |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
279 |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
280 static void SDL_UnlockAudio_Default(SDL_AudioDevice *audio) |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
281 { |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
282 if ( audio->thread && (SDL_ThreadID() == audio->threadid) ) { |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
283 return; |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
284 } |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
285 SDL_mutexV(audio->mixer_lock); |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
286 } |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
287 |
0 | 288 int SDL_AudioInit(const char *driver_name) |
289 { | |
290 SDL_AudioDevice *audio; | |
291 int i = 0, idx; | |
292 | |
293 /* Check to make sure we don't overwrite 'current_audio' */ | |
294 if ( current_audio != NULL ) { | |
295 SDL_AudioQuit(); | |
296 } | |
297 | |
298 /* Select the proper audio driver */ | |
299 audio = NULL; | |
300 idx = 0; | |
301 #ifdef unix | |
302 if ( (driver_name == NULL) && (getenv("ESPEAKER") != NULL) ) { | |
303 /* Ahem, we know that if ESPEAKER is set, user probably wants | |
304 to use ESD, but don't start it if it's not already running. | |
305 This probably isn't the place to do this, but... Shh! :) | |
306 */ | |
307 for ( i=0; bootstrap[i]; ++i ) { | |
308 if ( strcmp(bootstrap[i]->name, "esd") == 0 ) { | |
309 const char *esd_no_spawn; | |
310 | |
311 /* Don't start ESD if it's not running */ | |
312 esd_no_spawn = getenv("ESD_NO_SPAWN"); | |
313 if ( esd_no_spawn == NULL ) { | |
314 putenv("ESD_NO_SPAWN=1"); | |
315 } | |
316 if ( bootstrap[i]->available() ) { | |
317 audio = bootstrap[i]->create(0); | |
318 break; | |
319 } | |
320 #ifdef linux /* No unsetenv() on most platforms */ | |
321 if ( esd_no_spawn == NULL ) { | |
322 unsetenv("ESD_NO_SPAWN"); | |
323 } | |
324 #endif | |
325 } | |
326 } | |
327 } | |
328 #endif /* unix */ | |
329 if ( audio == NULL ) { | |
330 if ( driver_name != NULL ) { | |
331 #if 0 /* This will be replaced with a better driver selection API */ | |
332 if ( strrchr(driver_name, ':') != NULL ) { | |
333 idx = atoi(strrchr(driver_name, ':')+1); | |
334 } | |
335 #endif | |
336 for ( i=0; bootstrap[i]; ++i ) { | |
337 if (strncmp(bootstrap[i]->name, driver_name, | |
338 strlen(bootstrap[i]->name)) == 0) { | |
339 if ( bootstrap[i]->available() ) { | |
340 audio=bootstrap[i]->create(idx); | |
341 break; | |
342 } | |
343 } | |
344 } | |
345 } else { | |
346 for ( i=0; bootstrap[i]; ++i ) { | |
347 if ( bootstrap[i]->available() ) { | |
348 audio = bootstrap[i]->create(idx); | |
349 if ( audio != NULL ) { | |
350 break; | |
351 } | |
352 } | |
353 } | |
354 } | |
355 if ( audio == NULL ) { | |
356 SDL_SetError("No available audio device"); | |
357 #if 0 /* Don't fail SDL_Init() if audio isn't available. | |
358 SDL_OpenAudio() will handle it at that point. *sigh* | |
359 */ | |
360 return(-1); | |
361 #endif | |
362 } | |
363 } | |
364 current_audio = audio; | |
365 if ( current_audio ) { | |
366 current_audio->name = bootstrap[i]->name; | |
322
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
367 if ( !current_audio->LockAudio && !current_audio->UnlockAudio ) { |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
368 current_audio->LockAudio = SDL_LockAudio_Default; |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
369 current_audio->UnlockAudio = SDL_UnlockAudio_Default; |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
370 } |
0 | 371 } |
372 return(0); | |
373 } | |
374 | |
375 char *SDL_AudioDriverName(char *namebuf, int maxlen) | |
376 { | |
377 if ( current_audio != NULL ) { | |
378 strncpy(namebuf, current_audio->name, maxlen-1); | |
379 namebuf[maxlen-1] = '\0'; | |
380 return(namebuf); | |
381 } | |
382 return(NULL); | |
383 } | |
384 | |
385 int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained) | |
386 { | |
387 SDL_AudioDevice *audio; | |
388 | |
389 /* Start up the audio driver, if necessary */ | |
390 if ( ! current_audio ) { | |
391 if ( (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) || | |
392 (current_audio == NULL) ) { | |
393 return(-1); | |
394 } | |
395 } | |
396 audio = current_audio; | |
397 | |
262
ba5363e21df8
Don't allow multiple audio opens to succeed (until SDL 1.3)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
398 if (audio->opened) { |
ba5363e21df8
Don't allow multiple audio opens to succeed (until SDL 1.3)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
399 SDL_SetError("Audio device is already opened"); |
ba5363e21df8
Don't allow multiple audio opens to succeed (until SDL 1.3)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
400 return(-1); |
ba5363e21df8
Don't allow multiple audio opens to succeed (until SDL 1.3)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
401 } |
ba5363e21df8
Don't allow multiple audio opens to succeed (until SDL 1.3)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
402 |
0 | 403 /* Verify some parameters */ |
404 if ( desired->callback == NULL ) { | |
405 SDL_SetError("SDL_OpenAudio() passed a NULL callback"); | |
406 return(-1); | |
407 } | |
408 switch ( desired->channels ) { | |
409 case 1: /* Mono */ | |
410 case 2: /* Stereo */ | |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
936
diff
changeset
|
411 case 4: /* surround */ |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
936
diff
changeset
|
412 case 6: /* surround with center and lfe */ |
0 | 413 break; |
414 default: | |
415 SDL_SetError("1 (mono) and 2 (stereo) channels supported"); | |
416 return(-1); | |
417 } | |
418 | |
1204
f9794ee91dfc
Date: Tue, 13 Dec 2005 13:33:50 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
419 #if defined(macintosh) || (defined(__riscos__) && defined(DISABLE_THREADS)) |
0 | 420 /* FIXME: Need to implement PPC interrupt asm for SDL_LockAudio() */ |
421 #else | |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
322
diff
changeset
|
422 #if defined(__MINT__) && !defined(ENABLE_THREADS) |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
322
diff
changeset
|
423 /* Uses interrupt driven audio, without thread */ |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
322
diff
changeset
|
424 #else |
0 | 425 /* Create a semaphore for locking the sound buffers */ |
426 audio->mixer_lock = SDL_CreateMutex(); | |
427 if ( audio->mixer_lock == NULL ) { | |
428 SDL_SetError("Couldn't create mixer lock"); | |
429 SDL_CloseAudio(); | |
430 return(-1); | |
431 } | |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
322
diff
changeset
|
432 #endif /* __MINT__ */ |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
322
diff
changeset
|
433 #endif /* macintosh */ |
0 | 434 |
435 /* Calculate the silence and size of the audio specification */ | |
436 SDL_CalculateAudioSpec(desired); | |
437 | |
438 /* Open the audio subsystem */ | |
439 memcpy(&audio->spec, desired, sizeof(audio->spec)); | |
440 audio->convert.needed = 0; | |
441 audio->enabled = 1; | |
442 audio->paused = 1; | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
443 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
444 #ifndef ENABLE_AHI |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
445 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
446 /* AmigaOS opens audio inside the main loop */ |
0 | 447 audio->opened = audio->OpenAudio(audio, &audio->spec)+1; |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
448 |
0 | 449 if ( ! audio->opened ) { |
450 SDL_CloseAudio(); | |
451 return(-1); | |
452 } | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
453 #else |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
454 D(bug("Locking semaphore...")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
455 SDL_mutexP(audio->mixer_lock); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
456 |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
457 #if (defined(_WIN32) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
458 #undef SDL_CreateThread |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
459 audio->thread = SDL_CreateThread(SDL_RunAudio, audio, NULL, NULL); |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
460 #else |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
461 audio->thread = SDL_CreateThread(SDL_RunAudio, audio); |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
462 #endif |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
463 D(bug("Created thread...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
464 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
465 if ( audio->thread == NULL ) { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
466 SDL_mutexV(audio->mixer_lock); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
467 SDL_CloseAudio(); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
468 SDL_SetError("Couldn't create audio thread"); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
469 return(-1); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
470 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
471 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
472 while(!audio_configured) |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
473 SDL_Delay(100); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
474 #endif |
0 | 475 |
476 /* If the audio driver changes the buffer size, accept it */ | |
477 if ( audio->spec.samples != desired->samples ) { | |
478 desired->samples = audio->spec.samples; | |
479 SDL_CalculateAudioSpec(desired); | |
480 } | |
481 | |
482 /* Allocate a fake audio memory buffer */ | |
483 audio->fake_stream = SDL_AllocAudioMem(audio->spec.size); | |
484 if ( audio->fake_stream == NULL ) { | |
485 SDL_CloseAudio(); | |
486 SDL_OutOfMemory(); | |
487 return(-1); | |
488 } | |
489 | |
490 /* See if we need to do any conversion */ | |
808
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
491 if ( obtained != NULL ) { |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
492 memcpy(obtained, &audio->spec, sizeof(audio->spec)); |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
493 } else if ( desired->freq != audio->spec.freq || |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
494 desired->format != audio->spec.format || |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
495 desired->channels != audio->spec.channels ) { |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
496 /* Build an audio conversion block */ |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
497 if ( SDL_BuildAudioCVT(&audio->convert, |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
498 desired->format, desired->channels, |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
499 desired->freq, |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
500 audio->spec.format, audio->spec.channels, |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
501 audio->spec.freq) < 0 ) { |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
502 SDL_CloseAudio(); |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
503 return(-1); |
0 | 504 } |
808
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
505 if ( audio->convert.needed ) { |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
506 audio->convert.len = desired->size; |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
507 audio->convert.buf =(Uint8 *)SDL_AllocAudioMem( |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
508 audio->convert.len*audio->convert.len_mult); |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
509 if ( audio->convert.buf == NULL ) { |
0 | 510 SDL_CloseAudio(); |
808
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
511 SDL_OutOfMemory(); |
0 | 512 return(-1); |
513 } | |
514 } | |
515 } | |
516 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
517 #ifndef ENABLE_AHI |
0 | 518 /* Start the audio thread if necessary */ |
519 switch (audio->opened) { | |
520 case 1: | |
521 /* Start the audio thread */ | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
522 #if (defined(_WIN32) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
523 #undef SDL_CreateThread |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
524 audio->thread = SDL_CreateThread(SDL_RunAudio, audio, NULL, NULL); |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
525 #else |
0 | 526 audio->thread = SDL_CreateThread(SDL_RunAudio, audio); |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
527 #endif |
0 | 528 if ( audio->thread == NULL ) { |
529 SDL_CloseAudio(); | |
530 SDL_SetError("Couldn't create audio thread"); | |
531 return(-1); | |
532 } | |
533 break; | |
534 | |
535 default: | |
536 /* The audio is now playing */ | |
537 break; | |
538 } | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
539 #else |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
540 SDL_mutexV(audio->mixer_lock); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
541 D(bug("SDL_OpenAudio USCITA...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
542 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
543 #endif |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
544 |
0 | 545 return(0); |
546 } | |
547 | |
548 SDL_audiostatus SDL_GetAudioStatus(void) | |
549 { | |
550 SDL_AudioDevice *audio = current_audio; | |
551 SDL_audiostatus status; | |
552 | |
553 status = SDL_AUDIO_STOPPED; | |
554 if ( audio && audio->enabled ) { | |
555 if ( audio->paused ) { | |
556 status = SDL_AUDIO_PAUSED; | |
557 } else { | |
558 status = SDL_AUDIO_PLAYING; | |
559 } | |
560 } | |
561 return(status); | |
562 } | |
563 | |
564 void SDL_PauseAudio (int pause_on) | |
565 { | |
566 SDL_AudioDevice *audio = current_audio; | |
567 | |
568 if ( audio ) { | |
569 audio->paused = pause_on; | |
570 } | |
571 } | |
572 | |
573 void SDL_LockAudio (void) | |
574 { | |
575 SDL_AudioDevice *audio = current_audio; | |
576 | |
577 /* Obtain a lock on the mixing buffers */ | |
322
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
578 if ( audio && audio->LockAudio ) { |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
579 audio->LockAudio(audio); |
0 | 580 } |
581 } | |
582 | |
583 void SDL_UnlockAudio (void) | |
584 { | |
585 SDL_AudioDevice *audio = current_audio; | |
586 | |
587 /* Release lock on the mixing buffers */ | |
322
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
588 if ( audio && audio->UnlockAudio ) { |
fd93a09655e3
The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
589 audio->UnlockAudio(audio); |
0 | 590 } |
591 } | |
592 | |
593 void SDL_CloseAudio (void) | |
594 { | |
595 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
596 } | |
597 | |
598 void SDL_AudioQuit(void) | |
599 { | |
600 SDL_AudioDevice *audio = current_audio; | |
601 | |
602 if ( audio ) { | |
603 audio->enabled = 0; | |
604 if ( audio->thread != NULL ) { | |
605 SDL_WaitThread(audio->thread, NULL); | |
606 } | |
607 if ( audio->mixer_lock != NULL ) { | |
608 SDL_DestroyMutex(audio->mixer_lock); | |
609 } | |
610 if ( audio->fake_stream != NULL ) { | |
611 SDL_FreeAudioMem(audio->fake_stream); | |
612 } | |
613 if ( audio->convert.needed ) { | |
614 SDL_FreeAudioMem(audio->convert.buf); | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
615 |
0 | 616 } |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
617 #ifndef ENABLE_AHI |
0 | 618 if ( audio->opened ) { |
619 audio->CloseAudio(audio); | |
620 audio->opened = 0; | |
621 } | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
622 #endif |
0 | 623 /* Free the driver data */ |
624 audio->free(audio); | |
625 current_audio = NULL; | |
626 } | |
627 } | |
628 | |
629 #define NUM_FORMATS 6 | |
630 static int format_idx; | |
631 static int format_idx_sub; | |
632 static Uint16 format_list[NUM_FORMATS][NUM_FORMATS] = { | |
633 { AUDIO_U8, AUDIO_S8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB }, | |
634 { AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB }, | |
635 { AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_U8, AUDIO_S8 }, | |
636 { AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_U8, AUDIO_S8 }, | |
637 { AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U8, AUDIO_S8 }, | |
638 { AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_U8, AUDIO_S8 }, | |
639 }; | |
640 | |
641 Uint16 SDL_FirstAudioFormat(Uint16 format) | |
642 { | |
643 for ( format_idx=0; format_idx < NUM_FORMATS; ++format_idx ) { | |
644 if ( format_list[format_idx][0] == format ) { | |
645 break; | |
646 } | |
647 } | |
648 format_idx_sub = 0; | |
649 return(SDL_NextAudioFormat()); | |
650 } | |
651 | |
652 Uint16 SDL_NextAudioFormat(void) | |
653 { | |
654 if ( (format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS) ) { | |
655 return(0); | |
656 } | |
657 return(format_list[format_idx][format_idx_sub++]); | |
658 } | |
659 | |
660 void SDL_CalculateAudioSpec(SDL_AudioSpec *spec) | |
661 { | |
662 switch (spec->format) { | |
663 case AUDIO_U8: | |
664 spec->silence = 0x80; | |
665 break; | |
666 default: | |
667 spec->silence = 0x00; | |
668 break; | |
669 } | |
670 spec->size = (spec->format&0xFF)/8; | |
671 spec->size *= spec->channels; | |
672 spec->size *= spec->samples; | |
673 } |