OSDLAudio.cc

Go to the documentation of this file.
00001 #include "OSDLAudio.h"
00002 
00003 
00004 #include "OSDLUtils.h"          // for getBackendLastError
00005 #include "OSDLBasic.h"   // for OSDL::GetVersion
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 /* untested code follows... 
00027 Uint32 getChunkTimeMilliseconds(Mix_Chunk *chunk)
00028 {
00029     Uint32 points = 0;
00030     Uint32 frames = 0;
00031     int freq = 0;
00032     Uint16 fmt = 0;
00033     int chans = 0;
00034     // Chunks are converted to audio device format... 
00035     if (!Mix_QuerySpec(&freq, &fmt, &chans))
00036         return 0;  //never called Mix_OpenAudio()?!
00037 
00038     // bytes / samplesize == sample points 
00039     points = (chunk->alen / ((fmt & 0xFF) / 8));
00040 
00041     // sample points / channels == sample frames 
00042     frames = (points / chans);
00043 
00044     // (sample frames * 1000) / frequency == play length in ms 
00045     return (frames * 1000) / freq);
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://osdl.sourceforge.net",
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 

Generated on Fri Mar 30 14:46:59 2007 for OSDL by  doxygen 1.5.1