Move the sound driver out of arch.cpp.

This commit is contained in:
Steve Checkoway
2006-11-18 20:33:27 +00:00
parent 1e505ff81e
commit b85a488f89
10 changed files with 97 additions and 82 deletions
@@ -5,6 +5,7 @@
#include "LoadingWindow.h"
#include "RageFile.h"
#include "RageUtil.h"
extern "C"
{
@@ -0,0 +1,75 @@
#include "global.h"
#include "RageSoundDriver.h"
#include "RageLog.h"
#include "RageUtil.h"
#include "LocalizedString.h"
#include "Foreach.h"
map<istring, CreateSoundDriverFn> *RegisterSoundDriver::g_pRegistrees;
RegisterSoundDriver::RegisterSoundDriver( const istring &sName, CreateSoundDriverFn pfn )
{
if( g_pRegistrees == NULL )
g_pRegistrees = new map<istring, CreateSoundDriverFn>;
ASSERT( g_pRegistrees->find(sName) == g_pRegistrees->end() );
(*g_pRegistrees)[sName] = pfn;
}
static LocalizedString SOUND_DRIVERS_CANNOT_EMPTY( "Arch", "Sound Drivers cannot be empty." );
RageSoundDriver *MakeRageSoundDriver( const RString &drivers )
{
vector<RString> DriversToTry;
split( drivers, ",", DriversToTry, true );
if( DriversToTry.empty() )
RageException::Throw( "%s", SOUND_DRIVERS_CANNOT_EMPTY.GetValue().c_str() );
FOREACH_CONST( RString, DriversToTry, Driver )
{
map<istring, CreateSoundDriverFn>::const_iterator iter = RegisterSoundDriver::g_pRegistrees->find( istring(*Driver) );
if( iter == RegisterSoundDriver::g_pRegistrees->end() )
{
LOG->Trace( "Unknown sound driver: %s", Driver->c_str() );
continue;
}
RageSoundDriver *pRet = (iter->second)();
DEBUG_ASSERT( pRet );
const RString sError = pRet->Init();
if( sError.empty() )
{
LOG->Info( "Sound driver: %s", Driver->c_str() );
return pRet;
}
LOG->Info( "Couldn't load driver %s: %s", Driver->c_str(), sError.c_str() );
SAFE_DELETE( pRet );
}
return NULL;
}
/*
* (c) 2002-2006 Gleen Maynard, Steve Checkoway
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
@@ -1,6 +1,8 @@
#ifndef RAGE_SOUND_DRIVER
#define RAGE_SOUND_DRIVER
#include "RageUtil.h"
class RageSoundBase;
class RageSoundDriver
{
@@ -48,6 +50,19 @@ public:
virtual ~RageSoundDriver() { }
};
typedef RageSoundDriver *(*CreateSoundDriverFn)();
struct RegisterSoundDriver
{
static map<istring, CreateSoundDriverFn> *g_pRegistrees;
RegisterSoundDriver( const istring &sName, CreateSoundDriverFn pfn );
};
// Can't use Create##name because many of these have -sw suffixes.
#define REGISTER_SOUND_DRIVER_CLASS2( name, x ) \
static RageSoundDriver *Create##x() { return new RageSound_##x; } \
static RegisterSoundDriver register_##x( #name, Create##x )
#define REGISTER_SOUND_DRIVER_CLASS( name ) REGISTER_SOUND_DRIVER_CLASS2( name, name )
/*
* (c) 2002-2004 Glenn Maynard
* All rights reserved.
@@ -4,6 +4,8 @@
#include "archutils/Darwin/DarwinThreadHelpers.h"
#include <CoreServices/CoreServices.h>
REGISTER_SOUND_DRIVER_CLASS2( AudioUnit, AU );
static const UInt32 kFramesPerPacket = 1;
static const UInt32 kChannelsPerFrame = 2;
static const UInt32 kBitsPerChannel = 16;
@@ -36,7 +36,6 @@ private:
RageSemaphore m_Semaphore;
};
#define USE_RAGE_SOUND_AU
#endif
/*
* (c) 2004-2006 Steve Checkoway
@@ -6,6 +6,8 @@
#include "PrefsManager.h"
#include "archutils/Darwin/DarwinThreadHelpers.h"
REGISTER_SOUND_DRIVER_CLASS2( CoreAudio, CA );
static const UInt8 kAudioDeviceSectionInput = 0x01;
static const UInt8 kAudioDeviceSectionOutput = 0x00;
static const UInt8 kAudioDeviceSectionGlobal = 0x00;
@@ -51,7 +51,6 @@ private:
static OSStatus JackChanged( AudioDeviceID inDevice, UInt32 inChannel, Boolean isInput,
AudioDevicePropertyID inPropertyID, void *inData );
};
#define USE_RAGE_SOUND_CA
#endif
@@ -4,6 +4,8 @@
#include "RageUtil.h"
#include "PrefsManager.h"
REGISTER_SOUND_DRIVER_CLASS( Null );
const int channels = 2;
void RageSound_Null::Update()
-65
View File
@@ -112,71 +112,6 @@ MemoryCardDriver *MakeMemoryCardDriver()
return ret;
}
static LocalizedString SOUND_DRIVERS_CANNOT_EMPTY( "Arch", "Sound Drivers cannot be empty." );
RageSoundDriver *MakeRageSoundDriver( const RString &drivers )
{
vector<RString> DriversToTry;
split( drivers, ",", DriversToTry, true );
if( DriversToTry.empty() )
RageException::Throw( "%s", SOUND_DRIVERS_CANNOT_EMPTY.GetValue().c_str() );
RString Driver;
RageSoundDriver *ret = NULL;
for( unsigned i = 0; ret == NULL && i < DriversToTry.size(); ++i )
{
Driver = DriversToTry[i];
LOG->Trace( "Initializing driver: %s", DriversToTry[i].c_str() );
#ifdef USE_RAGE_SOUND_ALSA9
if( !DriversToTry[i].CompareNoCase("ALSA") ) ret = new RageSound_ALSA9;
#endif
#ifdef USE_RAGE_SOUND_ALSA9_SOFTWARE
if( !DriversToTry[i].CompareNoCase("ALSA-sw") ) ret = new RageSound_ALSA9_Software;
#endif
#ifdef USE_RAGE_SOUND_CA
if( !DriversToTry[i].CompareNoCase("CoreAudio") ) ret = new RageSound_CA;
#endif
#ifdef USE_RAGE_SOUND_AU
if( !DriversToTry[i].CompareNoCase("AudioUnit") ) ret = new RageSound_AU;
#endif
#ifdef USE_RAGE_SOUND_DSOUND
if( !DriversToTry[i].CompareNoCase("DirectSound") ) ret = new RageSound_DSound;
#endif
#ifdef USE_RAGE_SOUND_DSOUND_SOFTWARE
if( !DriversToTry[i].CompareNoCase("DirectSound-sw") ) ret = new RageSound_DSound_Software;
#endif
#ifdef USE_RAGE_SOUND_NULL
if( !DriversToTry[i].CompareNoCase("Null") ) ret = new RageSound_Null;
#endif
#ifdef USE_RAGE_SOUND_OSS
if( !DriversToTry[i].CompareNoCase("OSS") ) ret = new RageSound_OSS;
#endif
#ifdef USE_RAGE_SOUND_WAVE_OUT
if( !DriversToTry[i].CompareNoCase("WaveOut") ) ret = new RageSound_WaveOut;
#endif
if( ret == NULL )
{
LOG->Trace( "Unknown sound driver name: %s", DriversToTry[i].c_str() );
continue;
}
RString sError = ret->Init();
if( sError != "" )
{
LOG->Info( "Couldn't load driver %s: %s", DriversToTry[i].c_str(), sError.c_str() );
SAFE_DELETE( ret );
}
}
if( ret )
LOG->Info( "Sound driver: %s", Driver.c_str() );
return ret;
}
/*
* (c) 2002-2005 Glenn Maynard, Ben Anderson
* All rights reserved.
-15
View File
@@ -8,9 +8,6 @@
#include "LoadingWindow/LoadingWindow_Win32.h"
#include "LowLevelWindow/LowLevelWindow_Win32.h"
#include "MemoryCard/MemoryCardDriverThreaded_Windows.h"
#include "Sound/RageSoundDriver_DSound.h"
#include "Sound/RageSoundDriver_DSound_Software.h"
#include "Sound/RageSoundDriver_WaveOut.h"
#define DEFAULT_INPUT_DRIVER_LIST "DirectInput,Pump,Para"
#define DEFAULT_MOVIE_DRIVER_LIST "Theora,FFMpeg,DShow,Null"
#define DEFAULT_SOUND_DRIVER_LIST "DirectSound,DirectSound-sw,WaveOut,Null"
@@ -21,8 +18,6 @@
#include "LoadingWindow/LoadingWindow_Cocoa.h"
#include "LowLevelWindow/LowLevelWindow_Cocoa.h"
#include "MemoryCard/MemoryCardDriverThreaded_OSX.h"
#include "Sound/RageSoundDriver_CA.h"
#include "Sound/RageSoundDriver_AU.h"
#define DEFAULT_INPUT_DRIVER_LIST "Carbon"
#define DEFAULT_MOVIE_DRIVER_LIST "Theora,FFMpeg,Null"
#define DEFAULT_SOUND_DRIVER_LIST "AudioUnit,CoreAudio,Null"
@@ -33,8 +28,6 @@
#include "LoadingWindow/LoadingWindow_Xbox.h"
#include "LowLevelWindow/LowLevelWindow_Win32.h"
#include "MemoryCard/MemoryCardDriverThreaded_Windows.h"
#include "Sound/RageSoundDriver_DSound.h"
#include "Sound/RageSoundDriver_DSound_Software.h"
#define DEFAULT_INPUT_DRIVER_LIST "Xbox"
#define DEFAULT_MOVIE_DRIVER_LIST "Theora,FFMpeg,DShow,Null"
#define DEFAULT_SOUND_DRIVER_LIST "DirectSound,DirectSound-sw,Null"
@@ -56,13 +49,6 @@
#if defined(HAVE_GTK)
#include "LoadingWindow/LoadingWindow_Gtk.h"
#endif
#ifdef HAVE_ALSA
#include "Sound/RageSoundDriver_ALSA9.h"
#include "Sound/RageSoundDriver_ALSA9_Software.h"
#endif
#ifdef HAVE_OSS
#include "Sound/RageSoundDriver_OSS.h"
#endif
#if defined(LINUX)
#define DEFAULT_INPUT_DRIVER_LIST "X11,Joystick"
#else
@@ -78,7 +64,6 @@
#include "Lights/LightsDriver_SystemMessage.h"
#include "Lights/LightsDriver_Null.h"
#include "LoadingWindow/LoadingWindow_Null.h"
#include "Sound/RageSoundDriver_Null.h"
#include "MemoryCard/MemoryCardDriver_Null.h"
#endif