Version
menu_open
link

include/AK/SoundEngine/Common/AkSpeakerVolumes.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 // AkSpeakerVolumes.h
00029 
00036 
00037 #ifndef _AK_SPEAKER_VOLUMES_H_
00038 #define _AK_SPEAKER_VOLUMES_H_
00039 
00040 #include <AK/SoundEngine/Common/AkTypes.h>
00041 #include <AK/Tools/Common/AkPlatformFuncs.h>
00042 
00043 // Multi-channel volumes/mix.
00044 // ------------------------------------------------
00045 
00046 // Platform-specific section.
00047 //----------------------------------------------------------------------------------------------------
00048 
00049 #if defined( AK_XBOX360 )
00050 
00051     #include <AK/SoundEngine/Platforms/XBox360/AkSpeakerVolumes.h>
00052 
00053 #elif defined (AK_PS3)
00054 
00055     #include <AK/SoundEngine/Platforms/PS3/AkSpeakerVolumes.h>
00056     
00057 #else
00058 
00059     #include <AK/SoundEngine/Platforms/Generic/AkSpeakerVolumes.h>
00060 
00061 #endif
00062 
00063 // Cross-platform section.
00064 //----------------------------------------------------------------------------------------------------
00065 
00066 namespace AK
00067 {
00069 namespace SpeakerVolumes
00070 {
00071     typedef AkReal32 * VectorPtr;               
00072     typedef AkReal32 * MatrixPtr;               
00073     typedef const AkReal32 * ConstVectorPtr;    
00074     typedef const AkReal32 * ConstMatrixPtr;    
00075 
00077     namespace Vector
00078     {
00080         AkForceInline void Copy( VectorPtr in_pVolumesDst, ConstVectorPtr in_pVolumesSrc, AkUInt32 in_uNumChannels )
00081         {
00082             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
00083             if ( in_uNumChannels )
00084                 memcpy( in_pVolumesDst, in_pVolumesSrc, in_uNumChannels * sizeof( AkReal32 ) );
00085         }
00086 
00088         AkForceInline void Copy( VectorPtr in_pVolumesDst, ConstVectorPtr in_pVolumesSrc, AkUInt32 in_uNumChannels, AkReal32 in_fGain )
00089         {
00090             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
00091             for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
00092             {
00093                 in_pVolumesDst[uChan] = in_pVolumesSrc[uChan] * in_fGain;
00094             }
00095         }
00096 
00098         AkForceInline void Zero( VectorPtr in_pVolumes, AkUInt32 in_uNumChannels )
00099         {
00100             AKASSERT( in_pVolumes || in_uNumChannels == 0 );
00101             if ( in_uNumChannels )
00102                 memset( in_pVolumes, 0, in_uNumChannels * sizeof( AkReal32 ) );
00103         }
00104 
00106         AkForceInline void Add( VectorPtr in_pVolumesDst, ConstVectorPtr in_pVolumesSrc, AkUInt32 in_uNumChannels )
00107         {
00108             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
00109             for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
00110             {
00111                 in_pVolumesDst[uChan] += in_pVolumesSrc[uChan];
00112             }
00113         }
00114 
00116         AkForceInline AkReal32 L1Norm(ConstVectorPtr io_pVolumes, AkUInt32 in_uNumChannels)
00117         {
00118             AkReal32 total = 0;
00119             AKASSERT((io_pVolumes) || in_uNumChannels == 0);
00120             for (AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++)
00121             {
00122                 total += io_pVolumes[uChan];
00123             }
00124 
00125             return total;
00126         }
00127 
00129         AkForceInline void Mul( VectorPtr in_pVolumesDst, const AkReal32 in_fVol, AkUInt32 in_uNumChannels )
00130         {
00131             AKASSERT( in_pVolumesDst || in_uNumChannels == 0 );
00132             for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
00133             {
00134                 in_pVolumesDst[uChan] *= in_fVol;
00135             }
00136         }
00137 
00139         AkForceInline void Mul( VectorPtr in_pVolumesDst, ConstVectorPtr in_pVolumesSrc, AkUInt32 in_uNumChannels )
00140         {
00141             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
00142             for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
00143             {
00144                 in_pVolumesDst[uChan] *= in_pVolumesSrc[uChan];
00145             }
00146         }
00147 
00149         AkForceInline void Max( AkReal32 * in_pVolumesDst, const AkReal32 * in_pVolumesSrc, AkUInt32 in_uNumChannels )
00150         {
00151             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
00152             for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
00153             {
00154                 in_pVolumesDst[uChan] = AkMax( in_pVolumesDst[uChan], in_pVolumesSrc[uChan] );
00155             }
00156         }
00157         
00159         AkForceInline void Min( AkReal32 * in_pVolumesDst, const AkReal32 * in_pVolumesSrc, AkUInt32 in_uNumChannels )
00160         {
00161             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
00162             for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
00163             {
00164                 in_pVolumesDst[uChan] = AkMin( in_pVolumesDst[uChan], in_pVolumesSrc[uChan] );
00165             }
00166         }
00167     }
00168 
00170     namespace Matrix
00171     {
00173         AkForceInline AkUInt32 GetRequiredSize( AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut ) 
00174         {
00175             return in_uNumChannelsIn * Vector::GetRequiredSize( in_uNumChannelsOut );
00176         }
00177 
00179         AkForceInline AkUInt32 GetNumElements( AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut ) 
00180         {
00181             return in_uNumChannelsIn * Vector::GetNumElements( in_uNumChannelsOut );
00182         }
00183         
00185         AkForceInline VectorPtr GetChannel( MatrixPtr in_pVolumeMx, AkUInt32 in_uIdxChannelIn, AkUInt32 in_uNumChannelsOut ) 
00186         {
00187             AKASSERT( in_pVolumeMx );
00188             return in_pVolumeMx + in_uIdxChannelIn * Vector::GetNumElements( in_uNumChannelsOut );
00189         }
00190 
00192         AkForceInline ConstVectorPtr GetChannel( ConstMatrixPtr in_pVolumeMx, AkUInt32 in_uIdxChannelIn, AkUInt32 in_uNumChannelsOut ) 
00193         {
00194             AKASSERT( in_pVolumeMx );
00195             return in_pVolumeMx + in_uIdxChannelIn * Vector::GetNumElements( in_uNumChannelsOut );
00196         }
00197 
00199         AkForceInline void Copy( MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut )
00200         {
00201             AkUInt32 uNumElements = Matrix::GetNumElements( in_uNumChannelsIn, in_uNumChannelsOut );
00202             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || uNumElements == 0 );
00203             if ( uNumElements )
00204                 memcpy( in_pVolumesDst, in_pVolumesSrc, uNumElements * sizeof( AkReal32 ) );
00205         }
00206 
00208         AkForceInline void Copy( MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut, AkReal32 in_fGain )
00209         {
00210             AkUInt32 uNumElements = Matrix::GetNumElements( in_uNumChannelsIn, in_uNumChannelsOut );
00211             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || uNumElements == 0 );
00212             for ( AkUInt32 uChan = 0; uChan < uNumElements; uChan++ )
00213             {
00214                 in_pVolumesDst[uChan] = in_pVolumesSrc[uChan] * in_fGain;
00215             }
00216         }
00217 
00219         AkForceInline void Zero( MatrixPtr in_pVolumes, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut )
00220         {
00221             AkUInt32 uNumElements = Matrix::GetNumElements( in_uNumChannelsIn, in_uNumChannelsOut );
00222             AKASSERT( in_pVolumes || uNumElements == 0 );
00223             if ( uNumElements )
00224                 memset( in_pVolumes, 0, uNumElements * sizeof( AkReal32 ) );
00225         }
00226 
00228         AkForceInline void Mul( MatrixPtr in_pVolumesDst, const AkReal32 in_fVol, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut )
00229         {
00230             AkUInt32 uNumElements = Matrix::GetNumElements( in_uNumChannelsIn, in_uNumChannelsOut );
00231             AKASSERT( in_pVolumesDst || uNumElements == 0 );
00232             for ( AkUInt32 uChan = 0; uChan < uNumElements; uChan++ )
00233             {
00234                 in_pVolumesDst[uChan] *= in_fVol;
00235             }
00236         }
00237 
00239         AkForceInline void Add(MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut)
00240         {
00241             AkUInt32 uNumElements = Matrix::GetNumElements(in_uNumChannelsIn, in_uNumChannelsOut);
00242             AKASSERT((in_pVolumesDst && in_pVolumesSrc) || uNumElements == 0);
00243             for (AkUInt32 uChan = 0; uChan < uNumElements; uChan++)
00244             {
00245                 in_pVolumesDst[uChan] += in_pVolumesSrc[uChan];
00246             }
00247         }
00248         
00250         AkForceInline void AbsMax(MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut)
00251         {
00252             AkUInt32 uNumElements = Matrix::GetNumElements( in_uNumChannelsIn, in_uNumChannelsOut );
00253             AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || uNumElements == 0 );
00254             for ( AkUInt32 uChan = 0; uChan < uNumElements; uChan++ )
00255             {
00256                 in_pVolumesDst[uChan] = ((in_pVolumesDst[uChan] * in_pVolumesDst[uChan]) > (in_pVolumesSrc[uChan] * in_pVolumesSrc[uChan])) ? in_pVolumesDst[uChan] : in_pVolumesSrc[uChan];
00257             }
00258         }
00259     }
00260 }
00261 }
00262 
00263 #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