Mercurial > sdl-ios-xcode
annotate src/audio/SDL_audio.c @ 1660:8b9d79e7eacf SDL-1.3
Added API requested in bug #43:
Added SDL_GetNumVideoDrivers() and SDL_GetVideoDriver().
Replaced SDL_VideoDriverName() with SDL_GetCurrentVideoDriver()
Added SDL_GetNumAudioDrivers() and SDL_GetAudioDriver().
Replaced SDL_AudioDriverName() with SDL_GetCurrentAudioDriver()
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 20 May 2006 04:35:58 +0000 |
parents | 14717b52abc0 |
children | 782fd950bd46 |
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 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 /* Allow access to a raw mixing buffer */ | |
25 | |
26 #include "SDL.h" | |
27 #include "SDL_audio_c.h" | |
28 #include "SDL_audiomem.h" | |
29 #include "SDL_sysaudio.h" | |
30 | |
1190 | 31 #ifdef __OS2__ |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1442
diff
changeset
|
32 /* We'll need the DosSetPriority() API! */ |
1190 | 33 #define INCL_DOSPROCESS |
34 #include <os2.h> | |
35 #endif | |
36 | |
0 | 37 /* Available audio drivers */ |
38 static AudioBootStrap *bootstrap[] = { | |
1567
12b6d331d82a
Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
1562
diff
changeset
|
39 #if SDL_AUDIO_DRIVER_BSD |
12b6d331d82a
Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
1562
diff
changeset
|
40 &BSD_AUDIO_bootstrap, |
94
ae6e6b73333f
Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
41 #endif |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
42 #if SDL_AUDIO_DRIVER_OSS |
0 | 43 &DSP_bootstrap, |
44 &DMA_bootstrap, | |
45 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
46 #if SDL_AUDIO_DRIVER_ALSA |
0 | 47 &ALSA_bootstrap, |
48 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
49 #if SDL_AUDIO_DRIVER_QNXNTO |
663
8bedd6d61642
Date: Sat, 2 Aug 2003 16:22:51 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
654
diff
changeset
|
50 &QNXNTOAUDIO_bootstrap, |
8bedd6d61642
Date: Sat, 2 Aug 2003 16:22:51 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
654
diff
changeset
|
51 #endif |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
52 #if SDL_AUDIO_DRIVER_SUNAUDIO |
148
8758b8d42cd9
Audio subsystem no longer assumes sun audio API on UNIX systems
Sam Lantinga <slouken@libsdl.org>
parents:
121
diff
changeset
|
53 &SUNAUDIO_bootstrap, |
8758b8d42cd9
Audio subsystem no longer assumes sun audio API on UNIX systems
Sam Lantinga <slouken@libsdl.org>
parents:
121
diff
changeset
|
54 #endif |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
55 #if SDL_AUDIO_DRIVER_DMEDIA |
148
8758b8d42cd9
Audio subsystem no longer assumes sun audio API on UNIX systems
Sam Lantinga <slouken@libsdl.org>
parents:
121
diff
changeset
|
56 &DMEDIA_bootstrap, |
35
d3bc792e136d
Added detection of Open Sound System on Solaris x86
Sam Lantinga <slouken@lokigames.com>
parents:
21
diff
changeset
|
57 #endif |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
58 #if SDL_AUDIO_DRIVER_ARTS |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
59 &ARTS_bootstrap, |
0 | 60 #endif |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
61 #if SDL_AUDIO_DRIVER_ESD |
0 | 62 &ESD_bootstrap, |
63 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
64 #if SDL_AUDIO_DRIVER_NAS |
0 | 65 &NAS_bootstrap, |
66 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
67 #if SDL_AUDIO_DRIVER_DSOUND |
0 | 68 &DSOUND_bootstrap, |
69 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
70 #if SDL_AUDIO_DRIVER_WAVEOUT |
0 | 71 &WAVEOUT_bootstrap, |
72 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
73 #if SDL_AUDIO_DRIVER_PAUD |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
74 &Paud_bootstrap, |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
75 #endif |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
76 #if SDL_AUDIO_DRIVER_BAUDIO |
0 | 77 &BAUDIO_bootstrap, |
78 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
79 #if SDL_AUDIO_DRIVER_COREAUDIO |
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 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
82 #if SDL_AUDIO_DRIVER_SNDMGR |
0 | 83 &SNDMGR_bootstrap, |
84 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
85 #if SDL_AUDIO_DRIVER_AHI |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
86 &AHI_bootstrap, |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
87 #endif |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
88 #if SDL_AUDIO_DRIVER_MINT |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
630
diff
changeset
|
89 &MINTAUDIO_GSXB_bootstrap, |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
630
diff
changeset
|
90 &MINTAUDIO_MCSN_bootstrap, |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
630
diff
changeset
|
91 &MINTAUDIO_STFA_bootstrap, |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
630
diff
changeset
|
92 &MINTAUDIO_XBIOS_bootstrap, |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
630
diff
changeset
|
93 &MINTAUDIO_DMA8_bootstrap, |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
322
diff
changeset
|
94 #endif |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
95 #if SDL_AUDIO_DRIVER_DISK |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
38
diff
changeset
|
96 &DISKAUD_bootstrap, |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
38
diff
changeset
|
97 #endif |
1532
30f189cdd82b
Implemented dummy audio driver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1487
diff
changeset
|
98 #if SDL_AUDIO_DRIVER_DUMMY |
30f189cdd82b
Implemented dummy audio driver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1487
diff
changeset
|
99 &DUMMYAUD_bootstrap, |
30f189cdd82b
Implemented dummy audio driver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1487
diff
changeset
|
100 #endif |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
101 #if SDL_AUDIO_DRIVER_DC |
509
dad72daf44b3
Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
398
diff
changeset
|
102 &DCAUD_bootstrap, |
dad72daf44b3
Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
398
diff
changeset
|
103 #endif |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
104 #if SDL_AUDIO_DRIVER_MMEAUDIO |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
105 &MMEAUDIO_bootstrap, |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
106 #endif |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
107 #if SDL_AUDIO_DRIVER_DART |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
108 &DART_bootstrap, |
1190 | 109 #endif |
0 | 110 NULL |
111 }; | |
112 SDL_AudioDevice *current_audio = NULL; | |
113 | |
114 /* Various local functions */ | |
115 int SDL_AudioInit(const char *driver_name); | |
116 void SDL_AudioQuit(void); | |
117 | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
118 #if SDL_AUDIO_DRIVER_AHI |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
119 static int audio_configured = 0; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
120 #endif |
0 | 121 |
122 /* The general mixing thread function */ | |
1659 | 123 int SDLCALL SDL_RunAudio(void *audiop) |
0 | 124 { |
125 SDL_AudioDevice *audio = (SDL_AudioDevice *)audiop; | |
126 Uint8 *stream; | |
127 int stream_len; | |
128 void *udata; | |
1659 | 129 void (SDLCALL *fill)(void *userdata,Uint8 *stream, int len); |
0 | 130 int silence; |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
131 #if SDL_AUDIO_DRIVER_AHI |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
132 int started = 0; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
133 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
134 /* 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
|
135 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
136 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
|
137 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
138 D(bug("Before Openaudio...")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
139 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
|
140 { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
141 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
|
142 return(-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("OpenAudio...OK\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
145 #endif |
0 | 146 |
147 /* Perform any thread setup */ | |
148 if ( audio->ThreadInit ) { | |
149 audio->ThreadInit(audio); | |
150 } | |
151 audio->threadid = SDL_ThreadID(); | |
152 | |
153 /* Set up the mixing function */ | |
154 fill = audio->spec.callback; | |
155 udata = audio->spec.userdata; | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
156 |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
157 #if SDL_AUDIO_DRIVER_AHI |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
158 audio_configured = 1; |
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 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
|
161 SDL_mutexP(audio->mixer_lock); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
162 D(bug("Semaphore obtained...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
163 #endif |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
164 |
0 | 165 if ( audio->convert.needed ) { |
166 if ( audio->convert.src_format == AUDIO_U8 ) { | |
167 silence = 0x80; | |
168 } else { | |
169 silence = 0; | |
170 } | |
171 stream_len = audio->convert.len; | |
172 } else { | |
173 silence = audio->spec.silence; | |
174 stream_len = audio->spec.size; | |
175 } | |
1561
c724c4a99759
Try to fill the hardware audio buffer immediately.
Ryan C. Gordon <icculus@icculus.org>
parents:
1532
diff
changeset
|
176 |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
177 #if SDL_AUDIO_DRIVER_AHI |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
178 SDL_mutexV(audio->mixer_lock); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
179 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
|
180 #endif |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
181 |
1190 | 182 #ifdef __OS2__ |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1442
diff
changeset
|
183 /* Increase the priority of this thread to make sure that |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1442
diff
changeset
|
184 the audio will be continuous all the time! */ |
1190 | 185 #ifdef USE_DOSSETPRIORITY |
1442
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1408
diff
changeset
|
186 if (SDL_getenv("SDL_USE_TIMECRITICAL_AUDIO")) |
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1408
diff
changeset
|
187 { |
1190 | 188 #ifdef DEBUG_BUILD |
1442
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1408
diff
changeset
|
189 printf("[SDL_RunAudio] : Setting priority to TimeCritical+0! (TID%d)\n", SDL_ThreadID()); |
1190 | 190 #endif |
1442
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1408
diff
changeset
|
191 DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0); |
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1408
diff
changeset
|
192 } |
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1408
diff
changeset
|
193 else |
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1408
diff
changeset
|
194 { |
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1408
diff
changeset
|
195 #ifdef DEBUG_BUILD |
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1408
diff
changeset
|
196 printf("[SDL_RunAudio] : Setting priority to ForegroundServer+0! (TID%d)\n", SDL_ThreadID()); |
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1408
diff
changeset
|
197 #endif |
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1408
diff
changeset
|
198 DosSetPriority(PRTYS_THREAD, PRTYC_FOREGROUNDSERVER, 0, 0); |
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1408
diff
changeset
|
199 } |
1190 | 200 #endif |
201 #endif | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
202 |
0 | 203 /* Loop, filling the audio buffers */ |
204 while ( audio->enabled ) { | |
205 | |
206 /* Fill the current buffer with sound */ | |
207 if ( audio->convert.needed ) { | |
208 if ( audio->convert.buf ) { | |
209 stream = audio->convert.buf; | |
210 } else { | |
211 continue; | |
212 } | |
213 } else { | |
214 stream = audio->GetAudioBuf(audio); | |
215 if ( stream == NULL ) { | |
216 stream = audio->fake_stream; | |
217 } | |
218 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
219 SDL_memset(stream, silence, stream_len); |
0 | 220 |
221 if ( ! audio->paused ) { | |
222 SDL_mutexP(audio->mixer_lock); | |
223 (*fill)(udata, stream, stream_len); | |
224 SDL_mutexV(audio->mixer_lock); | |
225 } | |
226 | |
227 /* Convert the audio if necessary */ | |
228 if ( audio->convert.needed ) { | |
229 SDL_ConvertAudio(&audio->convert); | |
230 stream = audio->GetAudioBuf(audio); | |
231 if ( stream == NULL ) { | |
232 stream = audio->fake_stream; | |
233 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
234 SDL_memcpy(stream, audio->convert.buf, |
0 | 235 audio->convert.len_cvt); |
236 } | |
237 | |
238 /* Ready current buffer for play and change current buffer */ | |
239 if ( stream != audio->fake_stream ) { | |
240 audio->PlayAudio(audio); | |
1562 | 241 } |
242 | |
243 /* Wait for an audio buffer to become available */ | |
244 if ( stream == audio->fake_stream ) { | |
245 SDL_Delay((audio->spec.samples*1000)/audio->spec.freq); | |
246 } else { | |
247 audio->WaitAudio(audio); | |
0 | 248 } |
249 } | |
1562 | 250 |
0 | 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 |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
256 #if SDL_AUDIO_DRIVER_AHI |
21
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 |
1659 | 288 static Uint16 SDL_ParseAudioFormat(const char *string) |
289 { | |
290 Uint16 format = 0; | |
291 | |
292 switch (*string) { | |
293 case 'U': | |
294 ++string; | |
295 format |= 0x0000; | |
296 break; | |
297 case 'S': | |
298 ++string; | |
299 format |= 0x8000; | |
300 break; | |
301 default: | |
302 return 0; | |
303 } | |
304 switch (SDL_atoi(string)) { | |
305 case 8: | |
306 string += 1; | |
307 format |= 8; | |
308 break; | |
309 case 16: | |
310 string += 2; | |
311 format |= 16; | |
312 if ( SDL_strcmp(string, "LSB") == 0 | |
313 #if SDL_BYTEORDER == SDL_LIL_ENDIAN | |
314 || SDL_strcmp(string, "SYS") == 0 | |
315 #endif | |
316 ) { | |
317 format |= 0x0000; | |
318 } | |
319 if ( SDL_strcmp(string, "MSB") == 0 | |
320 #if SDL_BYTEORDER == SDL_BIG_ENDIAN | |
321 || SDL_strcmp(string, "SYS") == 0 | |
322 #endif | |
323 ) { | |
324 format |= 0x1000; | |
325 } | |
326 break; | |
327 default: | |
328 return 0; | |
329 } | |
330 return format; | |
331 } | |
332 | |
1660
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
333 int SDL_GetNumAudioDrivers(void) |
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
334 { |
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
335 return(SDL_arraysize(bootstrap)-1); |
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
336 } |
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
337 |
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
338 const char *SDL_GetAudioDriver(int index) |
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
339 { |
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
340 if ( index >= 0 && index < SDL_GetNumAudioDrivers() ) { |
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
341 return(bootstrap[index]->name); |
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
342 } |
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
343 return(NULL); |
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
344 } |
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
345 |
0 | 346 int SDL_AudioInit(const char *driver_name) |
347 { | |
348 SDL_AudioDevice *audio; | |
349 int i = 0, idx; | |
350 | |
351 /* Check to make sure we don't overwrite 'current_audio' */ | |
352 if ( current_audio != NULL ) { | |
353 SDL_AudioQuit(); | |
354 } | |
355 | |
356 /* Select the proper audio driver */ | |
357 audio = NULL; | |
358 idx = 0; | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
359 #if SDL_AUDIO_DRIVER_ESD |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
360 if ( (driver_name == NULL) && (SDL_getenv("ESPEAKER") != NULL) ) { |
0 | 361 /* Ahem, we know that if ESPEAKER is set, user probably wants |
362 to use ESD, but don't start it if it's not already running. | |
363 This probably isn't the place to do this, but... Shh! :) | |
364 */ | |
365 for ( i=0; bootstrap[i]; ++i ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
366 if ( SDL_strcmp(bootstrap[i]->name, "esd") == 0 ) { |
1341
d02b552e5304
Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
367 #ifdef HAVE_PUTENV |
0 | 368 const char *esd_no_spawn; |
369 | |
370 /* Don't start ESD if it's not running */ | |
1341
d02b552e5304
Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
371 esd_no_spawn = getenv("ESD_NO_SPAWN"); |
0 | 372 if ( esd_no_spawn == NULL ) { |
373 putenv("ESD_NO_SPAWN=1"); | |
374 } | |
1341
d02b552e5304
Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
375 #endif |
0 | 376 if ( bootstrap[i]->available() ) { |
377 audio = bootstrap[i]->create(0); | |
378 break; | |
379 } | |
1341
d02b552e5304
Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
380 #ifdef HAVE_UNSETENV |
0 | 381 if ( esd_no_spawn == NULL ) { |
382 unsetenv("ESD_NO_SPAWN"); | |
383 } | |
384 #endif | |
385 } | |
386 } | |
387 } | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
388 #endif /* SDL_AUDIO_DRIVER_ESD */ |
0 | 389 if ( audio == NULL ) { |
390 if ( driver_name != NULL ) { | |
391 #if 0 /* This will be replaced with a better driver selection API */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
392 if ( SDL_strrchr(driver_name, ':') != NULL ) { |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
393 idx = atoi(SDL_strrchr(driver_name, ':')+1); |
0 | 394 } |
395 #endif | |
396 for ( i=0; bootstrap[i]; ++i ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
397 if (SDL_strncmp(bootstrap[i]->name, driver_name, |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
398 SDL_strlen(bootstrap[i]->name)) == 0) { |
0 | 399 if ( bootstrap[i]->available() ) { |
400 audio=bootstrap[i]->create(idx); | |
401 break; | |
402 } | |
403 } | |
404 } | |
405 } else { | |
406 for ( i=0; bootstrap[i]; ++i ) { | |
407 if ( bootstrap[i]->available() ) { | |
408 audio = bootstrap[i]->create(idx); | |
409 if ( audio != NULL ) { | |
410 break; | |
411 } | |
412 } | |
413 } | |
414 } | |
415 if ( audio == NULL ) { | |
416 SDL_SetError("No available audio device"); | |
417 #if 0 /* Don't fail SDL_Init() if audio isn't available. | |
418 SDL_OpenAudio() will handle it at that point. *sigh* | |
419 */ | |
420 return(-1); | |
421 #endif | |
422 } | |
423 } | |
424 current_audio = audio; | |
425 if ( current_audio ) { | |
426 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
|
427 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
|
428 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
|
429 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
|
430 } |
0 | 431 } |
432 return(0); | |
433 } | |
434 | |
1660
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
435 const char *SDL_GetCurrentAudioDriver() |
0 | 436 { |
1660
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
437 if ( current_audio ) { |
8b9d79e7eacf
Added API requested in bug #43:
Sam Lantinga <slouken@libsdl.org>
parents:
1659
diff
changeset
|
438 return current_audio->name; |
0 | 439 } |
440 return(NULL); | |
441 } | |
442 | |
443 int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained) | |
444 { | |
445 SDL_AudioDevice *audio; | |
1659 | 446 const char *env; |
0 | 447 |
448 /* Start up the audio driver, if necessary */ | |
449 if ( ! current_audio ) { | |
450 if ( (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) || | |
451 (current_audio == NULL) ) { | |
452 return(-1); | |
453 } | |
454 } | |
455 audio = current_audio; | |
456 | |
262
ba5363e21df8
Don't allow multiple audio opens to succeed (until SDL 1.3)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
457 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
|
458 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
|
459 return(-1); |
ba5363e21df8
Don't allow multiple audio opens to succeed (until SDL 1.3)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
460 } |
ba5363e21df8
Don't allow multiple audio opens to succeed (until SDL 1.3)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
461 |
0 | 462 /* Verify some parameters */ |
1659 | 463 if ( desired->freq == 0 ) { |
464 env = SDL_getenv("SDL_AUDIO_FREQUENCY"); | |
465 if ( env ) { | |
466 desired->freq = SDL_atoi(env); | |
467 } | |
468 } | |
469 if ( desired->freq == 0 ) { | |
470 /* Pick some default audio frequency */ | |
471 desired->freq = 22050; | |
472 } | |
473 if ( desired->format == 0 ) { | |
474 env = SDL_getenv("SDL_AUDIO_FORMAT"); | |
475 if ( env ) { | |
476 desired->format = SDL_ParseAudioFormat(env); | |
477 } | |
478 } | |
479 if ( desired->format == 0 ) { | |
480 /* Pick some default audio format */ | |
481 desired->format = AUDIO_S16; | |
482 } | |
483 if ( desired->channels == 0 ) { | |
484 env = SDL_getenv("SDL_AUDIO_CHANNELS"); | |
485 if ( env ) { | |
486 desired->channels = SDL_atoi(env); | |
487 } | |
488 } | |
489 if ( desired->channels == 0 ) { | |
490 /* Pick a default number of channels */ | |
491 desired->channels = 2; | |
0 | 492 } |
493 switch ( desired->channels ) { | |
494 case 1: /* Mono */ | |
495 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
|
496 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
|
497 case 6: /* surround with center and lfe */ |
0 | 498 break; |
499 default: | |
500 SDL_SetError("1 (mono) and 2 (stereo) channels supported"); | |
501 return(-1); | |
502 } | |
1659 | 503 if ( desired->samples == 0 ) { |
504 env = SDL_getenv("SDL_AUDIO_SAMPLES"); | |
505 if ( env ) { | |
506 desired->samples = SDL_atoi(env); | |
507 } | |
508 } | |
509 if ( desired->samples == 0 ) { | |
510 /* Pick a default of ~46 ms at desired frequency */ | |
511 int samples = (desired->freq / 1000) * 46; | |
512 int power2 = 1; | |
513 while ( power2 < samples ) { | |
514 power2 *= 2; | |
515 } | |
516 desired->samples = power2; | |
517 } | |
518 if ( desired->callback == NULL ) { | |
519 SDL_SetError("SDL_OpenAudio() passed a NULL callback"); | |
520 return(-1); | |
521 } | |
0 | 522 |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
523 #if defined(__MACOS__) || (defined(__RISCOS__) && SDL_THREADS_DISABLED) |
0 | 524 /* FIXME: Need to implement PPC interrupt asm for SDL_LockAudio() */ |
525 #else | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
526 #if defined(__MINT__) && SDL_THREADS_DISABLED |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
322
diff
changeset
|
527 /* Uses interrupt driven audio, without thread */ |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
322
diff
changeset
|
528 #else |
0 | 529 /* Create a semaphore for locking the sound buffers */ |
530 audio->mixer_lock = SDL_CreateMutex(); | |
531 if ( audio->mixer_lock == NULL ) { | |
532 SDL_SetError("Couldn't create mixer lock"); | |
533 SDL_CloseAudio(); | |
534 return(-1); | |
535 } | |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
322
diff
changeset
|
536 #endif /* __MINT__ */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
537 #endif /* __MACOS__ */ |
0 | 538 |
539 /* Calculate the silence and size of the audio specification */ | |
540 SDL_CalculateAudioSpec(desired); | |
541 | |
542 /* Open the audio subsystem */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
543 SDL_memcpy(&audio->spec, desired, sizeof(audio->spec)); |
0 | 544 audio->convert.needed = 0; |
545 audio->enabled = 1; | |
546 audio->paused = 1; | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
547 |
1406
39ca9a4b22f3
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
548 #if !SDL_AUDIO_DRIVER_AHI |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
549 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
550 /* AmigaOS opens audio inside the main loop */ |
0 | 551 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
|
552 |
0 | 553 if ( ! audio->opened ) { |
554 SDL_CloseAudio(); | |
555 return(-1); | |
556 } | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
557 #else |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
558 D(bug("Locking semaphore...")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
559 SDL_mutexP(audio->mixer_lock); |
1408
ceb5c2fec4f1
Fixed some preprocessor mangling
Sam Lantinga <slouken@libsdl.org>
parents:
1406
diff
changeset
|
560 |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
561 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
562 audio->thread = SDL_CreateThread(SDL_RunAudio, audio); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
563 D(bug("Created thread...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
564 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
565 if ( audio->thread == NULL ) { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
566 SDL_mutexV(audio->mixer_lock); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
567 SDL_CloseAudio(); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
568 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
|
569 return(-1); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
570 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
571 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
572 while(!audio_configured) |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
573 SDL_Delay(100); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
574 #endif |
0 | 575 |
576 /* If the audio driver changes the buffer size, accept it */ | |
577 if ( audio->spec.samples != desired->samples ) { | |
578 desired->samples = audio->spec.samples; | |
579 SDL_CalculateAudioSpec(desired); | |
580 } | |
581 | |
582 /* Allocate a fake audio memory buffer */ | |
583 audio->fake_stream = SDL_AllocAudioMem(audio->spec.size); | |
584 if ( audio->fake_stream == NULL ) { | |
585 SDL_CloseAudio(); | |
586 SDL_OutOfMemory(); | |
587 return(-1); | |
588 } | |
589 | |
590 /* 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
|
591 if ( obtained != NULL ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
592 SDL_memcpy(obtained, &audio->spec, sizeof(audio->spec)); |
808
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
593 } else if ( desired->freq != audio->spec.freq || |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
594 desired->format != audio->spec.format || |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
595 desired->channels != audio->spec.channels ) { |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
596 /* Build an audio conversion block */ |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
597 if ( SDL_BuildAudioCVT(&audio->convert, |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
598 desired->format, desired->channels, |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
599 desired->freq, |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
600 audio->spec.format, audio->spec.channels, |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
601 audio->spec.freq) < 0 ) { |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
602 SDL_CloseAudio(); |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
603 return(-1); |
0 | 604 } |
808
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
605 if ( audio->convert.needed ) { |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
606 audio->convert.len = desired->size; |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
607 audio->convert.buf =(Uint8 *)SDL_AllocAudioMem( |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
608 audio->convert.len*audio->convert.len_mult); |
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
609 if ( audio->convert.buf == NULL ) { |
0 | 610 SDL_CloseAudio(); |
808
0defd90ef27c
Simplify code and clean up Valgrind warning
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
611 SDL_OutOfMemory(); |
0 | 612 return(-1); |
613 } | |
614 } | |
615 } | |
616 | |
1406
39ca9a4b22f3
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
617 #if !SDL_AUDIO_DRIVER_AHI |
0 | 618 /* Start the audio thread if necessary */ |
619 switch (audio->opened) { | |
620 case 1: | |
621 /* Start the audio thread */ | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
622 #if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) |
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
|
623 #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
|
624 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
|
625 #else |
0 | 626 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
|
627 #endif |
0 | 628 if ( audio->thread == NULL ) { |
629 SDL_CloseAudio(); | |
630 SDL_SetError("Couldn't create audio thread"); | |
631 return(-1); | |
632 } | |
633 break; | |
634 | |
635 default: | |
636 /* The audio is now playing */ | |
637 break; | |
638 } | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
639 #else |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
640 SDL_mutexV(audio->mixer_lock); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
641 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
|
642 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
643 #endif |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
644 |
0 | 645 return(0); |
646 } | |
647 | |
648 SDL_audiostatus SDL_GetAudioStatus(void) | |
649 { | |
650 SDL_AudioDevice *audio = current_audio; | |
651 SDL_audiostatus status; | |
652 | |
653 status = SDL_AUDIO_STOPPED; | |
654 if ( audio && audio->enabled ) { | |
655 if ( audio->paused ) { | |
656 status = SDL_AUDIO_PAUSED; | |
657 } else { | |
658 status = SDL_AUDIO_PLAYING; | |
659 } | |
660 } | |
661 return(status); | |
662 } | |
663 | |
664 void SDL_PauseAudio (int pause_on) | |
665 { | |
666 SDL_AudioDevice *audio = current_audio; | |
667 | |
668 if ( audio ) { | |
669 audio->paused = pause_on; | |
670 } | |
671 } | |
672 | |
673 void SDL_LockAudio (void) | |
674 { | |
675 SDL_AudioDevice *audio = current_audio; | |
676 | |
677 /* 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
|
678 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
|
679 audio->LockAudio(audio); |
0 | 680 } |
681 } | |
682 | |
683 void SDL_UnlockAudio (void) | |
684 { | |
685 SDL_AudioDevice *audio = current_audio; | |
686 | |
687 /* 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
|
688 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
|
689 audio->UnlockAudio(audio); |
0 | 690 } |
691 } | |
692 | |
693 void SDL_CloseAudio (void) | |
694 { | |
695 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
696 } | |
697 | |
698 void SDL_AudioQuit(void) | |
699 { | |
700 SDL_AudioDevice *audio = current_audio; | |
701 | |
702 if ( audio ) { | |
703 audio->enabled = 0; | |
704 if ( audio->thread != NULL ) { | |
705 SDL_WaitThread(audio->thread, NULL); | |
706 } | |
707 if ( audio->mixer_lock != NULL ) { | |
708 SDL_DestroyMutex(audio->mixer_lock); | |
709 } | |
710 if ( audio->fake_stream != NULL ) { | |
711 SDL_FreeAudioMem(audio->fake_stream); | |
712 } | |
713 if ( audio->convert.needed ) { | |
714 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
|
715 |
0 | 716 } |
1406
39ca9a4b22f3
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
717 #if !SDL_AUDIO_DRIVER_AHI |
0 | 718 if ( audio->opened ) { |
719 audio->CloseAudio(audio); | |
720 audio->opened = 0; | |
721 } | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
722 #endif |
0 | 723 /* Free the driver data */ |
724 audio->free(audio); | |
725 current_audio = NULL; | |
726 } | |
727 } | |
728 | |
729 #define NUM_FORMATS 6 | |
730 static int format_idx; | |
731 static int format_idx_sub; | |
732 static Uint16 format_list[NUM_FORMATS][NUM_FORMATS] = { | |
733 { AUDIO_U8, AUDIO_S8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB }, | |
734 { AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB }, | |
735 { AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_U8, AUDIO_S8 }, | |
736 { AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_U8, AUDIO_S8 }, | |
737 { AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U8, AUDIO_S8 }, | |
738 { AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_U8, AUDIO_S8 }, | |
739 }; | |
740 | |
741 Uint16 SDL_FirstAudioFormat(Uint16 format) | |
742 { | |
743 for ( format_idx=0; format_idx < NUM_FORMATS; ++format_idx ) { | |
744 if ( format_list[format_idx][0] == format ) { | |
745 break; | |
746 } | |
747 } | |
748 format_idx_sub = 0; | |
749 return(SDL_NextAudioFormat()); | |
750 } | |
751 | |
752 Uint16 SDL_NextAudioFormat(void) | |
753 { | |
754 if ( (format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS) ) { | |
755 return(0); | |
756 } | |
757 return(format_list[format_idx][format_idx_sub++]); | |
758 } | |
759 | |
760 void SDL_CalculateAudioSpec(SDL_AudioSpec *spec) | |
761 { | |
762 switch (spec->format) { | |
763 case AUDIO_U8: | |
764 spec->silence = 0x80; | |
765 break; | |
766 default: | |
767 spec->silence = 0x00; | |
768 break; | |
769 } | |
770 spec->size = (spec->format&0xFF)/8; | |
771 spec->size *= spec->channels; | |
772 spec->size *= spec->samples; | |
773 } |