19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL - Simple DirectMedia Layer
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is SDL_free software; you can redistribute it and/or
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    modify it under the terms of the GNU Lesser General Public
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License as published by the Free Software Foundation; either
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    version 2.1 of the License, or (at your option) any later version.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is distributed in the hope that it will be useful,
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    but WITHOUT ANY WARRANTY; without even the implied warranty of
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Lesser General Public License for more details.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    You should have received a copy of the GNU Lesser General Public
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License along with this library; if not, write to the Free Software
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Sam Lantinga
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    slouken@libsdl.org
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h"
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef _SDL_sysaudio_h
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define _SDL_sysaudio_h
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_mutex.h"
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_thread.h"
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The SDL audio driver */
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halltypedef struct SDL_AudioDevice SDL_AudioDevice;
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Define the SDL audio driver structure */
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define _THIS	SDL_AudioDevice *_this
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef _STATUS
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define _STATUS	SDL_status *status
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstruct SDL_AudioDevice {
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* * * */
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* The name of this audio driver */
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	const char *name;
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* * * */
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* The description of this audio driver */
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	const char *desc;
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* * * */
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Public driver functions */
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int  (*OpenAudio)(_THIS, SDL_AudioSpec *spec);
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	void (*ThreadInit)(_THIS);	/* Called by audio thread at start */
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	void (*WaitAudio)(_THIS);
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	void (*PlayAudio)(_THIS);
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint8 *(*GetAudioBuf)(_THIS);
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	void (*WaitDone)(_THIS);
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	void (*CloseAudio)(_THIS);
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* * * */
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Lock / Unlock functions added for the Mac port */
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	void (*LockAudio)(_THIS);
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	void (*UnlockAudio)(_THIS);
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	void (*SetCaption)(_THIS, const char *caption);
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* * * */
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Data common to all devices */
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* The current audio specification (shared with audio thread) */
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_AudioSpec spec;
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* An audio conversion block for audio format emulation */
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_AudioCVT convert;
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Current state flags */
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int enabled;
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int paused;
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int opened;
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Fake audio buffer for when the audio hardware is busy */
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint8 *fake_stream;
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* A semaphore for locking the mixing buffers */
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_mutex *mixer_lock;
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* A thread to feed the audio device */
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_Thread *thread;
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint32 threadid;
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* * * */
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Data private to this driver */
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	struct SDL_PrivateAudioData *hidden;
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* * * */
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* The function used to dispose of this structure */
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	void (*free)(_THIS);
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall};
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#undef _THIS
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halltypedef struct AudioBootStrap {
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	const char *name;
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	const char *desc;
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int (*available)(void);
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_AudioDevice *(*create)(int devindex);
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} AudioBootStrap;
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_BSD
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap BSD_AUDIO_bootstrap;
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_PULSE
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap PULSE_bootstrap;
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_ALSA
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap ALSA_bootstrap;
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_OSS
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap DSP_bootstrap;
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap DMA_bootstrap;
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_QNXNTO
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap QNXNTOAUDIO_bootstrap;
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_SUNAUDIO
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap SUNAUDIO_bootstrap;
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_DMEDIA
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap DMEDIA_bootstrap;
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_ARTS
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap ARTS_bootstrap;
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_ESD
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap ESD_bootstrap;
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_NAS
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap NAS_bootstrap;
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_DSOUND
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap DSOUND_bootstrap;
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_WAVEOUT
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap WAVEOUT_bootstrap;
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_PAUD
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap Paud_bootstrap;
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_BAUDIO
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap BAUDIO_bootstrap;
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_COREAUDIO
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap COREAUDIO_bootstrap;
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_SNDMGR
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap SNDMGR_bootstrap;
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_MINT
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap MINTAUDIO_GSXB_bootstrap;
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap MINTAUDIO_MCSN_bootstrap;
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap MINTAUDIO_STFA_bootstrap;
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap MINTAUDIO_XBIOS_bootstrap;
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap MINTAUDIO_DMA8_bootstrap;
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_DISK
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap DISKAUD_bootstrap;
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_DUMMY
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap DUMMYAUD_bootstrap;
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_DC
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap DCAUD_bootstrap;
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_NDS
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap NDSAUD_bootstrap;
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_MMEAUDIO
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap MMEAUDIO_bootstrap;
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_DART
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap DART_bootstrap;
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_AUDIO_DRIVER_EPOCAUDIO
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern AudioBootStrap EPOCAudio_bootstrap;
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* This is the current audio device */
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern SDL_AudioDevice *current_audio;
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* _SDL_sysaudio_h */
187