include/AK/SoundEngine/Common/AkCommonDefs.h
説明を見る。00001
00002
00003
00004
00006
00007
00008
00011
00012
00013 #ifndef _AK_COMMON_DEFS_H_
00014 #define _AK_COMMON_DEFS_H_
00015
00016 #include <AK/SoundEngine/Common/AkSpeakerConfig.h>
00017 #include <AK/SoundEngine/Common/AkSpeakerVolumes.h>
00018
00019
00020
00021
00022
00023
00024 #if defined(AK_71AUDIO)
00025 #define AK_SPEAKER_SETUP_DEFAULT_PLANE (AK_SPEAKER_SETUP_7POINT1) ///< All speakers on the plane, supported on this platform.
00026 #define AK_SUPPORTED_STANDARD_CHANNEL_MASK (AK_SPEAKER_SETUP_ALL_SPEAKERS) ///< Platform supports all standard channels.
00027 #elif defined(AK_LFECENTER) && defined(AK_REARCHANNELS)
00028 #define AK_SPEAKER_SETUP_DEFAULT_PLANE (AK_SPEAKER_SETUP_5POINT1) ///< All speakers on the plane, supported on this platform.
00029 #define AK_SUPPORTED_STANDARD_CHANNEL_MASK (AK_SPEAKER_SETUP_DEFAULT_PLANE) ///< Platform supports 5.1
00030 #elif defined(AK_REARCHANNELS)
00031 #ifdef AK_WII
00032 #define AK_SPEAKER_SETUP_DEFAULT_PLANE (AK_SPEAKER_SETUP_DPL2 | AK_SPEAKER_FRONT_CENTER) ///< All speakers on the plane, supported on this platform.
00033 #else
00034 #define AK_SPEAKER_SETUP_DEFAULT_PLANE (AK_SPEAKER_SETUP_4 | AK_SPEAKER_FRONT_CENTER) ///< All speakers on the plane, supported on this platform.
00035 #endif
00036 #define AK_SUPPORTED_STANDARD_CHANNEL_MASK (AK_SPEAKER_SETUP_DEFAULT_PLANE) ///< Most complete speaker configuration supported on this platform.
00037 #else
00038 #define AK_SPEAKER_SETUP_DEFAULT_PLANE (AK_SPEAKER_SETUP_STEREO | AK_SPEAKER_FRONT_CENTER) ///< All speakers on the plane, supported on this platform.
00039 #define AK_SUPPORTED_STANDARD_CHANNEL_MASK (AK_SPEAKER_SETUP_STEREO) ///< Most complete speaker configuration supported on this platform.
00040 #endif
00041
00042
00043 namespace AK
00044 {
00047 AkForceInline bool HasLFE( AkChannelMask in_uChannelMask )
00048 {
00049 return ( in_uChannelMask & AK_SPEAKER_LOW_FREQUENCY ) > 0;
00050 }
00051
00056 AkForceInline bool HasCenter( AkChannelMask in_uChannelMask )
00057 {
00058
00059 return ( in_uChannelMask & AK_SPEAKER_FRONT_CENTER ) > 0;
00060 }
00061
00065 AkForceInline AkUInt32 GetNumberOfAnglesForConfig( AkChannelMask in_uChannelMask )
00066 {
00067 AKASSERT( ( in_uChannelMask & ~AK_SPEAKER_SETUP_DEFAULT_PLANE ) == 0 );
00068
00069
00070 in_uChannelMask &= ~AK_SPEAKER_LOW_FREQUENCY;
00071
00072 in_uChannelMask &= ~AK_SPEAKER_FRONT_CENTER;
00073
00074
00075 AKASSERT( ( in_uChannelMask & AK_SPEAKER_BACK_CENTER ) || ( ( AK::GetNumNonZeroBits( in_uChannelMask ) % 2 ) == 0 ) );
00076 return AK::GetNumNonZeroBits( in_uChannelMask ) >> 1;
00077 }
00078 }
00079
00080
00081
00082
00083 const AkDataTypeID AK_INT = 0;
00084 const AkDataTypeID AK_FLOAT = 1;
00085
00086 const AkDataInterleaveID AK_INTERLEAVED = 0;
00087 const AkDataInterleaveID AK_NONINTERLEAVED = 1;
00088
00089
00090 const AkUInt32 AK_LE_NATIVE_BITSPERSAMPLE = 32;
00091 const AkUInt32 AK_LE_NATIVE_SAMPLETYPE = AK_FLOAT;
00092 const AkUInt32 AK_LE_NATIVE_INTERLEAVE = AK_NONINTERLEAVED;
00093
00095 enum AkChannelConfigType
00096 {
00097 AK_ChannelConfigType_Anonymous = 0x0,
00098 AK_ChannelConfigType_Standard = 0x1,
00099 AK_ChannelConfigType_Ambisonic = 0x2
00100 };
00101
00103 struct AkChannelConfig
00104 {
00105
00106
00107
00108
00109 AkUInt32 uNumChannels :8;
00110 AkUInt32 eConfigType :4;
00111 AkUInt32 uChannelMask :20;
00112
00114 AkForceInline AkChannelConfig()
00115 : uNumChannels( 0 )
00116 , eConfigType( 0 )
00117 , uChannelMask( 0 )
00118 {
00119 }
00120
00122 AkForceInline AkChannelConfig( AkChannelMask in_uChannelMask )
00123 {
00124 SetStandard( in_uChannelMask );
00125 }
00126
00128 AkForceInline bool operator!=( AkUInt32 in_uBitField )
00129 {
00130 return ( *((AkUInt32*)this) != in_uBitField );
00131 }
00132
00134 AkForceInline void Clear()
00135 {
00136 uNumChannels = 0;
00137 eConfigType = 0;
00138 uChannelMask = 0;
00139 }
00140
00142 AkForceInline void SetStandard( AkUInt32 in_uChannelMask )
00143 {
00144 uNumChannels = AK::GetNumNonZeroBits( in_uChannelMask );
00145 eConfigType = AK_ChannelConfigType_Standard;
00146 uChannelMask = in_uChannelMask;
00147 }
00148
00150 AkForceInline void SetStandardOrAnonymous( AkUInt32 in_uNumChannels, AkUInt32 in_uChannelMask )
00151 {
00152 AKASSERT( in_uChannelMask == 0 || in_uNumChannels == AK::GetNumNonZeroBits( in_uChannelMask ) );
00153 uNumChannels = in_uNumChannels;
00154 eConfigType = ( in_uChannelMask ) ? AK_ChannelConfigType_Standard : AK_ChannelConfigType_Anonymous;
00155 uChannelMask = in_uChannelMask;
00156 }
00157
00159 AkForceInline void SetAnonymous( AkUInt32 in_uNumChannels )
00160 {
00161 uNumChannels = in_uNumChannels;
00162 eConfigType = AK_ChannelConfigType_Anonymous;
00163 uChannelMask = 0;
00164 }
00165
00167 AkForceInline void SetAmbisonic( AkUInt32 in_uNumChannels )
00168 {
00169 uNumChannels = in_uNumChannels;
00170 eConfigType = AK_ChannelConfigType_Ambisonic;
00171 uChannelMask = 0;
00172 }
00173
00175 AkForceInline bool IsValid()
00176 {
00177 return uNumChannels != 0;
00178 }
00179
00181 AkForceInline void Serialize( AkUInt32 & out_uChannelConfig ) const
00182 {
00183 out_uChannelConfig = uNumChannels | ( eConfigType << 8 ) | ( uChannelMask << 12 );
00184 }
00185
00187 AkForceInline void Deserialize( AkUInt32 in_uChannelConfig )
00188 {
00189 uNumChannels = in_uChannelConfig & 0x000000ff;
00190 eConfigType = ( in_uChannelConfig >> 8 ) & 0x0000000f;
00191 uChannelMask = ( in_uChannelConfig >> 12 ) & 0x000fffff;
00192 }
00193
00195 AkForceInline AkChannelConfig RemoveLFE() const
00196 {
00197 AkChannelConfig newConfig = *this;
00198 #ifdef AK_LFECENTER
00199 AkUInt32 uNewChannelMask = newConfig.uChannelMask & ~AK_SPEAKER_LOW_FREQUENCY;
00200 AkUInt32 uNumLFEChannel = ( newConfig.uChannelMask - uNewChannelMask ) >> 3;
00201 AKASSERT( uNumLFEChannel == 0 || uNumLFEChannel == 1 );
00202 newConfig.uNumChannels -= uNumLFEChannel;
00203 newConfig.uChannelMask = uNewChannelMask;
00204 #endif
00205 return newConfig;
00206 }
00207
00209 AkForceInline AkChannelConfig RemoveCenter() const
00210 {
00211 AkChannelConfig newConfig = *this;
00212 #ifdef AK_LFECENTER
00213 AkUInt32 uNewChannelMask = newConfig.uChannelMask & ~AK_SPEAKER_FRONT_CENTER;
00214 AkUInt32 uNumCenterChannel = ( newConfig.uChannelMask - uNewChannelMask ) >> 2;
00215 AKASSERT( uNumCenterChannel == 0 || uNumCenterChannel == 1 );
00216 newConfig.uNumChannels -= uNumCenterChannel;
00217 newConfig.uChannelMask = uNewChannelMask;
00218 #endif
00219 return newConfig;
00220 }
00221
00223 AkForceInline bool operator==( const AkChannelConfig & in_other ) const
00224 {
00225 return uNumChannels == in_other.uNumChannels
00226 && eConfigType == in_other.eConfigType
00227 && uChannelMask == in_other.uChannelMask;
00228 }
00229
00231 AkForceInline bool operator!=( const AkChannelConfig & in_other ) const
00232 {
00233 return uNumChannels != in_other.uNumChannels
00234 || eConfigType != in_other.eConfigType
00235 || uChannelMask != in_other.uChannelMask;
00236 }
00237
00240 AkForceInline bool IsChannelConfigSupported() const
00241 {
00242 if ( eConfigType == AK_ChannelConfigType_Standard )
00243 {
00244 bool bIsSupported = true;
00245 switch ( uChannelMask )
00246 {
00247 case AK_SPEAKER_SETUP_MONO:
00248 case AK_SPEAKER_SETUP_STEREO:
00249 #ifdef AK_LFECENTER
00250 case AK_SPEAKER_SETUP_0POINT1:
00251 case AK_SPEAKER_SETUP_1POINT1:
00252 case AK_SPEAKER_SETUP_2POINT1:
00253 case AK_SPEAKER_SETUP_3STEREO:
00254 case AK_SPEAKER_SETUP_3POINT1:
00255 #ifdef AK_REARCHANNELS
00256 case AK_SPEAKER_SETUP_4:
00257 case AK_SPEAKER_SETUP_4POINT1:
00258 case AK_SPEAKER_SETUP_5:
00259 case AK_SPEAKER_SETUP_5POINT1:
00260 #endif
00261 #endif
00262 #ifdef AK_71AUDIO
00263 case AK_SPEAKER_SETUP_7:
00264 case AK_SPEAKER_SETUP_7POINT1:
00265 #endif // AK_71AUDIO
00266 break;
00267 default:
00268 bIsSupported = false;
00269 }
00270 return bIsSupported;
00271 }
00272 else if ( eConfigType == AK_ChannelConfigType_Anonymous )
00273 {
00274 return true;
00275 }
00276 else
00277 {
00278
00279 AKASSERT( eConfigType == AK_ChannelConfigType_Ambisonic );
00280 return false;
00281 }
00282 }
00283
00286 AkForceInline bool HasLFE() const
00287 {
00288 #ifdef AK_LFECENTER
00289 return AK::HasLFE( uChannelMask );
00290 #else
00291 return false;
00292 #endif
00293 }
00294
00299 AkForceInline bool HasCenter() const
00300 {
00301 #ifdef AK_LFECENTER
00302 return AK::HasCenter( uChannelMask );
00303 #else
00304 return false;
00305 #endif
00306 }
00307 };
00308
00310 struct AkAudioFormat
00311 {
00312 AkUInt32 uSampleRate;
00313
00314 AkChannelConfig channelConfig;
00315
00316 AkUInt32 uBitsPerSample :6;
00317 AkUInt32 uBlockAlign :10;
00318 AkUInt32 uTypeID :2;
00319 AkUInt32 uInterleaveID :1;
00320
00323 AkForceInline AkUInt32 GetNumChannels() const
00324 {
00325 return channelConfig.uNumChannels;
00326 }
00327
00330 AkForceInline bool HasLFE() const
00331 {
00332 return channelConfig.HasLFE();
00333 }
00334
00339 AkForceInline bool HasCenter() const
00340 {
00341 return channelConfig.HasCenter();
00342 }
00343
00346 AkForceInline AkUInt32 GetBitsPerSample() const
00347 {
00348 return uBitsPerSample;
00349 }
00350
00353 AkForceInline AkUInt32 GetBlockAlign() const
00354 {
00355 return uBlockAlign;
00356 }
00357
00360 AkForceInline AkUInt32 GetTypeID() const
00361 {
00362 return uTypeID;
00363 }
00364
00367 AkForceInline AkUInt32 GetInterleaveID() const
00368 {
00369 return uInterleaveID;
00370 }
00371
00374 void SetAll(
00375 AkUInt32 in_uSampleRate,
00376 AkChannelConfig in_channelConfig,
00377 AkUInt32 in_uBitsPerSample,
00378 AkUInt32 in_uBlockAlign,
00379 AkUInt32 in_uTypeID,
00380 AkUInt32 in_uInterleaveID
00381 )
00382 {
00383 uSampleRate = in_uSampleRate;
00384 channelConfig = in_channelConfig;
00385 uBitsPerSample = in_uBitsPerSample;
00386 uBlockAlign = in_uBlockAlign;
00387 uTypeID = in_uTypeID;
00388 uInterleaveID = in_uInterleaveID;
00389 }
00390
00393 AkForceInline bool IsChannelConfigSupported() const
00394 {
00395 return channelConfig.IsChannelConfigSupported();
00396 }
00397
00398 };
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411 #define AKMAKECLASSID( in_pluginType, in_companyID, in_pluginID ) \
00412 ( (in_pluginType) + ( (in_companyID) << 4 ) + ( (in_pluginID) << ( 4 + 12 ) ) )
00413
00414 #define AKGETPLUGINTYPEFROMCLASSID( in_classID ) ( (in_classID) & AkPluginTypeMask )
00415 #define AKGETCOMPANYIDFROMCLASSID( in_classID ) ( ( (in_classID) & 0x0000FFF0 ) >> 4 )
00416 #define AKGETPLUGINIDFROMCLASSID( in_classID ) ( ( (in_classID) & 0xFFFF0000 ) >> ( 4 + 12 ) )
00417
00418 #define CODECID_FROM_PLUGINID AKGETPLUGINIDFROMCLASSID
00419
00420
00421 namespace AK
00422 {
00424 class IAkMetering
00425 {
00426 protected:
00428 virtual ~IAkMetering(){}
00429
00430 public:
00431
00436 virtual AK::SpeakerVolumes::ConstVectorPtr GetPeak() = 0;
00437
00441 virtual AK::SpeakerVolumes::ConstVectorPtr GetTruePeak() = 0;
00442
00447 virtual AK::SpeakerVolumes::ConstVectorPtr GetRMS() = 0;
00448
00452 virtual AkReal32 GetKWeightedPower() = 0;
00453 };
00454 }
00455
00456
00457
00458
00467 #if defined AK_WII_FAMILY_HW || defined(AK_3DS)
00468 typedef AkInt16 AkSampleType;
00469 #else
00470 typedef AkReal32 AkSampleType;
00471 #endif
00472
00477 class AkAudioBuffer
00478 {
00479 public:
00480
00482 AkAudioBuffer()
00483 {
00484 Clear();
00485 }
00486
00488 AkForceInline void ClearData()
00489 {
00490 #if !defined(AK_WII_FAMILY_HW) && !defined(AK_3DS)
00491 pData = NULL;
00492 #else
00493 arData[0] = arData[1] = NULL;
00494 #endif
00495 }
00496
00498 AkForceInline void Clear()
00499 {
00500 ClearData();
00501 uValidFrames = 0;
00502 uMaxFrames = 0;
00503 eState = AK_DataNeeded;
00504 }
00505
00507
00508
00509 AkForceInline AkUInt32 NumChannels()
00510 {
00511 return channelConfig.uNumChannels;
00512 }
00513
00515 AkForceInline bool HasLFE()
00516 {
00517 return channelConfig.HasLFE();
00518 }
00519
00520 AkForceInline AkChannelConfig GetChannelConfig() const { return channelConfig; }
00521
00523
00525
00526
00527
00528
00529
00530
00531 #if !defined(AK_3DS) && !defined(AK_WII_FAMILY_HW)
00532 AkForceInline void * GetInterleavedData()
00533 {
00534 return pData;
00535 }
00536
00538 inline void AttachInterleavedData( void * in_pData, AkUInt16 in_uMaxFrames, AkUInt16 in_uValidFrames, AkChannelConfig in_channelConfig )
00539 {
00540 pData = in_pData;
00541 uMaxFrames = in_uMaxFrames;
00542 uValidFrames = in_uValidFrames;
00543 channelConfig = in_channelConfig;
00544 }
00545 #endif
00546
00547
00549
00550
00552 AkForceInline bool HasData()
00553 {
00554 #if !defined(AK_WII_FAMILY_HW) && !defined(AK_3DS)
00555 return ( NULL != pData );
00556 #else
00557 return ( NULL != arData[0] );
00558 #endif
00559 }
00560
00563 static inline AkUInt32 StandardToPipelineIndex(
00564 AkChannelConfig
00565 #ifdef AK_LFECENTER
00566 in_channelConfig
00567 #endif
00568 , AkUInt32 in_uChannelIdx
00569 )
00570 {
00571 #ifdef AK_LFECENTER
00572 if ( in_channelConfig.HasLFE() )
00573 {
00574 AKASSERT( in_channelConfig.eConfigType == AK_ChannelConfigType_Standard );
00575 AKASSERT( AK::GetNumNonZeroBits( in_channelConfig.uChannelMask ) );
00576 AkUInt32 uIdxLFE = AK::GetNumNonZeroBits( ( AK_SPEAKER_LOW_FREQUENCY - 1 ) & in_channelConfig.uChannelMask );
00577 if ( in_uChannelIdx == uIdxLFE )
00578 return in_channelConfig.uNumChannels - 1;
00579 else if ( in_uChannelIdx > uIdxLFE )
00580 return in_uChannelIdx - 1;
00581 }
00582 #endif
00583 return in_uChannelIdx;
00584 }
00585
00595 inline AkSampleType * GetChannel(
00596 AkUInt32 in_uIndex
00597 )
00598 {
00599 AKASSERT( in_uIndex < NumChannels() );
00600 #if defined (AK_WII_FAMILY_HW) || defined(AK_3DS)
00601 return (AkSampleType*)arData[in_uIndex];
00602 #else
00603 return (AkSampleType*)((AkUInt8*)(pData) + ( in_uIndex * sizeof(AkSampleType) * MaxFrames() ));
00604 #endif
00605 }
00606
00611 inline AkSampleType * GetLFE()
00612 {
00613 if ( channelConfig.uChannelMask & AK_SPEAKER_LOW_FREQUENCY )
00614 return GetChannel( NumChannels()-1 );
00615
00616 return (AkSampleType*)0;
00617 }
00618
00621 void ZeroPadToMaxFrames()
00622 {
00623
00624 const AkUInt32 uNumChannels = NumChannels();
00625 const AkUInt32 uNumZeroFrames = MaxFrames()-uValidFrames;
00626 if ( uNumZeroFrames )
00627 {
00628 for ( AkUInt32 i = 0; i < uNumChannels; ++i )
00629 {
00630 AKPLATFORM::AkMemSet( GetChannel(i) + uValidFrames, 0, uNumZeroFrames * sizeof(AkSampleType) );
00631 }
00632 uValidFrames = MaxFrames();
00633 }
00634 }
00635
00636 #if !defined(AK_3DS) && !defined(AK_WII_FAMILY_HW)
00637
00638 AkForceInline void AttachContiguousDeinterleavedData( void * in_pData, AkUInt16 in_uMaxFrames, AkUInt16 in_uValidFrames, AkChannelConfig in_channelConfig )
00639 {
00640 AttachInterleavedData( in_pData, in_uMaxFrames, in_uValidFrames, in_channelConfig );
00641 }
00643 AkForceInline void * DetachContiguousDeinterleavedData()
00644 {
00645 uMaxFrames = 0;
00646 uValidFrames = 0;
00647 channelConfig.Clear();
00648 void * pDataOld = pData;
00649 pData = NULL;
00650 return pDataOld;
00651 }
00652 #endif
00653
00654 #if defined(_DEBUG) && !defined(AK_WII_FAMILY_HW)
00655 bool CheckValidSamples()
00656 {
00657
00658 const AkUInt32 uNumChannels = NumChannels();
00659 for ( AkUInt32 i = 0; i < uNumChannels; ++i )
00660 {
00661 AkSampleType * AK_RESTRICT pfChan = GetChannel(i);
00662 if ( pfChan )
00663 {
00664 for ( AkUInt32 j = 0; j < uValidFrames; j++ )
00665 {
00666 AkSampleType fSample = *pfChan++;
00667 if ( fSample > 4.f )
00668 return false;
00669 else if ( fSample < -4.f )
00670 return false;
00671 }
00672 }
00673 }
00674
00675 return true;
00676 }
00677 #endif
00678
00679 #ifdef AK_PS3
00680
00681
00682
00683 AkForceInline void * GetDataStartDMA()
00684 {
00685 return pData;
00686 }
00687 #endif
00688
00689 #ifdef __SPU__
00690
00691
00692 AkForceInline void CreateFromDMA( void * in_pData, AkUInt16 in_uMaxFrames, AkUInt16 in_uValidFrames, AkChannelConfig in_channelConfig, AKRESULT in_eState )
00693 {
00694 pData = in_pData;
00695 uMaxFrames = in_uMaxFrames;
00696 uValidFrames = in_uValidFrames;
00697 channelConfig = in_channelConfig;
00698 eState = in_eState;
00699 }
00700 #endif
00701
00702
00703 #if !defined(AK_3DS) && !defined(AK_WII_FAMILY_HW)
00704 void RelocateMedia( AkUInt8* in_pNewMedia, AkUInt8* in_pOldMedia )
00705 {
00706 AkUIntPtr uMemoryOffset = (AkUIntPtr)in_pNewMedia - (AkUIntPtr)in_pOldMedia;
00707 pData = (void*) (((AkUIntPtr)pData) + uMemoryOffset);
00708 }
00709 #endif
00710
00711 protected:
00712 #if defined (AK_WII_FAMILY_HW) || defined(AK_3DS)
00713 void * arData[AK_VOICE_MAX_NUM_CHANNELS];
00714 #else
00715 void * pData;
00716 #endif
00717 AkChannelConfig channelConfig;
00718 public:
00719 AKRESULT eState;
00720 protected:
00721 AkUInt16 uMaxFrames;
00722
00723 public:
00726 AkForceInline AkUInt16 MaxFrames() { return uMaxFrames; }
00727
00728 AkUInt16 uValidFrames;
00729 } AK_ALIGN_DMA;
00730
00731 #endif // _AK_COMMON_DEFS_H_
00732
あなたのプロジェクトについて教えてください。ご不明な点はありませんか。
プロジェクトを登録していただくことで、ご利用開始のサポートをいたします。
Wwiseからはじめよう