Version
menu_open
link
Wwise SDK 2021.1.14
AkBankReadHelpers.h
Go to the documentation of this file.
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: v2021.1.14 Build: 6590
25  Copyright (c) 2006-2023 Audiokinetic Inc.
26 *******************************************************************************/
27 
28 #ifndef _AK_BANKREADHELPERS_H_
29 #define _AK_BANKREADHELPERS_H_
30 
31 namespace AK
32 {
33  template< typename T >
34  inline T ReadUnaligned(const AkUInt8* in_pVal)
35  {
36 #if defined(__GNUC__)
37  typedef T __attribute__((aligned(1))) UnalignedT;
38  return *reinterpret_cast<const UnalignedT *>(in_pVal);
39 #elif defined(_MSC_VER) && !defined(AK_CPU_X86)
40  return *reinterpret_cast<const T __unaligned *>(in_pVal); // __unaligned not supported on 32-bit x86
41 #else
42  return *reinterpret_cast<const T *>(in_pVal);
43 #endif
44  }
45 
46  template< typename T >
47  inline void WriteUnaligned(AkUInt8* out_pVal, const T in_val)
48  {
49 #if defined(__GNUC__)
50  #if defined(__has_warning)
51  #if __has_warning("-Walign-mismatch")
52  #define __IGNORE_RECENT_CLANG_WARNINGS
53  #pragma clang diagnostic push
54  #pragma clang diagnostic ignored "-Walign-mismatch"
55  #endif
56  #endif
57 
58  typedef T __attribute__((aligned(1))) UnalignedT;
59  *reinterpret_cast<UnalignedT *>(out_pVal) = in_val;
60 
61  #ifdef __IGNORE_RECENT_CLANG_WARNINGS
62  #undef __IGNORE_RECENT_CLANG_WARNINGS
63  #pragma clang diagnostic pop
64  #endif
65 #elif defined(_MSC_VER) && !defined(AK_CPU_X86)
66  *reinterpret_cast<T __unaligned *>(out_pVal) = in_val; // __unaligned not supported on 32-bit x86
67 #else
68  *reinterpret_cast<T *>(out_pVal) = in_val;
69 #endif
70  }
71 
72  /// Read data from bank and advance pointer.
73  template< typename T >
74  inline T ReadBankData(
75  AkUInt8*& in_rptr
76 #ifdef _DEBUG
77  , AkUInt32& in_rSize
78 #endif
79  )
80  {
81  T l_Value = ReadUnaligned<T>(in_rptr);
82 
83  in_rptr += sizeof(T);
84 #ifdef _DEBUG
85  in_rSize -= sizeof(T);
86 #endif
87  return l_Value;
88  }
89 
90  template< typename T >
92  AkUInt8*& in_rptr
93 #ifdef _DEBUG
94  , AkUInt32& in_rSize
95 #endif
96  )
97  {
98  AkUInt32 l_Value = 0;
99 
100  AkUInt8 currentByte = *in_rptr;
101  ++in_rptr;
102 #ifdef _DEBUG
103  --in_rSize;
104 #endif
105  l_Value = (currentByte & 0x7F);
106  while (0x80 & currentByte)
107  {
108  currentByte = *in_rptr;
109  ++in_rptr;
110 #ifdef _DEBUG
111  --in_rSize;
112 #endif
113  l_Value = l_Value << 7;
114  l_Value |= (currentByte & 0x7F);
115  }
116 
117  return (T)l_Value;
118  }
119 
120  inline char * ReadBankStringUtf8(
121  AkUInt8*& in_rptr
122 #ifdef _DEBUG
123  , AkUInt32& in_rSize
124 #endif
125  , AkUInt32& out_uStringSize)
126  {
127  char* pString = (char *)in_rptr;
128  out_uStringSize = 0;
129 
130  while (*in_rptr != 0)
131  {
132  ++in_rptr;
133 #ifdef _DEBUG
134  --in_rSize;
135 #endif
136  ++out_uStringSize;
137  }
138 
139  ++in_rptr;
140 #ifdef _DEBUG
141  --in_rSize;
142 #endif
143 
144  return pString;
145  }
146 }
147 
148 
149 #ifdef _DEBUG
150 
151 /// Read and return bank data of a given type, incrementing running pointer and decrementing block size for debug tracking purposes
152 #define READBANKDATA( _Type, _Ptr, _Size ) \
153  AK::ReadBankData<_Type>( _Ptr, _Size )
154 
155 #define READVARIABLESIZEBANKDATA( _Type, _Ptr, _Size ) \
156  AK::ReadVariableSizeBankData<_Type>( _Ptr, _Size )
157 
158 /// Read and return null-terminatd UTF-8 string stored in bank, and its size.
159 #define READBANKSTRING( _Ptr, _Size, _out_StringSize ) \
160  AK::ReadBankStringUtf8( _Ptr, _Size, _out_StringSize )
161 
162 /// Skip over some bank data of a given type, incrementing running pointer and decrementing block size for debug tracking purposes
163 #define SKIPBANKDATA( _Type, _Ptr, _Size ) \
164  ( _Ptr ) += sizeof( _Type ); \
165  ( _Size ) -= sizeof( _Type )
166 
167 /// Skip over some bank data by a given size in bytes, incrementing running pointer and decrementing block size for debug tracking purposes
168 #define SKIPBANKBYTES( _NumBytes, _Ptr, _Size ) \
169  ( _Size ) -= _NumBytes; \
170  ( _Ptr ) += _NumBytes
171 
172 /// Read and copy to a null-terminated UTF-8 string conversion from string stored in bank.
173 #define COPYBANKSTRING_CHAR( _Ptr, _Size, _OutPtr, _MaxOutPtrSize ) \
174  AKPLATFORM::SafeStrCpy( _OutPtr, ((const char*)_Ptr), (_MaxOutPtrSize) ); \
175  SKIPBANKBYTES( (AkUInt32)strlen((const char*)_Ptr) + 1, _Ptr, _Size )
176 
177 /// Read and copy to a null-terminated OSChar string conversion from string stored in bank.
178 #define COPYBANKSTRING_OSCHAR( _Ptr, _Size, _OutPtr, _MaxOutPtrSize ) \
179  AK_UTF8_TO_OSCHAR( _OutPtr, ((const char*)_Ptr), (_MaxOutPtrSize) ); \
180  SKIPBANKBYTES( (AkUInt32)strlen((const char*)_Ptr) + 1, _Ptr, _Size )
181 
182 /// Read and copy to a null-terminated wchar_t string conversion from string stored in bank.
183 #define COPYBANKSTRING_WCHAR( _Ptr, _Size, OutPtr, _MaxOutPtrSize ) \
184  AK_CHAR_TO_UTF16( _OutPtr, ((const char*)_Ptr), (_MaxOutPtrSize) ); \
185  SKIPBANKBYTES( (AkUInt32)strlen((const char*)_Ptr) + 1, _Ptr, _Size )
186 
187 
188 #else
189 
190 /// Read and return bank data of a given type, incrementing running pointer and decrementing block size for debug tracking purposes
191 #define READBANKDATA( _Type, _Ptr, _Size ) \
192  AK::ReadBankData<_Type>( _Ptr )
193 
194 #define READVARIABLESIZEBANKDATA( _Type, _Ptr, _Size ) \
195  AK::ReadVariableSizeBankData<_Type>( _Ptr )
196 
197 #define READBANKSTRING( _Ptr, _Size, _out_StringSize ) \
198  AK::ReadBankStringUtf8( _Ptr, _out_StringSize )
199 
200 /// Skip over some bank data of a given type, incrementing running pointer and decrementing block size for debug tracking purposes
201 #define SKIPBANKDATA( _Type, _Ptr, _Size ) \
202  ( _Ptr ) += sizeof( _Type )
203 
204 /// Skip over some bank data by a given size in bytes, incrementing running pointer and decrementing block size for debug tracking purposes
205 #define SKIPBANKBYTES( _NumBytes, _Ptr, _Size ) \
206  ( _Ptr ) += _NumBytes;
207 
208 /// Read and copy to a null-terminated UTF-8 string conversion from string stored in bank.
209 #define COPYBANKSTRING_CHAR( _Ptr, _Size, _OutPtr, _MaxPtrSize ) \
210  AKPLATFORM::SafeStrCpy( _OutPtr, (const char*)_Ptr, _MaxPtrSize ); \
211  SKIPBANKBYTES( (AkUInt32)strlen((const char*)_Ptr)+1, _Ptr, _Size )
212 
213 /// Read and copy to a null-terminated OSChar string conversion from string stored in bank.
214 #define COPYBANKSTRING_OSCHAR( _Ptr, _Size, _OutPtr, _MaxPtrSize ) \
215  AK_UTF8_TO_OSCHAR( _OutPtr, (const char*)_Ptr, _MaxPtrSize ); \
216  SKIPBANKBYTES( (AkUInt32)strlen((const char*)_Ptr)+1, _Ptr, _Size )
217 
218 /// Read and copy to a null-terminated wchar_t string conversion from string stored in bank.
219 #define COPYBANKSTRING_WCHAR( _Ptr, _Size, OutPtr, _MaxPtrSize ) \
220  AK_CHAR_TO_UTF16( _OutPtr, (const char*)_Ptr, _MaxPtrSize ); \
221  SKIPBANKBYTES( (AkUInt32)strlen((const char*)_Ptr)+1, _Ptr, _Size )
222 
223 #endif
224 
225 #define GETBANKDATABIT( _Data, _Shift ) \
226  (((_Data) >> (_Shift)) & 0x1)
227 
228 /// Helper macro to determine whether the full content of a block of memory was properly parsed
229 #ifdef _DEBUG
230  #define CHECKBANKDATASIZE( _DATASIZE_, _ERESULT_ ) AKASSERT( _DATASIZE_ == 0 || _ERESULT_ != AK_Success );
231 #else
232  #define CHECKBANKDATASIZE(_DATASIZE_, _ERESULT_ )
233 #endif
234 
235 #endif //_AK_BANKREADHELPERS_H_
Audiokinetic namespace.
void WriteUnaligned(AkUInt8 *out_pVal, const T in_val)
uint8_t AkUInt8
Unsigned 8-bit integer.
Definition: AkTypes.h:57
T ReadBankData(AkUInt8 *&in_rptr)
Read data from bank and advance pointer.
T ReadVariableSizeBankData(AkUInt8 *&in_rptr)
T ReadUnaligned(const AkUInt8 *in_pVal)
uint32_t AkUInt32
Unsigned 32-bit integer.
Definition: AkTypes.h:59
char * ReadBankStringUtf8(AkUInt8 *&in_rptr, AkUInt32 &out_uStringSize)

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