2009-07-27 05:47:50 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2009 Jonathon Fowler <jf@jonof.id.au>
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
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.
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
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.
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
See the GNU General Public License for more details.
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
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.
|
2016-06-05 04:46:28 +00:00
|
|
|
|
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"
|
|
|
|
|
2016-06-15 07:08:45 +00:00
|
|
|
#if defined MIXERTYPEWIN
|
2009-07-27 05:47:50 +00:00
|
|
|
# include "driver_directsound.h"
|
2016-06-15 07:08:45 +00:00
|
|
|
#elif defined MIXERTYPESDL
|
2015-07-08 03:34:09 +00:00
|
|
|
# include "driver_sdl.h"
|
2009-07-27 05:47:50 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int32_t ASS_SoundDriver = -1;
|
|
|
|
|
|
|
|
#define UNSUPPORTED { 0,0,0,0,0,0,0,0, },
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
static struct
|
|
|
|
{
|
|
|
|
int32_t (*GetError)(void);
|
|
|
|
const char *(*ErrorString)(int32_t);
|
2015-07-08 03:34:09 +00:00
|
|
|
int32_t (*Init)(int32_t *, int32_t *, void *);
|
2015-07-08 03:33:56 +00:00
|
|
|
void (*Shutdown)(void);
|
|
|
|
int32_t (*BeginPlayback)(char *, int32_t, int32_t, void (*)(void));
|
|
|
|
void (*StopPlayback)(void);
|
|
|
|
void (*Lock)(void);
|
|
|
|
void (*Unlock)(void);
|
2009-07-27 05:47:50 +00:00
|
|
|
} SoundDrivers[ASS_NumSoundCards] = {
|
2015-07-08 03:33:56 +00:00
|
|
|
|
|
|
|
// Everyone gets the "no sound" driver
|
|
|
|
{
|
|
|
|
NoSoundDrv_GetError, NoSoundDrv_ErrorString, 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
|
|
|
// Windows DirectSound
|
2016-06-15 07:08:45 +00:00
|
|
|
#if defined MIXERTYPEWIN
|
2015-07-08 03:33:56 +00:00
|
|
|
{
|
|
|
|
DirectSoundDrv_GetError, DirectSoundDrv_ErrorString, DirectSoundDrv_PCM_Init, DirectSoundDrv_PCM_Shutdown,
|
|
|
|
DirectSoundDrv_PCM_BeginPlayback, DirectSoundDrv_PCM_StopPlayback, DirectSoundDrv_PCM_Lock,
|
|
|
|
DirectSoundDrv_PCM_Unlock,
|
|
|
|
},
|
2015-07-08 03:34:09 +00:00
|
|
|
// Simple DirectMedia Layer
|
2016-06-15 07:08:45 +00:00
|
|
|
#elif defined MIXERTYPESDL
|
2015-07-08 03:34:09 +00:00
|
|
|
{
|
|
|
|
SDLDrv_GetError, SDLDrv_ErrorString, SDLDrv_PCM_Init, SDLDrv_PCM_Shutdown,
|
|
|
|
SDLDrv_PCM_BeginPlayback, SDLDrv_PCM_StopPlayback, SDLDrv_PCM_Lock, SDLDrv_PCM_Unlock,
|
|
|
|
},
|
|
|
|
#endif
|
2009-07-27 05:47:50 +00:00
|
|
|
};
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
int32_t SoundDriver_IsSupported(int32_t driver) { return (SoundDrivers[driver].GetError != 0); }
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
int32_t SoundDriver_GetError(void)
|
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
return SoundDriver_IsSupported(ASS_SoundDriver) ? SoundDrivers[ASS_SoundDriver].GetError() : -1;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char * SoundDriver_ErrorString( int32_t ErrorNumber )
|
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
if (ASS_SoundDriver < 0 || ASS_SoundDriver >= ASS_NumSoundCards)
|
|
|
|
return "No sound driver selected.";
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
if (!SoundDriver_IsSupported(ASS_SoundDriver))
|
|
|
|
return "Unsupported sound driver selected.";
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
return SoundDrivers[ASS_SoundDriver].ErrorString(ErrorNumber);
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2015-07-08 03:34:09 +00:00
|
|
|
int32_t SoundDriver_Init(int32_t *mixrate, int32_t *numchannels, void *initdata)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2015-07-08 03:34:09 +00:00
|
|
|
return SoundDrivers[ASS_SoundDriver].Init(mixrate, numchannels, initdata);
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
void SoundDriver_Shutdown(void) { SoundDrivers[ASS_SoundDriver].Shutdown(); }
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
int32_t SoundDriver_BeginPlayback(char *BufferStart, int32_t BufferSize, int32_t NumDivisions,
|
|
|
|
void (*CallBackFunc)(void))
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
return SoundDrivers[ASS_SoundDriver].BeginPlayback(BufferStart, BufferSize, NumDivisions, CallBackFunc);
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
void SoundDriver_StopPlayback(void) { SoundDrivers[ASS_SoundDriver].StopPlayback(); }
|
|
|
|
|
|
|
|
void SoundDriver_Lock(void) { SoundDrivers[ASS_SoundDriver].Lock(); }
|
|
|
|
|
|
|
|
void SoundDriver_Unlock(void) { SoundDrivers[ASS_SoundDriver].Unlock(); }
|