Version

menu_open

include/AK/SoundEngine/Common/AkCommonDefs.h

Go to the documentation of this file.
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 // AkCommonDefs.h
00029 
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 // AUDIO DATA FORMAT
00042 //-----------------------------------------------------------------------------
00043 
00044 // Audio data format.
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 // Native format currently the same on all supported platforms, may become platform specific in the future
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 
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     
00072     AkForceInline AkUInt32 GetNumChannels() const
00073     {
00074         return channelConfig.uNumChannels;
00075     }
00076 
00079     AkForceInline bool HasLFE() const
00080     { 
00081         return channelConfig.HasLFE(); 
00082     }
00083 
00088     AkForceInline bool HasCenter() const
00089     { 
00090         return channelConfig.HasCenter(); 
00091     }
00092 
00095     AkForceInline AkUInt32 GetBitsPerSample()   const                       
00096     { 
00097         return uBitsPerSample;
00098     }
00099 
00102     AkForceInline AkUInt32 GetBlockAlign() const
00103     {
00104         return uBlockAlign;
00105     }
00106 
00109     AkForceInline AkUInt32 GetTypeID() const
00110     {
00111         return uTypeID;
00112     }
00113 
00116     AkForceInline AkUInt32 GetInterleaveID() const
00117     {
00118         return uInterleaveID;
00119     }
00120 
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 
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 // Build a 32 bit class identifier based on the Plug-in type,
00169 // CompanyID and PluginID.
00170 //
00171 // Parameters:
00172 //   - in_pluginType: A value from enum AkPluginType (4 bits)
00173 //   - in_companyID: CompanyID as defined in the Plug-in's XML file (12 bits)
00174 //          * 0-63: Reserved for Audiokinetic
00175 //          * 64-255: Reserved for clients' in-house Plug-ins
00176 //          * 256-4095: Assigned by Audiokinetic to third-party plug-in developers
00177 //   - in_pluginID: PluginID as defined in the Plug-in's XML file (16 bits)
00178 //          * 0-65535: Set freely by the Plug-in developer
00179 #define AKMAKECLASSID( in_pluginType, in_companyID, in_pluginID ) \
00180     ( (in_pluginType) + ( (in_companyID) << 4 ) + ( (in_pluginID) << ( 4 + 12 ) ) )
00181 
00182 #define AKGETPLUGINTYPEFROMCLASSID( in_classID ) ( (in_classID) & AkPluginTypeMask )
00183 #define AKGETCOMPANYIDFROMCLASSID( in_classID ) ( ( (in_classID) & 0x0000FFF0 ) >> 4 )
00184 #define AKGETPLUGINIDFROMCLASSID( in_classID ) ( ( (in_classID) & 0xFFFF0000 ) >> ( 4 + 12 ) )
00185 
00186 #define CODECID_FROM_PLUGINID AKGETPLUGINIDFROMCLASSID
00187 
00188 
00189 namespace AK
00190 {
00192     class IAkMetering
00193     {
00194     protected:
00196         virtual ~IAkMetering(){}
00197 
00198     public:
00199 
00204         virtual AK::SpeakerVolumes::ConstVectorPtr GetPeak() = 0;
00205 
00209         virtual AK::SpeakerVolumes::ConstVectorPtr GetTruePeak() = 0;
00210 
00215         virtual AK::SpeakerVolumes::ConstVectorPtr GetRMS() = 0;
00216         
00220         virtual AkReal32 GetKWeightedPower() = 0;
00221     };
00222 }
00223 
00224 // Audio buffer.
00225 // ------------------------------------------------
00226 
00235 #if defined AK_WII_FAMILY_HW || defined(AK_3DS)
00236 typedef AkInt16 AkSampleType;   
00237 #else
00238 typedef AkReal32 AkSampleType;  
00239 #endif
00240 
00245 class AkAudioBuffer
00246 {
00247 public:
00248 
00250     AkAudioBuffer() 
00251     { 
00252         Clear(); 
00253     }
00254 
00256     AkForceInline void ClearData()
00257     {
00258 #if !defined(AK_WII_FAMILY_HW) && !defined(AK_3DS)
00259         pData = NULL;
00260 #else
00261         arData[0] = arData[1] = NULL;       
00262 #endif
00263     }
00264 
00266     AkForceInline void Clear()
00267     {
00268         ClearData();
00269         uValidFrames        = 0;
00270         uMaxFrames          = 0;
00271         eState              = AK_DataNeeded;
00272     }
00273     
00275 
00276 
00277     AkForceInline AkUInt32 NumChannels()
00278     {
00279         return channelConfig.uNumChannels;
00280     }
00281 
00283     AkForceInline bool HasLFE()
00284     { 
00285         return channelConfig.HasLFE(); 
00286     }
00287 
00288     AkForceInline AkChannelConfig GetChannelConfig() const { return channelConfig; }
00289 
00291 
00293 
00294 
00295 
00296 
00297 
00298 
00299 #if !defined(AK_3DS) && !defined(AK_WII_FAMILY_HW)
00300     AkForceInline void * GetInterleavedData()
00301     { 
00302         return pData; 
00303     }
00304 
00306     inline void AttachInterleavedData( void * in_pData, AkUInt16 in_uMaxFrames, AkUInt16 in_uValidFrames, AkChannelConfig in_channelConfig )
00307     { 
00308         pData = in_pData; 
00309         uMaxFrames = in_uMaxFrames; 
00310         uValidFrames = in_uValidFrames; 
00311         channelConfig = in_channelConfig; 
00312     }
00313 #endif
00314 
00315 
00317 
00318 
00320     AkForceInline bool HasData() 
00321     {
00322 #if !defined(AK_WII_FAMILY_HW) && !defined(AK_3DS)
00323         return ( NULL != pData ); 
00324 #else
00325         return ( NULL != arData[0] );
00326 #endif
00327     }
00328 
00331     static inline AkUInt32 StandardToPipelineIndex( 
00332         AkChannelConfig 
00333 #ifdef AK_LFECENTER
00334                         in_channelConfig        
00335 #endif
00336         , AkUInt32      in_uChannelIdx          
00337         )
00338     {
00339 #ifdef AK_LFECENTER
00340         if ( in_channelConfig.HasLFE() )
00341         {
00342             AKASSERT( in_channelConfig.eConfigType == AK_ChannelConfigType_Standard );  // in_channelConfig.HasLFE() would not have returned true otherwise.
00343             AKASSERT( AK::GetNumNonZeroBits( in_channelConfig.uChannelMask ) );
00344             AkUInt32 uIdxLFE = AK::GetNumNonZeroBits( ( AK_SPEAKER_LOW_FREQUENCY - 1 ) & in_channelConfig.uChannelMask );
00345             if ( in_uChannelIdx == uIdxLFE )
00346                 return in_channelConfig.uNumChannels - 1;
00347             else if ( in_uChannelIdx > uIdxLFE )
00348                 return in_uChannelIdx - 1;
00349         }
00350 #endif
00351         return in_uChannelIdx;
00352     }
00353 
00363     inline AkSampleType * GetChannel(
00364         AkUInt32 in_uIndex      
00365         )
00366     {
00367         AKASSERT( in_uIndex < NumChannels() );
00368 #if defined (AK_WII_FAMILY_HW) || defined(AK_3DS)
00369         return (AkSampleType*)arData[in_uIndex];
00370 #else
00371         return (AkSampleType*)((AkUInt8*)(pData) + ( in_uIndex * sizeof(AkSampleType) * MaxFrames() ));
00372 #endif
00373     }
00374 
00379     inline AkSampleType * GetLFE()
00380     {
00381         if ( channelConfig.uChannelMask & AK_SPEAKER_LOW_FREQUENCY )
00382             return GetChannel( NumChannels()-1 );
00383         
00384         return (AkSampleType*)0;
00385     }
00386 
00389     void ZeroPadToMaxFrames()
00390     {
00391         // Zero out all channels.
00392         const AkUInt32 uNumChannels = NumChannels();
00393         const AkUInt32 uNumZeroFrames = MaxFrames()-uValidFrames;
00394         if ( uNumZeroFrames )
00395         {
00396             for ( AkUInt32 i = 0; i < uNumChannels; ++i )
00397             {
00398                 AKPLATFORM::AkMemSet( GetChannel(i) + uValidFrames, 0, uNumZeroFrames * sizeof(AkSampleType) );
00399             }
00400             uValidFrames = MaxFrames();
00401         }
00402     }
00403 
00404 #if !defined(AK_3DS) && !defined(AK_WII_FAMILY_HW)
00405 
00406     AkForceInline void AttachContiguousDeinterleavedData( void * in_pData, AkUInt16 in_uMaxFrames, AkUInt16 in_uValidFrames, AkChannelConfig in_channelConfig )
00407     { 
00408         AttachInterleavedData( in_pData, in_uMaxFrames, in_uValidFrames, in_channelConfig );
00409     }
00411     AkForceInline void * DetachContiguousDeinterleavedData()
00412     {
00413         uMaxFrames = 0; 
00414         uValidFrames = 0; 
00415         channelConfig.Clear();
00416         void * pDataOld = pData;
00417         pData = NULL;
00418         return pDataOld;
00419     }
00420 #endif
00421 
00422 #if defined (AK_CHECK_AUDIO_BUFFER_VALID)
00423     bool CheckValidSamples()
00424     {
00425         // Zero out all channels.
00426         const AkUInt32 uNumChannels = NumChannels();
00427         for ( AkUInt32 i = 0; i < uNumChannels; ++i )
00428         {
00429             AkSampleType * AK_RESTRICT pfChan = GetChannel(i);
00430             if ( pfChan )
00431             {
00432                 for ( AkUInt32 j = 0; j < uValidFrames; j++ )
00433                 {
00434                     AkSampleType fSample = *pfChan++;
00435                     if ( fSample > 4.f )
00436                         return false;
00437                     else if ( fSample < -4.f )
00438                         return false;
00439                 }
00440             }
00441         }
00442 
00443         return true;
00444     }
00445 #endif
00446 
00447 #ifdef AK_PS3
00448 
00449 
00450 
00451     AkForceInline void * GetDataStartDMA()
00452     {
00453         return pData;
00454     }
00455 #endif
00456 
00457 #ifdef __SPU__
00458 
00459 
00460     AkForceInline void CreateFromDMA( void * in_pData, AkUInt16 in_uMaxFrames, AkUInt16 in_uValidFrames, AkChannelConfig in_channelConfig, AKRESULT in_eState )
00461     { 
00462         pData = in_pData; 
00463         uMaxFrames = in_uMaxFrames; 
00464         uValidFrames = in_uValidFrames; 
00465         channelConfig = in_channelConfig; 
00466         eState = in_eState;
00467     }
00468 #endif
00469 
00470 
00471 #if !defined(AK_3DS) && !defined(AK_WII_FAMILY_HW)
00472     void RelocateMedia( AkUInt8* in_pNewMedia,  AkUInt8* in_pOldMedia )
00473     {
00474         AkUIntPtr uMemoryOffset = (AkUIntPtr)in_pNewMedia - (AkUIntPtr)in_pOldMedia;
00475         pData = (void*) (((AkUIntPtr)pData) + uMemoryOffset);
00476     }
00477 #endif
00478 
00479 protected:
00480 #if defined (AK_WII_FAMILY_HW) || defined(AK_3DS)
00481     void *          arData[AK_VOICE_MAX_NUM_CHANNELS];  
00482 #else
00483     void *          pData;              
00484 #endif
00485     AkChannelConfig channelConfig;      
00486 public: 
00487     AKRESULT        eState;             
00488 protected:  
00489     AkUInt16        uMaxFrames;         
00490 
00491 public:
00494     AkForceInline AkUInt16 MaxFrames() { return uMaxFrames; }
00495     
00496     AkUInt16        uValidFrames;       
00497 } AK_ALIGN_DMA;
00498 
00499 #endif // _AK_COMMON_DEFS_H_
00500 

Cette page a-t-elle été utile ?

Besoin d'aide ?

Des questions ? Des problèmes ? Besoin de plus d'informations ? Contactez-nous, nous pouvons vous aider !

Visitez notre page d'Aide

Décrivez-nous de votre projet. Nous sommes là pour vous aider.

Enregistrez votre projet et nous vous aiderons à démarrer sans aucune obligation !

Partir du bon pied avec Wwise