Version
menu_open
link

include/AK/SoundEngine/Common/AkSpeakerVolumes.h

Go to the documentation of this file.
00001 
00002 //
00003 // Copyright (c) 2006 Audiokinetic Inc. / All Rights Reserved
00004 //
00006 
00007 // AkSpeakerVolumes.h
00008 
00015 
00016 #ifndef _AK_SPEAKER_VOLUMES_H_
00017 #define _AK_SPEAKER_VOLUMES_H_
00018 
00019 #include <AK/SoundEngine/Common/AkTypes.h>
00020 #include <AK/Tools/Common/AkPlatformFuncs.h>
00021 
00022 // Multi-channel volumes/mix.
00023 // ------------------------------------------------
00024 
00025 // Platform-specific section.
00026 //----------------------------------------------------------------------------------------------------
00027 
00028 #if defined( AK_XBOX360 )
00029 
00030     #include <AK/SoundEngine/Platforms/XBox360/AkSpeakerVolumes.h>
00031 
00032 #elif defined (AK_PS3)
00033 
00034     #include <AK/SoundEngine/Platforms/PS3/AkSpeakerVolumes.h>
00035     
00036 #else
00037 
00038     #include <AK/SoundEngine/Platforms/Generic/AkSpeakerVolumes.h>
00039 
00040 #endif
00041 
00042 // Cross-platform section.
00043 //----------------------------------------------------------------------------------------------------
00044 
00045 namespace AK
00046 {
00048 namespace SpeakerVolumes
00049 {
00050     typedef AkReal32 * VectorPtr;               
00051     typedef AkReal32 * MatrixPtr;               
00052     typedef const AkReal32 * ConstVectorPtr;    
00053     typedef const AkReal32 * ConstMatrixPtr;    
00054 
00056     namespace Vector
00057     {
00059         AkForceInline void Copy( VectorPtr in_pVolumesDst, ConstVectorPtr in_pVolumesSrc, AkUInt32 in_uNumChannels )
00060         {
00061             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
00062             if ( in_uNumChannels )
00063                 memcpy( in_pVolumesDst, in_pVolumesSrc, in_uNumChannels * sizeof( AkReal32 ) );
00064         }
00065 
00067         AkForceInline void Copy( VectorPtr in_pVolumesDst, ConstVectorPtr in_pVolumesSrc, AkUInt32 in_uNumChannels, AkReal32 in_fGain )
00068         {
00069             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
00070             for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
00071             {
00072                 in_pVolumesDst[uChan] = in_pVolumesSrc[uChan] * in_fGain;
00073             }
00074         }
00075 
00077         AkForceInline void Zero( VectorPtr in_pVolumes, AkUInt32 in_uNumChannels )
00078         {
00079             AKASSERT( in_pVolumes || in_uNumChannels == 0 );
00080             if ( in_uNumChannels )
00081                 memset( in_pVolumes, 0, in_uNumChannels * sizeof( AkReal32 ) );
00082         }
00083 
00085         AkForceInline void Add( VectorPtr in_pVolumesDst, ConstVectorPtr in_pVolumesSrc, AkUInt32 in_uNumChannels )
00086         {
00087             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
00088             for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
00089             {
00090                 in_pVolumesDst[uChan] += in_pVolumesSrc[uChan];
00091             }
00092         }
00093 
00095         AkForceInline void Mul( VectorPtr in_pVolumesDst, const AkReal32 in_fVol, AkUInt32 in_uNumChannels )
00096         {
00097             AKASSERT( in_pVolumesDst || in_uNumChannels == 0 );
00098             for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
00099             {
00100                 in_pVolumesDst[uChan] *= in_fVol;
00101             }
00102         }
00103 
00105         AkForceInline void Mul( VectorPtr in_pVolumesDst, ConstVectorPtr in_pVolumesSrc, AkUInt32 in_uNumChannels )
00106         {
00107             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
00108             for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
00109             {
00110                 in_pVolumesDst[uChan] *= in_pVolumesSrc[uChan];
00111             }
00112         }
00113 
00115         AkForceInline void Max( AkReal32 * in_pVolumesDst, const AkReal32 * in_pVolumesSrc, AkUInt32 in_uNumChannels )
00116         {
00117             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
00118             for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
00119             {
00120                 in_pVolumesDst[uChan] = AkMax( in_pVolumesDst[uChan], in_pVolumesSrc[uChan] );
00121             }
00122         }
00123         
00125         AkForceInline void Min( AkReal32 * in_pVolumesDst, const AkReal32 * in_pVolumesSrc, AkUInt32 in_uNumChannels )
00126         {
00127             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
00128             for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
00129             {
00130                 in_pVolumesDst[uChan] = AkMin( in_pVolumesDst[uChan], in_pVolumesSrc[uChan] );
00131             }
00132         }
00133     }
00134 
00136     namespace Matrix
00137     {
00139         AkForceInline AkUInt32 GetRequiredSize( AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut ) 
00140         {
00141             return in_uNumChannelsIn * Vector::GetRequiredSize( in_uNumChannelsOut );
00142         }
00143 
00145         AkForceInline AkUInt32 GetNumElements( AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut ) 
00146         {
00147             return in_uNumChannelsIn * Vector::GetNumElements( in_uNumChannelsOut );
00148         }
00149         
00151         AkForceInline VectorPtr GetChannel( MatrixPtr in_pVolumeMx, AkUInt32 in_uIdxChannelIn, AkUInt32 in_uNumChannelsOut ) 
00152         {
00153             AKASSERT( in_pVolumeMx );
00154             return in_pVolumeMx + in_uIdxChannelIn * Vector::GetNumElements( in_uNumChannelsOut );
00155         }
00156 
00158         AkForceInline ConstVectorPtr GetChannel( ConstMatrixPtr in_pVolumeMx, AkUInt32 in_uIdxChannelIn, AkUInt32 in_uNumChannelsOut ) 
00159         {
00160             AKASSERT( in_pVolumeMx );
00161             return in_pVolumeMx + in_uIdxChannelIn * Vector::GetNumElements( in_uNumChannelsOut );
00162         }
00163 
00165         AkForceInline void Copy( MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut )
00166         {
00167             AkUInt32 uNumElements = Matrix::GetNumElements( in_uNumChannelsIn, in_uNumChannelsOut );
00168             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || uNumElements == 0 );
00169             if ( uNumElements )
00170                 memcpy( in_pVolumesDst, in_pVolumesSrc, uNumElements * sizeof( AkReal32 ) );
00171         }
00172 
00174         AkForceInline void Copy( MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut, AkReal32 in_fGain )
00175         {
00176             AkUInt32 uNumElements = Matrix::GetNumElements( in_uNumChannelsIn, in_uNumChannelsOut );
00177             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || uNumElements == 0 );
00178             for ( AkUInt32 uChan = 0; uChan < uNumElements; uChan++ )
00179             {
00180                 in_pVolumesDst[uChan] = in_pVolumesSrc[uChan] * in_fGain;
00181             }
00182         }
00183 
00185         AkForceInline void Zero( MatrixPtr in_pVolumes, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut )
00186         {
00187             AkUInt32 uNumElements = Matrix::GetNumElements( in_uNumChannelsIn, in_uNumChannelsOut );
00188             AKASSERT( in_pVolumes || uNumElements == 0 );
00189             if ( uNumElements )
00190                 memset( in_pVolumes, 0, uNumElements * sizeof( AkReal32 ) );
00191         }
00192 
00194         AkForceInline void Mul( MatrixPtr in_pVolumesDst, const AkReal32 in_fVol, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut )
00195         {
00196             AkUInt32 uNumElements = Matrix::GetNumElements( in_uNumChannelsIn, in_uNumChannelsOut );
00197             AKASSERT( in_pVolumesDst || uNumElements == 0 );
00198             for ( AkUInt32 uChan = 0; uChan < uNumElements; uChan++ )
00199             {
00200                 in_pVolumesDst[uChan] *= in_fVol;
00201             }
00202         }
00203 
00205         AkForceInline void Add(AkReal32 * in_pVolumesDst, const AkReal32 * in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut)
00206         {
00207             AkUInt32 uNumElements = Matrix::GetNumElements(in_uNumChannelsIn, in_uNumChannelsOut);
00208             AKASSERT((in_pVolumesDst && in_pVolumesSrc) || uNumElements == 0);
00209             for (AkUInt32 uChan = 0; uChan < uNumElements; uChan++)
00210             {
00211                 in_pVolumesDst[uChan] += in_pVolumesSrc[uChan];
00212             }
00213         }
00214         
00216         AkForceInline void Max( AkReal32 * in_pVolumesDst, const AkReal32 * in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut )
00217         {
00218             AkUInt32 uNumElements = Matrix::GetNumElements( in_uNumChannelsIn, in_uNumChannelsOut );
00219             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || uNumElements == 0 );
00220             for ( AkUInt32 uChan = 0; uChan < uNumElements; uChan++ )
00221             {
00222                 in_pVolumesDst[uChan] = AkMax( in_pVolumesDst[uChan], in_pVolumesSrc[uChan] );
00223             }
00224         }
00225     }
00226 }
00227 }
00228 
00229 #endif  //_AK_SPEAKER_VOLUMES_H_

Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise