バージョン
menu_open
link
Wwise SDK 2018.1.11
AkBankReadHelpers.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  Version: <VERSION> Build: <BUILDNUMBER>
25  Copyright (c) <COPYRIGHTYEAR> Audiokinetic Inc.
26 *******************************************************************************/
27 
28 #ifndef _AK_BANKREADHELPERS_H_
29 #define _AK_BANKREADHELPERS_H_
30 
31 /// Read data from bank and advance pointer.
32 template< typename T >
33 inline T ReadBankData(
34  AkUInt8*& in_rptr
35 #ifdef _DEBUG
36  ,AkUInt32& in_rSize
37 #endif
38  )
39 {
40  T l_Value;
41 #if defined(AK_IOS) || defined(AK_ANDROID) || defined(AK_LINUX) || defined(__EMSCRIPTEN__) || defined (AK_NX)
42  typedef struct {T t;} __attribute__((__packed__)) packedStruct;
43  l_Value = ((packedStruct *)in_rptr)->t;
44 #else
45  l_Value = *( ( T* )in_rptr );
46 #endif
47 
48  in_rptr += sizeof( T );
49 #ifdef _DEBUG
50  in_rSize -= sizeof( T );
51 #endif
52  return l_Value;
53 }
54 
55 template< typename T >
57  AkUInt8*& in_rptr
58 #ifdef _DEBUG
59  , AkUInt32& in_rSize
60 #endif
61  )
62 {
63  AkUInt32 l_Value = 0;
64 
65  AkUInt8 currentByte = *in_rptr;
66  ++in_rptr;
67 #ifdef _DEBUG
68  --in_rSize;
69 #endif
70  l_Value = (currentByte & 0x7F);
71  while (0x80 & currentByte)
72  {
73  currentByte = *in_rptr;
74  ++in_rptr;
75 #ifdef _DEBUG
76  --in_rSize;
77 #endif
78  l_Value = l_Value << 7;
79  l_Value |= (currentByte & 0x7F);
80  }
81 
82  return (T)l_Value;
83 }
84 
85 inline char * ReadBankStringUtf8(
86  AkUInt8*& in_rptr
87 #ifdef _DEBUG
88  ,AkUInt32& in_rSize
89 #endif
90  ,AkUInt32& out_uStringSize )
91 {
92  out_uStringSize = ReadBankData<AkUInt32>( in_rptr
93 #ifdef _DEBUG
94  ,in_rSize
95 #endif
96  );
97 
98  char * pString = 0;
99  if ( out_uStringSize > 0 )
100  {
101  pString = reinterpret_cast<char*>( in_rptr );
102  in_rptr += out_uStringSize;
103 #ifdef _DEBUG
104  in_rSize -= out_uStringSize;
105 #endif
106  }
107  return pString;
108 }
109 
110 /// Read unaligned memory, const version
111 template< typename T >
112 inline T ReadUnaligned( const AkUInt8* in_rptr, AkUInt32 in_bytesToSkip = 0 )
113 {
114 #ifdef _DEBUG
115  AkUInt32 size = sizeof(T);
116 #endif
117  AkUInt8* ptr = const_cast<AkUInt8*>(in_rptr) + in_bytesToSkip;
118  return ReadBankData<T>(ptr
119 #ifdef _DEBUG
120  , size
121 #endif
122  );
123 }
124 
125 #ifdef __EMSCRIPTEN__
126 
127 /// Handle reading float not aligned on proper memory boundaries (banks are byte packed).
128 inline AkReal64 AlignFloat(AkReal64* ptr)
129 {
130  AkReal64 LocalValue;
131 
132  // Forcing the char copy instead of the memcpy, as memcpy was optimized....
133  char* pSource = (char*)ptr;
134  char* pDest = (char*)&LocalValue;
135  for( int i = 0; i < 8; ++i)
136  {
137  pDest[i] = pSource[i];
138  }
139 
140  //memcpy( &LocalValue, ptr, sizeof( AkReal64 ) );
141  return LocalValue;
142 }
143 
144 /// Read data from bank and advance pointer.
145 template<>
146 inline AkReal64 ReadBankData<AkReal64>(
147  AkUInt8*& in_rptr
148 #ifdef _DEBUG
149  ,AkUInt32& in_rSize
150 #endif
151  )
152 {
153  AkReal64 l_Value = AlignFloat( (AkReal64*)in_rptr );
154  in_rptr += sizeof( AkReal64 );
155 #ifdef _DEBUG
156  in_rSize -= sizeof( AkReal64 );
157 #endif
158  return l_Value;
159 }
160 #endif
161 
162 #if (defined(AK_IOS) && defined(_DEBUG)) // bug with iOS SDK 4.3 in Debug only
163 
164 /// Type conversion helper on some platforms.
165 template < typename TO, typename FROM >
166 inline TO union_cast( FROM value )
167 {
168  union { FROM from; TO to; } convert;
169  convert.from = value;
170  return convert.to;
171 }
172 
173 /// Handle reading float not aligned on proper memory boundaries (banks are byte packed).
174 inline AkReal32 AlignFloat( AkReal32* ptr )
175 {
176  AkUInt32 *puint = reinterpret_cast<AkUInt32 *>( ptr );
177  volatile AkUInt32 uint = *puint;
178  return union_cast<AkReal32>( uint );
179 }
180 
181 /// Read data from bank and advance pointer.
182 template<>
183 inline AkReal32 ReadBankData<AkReal32>(
184  AkUInt8*& in_rptr
185 #ifdef _DEBUG
186  ,AkUInt32& in_rSize
187 #endif
188  )
189 {
190  AkReal32 l_Value = AlignFloat( ( AkReal32* )in_rptr );
191  in_rptr += sizeof( AkReal32 );
192 #ifdef _DEBUG
193  in_rSize -= sizeof( AkReal32 );
194 #endif
195  return l_Value;
196 }
197 
198 /// Handle reading float not aligned on proper memory boundaries (banks are byte packed).
199 inline AkReal64 AlignFloat( AkReal64* ptr )
200 {
201  AkUInt64 *puint = reinterpret_cast<AkUInt64 *>( ptr );
202  volatile AkUInt64 uint = *puint;
203  return union_cast<AkReal64>( uint );
204 }
205 
206 /// Read data from bank and advance pointer.
207 template<>
208 inline AkReal64 ReadBankData<AkReal64>(
209  AkUInt8*& in_rptr
210 #ifdef _DEBUG
211  ,AkUInt32& in_rSize
212 #endif
213  )
214 {
215  AkReal64 l_Value = AlignFloat( ( AkReal64* )in_rptr );
216  in_rptr += sizeof( AkReal64 );
217 #ifdef _DEBUG
218  in_rSize -= sizeof( AkReal64 );
219 #endif
220  return l_Value;
221 }
222 #endif
223 
224 #ifdef _DEBUG
225 
226 /// Read and return bank data of a given type, incrementing running pointer and decrementing block size for debug tracking purposes
227 #define READBANKDATA( _Type, _Ptr, _Size ) \
228  ReadBankData<_Type>( _Ptr, _Size )
229 
230 #define READVARIABLESIZEBANKDATA( _Type, _Ptr, _Size ) \
231  ReadVariableSizeBankData<_Type>( _Ptr, _Size )
232 
233 /// Read and return non-null-terminatd UTF-8 string stored in bank, and its size.
234 #define READBANKSTRING_UTF8( _Ptr, _Size, _out_StringSize ) \
235  ReadBankStringUtf8( _Ptr, _Size, _out_StringSize )
236 
237 /// Read and return non-null-terminatd string stored in bank, and its size.
238 #define READBANKSTRING( _Ptr, _Size, _out_StringSize ) \
239  ReadBankStringUtf8( _Ptr, _Size, _out_StringSize ) //same as UTF-8 for now.
240 
241 /// Skip over some bank data of a given type, incrementing running pointer and decrementing block size for debug tracking purposes
242 #define SKIPBANKDATA( _Type, _Ptr, _Size ) \
243  ( _Ptr ) += sizeof( _Type ); \
244  ( _Size ) -= sizeof( _Type )
245 
246 /// Skip over some bank data by a given size in bytes, incrementing running pointer and decrementing block size for debug tracking purposes
247 #define SKIPBANKBYTES( _NumBytes, _Ptr, _Size ) \
248  ( _Ptr ) += _NumBytes; \
249  ( _Size ) -= _NumBytes
250 
251 #else
252 
253 /// Read and return bank data of a given type, incrementing running pointer and decrementing block size for debug tracking purposes
254 #define READBANKDATA( _Type, _Ptr, _Size ) \
255  ReadBankData<_Type>( _Ptr )
256 
257 #define READVARIABLESIZEBANKDATA( _Type, _Ptr, _Size ) \
258  ReadVariableSizeBankData<_Type>( _Ptr )
259 
260 #define READBANKSTRING_UTF8( _Ptr, _Size, _out_StringSize ) \
261  ReadBankStringUtf8( _Ptr, _out_StringSize )
262 
263 #define READBANKSTRING( _Ptr, _Size, _out_StringSize ) \
264  ReadBankStringUtf8( _Ptr, _out_StringSize )
265 
266 /// Skip over some bank data of a given type, incrementing running pointer and decrementing block size for debug tracking purposes
267 #define SKIPBANKDATA( _Type, _Ptr, _Size ) \
268  ( _Ptr ) += sizeof( _Type )
269 
270 /// Skip over some bank data by a given size in bytes, incrementing running pointer and decrementing block size for debug tracking purposes
271 #define SKIPBANKBYTES( _NumBytes, _Ptr, _Size ) \
272  ( _Ptr ) += _NumBytes;
273 
274 #endif
275 
276 #define GETBANKDATABIT( _Data, _Shift ) \
277  (((_Data) >> (_Shift)) & 0x1)
278 
279 /// Helper macro to determine whether the full content of a block of memory was properly parsed
280 #ifdef _DEBUG
281  #define CHECKBANKDATASIZE( _DATASIZE_, _ERESULT_ ) AKASSERT( _DATASIZE_ == 0 || _ERESULT_ != AK_Success );
282 #else
283  #define CHECKBANKDATASIZE(_DATASIZE_, _ERESULT_ )
284 #endif
285 
286 #endif //_AK_BANKREADHELPERS_H_
uint8_t AkUInt8
Unsigned 8-bit integer
Definition: AkTypes.h:77
uint64_t AkUInt64
Unsigned 64-bit integer
Definition: AkTypes.h:80
T ReadVariableSizeBankData(AkUInt8 *&in_rptr)
char * ReadBankStringUtf8(AkUInt8 *&in_rptr, AkUInt32 &out_uStringSize)
T ReadUnaligned(const AkUInt8 *in_rptr, AkUInt32 in_bytesToSkip=0)
Read unaligned memory, const version
double AkReal64
64-bit floating point
Definition: AkTypes.h:98
uint32_t AkUInt32
Unsigned 32-bit integer
Definition: AkTypes.h:79
T ReadBankData(AkUInt8 *&in_rptr)
Read data from bank and advance pointer.
float AkReal32
32-bit floating point
Definition: AkTypes.h:97

このページはお役に立ちましたか?

サポートは必要ですか?

ご質問や問題、ご不明点はございますか?お気軽にお問い合わせください。

サポートページをご確認ください

あなたのプロジェクトについて教えてください。ご不明な点はありませんか。

プロジェクトを登録していただくことで、ご利用開始のサポートをいたします。

Wwiseからはじめよう