include/AK/SoundEngine/Common/AkCommonDefs.h
浏览该文件的文档。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
00028
00029
00030
00031
00032
00033
00034 #ifndef _AK_COMMON_DEFS_H_
00035 #define _AK_COMMON_DEFS_H_
00036
00037 #include <AK/SoundEngine/Common/AkSpeakerConfig.h>
00038 #include <AK/SoundEngine/Common/AkSpeakerVolumes.h>
00039
00040
00041
00042
00043
00044
00045
00046
00047 const AkDataTypeID AK_INT = 0;
00048 const AkDataTypeID AK_FLOAT = 1;
00049
00050 const AkDataInterleaveID AK_INTERLEAVED = 0;
00051 const AkDataInterleaveID AK_NONINTERLEAVED = 1;
00052
00053
00054 const AkUInt32 AK_LE_NATIVE_BITSPERSAMPLE = 32;
00055 const AkUInt32 AK_LE_NATIVE_SAMPLETYPE = AK_FLOAT;
00056 const AkUInt32 AK_LE_NATIVE_INTERLEAVE = AK_NONINTERLEAVED;
00057
00058
00059 struct AkAudioFormat
00060 {
00061 AkUInt32 uSampleRate;
00062
00063 AkChannelConfig channelConfig;
00064
00065 AkUInt32 uBitsPerSample :6;
00066 AkUInt32 uBlockAlign :10;
00067 AkUInt32 uTypeID :2;
00068 AkUInt32 uInterleaveID :1;
00069
00070
00071
00072 AkForceInline AkUInt32 GetNumChannels() const
00073 {
00074 return channelConfig.uNumChannels;
00075 }
00076
00077
00078
00079 AkForceInline bool HasLFE() const
00080 {
00081 return channelConfig.HasLFE();
00082 }
00083
00084
00085
00086
00087
00088 AkForceInline bool HasCenter() const
00089 {
00090 return channelConfig.HasCenter();
00091 }
00092
00093
00094
00095 AkForceInline AkUInt32 GetBitsPerSample() const
00096 {
00097 return uBitsPerSample;
00098 }
00099
00100
00101
00102 AkForceInline AkUInt32 GetBlockAlign() const
00103 {
00104 return uBlockAlign;
00105 }
00106
00107
00108
00109 AkForceInline AkUInt32 GetTypeID() const
00110 {
00111 return uTypeID;
00112 }
00113
00114
00115
00116 AkForceInline AkUInt32 GetInterleaveID() const
00117 {
00118 return uInterleaveID;
00119 }
00120
00121
00122
00123 void SetAll(
00124 AkUInt32 in_uSampleRate,
00125 AkChannelConfig in_channelConfig,
00126 AkUInt32 in_uBitsPerSample,
00127 AkUInt32 in_uBlockAlign,
00128 AkUInt32 in_uTypeID,
00129 AkUInt32 in_uInterleaveID
00130 )
00131 {
00132 uSampleRate = in_uSampleRate;
00133 channelConfig = in_channelConfig;
00134 uBitsPerSample = in_uBitsPerSample;
00135 uBlockAlign = in_uBlockAlign;
00136 uTypeID = in_uTypeID;
00137 uInterleaveID = in_uInterleaveID;
00138 }
00139
00140
00141
00142 AkForceInline bool IsChannelConfigSupported() const
00143 {
00144 return channelConfig.IsChannelConfigSupported();
00145 }
00146
00147 AkForceInline bool operator==(const AkAudioFormat & in_other) const
00148 {
00149 return uSampleRate == in_other.uSampleRate
00150 && channelConfig == in_other.channelConfig
00151 && uBitsPerSample == in_other.uBitsPerSample
00152 && uBlockAlign == in_other.uBlockAlign
00153 && uTypeID == in_other.uTypeID
00154 && uInterleaveID == in_other.uInterleaveID;
00155 }
00156
00157 AkForceInline bool operator!=(const AkAudioFormat & in_other) const
00158 {
00159 return uSampleRate != in_other.uSampleRate
00160 || channelConfig != in_other.channelConfig
00161 || uBitsPerSample != in_other.uBitsPerSample
00162 || uBlockAlign != in_other.uBlockAlign
00163 || uTypeID != in_other.uTypeID
00164 || uInterleaveID != in_other.uInterleaveID;
00165 }
00166 };
00167
00168 enum AkSourceChannelOrdering
00169 {
00170 SourceChannelOrdering_Standard = 0,
00171
00172
00173 SourceChannelOrdering_Film,
00174 SourceChannelOrdering_FuMa
00175 };
00176
00177 #define AK_MAKE_CHANNELCONFIGOVERRIDE(_config,_order) ((AkInt64)_config.Serialize()|((AkInt64)_order<<32))
00178 #define AK_GET_CHANNELCONFIGOVERRIDE_CONFIG(_over) (_over&UINT_MAX)
00179 #define AK_GET_CHANNELCONFIGOVERRIDE_ORDERING(_over) ((AkSourceChannelOrdering)(_over>>32))
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 #define AKMAKECLASSID( in_pluginType, in_companyID, in_pluginID ) \
00193 ( (in_pluginType) + ( (in_companyID) << 4 ) + ( (in_pluginID) << ( 4 + 12 ) ) )
00194
00195 #define AKGETPLUGINTYPEFROMCLASSID( in_classID ) ( (in_classID) & AkPluginTypeMask )
00196 #define AKGETCOMPANYIDFROMCLASSID( in_classID ) ( ( (in_classID) & 0x0000FFF0 ) >> 4 )
00197 #define AKGETPLUGINIDFROMCLASSID( in_classID ) ( ( (in_classID) & 0xFFFF0000 ) >> ( 4 + 12 ) )
00198
00199 #define CODECID_FROM_PLUGINID AKGETPLUGINIDFROMCLASSID
00200
00201
00202 namespace AK
00203 {
00204
00205 class IAkMetering
00206 {
00207 protected:
00208
00209 virtual ~IAkMetering(){}
00210
00211 public:
00212
00213
00214
00215
00216
00217 virtual AK::SpeakerVolumes::ConstVectorPtr GetPeak() = 0;
00218
00219
00220
00221
00222 virtual AK::SpeakerVolumes::ConstVectorPtr GetTruePeak() = 0;
00223
00224
00225
00226
00227
00228 virtual AK::SpeakerVolumes::ConstVectorPtr GetRMS() = 0;
00229
00230
00231
00232
00233 virtual AkReal32 GetKWeightedPower() = 0;
00234 };
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 typedef AkReal32 AkSampleType;
00249
00250
00251
00252
00253
00254 class AkAudioBuffer
00255 {
00256 public:
00257
00258
00259 AkAudioBuffer()
00260 {
00261 Clear();
00262 }
00263
00264
00265 AkForceInline void ClearData()
00266 {
00267 pData = NULL;
00268 }
00269
00270
00271 AkForceInline void Clear()
00272 {
00273 ClearData();
00274 uValidFrames = 0;
00275 uMaxFrames = 0;
00276 eState = AK_DataNeeded;
00277 }
00278
00279
00280
00281
00282 AkForceInline AkUInt32 NumChannels() const
00283 {
00284 return channelConfig.uNumChannels;
00285 }
00286
00287
00288 AkForceInline bool HasLFE() const
00289 {
00290 return channelConfig.HasLFE();
00291 }
00292
00293 AkForceInline AkChannelConfig GetChannelConfig() const { return channelConfig; }
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 AkForceInline void * GetInterleavedData()
00305 {
00306 return pData;
00307 }
00308
00309
00310 inline void AttachInterleavedData( void * in_pData, AkUInt16 in_uMaxFrames, AkUInt16 in_uValidFrames, AkChannelConfig in_channelConfig )
00311 {
00312 pData = in_pData;
00313 uMaxFrames = in_uMaxFrames;
00314 uValidFrames = in_uValidFrames;
00315 channelConfig = in_channelConfig;
00316 }
00317
00318
00319
00320
00321
00322
00323 AkForceInline bool HasData() const
00324 {
00325 return ( NULL != pData );
00326 }
00327
00328
00329
00330 static inline AkUInt32 StandardToPipelineIndex(
00331 AkChannelConfig
00332 #ifdef AK_LFECENTER
00333 in_channelConfig
00334 #endif
00335 , AkUInt32 in_uChannelIdx
00336 )
00337 {
00338 #ifdef AK_LFECENTER
00339 if ( in_channelConfig.HasLFE() )
00340 {
00341 AKASSERT( in_channelConfig.eConfigType == AK_ChannelConfigType_Standard );
00342 AKASSERT( AK::GetNumNonZeroBits( in_channelConfig.uChannelMask ) );
00343 AkUInt32 uIdxLFE = AK::GetNumNonZeroBits( ( AK_SPEAKER_LOW_FREQUENCY - 1 ) & in_channelConfig.uChannelMask );
00344 if ( in_uChannelIdx == uIdxLFE )
00345 return in_channelConfig.uNumChannels - 1;
00346 else if ( in_uChannelIdx > uIdxLFE )
00347 return in_uChannelIdx - 1;
00348 }
00349 #endif
00350 return in_uChannelIdx;
00351 }
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362 inline AkSampleType * GetChannel(
00363 AkUInt32 in_uIndex
00364 )
00365 {
00366 AKASSERT( in_uIndex < NumChannels() );
00367 return (AkSampleType*)((AkUInt8*)(pData) + ( in_uIndex * sizeof(AkSampleType) * MaxFrames() ));
00368 }
00369
00370
00371
00372
00373
00374 inline AkSampleType * GetLFE()
00375 {
00376 if ( channelConfig.uChannelMask & AK_SPEAKER_LOW_FREQUENCY )
00377 return GetChannel( NumChannels()-1 );
00378
00379 return (AkSampleType*)0;
00380 }
00381
00382
00383
00384 void ZeroPadToMaxFrames()
00385 {
00386
00387 const AkUInt32 uNumChannels = NumChannels();
00388 const AkUInt32 uNumZeroFrames = MaxFrames()-uValidFrames;
00389 if ( uNumZeroFrames )
00390 {
00391 for ( AkUInt32 i = 0; i < uNumChannels; ++i )
00392 {
00393 AKPLATFORM::AkMemSet( GetChannel(i) + uValidFrames, 0, uNumZeroFrames * sizeof(AkSampleType) );
00394 }
00395 uValidFrames = MaxFrames();
00396 }
00397 }
00398
00399
00400 AkForceInline void AttachContiguousDeinterleavedData( void * in_pData, AkUInt16 in_uMaxFrames, AkUInt16 in_uValidFrames, AkChannelConfig in_channelConfig )
00401 {
00402 AttachInterleavedData( in_pData, in_uMaxFrames, in_uValidFrames, in_channelConfig );
00403 }
00404
00405 AkForceInline void * DetachContiguousDeinterleavedData()
00406 {
00407 uMaxFrames = 0;
00408 uValidFrames = 0;
00409 channelConfig.Clear();
00410 void * pDataOld = pData;
00411 pData = NULL;
00412 return pDataOld;
00413 }
00414
00415 #if defined(AK_CHECK_AUDIO_BUFFER_VALID)
00416 bool CheckValidSamples()
00417 {
00418
00419 const AkUInt32 uNumChannels = NumChannels();
00420 for ( AkUInt32 i = 0; i < uNumChannels; ++i )
00421 {
00422 AkSampleType * AK_RESTRICT pfChan = GetChannel(i);
00423 if ( pfChan )
00424 {
00425 for ( AkUInt32 j = 0; j < uValidFrames; j++ )
00426 {
00427 AkSampleType fSample = *pfChan++;
00428 if ( fSample > 4.f )
00429 return false;
00430 else if ( fSample < -4.f )
00431 return false;
00432 }
00433 }
00434 }
00435
00436 return true;
00437 }
00438 #endif
00439
00440
00441
00442 void RelocateMedia( AkUInt8* in_pNewMedia, AkUInt8* in_pOldMedia )
00443 {
00444 AkUIntPtr uMemoryOffset = (AkUIntPtr)in_pNewMedia - (AkUIntPtr)in_pOldMedia;
00445 pData = (void*) (((AkUIntPtr)pData) + uMemoryOffset);
00446 }
00447
00448 protected:
00449
00450 void * pData;
00451
00452 AkChannelConfig channelConfig;
00453 public:
00454 AKRESULT eState;
00455 protected:
00456 AkUInt16 uMaxFrames;
00457
00458 public:
00459
00460
00461 AkForceInline AkUInt16 MaxFrames() const { return uMaxFrames; }
00462
00463 AkUInt16 uValidFrames;
00464 } AK_ALIGN_DMA;
00465
00466 #endif // _AK_COMMON_DEFS_H_
00467
介绍一下自己的项目。我们会竭力为您提供帮助。
来注册自己的项目,我们帮您快速入门,不带任何附加条件!
开始 Wwise 之旅