00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "OSDLAudible.h"
00028
00029
00030 #include "OSDLAudio.h"
00031
00032
00033 #ifdef OSDL_USES_CONFIG_H
00034 #include "OSDLConfig.h"
00035 #endif // OSDL_USES_CONFIG_H
00036
00037
00038 #if OSDL_ARCH_NINTENDO_DS
00039 #include "OSDLConfigForNintendoDS.h"
00040 #endif // OSDL_ARCH_NINTENDO_DS
00041
00042
00043
00044 using std::string ;
00045
00046
00047 using namespace Ceylan::Log ;
00048 using namespace Ceylan::System ;
00049
00050 using namespace OSDL::Audio ;
00051
00052
00053
00054 extern const PlaybackCount OSDL::Audio::Loop = -1 ;
00055
00056 extern const Volume OSDL::Audio::MinVolume = 0 ;
00057
00058
00059 #if OSDL_ARCH_NINTENDO_DS
00060
00061 extern const Volume OSDL::Audio::MaxVolume = 127 ;
00062
00063 #else // OSDL_ARCH_NINTENDO_DS
00064
00065
00066 extern const Volume OSDL::Audio::MaxVolume = 128 ;
00067
00068 #endif // OSDL_ARCH_NINTENDO_DS
00069
00070
00071
00072 AudibleException::AudibleException( const std::string & reason ) :
00073 AudioException( reason )
00074 {
00075
00076 }
00077
00078
00079
00080 AudibleException::~AudibleException() throw()
00081 {
00082
00083 }
00084
00085
00086
00087
00088
00089
00090 Audible::Audible( bool convertedToOutputFormat ) :
00091 _convertedToOutputFormat( convertedToOutputFormat )
00092 {
00093
00094 }
00095
00096
00097
00098 Audible::~Audible() throw()
00099 {
00100
00101 }
00102
00103
00104
00105 bool Audible::isConvertedToOutputFormat() const
00106 {
00107
00108 return _convertedToOutputFormat ;
00109
00110 }
00111
00112
00113
00114 const string Audible::toString( Ceylan::VerbosityLevels level ) const
00115 {
00116
00117 string res = "Audible " ;
00118
00119 if ( ! _convertedToOutputFormat )
00120 res += "not " ;
00121
00122 res += "converted to output format" ;
00123
00124 return res ;
00125
00126 }
00127
00128
00129
00130 string Audible::FindAudiblePath( const string & audibleFilename )
00131 {
00132
00133 string audibleFullPath = audibleFilename ;
00134
00135
00136 if ( ! File::ExistsAsFileOrSymbolicLink( audibleFullPath ) )
00137 {
00138
00139
00140 try
00141 {
00142
00143 audibleFullPath = AudioModule::AudioFileLocator.find(
00144 audibleFullPath ) ;
00145
00146 }
00147 catch( const FileLocatorException & e )
00148 {
00149
00150
00151
00152 string currentDir ;
00153
00154 try
00155 {
00156 currentDir = Directory::GetCurrentWorkingDirectoryPath() ;
00157 }
00158 catch( const DirectoryException & exc )
00159 {
00160
00161 throw AudibleException(
00162 "Audible::FindAudiblePath: unable to find '"
00163 + audibleFilename
00164 + "', exception generation triggered another failure: "
00165 + exc.toString() + "." ) ;
00166 }
00167
00168 throw AudibleException( "Audible::FindAudiblePath: '"
00169 + audibleFilename
00170 + "' is not a regular file nor a symbolic link "
00171 "relative to the current directory (" + currentDir
00172 + ") and cannot be found through audio locator ("
00173 + AudioModule::AudioFileLocator.toString()
00174 + ") based on audio path environment variable ("
00175 + AudioModule::AudioPathEnvironmentVariable + ")." ) ;
00176
00177 }
00178 }
00179
00180 return audibleFullPath ;
00181
00182 }
00183
00184
00185
00186 int Audible::GetLoopsForPlayCount( PlaybackCount playCount )
00187 {
00188
00189 if ( playCount == 0 || playCount < Loop )
00190 throw AudibleException( "Audible::GetLoopsForPlayCount failed: "
00191 "the play count is out of bounds ("
00192 + Ceylan::toString( playCount ) + ")" ) ;
00193
00194 if ( playCount == Loop )
00195 return Loop ;
00196 else
00197 return ( playCount - 1 ) ;
00198
00199 }
00200