2009-07-27 05:47:50 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2009 Jonathon Fowler <jf@jonof.id.au>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2014-07-20 08:55:56 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstraction layer for hiding the various supported sound devices
|
|
|
|
* behind a common and opaque interface called on by MultiVoc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "drivers.h"
|
|
|
|
|
|
|
|
#include "driver_nosound.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_SDL
|
|
|
|
# include "driver_sdl.h"
|
|
|
|
#endif
|
|
|
|
|
2012-11-24 09:13:29 +00:00
|
|
|
#ifdef HAVE_DS
|
2009-07-27 05:47:50 +00:00
|
|
|
# include "driver_directsound.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int32_t ASS_SoundDriver = -1;
|
|
|
|
|
|
|
|
#define UNSUPPORTED { 0,0,0,0,0,0,0,0, },
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
int32_t (* GetError)(void);
|
|
|
|
const char * (* ErrorString)(int32_t);
|
2009-07-31 11:45:29 +00:00
|
|
|
int32_t (* Init)(int32_t *, int32_t *, int32_t *, void *);
|
2009-07-27 05:47:50 +00:00
|
|
|
void (* Shutdown)(void);
|
|
|
|
int32_t (* BeginPlayback)(char *, int32_t, int32_t, void ( * )(void) );
|
|
|
|
void (* StopPlayback)(void);
|
|
|
|
void (* Lock)(void);
|
|
|
|
void (* Unlock)(void);
|
|
|
|
} SoundDrivers[ASS_NumSoundCards] = {
|
|
|
|
|
|
|
|
// Everyone gets the "no sound" driver
|
|
|
|
{
|
|
|
|
NoSoundDrv_GetError,
|
|
|
|
NoSoundDrv_ErrorString,
|
2009-07-31 11:45:29 +00:00
|
|
|
NoSoundDrv_PCM_Init,
|
|
|
|
NoSoundDrv_PCM_Shutdown,
|
|
|
|
NoSoundDrv_PCM_BeginPlayback,
|
|
|
|
NoSoundDrv_PCM_StopPlayback,
|
|
|
|
NoSoundDrv_PCM_Lock,
|
|
|
|
NoSoundDrv_PCM_Unlock,
|
2009-07-27 05:47:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Simple DirectMedia Layer
|
|
|
|
#ifdef HAVE_SDL
|
|
|
|
{
|
|
|
|
SDLDrv_GetError,
|
|
|
|
SDLDrv_ErrorString,
|
2009-07-31 11:45:29 +00:00
|
|
|
SDLDrv_PCM_Init,
|
|
|
|
SDLDrv_PCM_Shutdown,
|
|
|
|
SDLDrv_PCM_BeginPlayback,
|
|
|
|
SDLDrv_PCM_StopPlayback,
|
|
|
|
SDLDrv_PCM_Lock,
|
|
|
|
SDLDrv_PCM_Unlock,
|
2009-07-27 05:47:50 +00:00
|
|
|
},
|
|
|
|
#else
|
|
|
|
UNSUPPORTED
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Windows DirectSound
|
2012-11-24 09:13:29 +00:00
|
|
|
#ifdef HAVE_DS
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
DirectSoundDrv_GetError,
|
|
|
|
DirectSoundDrv_ErrorString,
|
2009-07-31 11:45:29 +00:00
|
|
|
DirectSoundDrv_PCM_Init,
|
|
|
|
DirectSoundDrv_PCM_Shutdown,
|
|
|
|
DirectSoundDrv_PCM_BeginPlayback,
|
|
|
|
DirectSoundDrv_PCM_StopPlayback,
|
|
|
|
DirectSoundDrv_PCM_Lock,
|
|
|
|
DirectSoundDrv_PCM_Unlock,
|
2009-07-27 05:47:50 +00:00
|
|
|
},
|
|
|
|
#else
|
|
|
|
UNSUPPORTED
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int32_t SoundDriver_IsSupported(int32_t driver)
|
|
|
|
{
|
|
|
|
return (SoundDrivers[driver].GetError != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t SoundDriver_GetError(void)
|
|
|
|
{
|
|
|
|
if (!SoundDriver_IsSupported(ASS_SoundDriver)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return SoundDrivers[ASS_SoundDriver].GetError();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * SoundDriver_ErrorString( int32_t ErrorNumber )
|
|
|
|
{
|
|
|
|
if (ASS_SoundDriver < 0 || ASS_SoundDriver >= ASS_NumSoundCards) {
|
|
|
|
return "No sound driver selected.";
|
|
|
|
}
|
|
|
|
if (!SoundDriver_IsSupported(ASS_SoundDriver)) {
|
|
|
|
return "Unsupported sound driver selected.";
|
|
|
|
}
|
|
|
|
return SoundDrivers[ASS_SoundDriver].ErrorString(ErrorNumber);
|
|
|
|
}
|
|
|
|
|
2009-07-31 11:45:29 +00:00
|
|
|
int32_t SoundDriver_Init(int32_t *mixrate, int32_t *numchannels, int32_t *samplebits, void * initdata)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
return SoundDrivers[ASS_SoundDriver].Init(mixrate, numchannels, samplebits, initdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundDriver_Shutdown(void)
|
|
|
|
{
|
|
|
|
SoundDrivers[ASS_SoundDriver].Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t SoundDriver_BeginPlayback(char *BufferStart, int32_t BufferSize,
|
|
|
|
int32_t NumDivisions, void ( *CallBackFunc )( void ) )
|
|
|
|
{
|
|
|
|
return SoundDrivers[ASS_SoundDriver].BeginPlayback(BufferStart,
|
|
|
|
BufferSize, NumDivisions, CallBackFunc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundDriver_StopPlayback(void)
|
|
|
|
{
|
|
|
|
SoundDrivers[ASS_SoundDriver].StopPlayback();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundDriver_Lock(void)
|
|
|
|
{
|
|
|
|
SoundDrivers[ASS_SoundDriver].Lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundDriver_Unlock(void)
|
|
|
|
{
|
|
|
|
SoundDrivers[ASS_SoundDriver].Unlock();
|
|
|
|
}
|