バージョン
00001 /******************************************************************************* 00002 The content of this file includes portions of the AUDIOKINETIC Wwise Technology 00003 released in source code form as part of the SDK installer package. 00004 00005 Commercial License Usage 00006 00007 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology 00008 may use this file in accordance with the end user license agreement provided 00009 with the software or, alternatively, in accordance with the terms contained in a 00010 written agreement between you and Audiokinetic Inc. 00011 00012 Apache License Usage 00013 00014 Alternatively, this file may be used under the Apache License, Version 2.0 (the 00015 "Apache License"); you may not use this file except in compliance with the 00016 Apache License. You may obtain a copy of the Apache License at 00017 http://www.apache.org/licenses/LICENSE-2.0. 00018 00019 Unless required by applicable law or agreed to in writing, software distributed 00020 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 00021 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for 00022 the specific language governing permissions and limitations under the License. 00023 00024 Version: <VERSION> Build: <BUILDNUMBER> 00025 Copyright (c) <COPYRIGHTYEAR> Audiokinetic Inc. 00026 *******************************************************************************/ 00027 00028 #ifndef _AK_BANKREADHELPERS_H_ 00029 #define _AK_BANKREADHELPERS_H_ 00030 00031 #ifdef AK_WIIU 00032 #pragma ghs nowarning 1518 00033 #endif 00034 00036 template< typename T > 00037 inline T ReadBankData( 00038 AkUInt8*& in_rptr 00039 #ifdef _DEBUG 00040 ,AkUInt32& in_rSize 00041 #endif 00042 ) 00043 { 00044 T l_Value; 00045 #if defined(AK_IOS) || defined(AK_3DS) || defined(AK_ANDROID) || defined(AK_VITA) || defined(AK_LINUX) || defined(__EMSCRIPTEN__) || defined (AK_NX) 00046 typedef struct {T t;} __attribute__((__packed__)) packedStruct; 00047 l_Value = ((packedStruct *)in_rptr)->t; 00048 #else 00049 l_Value = *( ( T* )in_rptr ); 00050 #endif 00051 00052 in_rptr += sizeof( T ); 00053 #ifdef _DEBUG 00054 in_rSize -= sizeof( T ); 00055 #endif 00056 return l_Value; 00057 } 00058 00059 template< typename T > 00060 inline T ReadVariableSizeBankData( 00061 AkUInt8*& in_rptr 00062 #ifdef _DEBUG 00063 , AkUInt32& in_rSize 00064 #endif 00065 ) 00066 { 00067 AkUInt32 l_Value = 0; 00068 00069 AkUInt8 currentByte = *in_rptr; 00070 ++in_rptr; 00071 #ifdef _DEBUG 00072 --in_rSize; 00073 #endif 00074 l_Value = (currentByte & 0x7F); 00075 while (0x80 & currentByte) 00076 { 00077 currentByte = *in_rptr; 00078 ++in_rptr; 00079 #ifdef _DEBUG 00080 --in_rSize; 00081 #endif 00082 l_Value = l_Value << 7; 00083 l_Value |= (currentByte & 0x7F); 00084 } 00085 00086 return (T)l_Value; 00087 } 00088 00089 inline char * ReadBankStringUtf8( 00090 AkUInt8*& in_rptr 00091 #ifdef _DEBUG 00092 ,AkUInt32& in_rSize 00093 #endif 00094 ,AkUInt32& out_uStringSize ) 00095 { 00096 out_uStringSize = ReadBankData<AkUInt32>( in_rptr 00097 #ifdef _DEBUG 00098 ,in_rSize 00099 #endif 00100 ); 00101 00102 char * pString = 0; 00103 if ( out_uStringSize > 0 ) 00104 { 00105 pString = reinterpret_cast<char*>( in_rptr ); 00106 in_rptr += out_uStringSize; 00107 #ifdef _DEBUG 00108 in_rSize -= out_uStringSize; 00109 #endif 00110 } 00111 return pString; 00112 } 00113 00115 template< typename T > 00116 inline T ReadUnaligned( const AkUInt8* in_rptr, AkUInt32 in_bytesToSkip = 0 ) 00117 { 00118 #ifdef _DEBUG 00119 AkUInt32 size = sizeof(T); 00120 #endif 00121 AkUInt8* ptr = const_cast<AkUInt8*>(in_rptr) + in_bytesToSkip; 00122 return ReadBankData<T>(ptr 00123 #ifdef _DEBUG 00124 , size 00125 #endif 00126 ); 00127 } 00128 00129 #ifdef __EMSCRIPTEN__ 00130 00132 inline AkReal64 AlignFloat(AkReal64* ptr) 00133 { 00134 AkReal64 LocalValue; 00135 00136 // Forcing the char copy instead of the memcpy, as memcpy was optimized.... 00137 char* pSource = (char*)ptr; 00138 char* pDest = (char*)&LocalValue; 00139 for( int i = 0; i < 8; ++i) 00140 { 00141 pDest[i] = pSource[i]; 00142 } 00143 00144 //memcpy( &LocalValue, ptr, sizeof( AkReal64 ) ); 00145 return LocalValue; 00146 } 00147 00149 template<> 00150 inline AkReal64 ReadBankData<AkReal64>( 00151 AkUInt8*& in_rptr 00152 #ifdef _DEBUG 00153 ,AkUInt32& in_rSize 00154 #endif 00155 ) 00156 { 00157 AkReal64 l_Value = AlignFloat( (AkReal64*)in_rptr ); 00158 in_rptr += sizeof( AkReal64 ); 00159 #ifdef _DEBUG 00160 in_rSize -= sizeof( AkReal64 ); 00161 #endif 00162 return l_Value; 00163 } 00164 #endif 00165 00166 00167 #ifdef AK_XBOX360 00168 00169 inline AkReal32 AlignFloat( AkReal32* __unaligned ptr ) 00170 { 00171 return *ptr; 00172 } 00173 00175 template<> 00176 inline AkReal32 ReadBankData<AkReal32>( 00177 AkUInt8*& in_rptr 00178 #ifdef _DEBUG 00179 ,AkUInt32& in_rSize 00180 #endif 00181 ) 00182 { 00183 AkReal32 l_Value = AlignFloat( ( AkReal32* )in_rptr ); 00184 in_rptr += sizeof( AkReal32 ); 00185 #ifdef _DEBUG 00186 in_rSize -= sizeof( AkReal32 ); 00187 #endif 00188 return l_Value; 00189 } 00190 00192 inline AkReal64 AlignFloat( AkReal64* __unaligned ptr ) 00193 { 00194 return *ptr; 00195 } 00196 00198 template<> 00199 inline AkReal64 ReadBankData<AkReal64>( 00200 AkUInt8*& in_rptr 00201 #ifdef _DEBUG 00202 ,AkUInt32& in_rSize 00203 #endif 00204 ) 00205 { 00206 AkReal64 l_Value = AlignFloat( ( AkReal64* )in_rptr ); 00207 in_rptr += sizeof( AkReal64 ); 00208 #ifdef _DEBUG 00209 in_rSize -= sizeof( AkReal64 ); 00210 #endif 00211 return l_Value; 00212 } 00213 00214 #endif //AK_XBOX360 00215 00216 #if defined( __SNC__ ) // Valid for both Vita and PS3 (w/SN Compiler) 00217 00218 inline AkReal32 AlignFloat( AkReal32 __unaligned * ptr ) 00219 { 00220 return *ptr; 00221 } 00222 00224 template<> 00225 inline AkReal32 ReadBankData<AkReal32>( 00226 AkUInt8*& in_rptr 00227 #ifdef _DEBUG 00228 ,AkUInt32& in_rSize 00229 #endif 00230 ) 00231 { 00232 AkReal32 l_Value = AlignFloat( ( AkReal32* )in_rptr ); 00233 in_rptr += sizeof( AkReal32 ); 00234 #ifdef _DEBUG 00235 in_rSize -= sizeof( AkReal32 ); 00236 #endif 00237 return l_Value; 00238 } 00239 00241 inline AkReal64 AlignFloat( AkReal64 __unaligned * ptr ) 00242 { 00243 return *ptr; 00244 } 00245 00247 template<> 00248 inline AkReal64 ReadBankData<AkReal64>( 00249 AkUInt8*& in_rptr 00250 #ifdef _DEBUG 00251 ,AkUInt32& in_rSize 00252 #endif 00253 ) 00254 { 00255 AkReal64 l_Value = AlignFloat( ( AkReal64* )in_rptr ); 00256 in_rptr += sizeof( AkReal64 ); 00257 #ifdef _DEBUG 00258 in_rSize -= sizeof( AkReal64 ); 00259 #endif 00260 return l_Value; 00261 } 00262 00263 #elif defined (AK_PS3) || defined(AK_WII) || defined (AK_WIIU) || (defined(AK_IOS) && defined(_DEBUG)) // bug with iOS SDK 4.3 in Debug only 00264 00266 template < typename TO, typename FROM > 00267 inline TO union_cast( FROM value ) 00268 { 00269 union { FROM from; TO to; } convert; 00270 convert.from = value; 00271 return convert.to; 00272 } 00273 00275 inline AkReal32 AlignFloat( AkReal32* ptr ) 00276 { 00277 AkUInt32 *puint = reinterpret_cast<AkUInt32 *>( ptr ); 00278 volatile AkUInt32 uint = *puint; 00279 return union_cast<AkReal32>( uint ); 00280 } 00281 00283 template<> 00284 inline AkReal32 ReadBankData<AkReal32>( 00285 AkUInt8*& in_rptr 00286 #ifdef _DEBUG 00287 ,AkUInt32& in_rSize 00288 #endif 00289 ) 00290 { 00291 AkReal32 l_Value = AlignFloat( ( AkReal32* )in_rptr ); 00292 in_rptr += sizeof( AkReal32 ); 00293 #ifdef _DEBUG 00294 in_rSize -= sizeof( AkReal32 ); 00295 #endif 00296 return l_Value; 00297 } 00298 00300 inline AkReal64 AlignFloat( AkReal64* ptr ) 00301 { 00302 AkUInt64 *puint = reinterpret_cast<AkUInt64 *>( ptr ); 00303 volatile AkUInt64 uint = *puint; 00304 return union_cast<AkReal64>( uint ); 00305 } 00306 00308 template<> 00309 inline AkReal64 ReadBankData<AkReal64>( 00310 AkUInt8*& in_rptr 00311 #ifdef _DEBUG 00312 ,AkUInt32& in_rSize 00313 #endif 00314 ) 00315 { 00316 AkReal64 l_Value = AlignFloat( ( AkReal64* )in_rptr ); 00317 in_rptr += sizeof( AkReal64 ); 00318 #ifdef _DEBUG 00319 in_rSize -= sizeof( AkReal64 ); 00320 #endif 00321 return l_Value; 00322 } 00323 #endif // AK_PS3 || AK_WII 00324 00325 #ifdef _DEBUG 00326 00328 #define READBANKDATA( _Type, _Ptr, _Size ) \ 00329 ReadBankData<_Type>( _Ptr, _Size ) 00330 00331 #define READVARIABLESIZEBANKDATA( _Type, _Ptr, _Size ) \ 00332 ReadVariableSizeBankData<_Type>( _Ptr, _Size ) 00333 00335 #define READBANKSTRING_UTF8( _Ptr, _Size, _out_StringSize ) \ 00336 ReadBankStringUtf8( _Ptr, _Size, _out_StringSize ) 00337 00339 #define READBANKSTRING( _Ptr, _Size, _out_StringSize ) \ 00340 ReadBankStringUtf8( _Ptr, _Size, _out_StringSize ) //same as UTF-8 for now. 00341 00343 #define SKIPBANKDATA( _Type, _Ptr, _Size ) \ 00344 ( _Ptr ) += sizeof( _Type ); \ 00345 ( _Size ) -= sizeof( _Type ) 00346 00348 #define SKIPBANKBYTES( _NumBytes, _Ptr, _Size ) \ 00349 ( _Ptr ) += _NumBytes; \ 00350 ( _Size ) -= _NumBytes 00351 00352 #else 00353 00355 #define READBANKDATA( _Type, _Ptr, _Size ) \ 00356 ReadBankData<_Type>( _Ptr ) 00357 00358 #define READVARIABLESIZEBANKDATA( _Type, _Ptr, _Size ) \ 00359 ReadVariableSizeBankData<_Type>( _Ptr ) 00360 00361 #define READBANKSTRING_UTF8( _Ptr, _Size, _out_StringSize ) \ 00362 ReadBankStringUtf8( _Ptr, _out_StringSize ) 00363 00364 #define READBANKSTRING( _Ptr, _Size, _out_StringSize ) \ 00365 ReadBankStringUtf8( _Ptr, _out_StringSize ) 00366 00368 #define SKIPBANKDATA( _Type, _Ptr, _Size ) \ 00369 ( _Ptr ) += sizeof( _Type ) 00370 00372 #define SKIPBANKBYTES( _NumBytes, _Ptr, _Size ) \ 00373 ( _Ptr ) += _NumBytes; 00374 00375 #endif 00376 00377 #define GETBANKDATABIT( _Data, _Shift ) \ 00378 (((_Data) >> (_Shift)) & 0x1) 00379 00381 #ifdef _DEBUG 00382 #define CHECKBANKDATASIZE( _DATASIZE_, _ERESULT_ ) AKASSERT( _DATASIZE_ == 0 || _ERESULT_ != AK_Success ); 00383 #else 00384 #define CHECKBANKDATASIZE(_DATASIZE_, _ERESULT_ ) 00385 #endif 00386 00387 #ifdef AK_WIIU 00388 #pragma ghs endnowarning 1518 00389 #endif 00390 00391 #endif //_AK_BANKREADHELPERS_H_