00001 00002 // 00003 // Copyright (c) 2006 Audiokinetic Inc. / All Rights Reserved 00004 // 00006 00009 00010 #ifndef _IAK_PLUGIN_H_ 00011 #define _IAK_PLUGIN_H_ 00012 00013 #include <AK/SoundEngine/Common/AkCommonDefs.h> 00014 #include <AK/SoundEngine/Common/IAkRTPCSubscriber.h> 00015 #include <AK/SoundEngine/Common/IAkPluginMemAlloc.h> 00016 #include <AK/SoundEngine/Common/AkFPUtilities.h> 00017 #include <AK/Tools/Common/AkLock.h> 00018 #include <AK/Tools/Common/AkPlatformFuncs.h> 00019 #include <AK/Tools/Common/AkMonitorError.h> 00020 #include <AK/SoundEngine/Common/AkSoundEngineExport.h> 00021 #include <AK/SoundEngine/Common/IAkProcessorFeatures.h> 00022 #include <AK/SoundEngine/Common/AkMidiTypes.h> 00023 00024 #ifndef AK_WII 00025 // math.h may cause conflicts on the Wii due to inclusion order. 00026 #include <math.h> 00027 #endif 00028 00029 #if defined AK_CPU_X86 || defined AK_CPU_X86_64 00030 #include <xmmintrin.h> 00031 #endif 00032 00033 #ifdef AK_XBOX360 00034 #include "ppcintrinsics.h" 00035 #endif 00036 00037 #ifdef __PPU__ 00038 #include <altivec.h> 00039 #include <ppu_intrinsics.h> 00040 #include <stdlib.h> 00041 #include <string.h> 00042 #endif 00043 00044 #ifdef AK_PS3 00045 #include <AK/Plugin/PluginServices/PS3/MultiCoreServices.h> 00046 #endif 00047 00048 #ifdef AK_WII 00049 #include <revolution/ax.h> 00050 #endif 00051 00052 #ifdef AK_WIIU 00053 #include <cafe/ax.h> 00054 #endif 00055 00056 #ifdef AK_3DS 00057 #include <nn/snd.h> 00058 #endif 00059 00060 #ifdef AK_VITA_HW 00061 #include <ngs.h> 00062 #endif 00063 00064 /*#ifdef AK_PS4 00065 #include <audioout.h> 00066 #endif*/ 00067 00068 00072 enum AkPluginType 00073 { 00074 AkPluginTypeNone = 0, 00075 AkPluginTypeCodec = 1, 00076 AkPluginTypeSource = 2, 00077 AkPluginTypeEffect = 3, 00078 AkPluginTypeMotionDevice = 4, 00079 AkPluginTypeMotionSource = 5, 00080 AkPluginTypeMixer = 6, 00081 AkPluginTypeSink = 7, 00082 AkPluginTypeMask = 0xf 00083 }; 00084 00090 struct AkPluginInfo 00091 { 00092 AkPluginType eType; 00093 bool bIsInPlace; 00094 bool bIsAsynchronous; 00095 }; 00096 00097 namespace AK 00098 { 00099 class IAkStreamMgr; 00100 00102 class IAkGameObjectPluginInfo 00103 { 00104 protected: 00106 virtual ~IAkGameObjectPluginInfo(){} 00107 00108 public: 00109 00111 virtual AkGameObjectID GetGameObjectID() const = 0; 00112 00127 virtual AkUInt32 GetNumEmitterListenerPairs() const = 0; 00128 00143 virtual AKRESULT GetEmitterListenerPair( 00144 AkUInt32 in_uIndex, 00145 AkEmitterListenerPair & out_emitterListenerPair 00146 ) const = 0; 00147 00154 virtual AkUInt32 GetNumGameObjectPositions() const = 0; 00155 00164 virtual AKRESULT GetGameObjectPosition( 00165 AkUInt32 in_uIndex, 00166 AkSoundPosition & out_position 00167 ) const = 0; 00168 00174 virtual SoundEngine::MultiPositionType GetGameObjectMultiPositionType() const = 0; 00175 00179 virtual AkReal32 GetGameObjectScaling() const = 0; 00180 00189 virtual AkUInt32 GetListenerMask() const = 0; 00190 00199 virtual AKRESULT GetListenerData( 00200 AkUInt32 in_uListenerMask, 00201 AkListener & out_listener 00202 ) const = 0; 00203 }; 00204 00207 class IAkVoicePluginInfo : public IAkGameObjectPluginInfo 00208 { 00209 protected: 00211 virtual ~IAkVoicePluginInfo(){} 00212 00213 public: 00214 00216 virtual AkPlayingID GetPlayingID() const = 0; 00217 00220 virtual AkPriority GetPriority() const = 0; 00221 00224 virtual AkPriority ComputePriorityWithDistance( 00225 AkReal32 in_fDistance 00226 ) const = 0; 00227 }; 00228 00230 class IAkPluginContextBase 00231 { 00232 protected: 00234 virtual ~IAkPluginContextBase(){} 00235 00236 public: 00237 00239 virtual IAkStreamMgr * GetStreamMgr() const = 0; 00240 00244 virtual AkUInt16 GetMaxBufferLength() const = 0; 00245 00253 virtual AKRESULT GetOutputID( 00254 AkUInt32 & out_uOutputID, 00255 AkUInt32 & out_uDeviceType 00256 ) const = 0; 00257 00262 virtual void GetPluginMedia( 00263 AkUInt32 in_dataIndex, 00264 AkUInt8* &out_rpData, 00265 AkUInt32 &out_rDataSize 00266 ) = 0; 00267 00274 virtual AKRESULT PostMonitorMessage( 00275 const char* in_pszError, 00276 AK::Monitor::ErrorLevel in_eErrorLevel 00277 ) = 0; 00278 00292 virtual AKRESULT PostMonitorData( 00293 void * in_pData, 00294 AkUInt32 in_uDataSize 00295 ) = 0; 00296 00303 virtual bool CanPostMonitorData() = 0; 00304 00305 #if (defined AK_CPU_X86 || defined AK_CPU_X86_64) && !(defined AK_IOS) 00306 00307 virtual IAkProcessorFeatures * GetProcessorFeatures() = 0; 00308 #endif 00309 }; 00310 00314 class IAkEffectPluginContext : public IAkPluginContextBase 00315 { 00316 protected: 00318 virtual ~IAkEffectPluginContext(){} 00319 00320 public: 00321 00325 virtual bool IsSendModeEffect() const = 0; 00326 00329 virtual IAkVoicePluginInfo * GetVoiceInfo() = 0; 00330 }; 00331 00335 class IAkSourcePluginContext : public IAkPluginContextBase 00336 { 00337 protected: 00339 virtual ~IAkSourcePluginContext(){} 00340 00341 public: 00342 00345 virtual AkUInt16 GetNumLoops() const = 0; 00346 00349 virtual IAkVoicePluginInfo * GetVoiceInfo() = 0; 00350 00354 virtual AkMidiEvent GetMidiEvent() const = 0; 00355 }; 00356 00358 class IAkMixerPluginContext : public IAkPluginContextBase 00359 { 00360 protected: 00362 virtual ~IAkMixerPluginContext(){} 00363 00364 public: 00365 00369 virtual AkUniqueID GetBusID() = 0; 00370 00375 virtual AkBusType GetBusType() = 0; 00376 00379 virtual AkReal32 GetDownstreamGain() = 0; 00380 00397 virtual AKRESULT GetSpeakerAngles( 00398 AkReal32 * io_pfSpeakerAngles, 00399 AkUInt32 & io_uNumAngles, 00400 AkReal32 & out_fHeightAngle 00401 ) = 0; 00402 00404 00405 00407 virtual void ComputeSpeakerVolumesDirect( 00408 AkChannelConfig in_inputConfig, 00409 AkChannelConfig in_outputConfig, 00410 AkReal32 in_fCenterPerc, 00411 AK::SpeakerVolumes::MatrixPtr out_mxVolumes 00412 ) = 0; 00413 00415 virtual void ComputeSpeakerVolumesPanner( 00416 const AkVector & in_position, 00417 AkReal32 in_fCenterPct, 00418 AkChannelConfig in_inputConfig, 00419 AkChannelConfig in_outputConfig, 00420 AK::SpeakerVolumes::MatrixPtr out_mxVolumes 00421 ) = 0; 00422 00424 virtual AKRESULT ComputePlanarVBAPGains( 00425 AkReal32 in_fAngle, 00426 AkChannelConfig in_outputConfig, 00427 AkReal32 in_fCenterPerc, 00428 AK::SpeakerVolumes::VectorPtr out_vVolumes 00429 ) = 0; 00430 00432 virtual AKRESULT InitSphericalVBAP( 00433 AK::IAkPluginMemAlloc* in_pAllocator, 00434 const AkSphericalCoord* in_SphericalPositions, 00435 const AkUInt32 in_NbPoints, 00436 void *& out_pPannerData 00437 ) = 0; 00438 00440 virtual AKRESULT ComputeSphericalVBAPGains( 00441 void* in_pPannerData, 00442 AkReal32 in_fAzimuth, 00443 AkReal32 in_fElevation, 00444 AkUInt32 in_uNumChannels, 00445 AK::SpeakerVolumes::VectorPtr out_vVolumes 00446 ) = 0; 00447 00449 virtual AKRESULT TermSphericalVBAP( 00450 AK::IAkPluginMemAlloc* in_pAllocator, 00451 void* in_pPannerData 00452 ) = 0; 00453 00455 virtual AKRESULT Compute3DPositioning( 00456 AkReal32 in_fAngle, 00457 AkReal32 in_fSpread, 00458 AkReal32 in_fFocus, 00459 AkChannelConfig in_inputConfig, 00460 AkChannelConfig in_outputConfig, 00461 AkReal32 in_fCenterPerc, 00462 AK::SpeakerVolumes::MatrixPtr out_mxVolumes 00463 ) = 0; 00464 00466 virtual void MixNinNChannels( 00467 AkAudioBuffer * in_pInputBuffer, 00468 AkAudioBuffer * in_pMixBuffer, 00469 AkReal32 in_fPrevGain, 00470 AkReal32 in_fNextGain, 00471 AK::SpeakerVolumes::MatrixPtr in_mxPrevVolumes, 00472 AK::SpeakerVolumes::MatrixPtr in_mxNextVolumes 00473 ) = 0; 00474 00476 virtual void Mix1inNChannels( 00477 AkReal32 * AK_RESTRICT in_pInChannel, 00478 AkAudioBuffer * in_pMixBuffer, 00479 AkReal32 in_fPrevGain, 00480 AkReal32 in_fNextGain, 00481 AK::SpeakerVolumes::VectorPtr in_vPrevVolumes, 00482 AK::SpeakerVolumes::VectorPtr in_vNextVolumes 00483 ) = 0; 00484 00486 virtual void MixChannel( 00487 AkReal32 * AK_RESTRICT in_pInBuffer, 00488 AkReal32 * AK_RESTRICT in_pOutBuffer, 00489 AkReal32 in_fPrevGain, 00490 AkReal32 in_fNextGain, 00491 AkUInt16 in_uNumFrames 00492 ) = 0; 00493 00495 00497 00498 00503 virtual void EnableMetering( AkMeteringFlags in_eFlags ) = 0; 00504 }; 00505 00511 class IAkPluginParam : public IAkRTPCSubscriber 00512 { 00513 protected: 00515 virtual ~IAkPluginParam(){} 00516 00517 public: 00523 virtual IAkPluginParam * Clone( 00524 IAkPluginMemAlloc * in_pAllocator 00525 ) = 0; 00526 00534 virtual AKRESULT Init( 00535 IAkPluginMemAlloc * in_pAllocator, 00536 const void * in_pParamsBlock, 00537 AkUInt32 in_uBlockSize 00538 ) = 0; 00539 00545 virtual AKRESULT Term( 00546 IAkPluginMemAlloc * in_pAllocator 00547 ) = 0; 00548 00553 virtual AKRESULT SetParamsBlock( 00554 const void *in_pParamsBlock, 00555 AkUInt32 in_uBlockSize 00556 ) = 0; 00557 00563 virtual AKRESULT SetParam( 00564 AkPluginParamID in_paramID, 00565 const void * in_pValue, 00566 AkUInt32 in_uParamSize 00567 ) = 0; 00568 00576 static const AkPluginParamID ALL_PLUGIN_DATA_ID = 0x7FFF; 00577 }; 00578 00582 class IAkPlugin 00583 { 00584 protected: 00586 virtual ~IAkPlugin(){} 00587 00588 public: 00594 virtual AKRESULT Term( 00595 IAkPluginMemAlloc * in_pAllocator 00596 ) = 0; 00597 00603 virtual AKRESULT Reset() = 0; 00604 00610 virtual AKRESULT GetPluginInfo( 00611 AkPluginInfo & out_rPluginInfo 00612 ) = 0; 00613 00621 virtual bool SupportMediaRelocation() const 00622 { 00623 return false; 00624 } 00625 00638 virtual AKRESULT RelocateMedia( 00639 AkUInt8* /*in_pNewMedia*/, 00640 AkUInt8* /*in_pOldMedia*/ 00641 ) 00642 { 00643 return AK_NotImplemented; 00644 } 00645 00646 }; 00647 00649 class IAkEffectPlugin : public IAkPlugin 00650 { 00651 protected: 00653 virtual ~IAkEffectPlugin(){} 00654 00655 public: 00660 virtual AKRESULT Init( 00661 IAkPluginMemAlloc * in_pAllocator, 00662 IAkEffectPluginContext * in_pEffectPluginContext, 00663 IAkPluginParam * in_pParams, 00664 AkAudioFormat & io_rFormat 00665 ) = 0; 00666 00667 #if defined AK_WII_FAMILY_HW 00668 00669 virtual AXAuxCallback GetFXCallback() = 0; 00670 00672 virtual void* GetFXParams() = 0; 00673 00679 virtual AkUInt32 GetTailTime() = 0; 00680 #endif 00681 #ifdef AK_3DS 00682 00683 virtual void Update() = 0; 00684 00686 virtual nn::snd::CTR::AuxCallback GetFXCallback() = 0; 00687 00693 virtual AkUInt32 GetTailTime() = 0; 00694 #endif 00695 #ifdef AK_VITA_HW 00696 virtual const SceNgsVoiceDefinition * GetVoiceDefinition(){ AKASSERT( false && "Non hardware plugin called on Vita HW" ); return NULL; } 00697 virtual AKRESULT AttachVoice( SceNgsHVoice in_hVoice){ AKASSERT( false && "Non hardware plugin called on Vita HW" ); return AK_Fail; } 00698 virtual AkReal32 GetTailTime() const { AKASSERT( false && "Non hardware plugin called on Vita HW" ); return 0; } 00699 virtual AKRESULT SetBypass( SceUInt32 in_uBypassFlag ) { AKASSERT( false && "Non hardware plugin called on Vita HW" ); return AK_Fail; } 00700 #endif 00701 }; 00702 00704 class IAkInPlaceEffectPlugin : public IAkEffectPlugin 00705 { 00706 public: 00714 virtual void Execute( 00715 AkAudioBuffer * io_pBuffer 00716 #ifdef AK_PS3 00717 , AK::MultiCoreServices::DspProcess*& out_pDspProcess 00718 #endif 00719 ) = 0; 00720 00724 virtual AKRESULT TimeSkip( 00725 AkUInt32 in_uFrames 00726 ) = 0; 00727 }; 00728 00729 00731 class IAkOutOfPlaceEffectPlugin : public IAkEffectPlugin 00732 { 00733 public: 00740 virtual void Execute( 00741 AkAudioBuffer * in_pBuffer, 00742 AkUInt32 in_uInOffset, 00743 AkAudioBuffer * out_pBuffer 00744 #ifdef AK_PS3 00745 , AK::MultiCoreServices::DspProcess*& out_pDspProcess 00746 #endif 00747 ) = 0; 00748 00752 virtual AKRESULT TimeSkip( 00753 AkUInt32 &io_uFrames 00754 ) = 0; 00755 }; 00756 00758 class IAkMixerInputContext 00759 { 00760 protected: 00762 virtual ~IAkMixerInputContext(){} 00763 00764 public: 00765 00770 virtual IAkPluginParam * GetInputParam() = 0; 00771 00774 virtual IAkVoicePluginInfo * GetVoiceInfo() = 0; 00775 00778 virtual AkConnectionType GetConnectionType() = 0; 00779 00789 virtual AkUniqueID GetAudioNodeID() = 0; 00790 00794 virtual void * GetUserData() = 0; 00795 00799 virtual void SetUserData( void * in_pUserData ) = 0; 00800 00803 00804 00808 virtual bool IsPositioningEnabled() = 0; 00809 00815 virtual AkReal32 GetCenterPerc() = 0; 00816 00821 virtual AkPannerType GetPannerType() = 0; 00822 00827 virtual AkPositionSourceType GetPositionSourceType() = 0; 00828 00835 virtual void GetPannerPosition( 00836 AkVector & out_position 00837 ) = 0; 00838 00842 virtual AkUInt32 GetNum3DPositions() = 0; 00843 00852 virtual AKRESULT Get3DPosition( 00853 AkUInt32 in_uIndex, 00854 AkEmitterListenerPair & out_soundPosition 00855 ) = 0; 00856 00863 virtual AkReal32 GetSpread( 00864 AkUInt32 in_uIndex 00865 ) = 0; 00866 00873 virtual AkReal32 GetFocus( 00874 AkUInt32 in_uIndex 00875 ) = 0; 00876 00879 virtual bool GetMaxAttenuationDistance( 00880 AkReal32 & out_fMaxAttenuationDistance 00881 ) = 0; 00882 00884 virtual void GetSpatializedVolumes( 00885 AK::SpeakerVolumes::MatrixPtr out_mxPrevVolumes, 00886 AK::SpeakerVolumes::MatrixPtr out_mxNextVolumes 00887 ) = 0; 00888 00890 }; 00891 00895 class IAkSinkPluginContext : public IAkPluginContextBase 00896 { 00897 protected: 00899 virtual ~IAkSinkPluginContext(){} 00900 00901 public: 00902 00908 virtual bool IsPrimary() = 0; 00909 00924 virtual AKRESULT SignalAudioThread() = 0; 00925 00928 virtual AkUInt16 GetNumRefillsInVoice() = 0; 00929 }; 00930 00932 class IAkSinkPlugin : public IAkPlugin 00933 { 00934 public: 00935 00938 virtual AKRESULT Init( 00939 IAkPluginMemAlloc * in_pAllocator, 00940 IAkSinkPluginContext * in_pSinkPluginContext, 00941 AkAudioFormat & io_rFormat 00942 ) = 0; 00943 00951 virtual AKRESULT IsDataNeeded( 00952 AkUInt32 & out_uNumFramesNeeded 00953 ) = 0; 00954 00963 virtual void Consume( 00964 AkAudioBuffer * in_pInputBuffer, 00965 AkRamp in_gain 00966 ) = 0; 00967 00971 virtual void OnFrameEnd() = 0; 00972 00975 virtual bool IsStarved() = 0; 00976 00978 virtual void ResetStarved() = 0; 00979 }; 00980 00982 class IAkSourcePlugin : public IAkPlugin 00983 { 00984 protected: 00986 virtual ~IAkSourcePlugin(){} 00987 00988 public: 00993 virtual AKRESULT Init( 00994 IAkPluginMemAlloc * in_pAllocator, 00995 IAkSourcePluginContext * in_pSourcePluginContext, 00996 IAkPluginParam * in_pParams, 00997 AkAudioFormat & io_rFormat 00998 ) = 0; 00999 01004 virtual AkReal32 GetDuration() const = 0; 01005 01013 virtual AkReal32 GetEnvelope() const 01014 { 01015 return 1.f; 01016 } 01017 01027 virtual AKRESULT StopLooping(){ return AK_Success; } 01028 01041 virtual AKRESULT Seek( 01042 AkUInt32 /* in_uPosition */ 01043 ) { return AK_Success; } 01044 01051 virtual AKRESULT TimeSkip( 01052 AkUInt32 & /*io_uFrames */ 01053 ) { return AK_NotImplemented; } 01054 01060 virtual void Execute( 01061 AkAudioBuffer * io_pBuffer 01062 #ifdef AK_PS3 01063 , AK::MultiCoreServices::DspProcess*& out_pDspProcess 01064 #endif 01065 ) = 0; 01066 }; 01067 01068 #if defined AK_WII 01069 01070 static AkForceInline AkInt16 AK_FLOAT_TO_SAMPLETYPE(AkReal32 in_fIn) 01071 { 01072 AkInt32 i32 = (AkInt32)(in_fIn * 0x7FFF); 01073 i32 -= ((i32<=32767)-1)&(i32-32767); 01074 i32 -= ((i32>=-32768)-1)&(i32+32768); 01075 AkInt16 i16 = (AkInt16)i32; 01076 return i16; 01077 } 01078 01080 static AkForceInline AkInt16 AK_FLOAT_TO_SAMPLETYPE_NOCLIP(AkReal32 in_fIn) 01081 { 01082 return (AkInt16)(in_fIn * 0x7FFF); 01083 } 01084 01086 static AkForceInline AkReal32 AK_SAMPLETYPE_TO_FLOAT(AkInt16 in_iIn) 01087 { 01088 return (((AkReal32)in_iIn) * (1.f/0x7FFF)); 01089 } 01090 #else 01091 01092 #define AK_FLOAT_TO_SAMPLETYPE( __in__ ) (__in__) 01093 01094 #define AK_FLOAT_TO_SAMPLETYPE_NOCLIP( __in__ ) (__in__) 01095 01096 #define AK_SAMPLETYPE_TO_FLOAT( __in__ ) (__in__) 01097 #endif 01098 01099 #define AK_DBTOLIN( __db__ ) (powf(10.f,(__db__) * 0.05f)) 01100 } 01101 01103 AK_CALLBACK( AK::IAkPlugin*, AkCreatePluginCallback )( AK::IAkPluginMemAlloc * in_pAllocator ); 01105 AK_CALLBACK( AK::IAkPluginParam*, AkCreateParamCallback )( AK::IAkPluginMemAlloc * in_pAllocator ); 01106 01107 #endif // _IAK_PLUGIN_H_
Questions? Problems? Need more info? Contact us, and we can help!
Visit our Support pageRegister your project and we'll help you get started with no strings attached!
Get started with Wwise