00001 #include "OSDLAudio.h"
00002
00003
00004 #include "OSDLUtils.h"
00005 #include "OSDLBasic.h"
00006
00007
00008 #include "SDL.h"
00009
00010
00011 #include <list>
00012 using std::list ;
00013
00014 using std::string ;
00015
00016
00017
00018 using namespace Ceylan::Log ;
00019
00020 using namespace OSDL::Audio ;
00021
00022
00023 bool AudioModule::_AudioInitialized = false ;
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00052 string AudioModule::SDLEnvironmentVariables[] =
00053 {
00054
00055 "AUDIODEV",
00056 "SDL_AUDIODRIVER",
00057 "SDL_DISKAUDIOFILE",
00058 "SDL_DISKAUDIODELAY",
00059 "SDL_DSP_NOSELECT",
00060 "SDL_PATH_DSP"
00061
00062 } ;
00063
00064
00065
00066 AudioException::AudioException( const string & reason ) throw() :
00067 OSDL::Exception( reason )
00068 {
00069
00070 }
00071
00072
00073 AudioException::~AudioException() throw()
00074 {
00075
00076 }
00077
00078
00079 AudioModule::AudioModule() throw( AudioException ) :
00080 Ceylan::Module(
00081 "OSDL Audio module",
00082 "This is the root audio module of OSDL",
00083 "http:
00084 "Olivier Boudeville",
00085 "olivier.boudeville@online.fr",
00086 OSDL::GetVersion(),
00087 "LGPL" )
00088 {
00089
00090 send( "Initializing audio subsystem." ) ;
00091
00092 if ( SDL_InitSubSystem(
00093 CommonModule::UseAudio ) != CommonModule::BackendSuccess )
00094 throw AudioException( "AudioModule constructor : "
00095 "unable to initialize audio subsystem : "
00096 + Utils::getBackendLastError() ) ;
00097
00098 _AudioInitialized = true ;
00099
00100 send( "Audio subsystem initialized." ) ;
00101
00102 dropIdentifier() ;
00103
00104 }
00105
00106
00107 AudioModule::~AudioModule() throw()
00108 {
00109
00110 send( "Stopping audio subsystem." ) ;
00111
00112 SDL_QuitSubSystem( CommonModule::UseAudio ) ;
00113
00114 send( "Audio subsystem stopped." ) ;
00115
00116 }
00117
00118
00119 const string AudioModule::toString( Ceylan::VerbosityLevels level )
00120 const throw()
00121 {
00122
00123 string res = "Audio module" ;
00124
00125 if ( level == Ceylan::low )
00126 return res ;
00127
00128 res += ". " + Ceylan::Module::toString() ;
00129
00130 return res ;
00131
00132 }
00133
00134
00135 string AudioModule::DescribeEnvironmentVariables() throw()
00136 {
00137
00138 Ceylan::Uint16 varCount =
00139 sizeof( SDLEnvironmentVariables ) / sizeof (char * ) ;
00140
00141 string result = "Examining the " + Ceylan::toString( varCount )
00142 + " audio-related environment variables for SDL backend :" ;
00143
00144 list<string> variables ;
00145
00146 string var, value ;
00147
00148 bool htmlFormat = Ceylan::TextDisplayable::GetOutputFormat() ;
00149
00150 for ( Ceylan::Uint16 i = 0; i < varCount; i++ )
00151 {
00152 var = SDLEnvironmentVariables[ i ] ;
00153 value = Ceylan::System::getEnvironmentVariable( var ) ;
00154
00155 if ( value.empty() )
00156 {
00157 if ( htmlFormat )
00158 {
00159 variables.push_back( "<em>" + var + "</em> is not set." ) ;
00160 }
00161 else
00162 {
00163 variables.push_back( var + " is not set." ) ;
00164 }
00165 }
00166 else
00167 {
00168 if ( htmlFormat )
00169 {
00170 variables.push_back( "<b>" + var + "</b> set to ["
00171 + value + "]." ) ;
00172 }
00173 else
00174 {
00175 variables.push_back( var + " set to [" + value + "]." ) ;
00176 }
00177 }
00178
00179 }
00180
00181 return result + Ceylan::formatStringList( variables ) ;
00182
00183 }
00184
00185
00186 bool AudioModule::IsAudioInitialized() throw()
00187 {
00188
00189 return _AudioInitialized ;
00190
00191 }
00192