2001-04-26 16:45:43 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2006-02-01 06:32:25 +00:00
|
|
|
Copyright (C) 1997-2006 Sam Lantinga
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2006-02-01 06:32:25 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2001-04-26 16:45:43 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2006-02-01 06:32:25 +00:00
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-02-01 06:32:25 +00:00
|
|
|
Lesser General Public License for more details.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-02-01 06:32:25 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
Sam Lantinga
|
2001-12-14 12:38:15 +00:00
|
|
|
slouken@libsdl.org
|
2001-04-26 16:45:43 +00:00
|
|
|
*/
|
2006-02-21 08:46:50 +00:00
|
|
|
#include "SDL_config.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* Allow access to a raw mixing buffer */
|
|
|
|
|
|
|
|
#include "SDL.h"
|
|
|
|
#include "SDL_audio_c.h"
|
|
|
|
#include "SDL_audiomem.h"
|
|
|
|
#include "SDL_sysaudio.h"
|
|
|
|
|
2005-11-23 07:29:56 +00:00
|
|
|
#ifdef __OS2__
|
2006-03-09 06:33:21 +00:00
|
|
|
/* We'll need the DosSetPriority() API! */
|
2005-11-23 07:29:56 +00:00
|
|
|
#define INCL_DOSPROCESS
|
|
|
|
#include <os2.h>
|
|
|
|
#endif
|
|
|
|
|
2001-04-26 16:45:43 +00:00
|
|
|
/* Available audio drivers */
|
|
|
|
static AudioBootStrap *bootstrap[] = {
|
2006-03-21 09:33:54 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_BSD
|
2006-07-10 21:04:37 +00:00
|
|
|
&BSD_AUDIO_bootstrap,
|
2001-07-08 09:00:06 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_OSS
|
2006-07-10 21:04:37 +00:00
|
|
|
&DSP_bootstrap,
|
|
|
|
&DMA_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_ALSA
|
2006-07-10 21:04:37 +00:00
|
|
|
&ALSA_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_QNXNTO
|
2006-07-10 21:04:37 +00:00
|
|
|
&QNXNTOAUDIO_bootstrap,
|
Date: Sat, 2 Aug 2003 16:22:51 +0300
From: "Mike Gorchak"
Subject: New patches for QNX6
Here my patches for the SDL/QNX:
QNXSDL.diff - diff to non-QNX related sources:
- updated BUGS file, I think QNX6 is now will be officially supported
- configure.in - added shared library support for QNX, and removed dependency between the ALSA and QNX6.
- SDL_audio.c - added QNX NTO sound bootstrap insted of ALSA's.
- SDL_sysaudio.h - the same.
- SDL_nto_audio.c - the same.
- SDL_video.c - right now, QNX doesn't offer any method to obtain pointers to the OpenGL functions by function name, so they must be hardcoded in library, otherwise OpenGL will not be supported.
- testsprite.c - fixed: do not draw vertical red line if we are in non-double-buffered mode.
sdlqnxph.tar.gz - archive of the ./src/video/photon/* . Too many changes in code to make diffs :) :
+ Added stub for support hide/unhide window event
+ Added full YUV overlays support.
+ Added window maximize support.
+ Added mouse wheel events.
+ Added support for some specific key codes in Unicode mode (like ESC).
+ Added more checks to the all memory allocation code.
+ Added SDL_DOUBLEBUF support in all fullscreen modes.
+ Added fallback to window mode, if desired fullscreen mode is not supported.
+ Added stub support for the GL_LoadLibrary and GL_GetProcAddress functions.
+ Added resizable window support without caption.
! Fixed bug in the Ph_EV_EXPOSE event handler, when rectangles to update is 0 and when width or height of the rectangle is 0.
! Fixed bug in the event handler code. Events has not been passed to the window widget handler.
! Fixed codes for Win keys (Super/Hyper/Menu).
! Fixed memory leak, when deallocation palette.
! Fixed palette emulation code bugs.
! Fixed fullscreen and hwsurface handling.
! Fixed CLOSE button bug. First event was passed to the handler, but second terminated the application. Now all events passed to the application correctly.
- Removed all printfs in code, now SDL_SetError used instead of them.
- Disabled ToggleFullScreen function.
README.QNX - updated README.QNX file. Added much more issues.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40664
2003-08-04 00:52:42 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_SUNAUDIO
|
2006-07-10 21:04:37 +00:00
|
|
|
&SUNAUDIO_bootstrap,
|
2001-08-09 13:09:47 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_DMEDIA
|
2006-07-10 21:04:37 +00:00
|
|
|
&DMEDIA_bootstrap,
|
2001-05-23 00:36:17 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_ARTS
|
2006-07-10 21:04:37 +00:00
|
|
|
&ARTS_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_ESD
|
2006-07-10 21:04:37 +00:00
|
|
|
&ESD_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_NAS
|
2006-07-10 21:04:37 +00:00
|
|
|
&NAS_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_DSOUND
|
2006-07-10 21:04:37 +00:00
|
|
|
&DSOUND_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_WAVEOUT
|
2006-07-10 21:04:37 +00:00
|
|
|
&WAVEOUT_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_PAUD
|
2006-07-10 21:04:37 +00:00
|
|
|
&Paud_bootstrap,
|
2006-02-16 10:11:48 +00:00
|
|
|
#endif
|
|
|
|
#if SDL_AUDIO_DRIVER_BAUDIO
|
2006-07-10 21:04:37 +00:00
|
|
|
&BAUDIO_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_COREAUDIO
|
2006-07-10 21:04:37 +00:00
|
|
|
&COREAUDIO_bootstrap,
|
2004-08-21 02:06:30 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_SNDMGR
|
2006-07-10 21:04:37 +00:00
|
|
|
&SNDMGR_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_AHI
|
2006-07-10 21:04:37 +00:00
|
|
|
&AHI_bootstrap,
|
2001-05-10 20:13:29 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_MINT
|
2006-07-10 21:04:37 +00:00
|
|
|
&MINTAUDIO_GSXB_bootstrap,
|
|
|
|
&MINTAUDIO_MCSN_bootstrap,
|
|
|
|
&MINTAUDIO_STFA_bootstrap,
|
|
|
|
&MINTAUDIO_XBIOS_bootstrap,
|
|
|
|
&MINTAUDIO_DMA8_bootstrap,
|
2002-06-10 20:42:53 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_DISK
|
2006-07-10 21:04:37 +00:00
|
|
|
&DISKAUD_bootstrap,
|
2002-10-05 16:50:56 +00:00
|
|
|
#endif
|
2006-03-14 08:53:33 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_DUMMY
|
2006-07-10 21:04:37 +00:00
|
|
|
&DUMMYAUD_bootstrap,
|
2006-03-14 08:53:33 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_DC
|
2006-07-10 21:04:37 +00:00
|
|
|
&DCAUD_bootstrap,
|
2003-05-29 04:44:13 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_MMEAUDIO
|
2006-07-10 21:04:37 +00:00
|
|
|
&MMEAUDIO_bootstrap,
|
2006-02-16 10:11:48 +00:00
|
|
|
#endif
|
|
|
|
#if SDL_AUDIO_DRIVER_DART
|
2006-07-10 21:04:37 +00:00
|
|
|
&DART_bootstrap,
|
2001-06-16 01:51:42 +00:00
|
|
|
#endif
|
2006-07-10 21:04:37 +00:00
|
|
|
NULL
|
2001-04-26 16:45:43 +00:00
|
|
|
};
|
|
|
|
SDL_AudioDevice *current_audio = NULL;
|
|
|
|
|
|
|
|
/* Various local functions */
|
|
|
|
int SDL_AudioInit(const char *driver_name);
|
|
|
|
void SDL_AudioQuit(void);
|
|
|
|
|
2006-02-21 08:46:50 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_AHI
|
2001-05-10 20:13:29 +00:00
|
|
|
static int audio_configured = 0;
|
|
|
|
#endif
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* The general mixing thread function */
|
2006-07-10 21:04:37 +00:00
|
|
|
int SDLCALL
|
|
|
|
SDL_RunAudio(void *audiop)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_AudioDevice *audio = (SDL_AudioDevice *) audiop;
|
|
|
|
Uint8 *stream;
|
|
|
|
int stream_len;
|
|
|
|
void *udata;
|
|
|
|
void (SDLCALL * fill) (void *userdata, Uint8 * stream, int len);
|
|
|
|
int silence;
|
2006-02-21 08:46:50 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_AHI
|
2006-07-10 21:04:37 +00:00
|
|
|
int started = 0;
|
2001-05-10 20:13:29 +00:00
|
|
|
|
|
|
|
/* AmigaOS NEEDS that the audio driver is opened in the thread that uses it! */
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
D(bug("Task audio started audio struct:<%lx>...\n", audiop));
|
2001-05-10 20:13:29 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
D(bug("Before Openaudio..."));
|
|
|
|
if (audio->OpenAudio(audio, &audio->spec) == -1) {
|
|
|
|
D(bug("Open audio failed...\n"));
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
D(bug("OpenAudio...OK\n"));
|
2001-05-10 20:13:29 +00:00
|
|
|
#endif
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Perform any thread setup */
|
|
|
|
if (audio->ThreadInit) {
|
|
|
|
audio->ThreadInit(audio);
|
|
|
|
}
|
|
|
|
audio->threadid = SDL_ThreadID();
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Set up the mixing function */
|
|
|
|
fill = audio->spec.callback;
|
|
|
|
udata = audio->spec.userdata;
|
2001-05-10 20:13:29 +00:00
|
|
|
|
2006-02-21 08:46:50 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_AHI
|
2006-07-10 21:04:37 +00:00
|
|
|
audio_configured = 1;
|
2001-05-10 20:13:29 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
D(bug("Audio configured... Checking for conversion\n"));
|
|
|
|
SDL_mutexP(audio->mixer_lock);
|
|
|
|
D(bug("Semaphore obtained...\n"));
|
2001-05-10 20:13:29 +00:00
|
|
|
#endif
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
if (audio->convert.needed) {
|
|
|
|
if (audio->convert.src_format == AUDIO_U8) {
|
|
|
|
silence = 0x80;
|
|
|
|
} else {
|
|
|
|
silence = 0;
|
|
|
|
}
|
|
|
|
stream_len = audio->convert.len;
|
|
|
|
} else {
|
|
|
|
silence = audio->spec.silence;
|
|
|
|
stream_len = audio->spec.size;
|
|
|
|
}
|
2006-03-21 00:56:10 +00:00
|
|
|
|
2006-02-21 08:46:50 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_AHI
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_mutexV(audio->mixer_lock);
|
|
|
|
D(bug("Entering audio loop...\n"));
|
2001-05-10 20:13:29 +00:00
|
|
|
#endif
|
|
|
|
|
2005-11-23 07:29:56 +00:00
|
|
|
#ifdef __OS2__
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Increase the priority of this thread to make sure that
|
|
|
|
the audio will be continuous all the time! */
|
2005-11-23 07:29:56 +00:00
|
|
|
#ifdef USE_DOSSETPRIORITY
|
2006-07-10 21:04:37 +00:00
|
|
|
if (SDL_getenv("SDL_USE_TIMECRITICAL_AUDIO")) {
|
2005-11-23 07:29:56 +00:00
|
|
|
#ifdef DEBUG_BUILD
|
2006-07-10 21:04:37 +00:00
|
|
|
printf
|
|
|
|
("[SDL_RunAudio] : Setting priority to TimeCritical+0! (TID%d)\n",
|
|
|
|
SDL_ThreadID());
|
2005-11-23 07:29:56 +00:00
|
|
|
#endif
|
2006-07-10 21:04:37 +00:00
|
|
|
DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);
|
|
|
|
} else {
|
2006-02-26 19:30:21 +00:00
|
|
|
#ifdef DEBUG_BUILD
|
2006-07-10 21:04:37 +00:00
|
|
|
printf
|
|
|
|
("[SDL_RunAudio] : Setting priority to ForegroundServer+0! (TID%d)\n",
|
|
|
|
SDL_ThreadID());
|
|
|
|
#endif
|
|
|
|
DosSetPriority(PRTYS_THREAD, PRTYC_FOREGROUNDSERVER, 0, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Loop, filling the audio buffers */
|
|
|
|
while (audio->enabled) {
|
|
|
|
|
|
|
|
/* Fill the current buffer with sound */
|
|
|
|
if (audio->convert.needed) {
|
|
|
|
if (audio->convert.buf) {
|
|
|
|
stream = audio->convert.buf;
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stream = audio->GetAudioBuf(audio);
|
|
|
|
if (stream == NULL) {
|
|
|
|
stream = audio->fake_stream;
|
|
|
|
}
|
2006-02-26 19:30:21 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_memset(stream, silence, stream_len);
|
2001-05-10 20:13:29 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
if (!audio->paused) {
|
|
|
|
SDL_mutexP(audio->mixer_lock);
|
|
|
|
(*fill) (udata, stream, stream_len);
|
|
|
|
SDL_mutexV(audio->mixer_lock);
|
|
|
|
}
|
2001-05-10 20:13:29 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Convert the audio if necessary */
|
|
|
|
if (audio->convert.needed) {
|
|
|
|
SDL_ConvertAudio(&audio->convert);
|
|
|
|
stream = audio->GetAudioBuf(audio);
|
|
|
|
if (stream == NULL) {
|
|
|
|
stream = audio->fake_stream;
|
|
|
|
}
|
|
|
|
SDL_memcpy(stream, audio->convert.buf, audio->convert.len_cvt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ready current buffer for play and change current buffer */
|
|
|
|
if (stream != audio->fake_stream) {
|
|
|
|
audio->PlayAudio(audio);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for an audio buffer to become available */
|
|
|
|
if (stream == audio->fake_stream) {
|
|
|
|
SDL_Delay((audio->spec.samples * 1000) / audio->spec.freq);
|
|
|
|
} else {
|
|
|
|
audio->WaitAudio(audio);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for the audio to drain.. */
|
|
|
|
if (audio->WaitDone) {
|
|
|
|
audio->WaitDone(audio);
|
|
|
|
}
|
2006-02-21 08:46:50 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_AHI
|
2006-07-10 21:04:37 +00:00
|
|
|
D(bug("WaitAudio...Done\n"));
|
2001-05-10 20:13:29 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
audio->CloseAudio(audio);
|
2001-05-10 20:13:29 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
D(bug("CloseAudio..Done, subtask exiting...\n"));
|
|
|
|
audio_configured = 0;
|
2005-11-23 07:29:56 +00:00
|
|
|
#endif
|
|
|
|
#ifdef __OS2__
|
|
|
|
#ifdef DEBUG_BUILD
|
2006-07-10 21:04:37 +00:00
|
|
|
printf("[SDL_RunAudio] : Task exiting. (TID%d)\n", SDL_ThreadID());
|
2005-11-23 07:29:56 +00:00
|
|
|
#endif
|
2001-05-10 20:13:29 +00:00
|
|
|
#endif
|
2006-07-10 21:04:37 +00:00
|
|
|
return (0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static void
|
|
|
|
SDL_LockAudio_Default(SDL_AudioDevice * audio)
|
2002-03-30 19:48:56 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (audio->thread && (SDL_ThreadID() == audio->threadid)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SDL_mutexP(audio->mixer_lock);
|
2002-03-30 19:48:56 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static void
|
|
|
|
SDL_UnlockAudio_Default(SDL_AudioDevice * audio)
|
2002-03-30 19:48:56 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (audio->thread && (SDL_ThreadID() == audio->threadid)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SDL_mutexV(audio->mixer_lock);
|
2002-03-30 19:48:56 +00:00
|
|
|
}
|
|
|
|
|
First shot at new audio data types (int32 and float32).
Notable changes:
- Converters between types are autogenerated. Instead of making multiple
passes over the data with seperate filters for endianess, size, signedness,
etc, converting between data types is always one specialized filter. This
simplifies SDL_BuildAudioCVT(), which otherwise had a million edge cases
with the new types, and makes the actually conversions more CPU cache
friendly. Left a stub for adding specific optimized versions of these
routines (SSE/MMX/Altivec, assembler, etc)
- Autogenerated converters are built by SDL/src/audio/sdlgenaudiocvt.pl. This
does not need to be run unless tweaking the code, and thus doesn't need
integration into the build system.
- Went through all the drivers and tried to weed out all the "Uint16"
references that are better specified with the new SDL_AudioFormat typedef.
- Cleaned out a bunch of hardcoded bitwise magic numbers and replaced them
with new SDL_AUDIO_* macros.
- Added initial float32 and int32 support code. Theoretically, existing
drivers will push these through converters to get the data they want to
feed to the hardware.
Still TODO:
- Optimize and debug new converters.
- Update the CoreAudio backend to accept float32 data directly.
- Other backends, too?
- SDL_LoadWAV() needs to be updated to support int32 and float32 .wav files
(both of which exist and can be generated by 'sox' for testing purposes).
- Update the mixer to handle new datatypes.
- Optionally update SDL_sound and SDL_mixer, etc.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402029
2006-08-24 12:10:46 +00:00
|
|
|
static SDL_AudioFormat
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_ParseAudioFormat(const char *string)
|
2006-05-09 08:52:54 +00:00
|
|
|
{
|
First shot at new audio data types (int32 and float32).
Notable changes:
- Converters between types are autogenerated. Instead of making multiple
passes over the data with seperate filters for endianess, size, signedness,
etc, converting between data types is always one specialized filter. This
simplifies SDL_BuildAudioCVT(), which otherwise had a million edge cases
with the new types, and makes the actually conversions more CPU cache
friendly. Left a stub for adding specific optimized versions of these
routines (SSE/MMX/Altivec, assembler, etc)
- Autogenerated converters are built by SDL/src/audio/sdlgenaudiocvt.pl. This
does not need to be run unless tweaking the code, and thus doesn't need
integration into the build system.
- Went through all the drivers and tried to weed out all the "Uint16"
references that are better specified with the new SDL_AudioFormat typedef.
- Cleaned out a bunch of hardcoded bitwise magic numbers and replaced them
with new SDL_AUDIO_* macros.
- Added initial float32 and int32 support code. Theoretically, existing
drivers will push these through converters to get the data they want to
feed to the hardware.
Still TODO:
- Optimize and debug new converters.
- Update the CoreAudio backend to accept float32 data directly.
- Other backends, too?
- SDL_LoadWAV() needs to be updated to support int32 and float32 .wav files
(both of which exist and can be generated by 'sox' for testing purposes).
- Update the mixer to handle new datatypes.
- Optionally update SDL_sound and SDL_mixer, etc.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402029
2006-08-24 12:10:46 +00:00
|
|
|
SDL_AudioFormat format = 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
switch (*string) {
|
|
|
|
case 'U':
|
|
|
|
++string;
|
|
|
|
format |= 0x0000;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
++string;
|
|
|
|
format |= 0x8000;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
switch (SDL_atoi(string)) {
|
|
|
|
case 8:
|
|
|
|
string += 1;
|
|
|
|
format |= 8;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
string += 2;
|
|
|
|
format |= 16;
|
|
|
|
if (SDL_strcmp(string, "LSB") == 0
|
2006-05-09 08:52:54 +00:00
|
|
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
2006-07-10 21:04:37 +00:00
|
|
|
|| SDL_strcmp(string, "SYS") == 0
|
2006-05-09 08:52:54 +00:00
|
|
|
#endif
|
2006-07-10 21:04:37 +00:00
|
|
|
) {
|
|
|
|
format |= 0x0000;
|
|
|
|
}
|
|
|
|
if (SDL_strcmp(string, "MSB") == 0
|
2006-05-09 08:52:54 +00:00
|
|
|
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
2006-07-10 21:04:37 +00:00
|
|
|
|| SDL_strcmp(string, "SYS") == 0
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
format |= 0x1000;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return format;
|
2006-05-09 08:52:54 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_GetNumAudioDrivers(void)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
return (SDL_arraysize(bootstrap) - 1);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
const char *
|
|
|
|
SDL_GetAudioDriver(int index)
|
|
|
|
{
|
|
|
|
if (index >= 0 && index < SDL_GetNumAudioDrivers()) {
|
|
|
|
return (bootstrap[index]->name);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_AudioInit(const char *driver_name)
|
|
|
|
{
|
|
|
|
SDL_AudioDevice *audio;
|
|
|
|
int i = 0, idx;
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Check to make sure we don't overwrite 'current_audio' */
|
|
|
|
if (current_audio != NULL) {
|
|
|
|
SDL_AudioQuit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Select the proper audio driver */
|
|
|
|
audio = NULL;
|
|
|
|
idx = 0;
|
2006-07-15 19:30:18 +00:00
|
|
|
if (driver_name == NULL) {
|
|
|
|
driver_name = SDL_getenv("SDL_AUDIODRIVER");
|
|
|
|
}
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_ESD
|
2006-07-10 21:04:37 +00:00
|
|
|
if ((driver_name == NULL) && (SDL_getenv("ESPEAKER") != NULL)) {
|
|
|
|
/* Ahem, we know that if ESPEAKER is set, user probably wants
|
|
|
|
to use ESD, but don't start it if it's not already running.
|
|
|
|
This probably isn't the place to do this, but... Shh! :)
|
|
|
|
*/
|
|
|
|
for (i = 0; bootstrap[i]; ++i) {
|
2006-10-01 02:06:37 +00:00
|
|
|
if (SDL_strcasecmp(bootstrap[i]->name, "esd") == 0) {
|
2006-02-07 12:11:33 +00:00
|
|
|
#ifdef HAVE_PUTENV
|
2006-07-10 21:04:37 +00:00
|
|
|
const char *esd_no_spawn;
|
|
|
|
|
|
|
|
/* Don't start ESD if it's not running */
|
|
|
|
esd_no_spawn = getenv("ESD_NO_SPAWN");
|
|
|
|
if (esd_no_spawn == NULL) {
|
|
|
|
putenv("ESD_NO_SPAWN=1");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (bootstrap[i]->available()) {
|
|
|
|
audio = bootstrap[i]->create(0);
|
|
|
|
break;
|
|
|
|
}
|
2006-02-07 12:11:33 +00:00
|
|
|
#ifdef HAVE_UNSETENV
|
2006-07-10 21:04:37 +00:00
|
|
|
if (esd_no_spawn == NULL) {
|
|
|
|
unsetenv("ESD_NO_SPAWN");
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-02-16 10:11:48 +00:00
|
|
|
#endif /* SDL_AUDIO_DRIVER_ESD */
|
2006-07-10 21:04:37 +00:00
|
|
|
if (audio == NULL) {
|
|
|
|
if (driver_name != NULL) {
|
|
|
|
for (i = 0; bootstrap[i]; ++i) {
|
2006-10-01 02:06:37 +00:00
|
|
|
if (SDL_strcasecmp(bootstrap[i]->name, driver_name) == 0) {
|
2006-07-10 21:04:37 +00:00
|
|
|
if (bootstrap[i]->available()) {
|
|
|
|
audio = bootstrap[i]->create(idx);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; bootstrap[i]; ++i) {
|
|
|
|
if (bootstrap[i]->available()) {
|
|
|
|
audio = bootstrap[i]->create(idx);
|
|
|
|
if (audio != NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (audio == NULL) {
|
|
|
|
if (driver_name) {
|
|
|
|
SDL_SetError("%s not available", driver_name);
|
|
|
|
} else {
|
|
|
|
SDL_SetError("No available audio device");
|
|
|
|
}
|
2006-07-15 19:30:18 +00:00
|
|
|
#if 0
|
|
|
|
/* Don't fail SDL_Init() if audio isn't available.
|
|
|
|
SDL_OpenAudio() will handle it at that point. *sigh*
|
|
|
|
*/
|
2006-07-10 21:04:37 +00:00
|
|
|
return (-1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
current_audio = audio;
|
|
|
|
if (current_audio) {
|
|
|
|
current_audio->name = bootstrap[i]->name;
|
|
|
|
if (!current_audio->LockAudio && !current_audio->UnlockAudio) {
|
|
|
|
current_audio->LockAudio = SDL_LockAudio_Default;
|
|
|
|
current_audio->UnlockAudio = SDL_UnlockAudio_Default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/*
|
|
|
|
* Get the current audio driver name
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
SDL_GetCurrentAudioDriver()
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (current_audio) {
|
|
|
|
return current_audio->name;
|
|
|
|
}
|
|
|
|
return (NULL);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_OpenAudio(SDL_AudioSpec * desired, SDL_AudioSpec * obtained)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_AudioDevice *audio;
|
|
|
|
const char *env;
|
|
|
|
|
|
|
|
/* Start up the audio driver, if necessary */
|
|
|
|
if (!current_audio) {
|
|
|
|
if ((SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) ||
|
|
|
|
(current_audio == NULL)) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
audio = current_audio;
|
|
|
|
|
|
|
|
if (audio->opened) {
|
|
|
|
SDL_SetError("Audio device is already opened");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify some parameters */
|
|
|
|
if (desired->freq == 0) {
|
|
|
|
env = SDL_getenv("SDL_AUDIO_FREQUENCY");
|
|
|
|
if (env) {
|
|
|
|
desired->freq = SDL_atoi(env);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (desired->freq == 0) {
|
|
|
|
/* Pick some default audio frequency */
|
|
|
|
desired->freq = 22050;
|
|
|
|
}
|
|
|
|
if (desired->format == 0) {
|
|
|
|
env = SDL_getenv("SDL_AUDIO_FORMAT");
|
|
|
|
if (env) {
|
|
|
|
desired->format = SDL_ParseAudioFormat(env);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (desired->format == 0) {
|
|
|
|
/* Pick some default audio format */
|
|
|
|
desired->format = AUDIO_S16;
|
|
|
|
}
|
|
|
|
if (desired->channels == 0) {
|
|
|
|
env = SDL_getenv("SDL_AUDIO_CHANNELS");
|
|
|
|
if (env) {
|
2006-07-14 06:40:53 +00:00
|
|
|
desired->channels = (Uint8) SDL_atoi(env);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (desired->channels == 0) {
|
|
|
|
/* Pick a default number of channels */
|
|
|
|
desired->channels = 2;
|
|
|
|
}
|
|
|
|
switch (desired->channels) {
|
|
|
|
case 1: /* Mono */
|
|
|
|
case 2: /* Stereo */
|
|
|
|
case 4: /* surround */
|
|
|
|
case 6: /* surround with center and lfe */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SDL_SetError("1 (mono) and 2 (stereo) channels supported");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (desired->samples == 0) {
|
|
|
|
env = SDL_getenv("SDL_AUDIO_SAMPLES");
|
|
|
|
if (env) {
|
2006-07-14 06:40:53 +00:00
|
|
|
desired->samples = (Uint16) SDL_atoi(env);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (desired->samples == 0) {
|
|
|
|
/* Pick a default of ~46 ms at desired frequency */
|
|
|
|
int samples = (desired->freq / 1000) * 46;
|
|
|
|
int power2 = 1;
|
|
|
|
while (power2 < samples) {
|
|
|
|
power2 *= 2;
|
|
|
|
}
|
|
|
|
desired->samples = power2;
|
|
|
|
}
|
|
|
|
if (desired->callback == NULL) {
|
|
|
|
SDL_SetError("SDL_OpenAudio() passed a NULL callback");
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-02-16 10:11:48 +00:00
|
|
|
#if defined(__MINT__) && SDL_THREADS_DISABLED
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Uses interrupt driven audio, without thread */
|
2001-04-26 16:45:43 +00:00
|
|
|
#else
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Create a semaphore for locking the sound buffers */
|
|
|
|
audio->mixer_lock = SDL_CreateMutex();
|
|
|
|
if (audio->mixer_lock == NULL) {
|
|
|
|
SDL_SetError("Couldn't create mixer lock");
|
|
|
|
SDL_CloseAudio();
|
|
|
|
return (-1);
|
|
|
|
}
|
2002-06-10 20:42:53 +00:00
|
|
|
#endif /* __MINT__ */
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Calculate the silence and size of the audio specification */
|
|
|
|
SDL_CalculateAudioSpec(desired);
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Open the audio subsystem */
|
|
|
|
SDL_memcpy(&audio->spec, desired, sizeof(audio->spec));
|
|
|
|
audio->convert.needed = 0;
|
|
|
|
audio->enabled = 1;
|
|
|
|
audio->paused = 1;
|
2001-05-10 20:13:29 +00:00
|
|
|
|
2006-02-21 09:14:58 +00:00
|
|
|
#if !SDL_AUDIO_DRIVER_AHI
|
2001-05-10 20:13:29 +00:00
|
|
|
|
|
|
|
/* AmigaOS opens audio inside the main loop */
|
2006-07-10 21:04:37 +00:00
|
|
|
audio->opened = audio->OpenAudio(audio, &audio->spec) + 1;
|
2001-05-10 20:13:29 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
if (!audio->opened) {
|
|
|
|
SDL_CloseAudio();
|
|
|
|
return (-1);
|
|
|
|
}
|
2001-05-10 20:13:29 +00:00
|
|
|
#else
|
2006-07-10 21:04:37 +00:00
|
|
|
D(bug("Locking semaphore..."));
|
|
|
|
SDL_mutexP(audio->mixer_lock);
|
|
|
|
|
|
|
|
|
|
|
|
audio->thread = SDL_CreateThread(SDL_RunAudio, audio);
|
|
|
|
D(bug("Created thread...\n"));
|
|
|
|
|
|
|
|
if (audio->thread == NULL) {
|
|
|
|
SDL_mutexV(audio->mixer_lock);
|
|
|
|
SDL_CloseAudio();
|
|
|
|
SDL_SetError("Couldn't create audio thread");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!audio_configured)
|
|
|
|
SDL_Delay(100);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* If the audio driver changes the buffer size, accept it */
|
|
|
|
if (audio->spec.samples != desired->samples) {
|
|
|
|
desired->samples = audio->spec.samples;
|
|
|
|
SDL_CalculateAudioSpec(desired);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a fake audio memory buffer */
|
|
|
|
audio->fake_stream = SDL_AllocAudioMem(audio->spec.size);
|
|
|
|
if (audio->fake_stream == NULL) {
|
|
|
|
SDL_CloseAudio();
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See if we need to do any conversion */
|
|
|
|
if (obtained != NULL) {
|
|
|
|
SDL_memcpy(obtained, &audio->spec, sizeof(audio->spec));
|
|
|
|
} else if (desired->freq != audio->spec.freq ||
|
|
|
|
desired->format != audio->spec.format ||
|
|
|
|
desired->channels != audio->spec.channels) {
|
|
|
|
/* Build an audio conversion block */
|
|
|
|
if (SDL_BuildAudioCVT(&audio->convert,
|
|
|
|
desired->format, desired->channels,
|
|
|
|
desired->freq,
|
|
|
|
audio->spec.format, audio->spec.channels,
|
|
|
|
audio->spec.freq) < 0) {
|
|
|
|
SDL_CloseAudio();
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (audio->convert.needed) {
|
|
|
|
audio->convert.len = desired->size;
|
|
|
|
audio->convert.buf =
|
|
|
|
(Uint8 *) SDL_AllocAudioMem(audio->convert.len *
|
|
|
|
audio->convert.len_mult);
|
|
|
|
if (audio->convert.buf == NULL) {
|
|
|
|
SDL_CloseAudio();
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-02-21 09:14:58 +00:00
|
|
|
#if !SDL_AUDIO_DRIVER_AHI
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Start the audio thread if necessary */
|
|
|
|
switch (audio->opened) {
|
|
|
|
case 1:
|
|
|
|
/* Start the audio thread */
|
2006-02-21 08:46:50 +00:00
|
|
|
#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC)
|
2006-02-06 08:28:51 +00:00
|
|
|
#undef SDL_CreateThread
|
2006-07-10 21:04:37 +00:00
|
|
|
audio->thread = SDL_CreateThread(SDL_RunAudio, audio, NULL, NULL);
|
2006-02-06 08:28:51 +00:00
|
|
|
#else
|
2006-07-10 21:04:37 +00:00
|
|
|
audio->thread = SDL_CreateThread(SDL_RunAudio, audio);
|
|
|
|
#endif
|
|
|
|
if (audio->thread == NULL) {
|
|
|
|
SDL_CloseAudio();
|
|
|
|
SDL_SetError("Couldn't create audio thread");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* The audio is now playing */
|
|
|
|
break;
|
|
|
|
}
|
2001-05-10 20:13:29 +00:00
|
|
|
#else
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_mutexV(audio->mixer_lock);
|
|
|
|
D(bug("SDL_OpenAudio USCITA...\n"));
|
2001-05-10 20:13:29 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
return (0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_audiostatus
|
|
|
|
SDL_GetAudioStatus(void)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_AudioDevice *audio = current_audio;
|
|
|
|
SDL_audiostatus status;
|
|
|
|
|
|
|
|
status = SDL_AUDIO_STOPPED;
|
|
|
|
if (audio && audio->enabled) {
|
|
|
|
if (audio->paused) {
|
|
|
|
status = SDL_AUDIO_PAUSED;
|
|
|
|
} else {
|
|
|
|
status = SDL_AUDIO_PLAYING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (status);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_PauseAudio(int pause_on)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_AudioDevice *audio = current_audio;
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
if (audio) {
|
|
|
|
audio->paused = pause_on;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_LockAudio(void)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_AudioDevice *audio = current_audio;
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Obtain a lock on the mixing buffers */
|
|
|
|
if (audio && audio->LockAudio) {
|
|
|
|
audio->LockAudio(audio);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_UnlockAudio(void)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_AudioDevice *audio = current_audio;
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Release lock on the mixing buffers */
|
|
|
|
if (audio && audio->UnlockAudio) {
|
|
|
|
audio->UnlockAudio(audio);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_CloseAudio(void)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_AudioQuit(void)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_AudioDevice *audio = current_audio;
|
|
|
|
|
|
|
|
if (audio) {
|
|
|
|
audio->enabled = 0;
|
|
|
|
if (audio->thread != NULL) {
|
|
|
|
SDL_WaitThread(audio->thread, NULL);
|
|
|
|
}
|
|
|
|
if (audio->mixer_lock != NULL) {
|
|
|
|
SDL_DestroyMutex(audio->mixer_lock);
|
|
|
|
}
|
|
|
|
if (audio->fake_stream != NULL) {
|
|
|
|
SDL_FreeAudioMem(audio->fake_stream);
|
|
|
|
}
|
|
|
|
if (audio->convert.needed) {
|
|
|
|
SDL_FreeAudioMem(audio->convert.buf);
|
|
|
|
|
|
|
|
}
|
2006-02-21 09:14:58 +00:00
|
|
|
#if !SDL_AUDIO_DRIVER_AHI
|
2006-07-10 21:04:37 +00:00
|
|
|
if (audio->opened) {
|
|
|
|
audio->CloseAudio(audio);
|
|
|
|
audio->opened = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* Free the driver data */
|
|
|
|
audio->free(audio);
|
|
|
|
current_audio = NULL;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
First shot at new audio data types (int32 and float32).
Notable changes:
- Converters between types are autogenerated. Instead of making multiple
passes over the data with seperate filters for endianess, size, signedness,
etc, converting between data types is always one specialized filter. This
simplifies SDL_BuildAudioCVT(), which otherwise had a million edge cases
with the new types, and makes the actually conversions more CPU cache
friendly. Left a stub for adding specific optimized versions of these
routines (SSE/MMX/Altivec, assembler, etc)
- Autogenerated converters are built by SDL/src/audio/sdlgenaudiocvt.pl. This
does not need to be run unless tweaking the code, and thus doesn't need
integration into the build system.
- Went through all the drivers and tried to weed out all the "Uint16"
references that are better specified with the new SDL_AudioFormat typedef.
- Cleaned out a bunch of hardcoded bitwise magic numbers and replaced them
with new SDL_AUDIO_* macros.
- Added initial float32 and int32 support code. Theoretically, existing
drivers will push these through converters to get the data they want to
feed to the hardware.
Still TODO:
- Optimize and debug new converters.
- Update the CoreAudio backend to accept float32 data directly.
- Other backends, too?
- SDL_LoadWAV() needs to be updated to support int32 and float32 .wav files
(both of which exist and can be generated by 'sox' for testing purposes).
- Update the mixer to handle new datatypes.
- Optionally update SDL_sound and SDL_mixer, etc.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402029
2006-08-24 12:10:46 +00:00
|
|
|
#define NUM_FORMATS 10
|
2001-04-26 16:45:43 +00:00
|
|
|
static int format_idx;
|
|
|
|
static int format_idx_sub;
|
First shot at new audio data types (int32 and float32).
Notable changes:
- Converters between types are autogenerated. Instead of making multiple
passes over the data with seperate filters for endianess, size, signedness,
etc, converting between data types is always one specialized filter. This
simplifies SDL_BuildAudioCVT(), which otherwise had a million edge cases
with the new types, and makes the actually conversions more CPU cache
friendly. Left a stub for adding specific optimized versions of these
routines (SSE/MMX/Altivec, assembler, etc)
- Autogenerated converters are built by SDL/src/audio/sdlgenaudiocvt.pl. This
does not need to be run unless tweaking the code, and thus doesn't need
integration into the build system.
- Went through all the drivers and tried to weed out all the "Uint16"
references that are better specified with the new SDL_AudioFormat typedef.
- Cleaned out a bunch of hardcoded bitwise magic numbers and replaced them
with new SDL_AUDIO_* macros.
- Added initial float32 and int32 support code. Theoretically, existing
drivers will push these through converters to get the data they want to
feed to the hardware.
Still TODO:
- Optimize and debug new converters.
- Update the CoreAudio backend to accept float32 data directly.
- Other backends, too?
- SDL_LoadWAV() needs to be updated to support int32 and float32 .wav files
(both of which exist and can be generated by 'sox' for testing purposes).
- Update the mixer to handle new datatypes.
- Optionally update SDL_sound and SDL_mixer, etc.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402029
2006-08-24 12:10:46 +00:00
|
|
|
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS] = {
|
2006-07-10 21:04:37 +00:00
|
|
|
{AUDIO_U8, AUDIO_S8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB,
|
First shot at new audio data types (int32 and float32).
Notable changes:
- Converters between types are autogenerated. Instead of making multiple
passes over the data with seperate filters for endianess, size, signedness,
etc, converting between data types is always one specialized filter. This
simplifies SDL_BuildAudioCVT(), which otherwise had a million edge cases
with the new types, and makes the actually conversions more CPU cache
friendly. Left a stub for adding specific optimized versions of these
routines (SSE/MMX/Altivec, assembler, etc)
- Autogenerated converters are built by SDL/src/audio/sdlgenaudiocvt.pl. This
does not need to be run unless tweaking the code, and thus doesn't need
integration into the build system.
- Went through all the drivers and tried to weed out all the "Uint16"
references that are better specified with the new SDL_AudioFormat typedef.
- Cleaned out a bunch of hardcoded bitwise magic numbers and replaced them
with new SDL_AUDIO_* macros.
- Added initial float32 and int32 support code. Theoretically, existing
drivers will push these through converters to get the data they want to
feed to the hardware.
Still TODO:
- Optimize and debug new converters.
- Update the CoreAudio backend to accept float32 data directly.
- Other backends, too?
- SDL_LoadWAV() needs to be updated to support int32 and float32 .wav files
(both of which exist and can be generated by 'sox' for testing purposes).
- Update the mixer to handle new datatypes.
- Optionally update SDL_sound and SDL_mixer, etc.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402029
2006-08-24 12:10:46 +00:00
|
|
|
AUDIO_U16MSB, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB},
|
2006-07-10 21:04:37 +00:00
|
|
|
{AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB,
|
First shot at new audio data types (int32 and float32).
Notable changes:
- Converters between types are autogenerated. Instead of making multiple
passes over the data with seperate filters for endianess, size, signedness,
etc, converting between data types is always one specialized filter. This
simplifies SDL_BuildAudioCVT(), which otherwise had a million edge cases
with the new types, and makes the actually conversions more CPU cache
friendly. Left a stub for adding specific optimized versions of these
routines (SSE/MMX/Altivec, assembler, etc)
- Autogenerated converters are built by SDL/src/audio/sdlgenaudiocvt.pl. This
does not need to be run unless tweaking the code, and thus doesn't need
integration into the build system.
- Went through all the drivers and tried to weed out all the "Uint16"
references that are better specified with the new SDL_AudioFormat typedef.
- Cleaned out a bunch of hardcoded bitwise magic numbers and replaced them
with new SDL_AUDIO_* macros.
- Added initial float32 and int32 support code. Theoretically, existing
drivers will push these through converters to get the data they want to
feed to the hardware.
Still TODO:
- Optimize and debug new converters.
- Update the CoreAudio backend to accept float32 data directly.
- Other backends, too?
- SDL_LoadWAV() needs to be updated to support int32 and float32 .wav files
(both of which exist and can be generated by 'sox' for testing purposes).
- Update the mixer to handle new datatypes.
- Optionally update SDL_sound and SDL_mixer, etc.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402029
2006-08-24 12:10:46 +00:00
|
|
|
AUDIO_U16MSB, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB},
|
|
|
|
{AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S32LSB,
|
|
|
|
AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_U8, AUDIO_S8},
|
|
|
|
{AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_S32MSB,
|
|
|
|
AUDIO_S32LSB, AUDIO_F32MSB, AUDIO_F32LSB, AUDIO_U8, AUDIO_S8},
|
|
|
|
{AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S32LSB,
|
|
|
|
AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_U8, AUDIO_S8},
|
|
|
|
{AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_S32MSB,
|
|
|
|
AUDIO_S32LSB, AUDIO_F32MSB, AUDIO_F32LSB, AUDIO_U8, AUDIO_S8},
|
2006-08-31 20:59:42 +00:00
|
|
|
{AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_S16LSB,
|
|
|
|
AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_U8, AUDIO_S8},
|
|
|
|
{AUDIO_S32MSB, AUDIO_S32LSB, AUDIO_F32MSB, AUDIO_F32LSB, AUDIO_S16MSB,
|
|
|
|
AUDIO_S16LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_U8, AUDIO_S8},
|
|
|
|
{AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_S16LSB,
|
|
|
|
AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_U8, AUDIO_S8},
|
|
|
|
{AUDIO_F32MSB, AUDIO_F32LSB, AUDIO_S32MSB, AUDIO_S32LSB, AUDIO_S16MSB,
|
|
|
|
AUDIO_S16LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_U8, AUDIO_S8},
|
2001-04-26 16:45:43 +00:00
|
|
|
};
|
|
|
|
|
First shot at new audio data types (int32 and float32).
Notable changes:
- Converters between types are autogenerated. Instead of making multiple
passes over the data with seperate filters for endianess, size, signedness,
etc, converting between data types is always one specialized filter. This
simplifies SDL_BuildAudioCVT(), which otherwise had a million edge cases
with the new types, and makes the actually conversions more CPU cache
friendly. Left a stub for adding specific optimized versions of these
routines (SSE/MMX/Altivec, assembler, etc)
- Autogenerated converters are built by SDL/src/audio/sdlgenaudiocvt.pl. This
does not need to be run unless tweaking the code, and thus doesn't need
integration into the build system.
- Went through all the drivers and tried to weed out all the "Uint16"
references that are better specified with the new SDL_AudioFormat typedef.
- Cleaned out a bunch of hardcoded bitwise magic numbers and replaced them
with new SDL_AUDIO_* macros.
- Added initial float32 and int32 support code. Theoretically, existing
drivers will push these through converters to get the data they want to
feed to the hardware.
Still TODO:
- Optimize and debug new converters.
- Update the CoreAudio backend to accept float32 data directly.
- Other backends, too?
- SDL_LoadWAV() needs to be updated to support int32 and float32 .wav files
(both of which exist and can be generated by 'sox' for testing purposes).
- Update the mixer to handle new datatypes.
- Optionally update SDL_sound and SDL_mixer, etc.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402029
2006-08-24 12:10:46 +00:00
|
|
|
SDL_AudioFormat
|
|
|
|
SDL_FirstAudioFormat(SDL_AudioFormat format)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
for (format_idx = 0; format_idx < NUM_FORMATS; ++format_idx) {
|
|
|
|
if (format_list[format_idx][0] == format) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
format_idx_sub = 0;
|
|
|
|
return (SDL_NextAudioFormat());
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
First shot at new audio data types (int32 and float32).
Notable changes:
- Converters between types are autogenerated. Instead of making multiple
passes over the data with seperate filters for endianess, size, signedness,
etc, converting between data types is always one specialized filter. This
simplifies SDL_BuildAudioCVT(), which otherwise had a million edge cases
with the new types, and makes the actually conversions more CPU cache
friendly. Left a stub for adding specific optimized versions of these
routines (SSE/MMX/Altivec, assembler, etc)
- Autogenerated converters are built by SDL/src/audio/sdlgenaudiocvt.pl. This
does not need to be run unless tweaking the code, and thus doesn't need
integration into the build system.
- Went through all the drivers and tried to weed out all the "Uint16"
references that are better specified with the new SDL_AudioFormat typedef.
- Cleaned out a bunch of hardcoded bitwise magic numbers and replaced them
with new SDL_AUDIO_* macros.
- Added initial float32 and int32 support code. Theoretically, existing
drivers will push these through converters to get the data they want to
feed to the hardware.
Still TODO:
- Optimize and debug new converters.
- Update the CoreAudio backend to accept float32 data directly.
- Other backends, too?
- SDL_LoadWAV() needs to be updated to support int32 and float32 .wav files
(both of which exist and can be generated by 'sox' for testing purposes).
- Update the mixer to handle new datatypes.
- Optionally update SDL_sound and SDL_mixer, etc.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402029
2006-08-24 12:10:46 +00:00
|
|
|
SDL_AudioFormat
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_NextAudioFormat(void)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if ((format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS)) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (format_list[format_idx][format_idx_sub++]);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_CalculateAudioSpec(SDL_AudioSpec * spec)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
switch (spec->format) {
|
|
|
|
case AUDIO_U8:
|
|
|
|
spec->silence = 0x80;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
spec->silence = 0x00;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
spec->size = (spec->format & 0xFF) / 8;
|
|
|
|
spec->size *= spec->channels;
|
|
|
|
spec->size *= spec->samples;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|