123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663 |
- #ifndef _AK_COMMON_DEFS_H_
- #define _AK_COMMON_DEFS_H_
- #include <AK/SoundEngine/Common/AkSpeakerConfig.h>
- #include <AK/SoundEngine/Common/AkSpeakerVolumes.h>
- #include <AK/SoundEngine/Common/IAkPluginMemAlloc.h>
- #include <AK/Tools/Common/AkArray.h>
- #include <AK/Tools/Common/AkString.h>
- const AkDataTypeID AK_INT = 0;
- const AkDataTypeID AK_FLOAT = 1;
- const AkDataInterleaveID AK_INTERLEAVED = 0;
- const AkDataInterleaveID AK_NONINTERLEAVED = 1;
- const AkUInt32 AK_LE_NATIVE_BITSPERSAMPLE = 32;
- const AkUInt32 AK_LE_NATIVE_SAMPLETYPE = AK_FLOAT;
- const AkUInt32 AK_LE_NATIVE_INTERLEAVE = AK_NONINTERLEAVED;
- struct AkAudioFormat
- {
- AkUInt32 uSampleRate;
- AkChannelConfig channelConfig;
- AkUInt32 uBitsPerSample :6;
- AkUInt32 uBlockAlign :10;
- AkUInt32 uTypeID :2;
- AkUInt32 uInterleaveID :1;
-
-
-
- AkForceInline AkUInt32 GetNumChannels() const
- {
- return channelConfig.uNumChannels;
- }
-
-
- AkForceInline bool HasLFE() const
- {
- return channelConfig.HasLFE();
- }
-
-
-
-
- AkForceInline bool HasCenter() const
- {
- return channelConfig.HasCenter();
- }
-
-
- AkForceInline AkUInt32 GetBitsPerSample() const
- {
- return uBitsPerSample;
- }
-
-
- AkForceInline AkUInt32 GetBlockAlign() const
- {
- return uBlockAlign;
- }
-
-
- AkForceInline AkUInt32 GetTypeID() const
- {
- return uTypeID;
- }
-
-
- AkForceInline AkUInt32 GetInterleaveID() const
- {
- return uInterleaveID;
- }
-
-
- void SetAll(
- AkUInt32 in_uSampleRate,
- AkChannelConfig in_channelConfig,
- AkUInt32 in_uBitsPerSample,
- AkUInt32 in_uBlockAlign,
- AkUInt32 in_uTypeID,
- AkUInt32 in_uInterleaveID
- )
- {
- uSampleRate = in_uSampleRate;
- channelConfig = in_channelConfig;
- uBitsPerSample = in_uBitsPerSample;
- uBlockAlign = in_uBlockAlign;
- uTypeID = in_uTypeID;
- uInterleaveID = in_uInterleaveID;
- }
- AkForceInline bool operator==(const AkAudioFormat & in_other) const
- {
- return uSampleRate == in_other.uSampleRate
- && channelConfig == in_other.channelConfig
- && uBitsPerSample == in_other.uBitsPerSample
- && uBlockAlign == in_other.uBlockAlign
- && uTypeID == in_other.uTypeID
- && uInterleaveID == in_other.uInterleaveID;
- }
- AkForceInline bool operator!=(const AkAudioFormat & in_other) const
- {
- return uSampleRate != in_other.uSampleRate
- || channelConfig != in_other.channelConfig
- || uBitsPerSample != in_other.uBitsPerSample
- || uBlockAlign != in_other.uBlockAlign
- || uTypeID != in_other.uTypeID
- || uInterleaveID != in_other.uInterleaveID;
- }
- };
- typedef AkUInt8(*AkChannelMappingFunc)(const AkChannelConfig &config, AkUInt8 idx);
- enum AkSourceChannelOrdering
- {
- SourceChannelOrdering_Standard = 0,
-
- SourceChannelOrdering_Film,
- SourceChannelOrdering_FuMa
- };
- #define AK_MAKE_CHANNELCONFIGOVERRIDE(_config,_order) ((AkInt64)_config.Serialize()|((AkInt64)_order<<32))
- #define AK_GET_CHANNELCONFIGOVERRIDE_CONFIG(_over) (_over&UINT_MAX)
- #define AK_GET_CHANNELCONFIGOVERRIDE_ORDERING(_over) ((AkSourceChannelOrdering)(_over>>32))
- #define AKMAKECLASSID( in_pluginType, in_companyID, in_pluginID ) \
- ( (in_pluginType) + ( (in_companyID) << 4 ) + ( (in_pluginID) << ( 4 + 12 ) ) )
- #define AKGETPLUGINTYPEFROMCLASSID( in_classID ) ( (in_classID) & AkPluginTypeMask )
- #define AKGETCOMPANYIDFROMCLASSID( in_classID ) ( ( (in_classID) & 0x0000FFF0 ) >> 4 )
- #define AKGETPLUGINIDFROMCLASSID( in_classID ) ( ( (in_classID) & 0xFFFF0000 ) >> ( 4 + 12 ) )
- #define CODECID_FROM_PLUGINID AKGETPLUGINIDFROMCLASSID
- namespace AK
- {
-
- struct AkMetering
- {
-
-
- AK::SpeakerVolumes::VectorPtr peak;
-
-
- AK::SpeakerVolumes::VectorPtr truePeak;
-
-
- AK::SpeakerVolumes::VectorPtr rms;
-
-
- AkReal32 fMeanPowerK;
- };
- static inline bool IsBankCodecID(AkUInt32 in_codecID)
- {
- return in_codecID == AKCODECID_BANK ||
- in_codecID == AKCODECID_BANK_EVENT ||
- in_codecID == AKCODECID_BANK_BUS;
- }
- }
- #define AK_DEFAULT_LISTENER_POSITION_X (0.0f)
- #define AK_DEFAULT_LISTENER_POSITION_Y (0.0f)
- #define AK_DEFAULT_LISTENER_POSITION_Z (0.0f)
- #define AK_DEFAULT_LISTENER_FRONT_X (0.0f)
- #define AK_DEFAULT_LISTENER_FRONT_Y (0.0f)
- #define AK_DEFAULT_LISTENER_FRONT_Z (1.0f)
- #define AK_DEFAULT_TOP_X (0.0f)
- #define AK_DEFAULT_TOP_Y (1.0f)
- #define AK_DEFAULT_TOP_Z (0.0f)
- struct Ak3dData
- {
- Ak3dData()
- : spread(1.f)
- , focus(1.f)
- , uEmitterChannelMask(0xffff)
- {
- xform.Set(AK_DEFAULT_LISTENER_POSITION_X, AK_DEFAULT_LISTENER_POSITION_Y, AK_DEFAULT_LISTENER_POSITION_Z, AK_DEFAULT_LISTENER_FRONT_X, AK_DEFAULT_LISTENER_FRONT_Y, AK_DEFAULT_LISTENER_FRONT_Z, AK_DEFAULT_TOP_X, AK_DEFAULT_TOP_Y, AK_DEFAULT_TOP_Z);
- }
- AkTransform xform;
- AkReal32 spread;
- AkReal32 focus;
- AkChannelMask uEmitterChannelMask;
- };
- struct AkBehavioralPositioningData
- {
- AkBehavioralPositioningData()
- : center(1.f)
- , panLR(0.f)
- , panBF(0.f)
- , panDU(0.f)
- , panSpatMix(1.f)
- , spatMode(AK_SpatializationMode_None)
- , panType(AK_DirectSpeakerAssignment)
- , enableHeightSpread(true)
- {}
- AkReal32 center;
- AkReal32 panLR;
- AkReal32 panBF;
- AkReal32 panDU;
- AkReal32 panSpatMix;
- Ak3DSpatializationMode spatMode;
- AkSpeakerPanningType panType;
- bool enableHeightSpread;
- };
- struct AkPositioningData
- {
- Ak3dData threeD;
- AkBehavioralPositioningData behavioral;
- };
- namespace AK
- {
- class IAkPluginParam;
- }
- struct AkAudioObject
- {
-
- AkAudioObject()
- :key(AK_INVALID_AUDIO_OBJECT_ID)
- ,cumulativeGain(1.f, 1.f)
- ,instigatorID(AK_INVALID_PIPELINE_ID)
- ,priority(AK_DEFAULT_PRIORITY)
- {}
-
- ~AkAudioObject()
- {
- arCustomMetadata.Term();
- objectName.Term();
- }
- AkAudioObjectID key;
- AkPositioningData positioning;
- AkRamp cumulativeGain;
-
- struct CustomMetadata
- {
- AkPluginID pluginID;
- AK::IAkPluginParam* pParam;
- AkUniqueID contextID;
- };
-
- class ArrayCustomMetadata : public AkArray<CustomMetadata, const CustomMetadata&, AkPluginArrayAllocator>
- {
- public:
- using ArrayType = AkArray<CustomMetadata, const CustomMetadata&, AkPluginArrayAllocator>;
- ArrayType::Iterator FindByPluginID(AkPluginID pluginID) const
- {
- for (auto it = Begin(); it != End(); ++it)
- {
- if ((*it).pluginID == pluginID)
- return it;
- }
- return End();
- }
- };
- ArrayCustomMetadata arCustomMetadata;
- AkPipelineID instigatorID;
- typedef AkString<AkPluginArrayAllocator, char> String;
- String objectName;
- AkPriority priority;
-
- void CopyContents(
- const AkAudioObject& in_src
- )
- {
- positioning = in_src.positioning;
- cumulativeGain = in_src.cumulativeGain;
- arCustomMetadata.Copy(in_src.arCustomMetadata);
- instigatorID = in_src.instigatorID;
- objectName = in_src.objectName;
- priority = in_src.priority;
- }
- void SetCustomMetadata(CustomMetadata* in_aCustomMetadata, AkUInt32 in_uLength)
- {
- if (arCustomMetadata.Resize(in_uLength))
- {
- for (int i = 0; i < (int)in_uLength; ++i)
- {
- arCustomMetadata[i] = in_aCustomMetadata[i];
- }
- }
- }
-
- void Transfer(
- AkAudioObject& in_from
- )
- {
- key = in_from.key;
- positioning = in_from.positioning;
- cumulativeGain = in_from.cumulativeGain;
- arCustomMetadata.Transfer(in_from.arCustomMetadata);
- instigatorID = in_from.instigatorID;
- objectName.Transfer(in_from.objectName);
- priority = in_from.priority;
- }
-
-
- AKRESULT SetName(
- AK::IAkPluginMemAlloc* in_pAllocator,
- const char* in_szName
- )
- {
- objectName.Init(in_pAllocator);
- objectName = in_szName;
- return objectName.AllocCopy();
- }
-
- void ResetState()
- {
- arCustomMetadata.Term();
- objectName.ClearReference();
- }
- };
- struct Ak3DAudioSinkCapabilities
- {
- AkChannelConfig channelConfig;
- AkUInt32 uMaxSystemAudioObjects;
- AkUInt32 uAvailableSystemAudioObjects;
- bool bPassthrough;
- bool bMultiChannelObjects;
- };
- enum class AkAudioObjectDestination
- {
- eDefault = 0,
- eMainMix = 1,
- ePassthrough = 2,
- eSystemAudioObject = 3
- };
- typedef AkReal32 AkSampleType;
- class AkAudioBuffer
- {
- public:
-
- AkAudioBuffer()
- {
- Clear();
- }
-
- AkForceInline void ClearData()
- {
- pData = NULL;
- uValidFrames = 0;
- }
-
- AkForceInline void Clear()
- {
- ClearData();
- uMaxFrames = 0;
- eState = AK_DataNeeded;
- }
-
-
-
-
- AkForceInline AkUInt32 NumChannels() const
- {
- return channelConfig.uNumChannels;
- }
-
- AkForceInline bool HasLFE() const
- {
- return channelConfig.HasLFE();
- }
- AkForceInline AkChannelConfig GetChannelConfig() const { return channelConfig; }
-
-
-
-
-
-
-
-
- AkForceInline void * GetInterleavedData()
- {
- return pData;
- }
-
- inline void AttachInterleavedData( void * in_pData, AkUInt16 in_uMaxFrames, AkUInt16 in_uValidFrames )
- {
- pData = in_pData;
- uMaxFrames = in_uMaxFrames;
- uValidFrames = in_uValidFrames;
- AKASSERT(channelConfig.IsValid());
- }
-
- inline void AttachInterleavedData( void * in_pData, AkUInt16 in_uMaxFrames, AkUInt16 in_uValidFrames, AkChannelConfig in_channelConfig )
- {
- pData = in_pData;
- uMaxFrames = in_uMaxFrames;
- uValidFrames = in_uValidFrames;
- channelConfig = in_channelConfig;
- }
-
-
-
-
- AkForceInline bool HasData() const
- {
- return ( NULL != pData );
- }
-
-
- static inline AkUInt32 StandardToPipelineIndex(
- AkChannelConfig in_channelConfig,
- AkUInt32 in_uChannelIdx
- )
- {
- if ( in_channelConfig.HasLFE() )
- {
- AKASSERT( in_channelConfig.eConfigType == AK_ChannelConfigType_Standard );
- AKASSERT( AK::GetNumNonZeroBits( in_channelConfig.uChannelMask ) );
- AkUInt32 uIdxLFE = AK::GetNumNonZeroBits( ( AK_SPEAKER_LOW_FREQUENCY - 1 ) & in_channelConfig.uChannelMask );
- if ( in_uChannelIdx == uIdxLFE )
- return in_channelConfig.uNumChannels - 1;
- else if ( in_uChannelIdx > uIdxLFE )
- return in_uChannelIdx - 1;
- }
- return in_uChannelIdx;
- }
-
-
-
-
-
-
-
-
-
- inline AkSampleType * GetChannel(
- AkUInt32 in_uIndex
- )
- {
- AKASSERT( in_uIndex < NumChannels() );
- return (AkSampleType*)((AkUInt8*)(pData) + ( in_uIndex * sizeof(AkSampleType) * MaxFrames() ));
- }
-
-
-
-
- inline AkSampleType * GetLFE()
- {
- if ( channelConfig.uChannelMask & AK_SPEAKER_LOW_FREQUENCY )
- return GetChannel( NumChannels()-1 );
-
- return (AkSampleType*)0;
- }
-
-
- void ZeroPadToMaxFrames()
- {
- AKASSERT(pData != nullptr || MaxFrames() == 0);
-
- const AkUInt32 uNumChannels = NumChannels();
- const AkUInt32 uNumCurrentFrames = AkMin(uValidFrames, MaxFrames());
- const AkUInt32 uNumZeroFrames = MaxFrames() - uNumCurrentFrames;
- if ( uNumZeroFrames )
- {
- AKASSERT(pData != nullptr);
- for ( AkUInt32 i = 0; i < uNumChannels; ++i )
- {
- AKPLATFORM::AkMemSet( GetChannel(i) + uNumCurrentFrames, 0, uNumZeroFrames * sizeof(AkSampleType) );
- }
- uValidFrames = MaxFrames();
- }
- }
-
- AkForceInline void AttachContiguousDeinterleavedData( void * in_pData, AkUInt16 in_uMaxFrames, AkUInt16 in_uValidFrames, AkChannelConfig in_channelConfig )
- {
- AttachInterleavedData( in_pData, in_uMaxFrames, in_uValidFrames, in_channelConfig );
- }
-
- AkForceInline void * DetachContiguousDeinterleavedData()
- {
- uMaxFrames = 0;
- uValidFrames = 0;
- channelConfig.Clear();
- void * pDataOld = pData;
- pData = NULL;
- return pDataOld;
- }
- bool CheckValidSamples();
-
- void RelocateMedia( AkUInt8* in_pNewMedia, AkUInt8* in_pOldMedia )
- {
- AkUIntPtr uMemoryOffset = (AkUIntPtr)in_pNewMedia - (AkUIntPtr)in_pOldMedia;
- pData = (void*) (((AkUIntPtr)pData) + uMemoryOffset);
- }
-
-
- AkForceInline AkUInt16 MaxFrames() const { return uMaxFrames; }
- protected:
- void * pData;
- AkChannelConfig channelConfig;
- public:
- AKRESULT eState;
- protected:
- AkUInt16 uMaxFrames;
- public:
- AkUInt16 uValidFrames;
- };
- struct AkAudioObjects
- {
- AkAudioObjects(AkUInt32 in_uNumObjects = 0, AkAudioBuffer** in_ppObjectBuffers = nullptr, AkAudioObject** in_ppObjects = nullptr)
- : uNumObjects(in_uNumObjects)
- , ppObjectBuffers(in_ppObjectBuffers)
- , ppObjects(in_ppObjects)
- {}
- AkUInt32 uNumObjects;
- AkAudioBuffer** ppObjectBuffers;
- AkAudioObject** ppObjects;
- };
- #endif
|