버전

menu_open
Wwise SDK 2022.1.18
AkSpeakerVolumes.h
이 파일의 문서화 페이지로 가기
1 /*******************************************************************************
2 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
3 released in source code form as part of the SDK installer package.
4 
5 Commercial License Usage
6 
7 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
8 may use this file in accordance with the end user license agreement provided
9 with the software or, alternatively, in accordance with the terms contained in a
10 written agreement between you and Audiokinetic Inc.
11 
12 Apache License Usage
13 
14 Alternatively, this file may be used under the Apache License, Version 2.0 (the
15 "Apache License"); you may not use this file except in compliance with the
16 Apache License. You may obtain a copy of the Apache License at
17 http://www.apache.org/licenses/LICENSE-2.0.
18 
19 Unless required by applicable law or agreed to in writing, software distributed
20 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
21 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
22 the specific language governing permissions and limitations under the License.
23 
24  Copyright (c) 2024 Audiokinetic Inc.
25 *******************************************************************************/
26 
27 // AkSpeakerVolumes.h
28 
29 /// \file
30 /// Multi-channel volume definitions and services.
31 /// Always associated with an AkChannelConfig. In the case of standard configurations, the volume items ordering
32 /// match the bit ordering in the channel mask, except for the LFE which is skipped and placed at the end of the
33 /// volume array.
34 /// Refer to \ref goingfurther_speakermatrixcallback for an example of how to manipulate speaker volume vectors/matrices.
35 
36 #ifndef _AK_SPEAKER_VOLUMES_H_
37 #define _AK_SPEAKER_VOLUMES_H_
38 
40 #include <AK/SoundEngine/Platforms/Generic/AkSpeakerVolumes.h>
42 
43 namespace AK
44 {
45 /// Multi-channel volume definitions and services.
46 namespace SpeakerVolumes
47 {
48  typedef AkReal32 * VectorPtr; ///< Volume vector. Access each element with the standard bracket [] operator.
49  typedef AkReal32 * MatrixPtr; ///< Volume matrix. Access each input channel vector with AK::SpeakerVolumes::Matrix::GetChannel().
50  typedef const AkReal32 * ConstVectorPtr; ///< Constant volume vector. Access each element with the standard bracket [] operator.
51  typedef const AkReal32 * ConstMatrixPtr; ///< Constant volume matrix. Access each input channel vector with AK::SpeakerVolumes::Matrix::GetChannel().
52 
53  /// Volume vector services.
54  namespace Vector
55  {
56  /// Copy volumes.
57  AkForceInline void Copy( VectorPtr in_pVolumesDst, ConstVectorPtr in_pVolumesSrc, AkUInt32 in_uNumChannels )
58  {
59  AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
60  if ( in_uNumChannels )
61  memcpy( in_pVolumesDst, in_pVolumesSrc, in_uNumChannels * sizeof( AkReal32 ) );
62  }
63 
64  /// Copy volumes with gain.
65  AkForceInline void Copy( VectorPtr in_pVolumesDst, ConstVectorPtr in_pVolumesSrc, AkUInt32 in_uNumChannels, AkReal32 in_fGain )
66  {
67  AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
68  for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
69  {
70  in_pVolumesDst[uChan] = in_pVolumesSrc[uChan] * in_fGain;
71  }
72  }
73 
74  /// Clear volumes.
75  AkForceInline void Zero( VectorPtr in_pVolumes, AkUInt32 in_uNumChannels )
76  {
77  AKASSERT( in_pVolumes || in_uNumChannels == 0 );
78  if ( in_uNumChannels )
79  memset( in_pVolumes, 0, in_uNumChannels * sizeof( AkReal32 ) );
80  }
81 
82  /// Accumulate two volume vectors.
83  AkForceInline void Add( VectorPtr in_pVolumesDst, ConstVectorPtr in_pVolumesSrc, AkUInt32 in_uNumChannels )
84  {
85  AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
86  for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
87  {
88  in_pVolumesDst[uChan] += in_pVolumesSrc[uChan];
89  }
90  }
91 
92  /// Compute the sum of all components of a volume vector.
93  AkForceInline AkReal32 L1Norm(ConstVectorPtr io_pVolumes, AkUInt32 in_uNumChannels)
94  {
95  AkReal32 total = 0;
96  AKASSERT((io_pVolumes) || in_uNumChannels == 0);
97  for (AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++)
98  {
99  total += io_pVolumes[uChan];
100  }
101 
102  return total;
103  }
104 
105  /// Multiply volume vector with a scalar.
106  AkForceInline void Mul( VectorPtr in_pVolumesDst, const AkReal32 in_fVol, AkUInt32 in_uNumChannels )
107  {
108  AKASSERT( in_pVolumesDst || in_uNumChannels == 0 );
109  for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
110  {
111  in_pVolumesDst[uChan] *= in_fVol;
112  }
113  }
114 
115  /// Multiply two volume vectors.
116  AkForceInline void Mul( VectorPtr in_pVolumesDst, ConstVectorPtr in_pVolumesSrc, AkUInt32 in_uNumChannels )
117  {
118  AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
119  for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
120  {
121  in_pVolumesDst[uChan] *= in_pVolumesSrc[uChan];
122  }
123  }
124 
125  /// Get max for all elements of two volume vectors, independently.
126  AkForceInline void Max( AkReal32 * in_pVolumesDst, const AkReal32 * in_pVolumesSrc, AkUInt32 in_uNumChannels )
127  {
128  AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
129  for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
130  {
131  in_pVolumesDst[uChan] = AkMax( in_pVolumesDst[uChan], in_pVolumesSrc[uChan] );
132  }
133  }
134 
135  /// Get min for all elements of two volume vectors, independently.
136  AkForceInline void Min( AkReal32 * in_pVolumesDst, const AkReal32 * in_pVolumesSrc, AkUInt32 in_uNumChannels )
137  {
138  AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || in_uNumChannels == 0 );
139  for ( AkUInt32 uChan = 0; uChan < in_uNumChannels; uChan++ )
140  {
141  in_pVolumesDst[uChan] = AkMin( in_pVolumesDst[uChan], in_pVolumesSrc[uChan] );
142  }
143  }
144  }
145 
146  /// Volume matrix (multi-in/multi-out channel configurations) services.
147  namespace Matrix
148  {
149  /// Compute size (in bytes) required for given channel configurations.
150  AkForceInline AkUInt32 GetRequiredSize( AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut )
151  {
152  return in_uNumChannelsIn * Vector::GetRequiredSize( in_uNumChannelsOut );
153  }
154 
155  /// Compute size (in number of elements) required for given channel configurations.
156  AkForceInline AkUInt32 GetNumElements( AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut )
157  {
158  return in_uNumChannelsIn * Vector::GetNumElements( in_uNumChannelsOut );
159  }
160 
161  /// Get pointer to volume distribution for input channel in_uIdxChannelIn.
162  AkForceInline VectorPtr GetChannel( MatrixPtr in_pVolumeMx, AkUInt32 in_uIdxChannelIn, AkUInt32 in_uNumChannelsOut )
163  {
164  AKASSERT( in_pVolumeMx );
165  return in_pVolumeMx + in_uIdxChannelIn * Vector::GetNumElements( in_uNumChannelsOut );
166  }
167 
168  /// Get pointer to volume distribution for input channel in_uIdxChannelIn.
169  AkForceInline ConstVectorPtr GetChannel( ConstMatrixPtr in_pVolumeMx, AkUInt32 in_uIdxChannelIn, AkUInt32 in_uNumChannelsOut )
170  {
171  AKASSERT( in_pVolumeMx );
172  return in_pVolumeMx + in_uIdxChannelIn * Vector::GetNumElements( in_uNumChannelsOut );
173  }
174 
175  /// Copy matrix.
176  AkForceInline void Copy( MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut )
177  {
178  AkUInt32 uNumElements = Matrix::GetNumElements( in_uNumChannelsIn, in_uNumChannelsOut );
179  AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || uNumElements == 0 );
180  if ( uNumElements )
181  memcpy( in_pVolumesDst, in_pVolumesSrc, uNumElements * sizeof( AkReal32 ) );
182  }
183 
184  /// Copy matrix with gain.
185  AkForceInline void Copy( MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut, AkReal32 in_fGain )
186  {
187  AkUInt32 uNumElements = Matrix::GetNumElements( in_uNumChannelsIn, in_uNumChannelsOut );
188  AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || uNumElements == 0 );
189  for ( AkUInt32 uChan = 0; uChan < uNumElements; uChan++ )
190  {
191  in_pVolumesDst[uChan] = in_pVolumesSrc[uChan] * in_fGain;
192  }
193  }
194 
195  /// Clear matrix.
196  AkForceInline void Zero( MatrixPtr in_pVolumes, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut )
197  {
198  AkUInt32 uNumElements = Matrix::GetNumElements( in_uNumChannelsIn, in_uNumChannelsOut );
199  AKASSERT( in_pVolumes || uNumElements == 0 );
200  if ( uNumElements )
201  memset( in_pVolumes, 0, uNumElements * sizeof( AkReal32 ) );
202  }
203 
204  /// Multiply a matrix with a scalar.
205  AkForceInline void Mul( MatrixPtr in_pVolumesDst, const AkReal32 in_fVol, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut )
206  {
207  AkUInt32 uNumElements = Matrix::GetNumElements( in_uNumChannelsIn, in_uNumChannelsOut );
208  AKASSERT( in_pVolumesDst || uNumElements == 0 );
209  for ( AkUInt32 uChan = 0; uChan < uNumElements; uChan++ )
210  {
211  in_pVolumesDst[uChan] *= in_fVol;
212  }
213  }
214 
215  /// Add all elements of two volume matrices, independently.
216  AkForceInline void Add(MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut)
217  {
218  AkUInt32 uNumElements = Matrix::GetNumElements(in_uNumChannelsIn, in_uNumChannelsOut);
219  AKASSERT((in_pVolumesDst && in_pVolumesSrc) || uNumElements == 0);
220  for (AkUInt32 uChan = 0; uChan < uNumElements; uChan++)
221  {
222  in_pVolumesDst[uChan] += in_pVolumesSrc[uChan];
223  }
224  }
225 
226  /// Pointwise Multiply-Add of all elements of two volume matrices.
227  AkForceInline void MAdd(MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut, AkReal32 in_fGain)
228  {
229  AkUInt32 uNumElements = Matrix::GetNumElements(in_uNumChannelsIn, in_uNumChannelsOut);
230  AKASSERT((in_pVolumesDst && in_pVolumesSrc) || uNumElements == 0);
231  for (AkUInt32 uChan = 0; uChan < uNumElements; uChan++)
232  {
233  in_pVolumesDst[uChan] += in_pVolumesSrc[uChan] * in_fGain;
234  }
235  }
236 
237  /// Get absolute max for all elements of two volume matrices, independently.
238  AkForceInline void AbsMax(MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut)
239  {
240  AkUInt32 uNumElements = Matrix::GetNumElements( in_uNumChannelsIn, in_uNumChannelsOut );
241  AKASSERT( ( in_pVolumesDst && in_pVolumesSrc ) || uNumElements == 0 );
242  for ( AkUInt32 uChan = 0; uChan < uNumElements; uChan++ )
243  {
244  in_pVolumesDst[uChan] = ((in_pVolumesDst[uChan] * in_pVolumesDst[uChan]) > (in_pVolumesSrc[uChan] * in_pVolumesSrc[uChan])) ? in_pVolumesDst[uChan] : in_pVolumesSrc[uChan];
245  }
246  }
247 
248  /// Get max for all elements of two volume matrices, independently.
249  AkForceInline void Max(MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut)
250  {
251  AkUInt32 uNumElements = Matrix::GetNumElements(in_uNumChannelsIn, in_uNumChannelsOut);
252  AKASSERT((in_pVolumesDst && in_pVolumesSrc) || uNumElements == 0);
253  for (AkUInt32 uChan = 0; uChan < uNumElements; uChan++)
254  {
255  in_pVolumesDst[uChan] = (in_pVolumesDst[uChan] > in_pVolumesSrc[uChan]) ? in_pVolumesDst[uChan] : in_pVolumesSrc[uChan];
256  }
257  }
258  }
259 }
260 }
261 
262 #endif //_AK_SPEAKER_VOLUMES_H_
#define AkMin(x1, x2)
AkForceInline void Copy(VectorPtr in_pVolumesDst, ConstVectorPtr in_pVolumesSrc, AkUInt32 in_uNumChannels)
Copy volumes.
Audiokinetic namespace
#define AkMax(x1, x2)
AkForceInline AkReal32 L1Norm(ConstVectorPtr io_pVolumes, AkUInt32 in_uNumChannels)
Compute the sum of all components of a volume vector.
AkForceInline void Max(AkReal32 *in_pVolumesDst, const AkReal32 *in_pVolumesSrc, AkUInt32 in_uNumChannels)
Get max for all elements of two volume vectors, independently.
AkForceInline AkUInt32 GetRequiredSize(AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut)
Compute size (in bytes) required for given channel configurations.
AkForceInline void Zero(MatrixPtr in_pVolumes, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut)
Clear matrix.
AkForceInline AkUInt32 GetNumElements(AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut)
Compute size (in number of elements) required for given channel configurations.
float AkReal32
32-bit floating point
AkForceInline void AbsMax(MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut)
Get absolute max for all elements of two volume matrices, independently.
AkReal32 * VectorPtr
Volume vector. Access each element with the standard bracket [] operator.
AkForceInline VectorPtr GetChannel(MatrixPtr in_pVolumeMx, AkUInt32 in_uIdxChannelIn, AkUInt32 in_uNumChannelsOut)
Get pointer to volume distribution for input channel in_uIdxChannelIn.
#define AKASSERT(Condition)
Definition: AkAssert.h:67
AkForceInline void Add(MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut)
Add all elements of two volume matrices, independently.
const AkReal32 * ConstMatrixPtr
Constant volume matrix. Access each input channel vector with AK::SpeakerVolumes::Matrix::GetChannel(...
AkForceInline void Zero(VectorPtr in_pVolumes, AkUInt32 in_uNumChannels)
Clear volumes.
AkForceInline void MAdd(MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut, AkReal32 in_fGain)
Pointwise Multiply-Add of all elements of two volume matrices.
AkForceInline void Add(VectorPtr in_pVolumesDst, ConstVectorPtr in_pVolumesSrc, AkUInt32 in_uNumChannels)
Accumulate two volume vectors.
AkReal32 * MatrixPtr
Volume matrix. Access each input channel vector with AK::SpeakerVolumes::Matrix::GetChannel().
AkForceInline void Mul(MatrixPtr in_pVolumesDst, const AkReal32 in_fVol, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut)
Multiply a matrix with a scalar.
uint32_t AkUInt32
Unsigned 32-bit integer
AkForceInline void Copy(MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut)
Copy matrix.
AkForceInline void Max(MatrixPtr in_pVolumesDst, ConstMatrixPtr in_pVolumesSrc, AkUInt32 in_uNumChannelsIn, AkUInt32 in_uNumChannelsOut)
Get max for all elements of two volume matrices, independently.
#define AkForceInline
Definition: AkTypes.h:63
const AkReal32 * ConstVectorPtr
Constant volume vector. Access each element with the standard bracket [] operator.
AkForceInline void Min(AkReal32 *in_pVolumesDst, const AkReal32 *in_pVolumesSrc, AkUInt32 in_uNumChannels)
Get min for all elements of two volume vectors, independently.
AkForceInline void Mul(VectorPtr in_pVolumesDst, const AkReal32 in_fVol, AkUInt32 in_uNumChannels)
Multiply volume vector with a scalar.

이 페이지가 도움이 되었나요?

지원이 필요하신가요?

질문이 있으신가요? 문제를 겪고 계신가요? 더 많은 정보가 필요하신가요? 저희에게 문의해주시면 도와드리겠습니다!

지원 페이지를 방문해 주세요

작업하는 프로젝트에 대해 알려주세요. 언제든지 도와드릴 준비가 되어 있습니다.

프로젝트를 등록하세요. 아무런 조건이나 의무 사항 없이 빠른 시작을 도와드리겠습니다.

Wwise를 시작해 보세요