Version
menu_open
link
Wwise SDK 2021.1.14
AkPlatformFuncs.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 #pragma once
29 
32 
33 #include <nn/os.h>
34 
35 #include <time.h>
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <wchar.h>
40 
41 #define AkMax(x1, x2) (((x1) > (x2))? (x1): (x2))
42 #define AkMin(x1, x2) (((x1) < (x2))? (x1): (x2))
43 #define AkClamp(x, min, max) ((x) < (min)) ? (min) : (((x) > (max) ? (max) : (x)))
44 
45 //-----------------------------------------------------------------------------
46 // Platform-specific thread properties definition.
47 //-----------------------------------------------------------------------------
48 struct AkThreadProperties
49 {
50  AkInt32 nPriority; ///< Thread priority. 0=highest, 31=lowest.
51  size_t uStackSize; ///< Thread stack size.
52  int iIdealCore; ///< Preferred core number: see nn::os::SetThreadCoreMask documentation.
53  nn::Bit64 affinityMask; ///< Affinity mask for each core: see nn::os::SetThreadCoreMask documentation.
54 };
55 
56 //-----------------------------------------------------------------------------
57 // External variables.
58 //-----------------------------------------------------------------------------
59 // g_fFreqRatio is used by time helpers to return time values in milliseconds.
60 // It is declared and updated by the sound engine.
61 namespace AK
62 {
63  extern AkReal32 g_fFreqRatio;
64 }
65 
66 #define AK_DECLARE_THREAD_ROUTINE( FuncName ) void FuncName(void* lpParameter)
67 #define AK_THREAD_RETURN( _param_ ) return // (_param_)
68 #define AK_THREAD_ROUTINE_PARAMETER lpParameter
69 #define AK_GET_THREAD_ROUTINE_PARAMETER_PTR(type) reinterpret_cast<type*>( AK_THREAD_ROUTINE_PARAMETER )
70 
71 #define AK_NULL_THREAD nullptr
72 
73 #define AK_THREAD_PRIORITY_NORMAL (nn::os::DefaultThreadPriority)
74 #define AK_THREAD_PRIORITY_ABOVE_NORMAL (nn::os::DefaultThreadPriority-1)
75 #define AK_DEFAULT_STACK_SIZE (128*1024)
76 #define AK_VM_PAGE_SIZE (nn::os::MemoryPageSize)
77 
78 #define AK_INFINITE (-1)
79 
80 namespace AKPLATFORM
81 {
82  // Simple automatic event API
83  // ------------------------------------------------------------------
84 
85  /// Platform Independent Helper
86  AkForceInline void AkClearEvent(AkEvent &out_event)
87  {
88  memset(&out_event, 0, sizeof(out_event));
89  }
90 
91  /// Platform Independent Helper
93  {
94  nn::os::InitializeEvent(&out_event, false, nn::os::EventClearMode_AutoClear);
95  return AK_Success;
96  }
97 
98  /// Platform Independent Helper
99  AkForceInline void AkDestroyEvent(AkEvent & io_event)
100  {
101  if (io_event._state == nn::os::EventType::State_Initialized)
102  nn::os::FinalizeEvent(&io_event);
103  }
104 
105  /// Platform Independent Helper
106  AkForceInline void AkWaitForEvent(AkEvent & in_event)
107  {
108  AKASSERT(in_event._state == nn::os::EventType::State_Initialized);
109  nn::os::WaitEvent(&in_event);
110  }
111 
112  /// Platform Independent Helper
114  {
115  AKASSERT(in_event._state == nn::os::EventType::State_Initialized);
116  nn::os::SignalEvent(&in_event);
117  }
118 
119  /// Platform Independent Helper
120  inline AKRESULT AkCreateSemaphore( AkSemaphore * out_semaphore, AkUInt32 in_initialCount )
121  {
122  nn::os::InitializeSemaphore(
123  out_semaphore,
124  in_initialCount,
125  INT_MAX );
126  return AK_Success;
127  }
128 
129  /// Platform Independent Helper
130  inline void AkDestroySemaphore( AkSemaphore * io_semaphore )
131  {
132  nn::os::FinalizeSemaphore(io_semaphore);
133  }
134 
135  /// Platform Independent Helper - Semaphore wait, aka Operation P. Decrements value of semaphore, and, if the semaphore would be less than 0, waits for the semaphore to be released.
136  inline void AkWaitForSemaphore( AkSemaphore * in_semaphore )
137  {
138  nn::os::AcquireSemaphore(in_semaphore);
139  }
140 
141  /// Platform Independent Helper - Semaphore signal, aka Operation V. Increments value of semaphore.
142  inline void AkReleaseSemaphore( AkSemaphore * in_semaphore )
143  {
144  nn::os::ReleaseSemaphore(in_semaphore);
145  }
146 
147  // Virtual Memory
148  // ------------------------------------------------------------------
149 
150  // On NX, virtual memory is OFF by default (and unavailable on NX32) : use aligned heap alloc for "VM" page allocations.
151 
152  //AkForceInline void* AllocVM(size_t size, size_t* extra)
153  //{
154  // size = (size + nn::os::MemoryPageSize - 1) / nn::os::MemoryPageSize * nn::os::MemoryPageSize;
155  // uintptr_t region;
156  // auto result = nn::os::AllocateAddressRegion(&region, size);
157  // if (result.IsFailure())
158  // {
159  // // Allocation of address space fails.
160  // return nullptr;
161  // }
162 
163  // result = nn::os::AllocateMemoryPages(region, size);
164  // if (result.IsFailure())
165  // {
166  // // Allocation of physical memory fails.
167  // return nullptr;
168  // }
169 
170  // return reinterpret_cast<void *>(region);
171  //}
172 
173  //AkForceInline void FreeVM(void* address, size_t size, size_t extra, size_t release)
174  //{
175  // if (release)
176  // {
177  // auto result = nn::os::FreeAddressRegion(reinterpret_cast<uintptr_t>(address));
178  // AKASSERT(!result.IsFailure());
179  // {
180  // // Freeing fails.
181  // return;
182  // }
183  // }
184  //}
185 
186  AkForceInline void* AllocVM(size_t size, size_t* /*extra*/)
187  {
188  return aligned_alloc(nn::os::MemoryPageSize, size);
189  }
190 
191  AkForceInline void FreeVM(void* address, size_t /*size*/, size_t /*extra*/, size_t release)
192  {
193  if (release)
194  {
195  free(address);
196  }
197  }
198 
199  // Threads
200  // ------------------------------------------------------------------
201 
202  /// Platform Independent Helper
203  AkForceInline bool AkIsValidThread(AkThread * in_pThread)
204  {
205  return in_pThread->thread._state != nn::os::ThreadType::State_NotInitialized;
206  }
207 
208  /// Platform Independent Helper
209  AkForceInline void AkClearThread(AkThread * in_pThread)
210  {
211  in_pThread->thread._state = nn::os::ThreadType::State_NotInitialized;
212  }
213 
214  /// Platform Independent Helper
215  AkForceInline void AkCloseThread(AkThread * in_pThread)
216  {
217  nn::os::DestroyThread(&in_pThread->thread);
218  FreeVM((void *)in_pThread->pStackAlloc, in_pThread->uStackSize, 1, in_pThread->sizExtra);
219  in_pThread->pStackAlloc = nullptr;
220  }
221 
222 #define AkExitThread( _result ) return
223 
224  /// Platform Independent Helper
226  {
227  out_threadProperties.nPriority = AK_THREAD_PRIORITY_NORMAL;
228  out_threadProperties.uStackSize = AK_DEFAULT_STACK_SIZE;
229  out_threadProperties.iIdealCore = nn::os::IdealCoreUseDefaultValue;
230  out_threadProperties.affinityMask = 0; // ignored when iIdealCore == nn::os::IdealCoreUseDefaultValue
231  }
232 
233  /// Platform Independent Helper
235  AkThreadRoutine pStartRoutine, // Thread routine.
236  void * in_pParams, // Routine params.
237  const AkThreadProperties & in_threadProperties, // Properties.
238  AkThread * out_pThread, // Returned thread handle.
239  const char * in_szThreadName) // Opt thread name.
240  {
241  AKASSERT(out_pThread != NULL);
242  AKASSERT(in_threadProperties.uStackSize > 0);
243  AKASSERT(in_threadProperties.nPriority >= nn::os::HighestThreadPriority && in_threadProperties.nPriority <= nn::os::LowestThreadPriority);
244 
245  out_pThread->pStackAlloc = (AkUInt8 *)AllocVM(in_threadProperties.uStackSize, &out_pThread->sizExtra);
246  if (!out_pThread->pStackAlloc)
247  return;
248 
249  out_pThread->uStackSize = in_threadProperties.uStackSize;
250 
251  nn::Result result;
252 
253  result = nn::os::CreateThread(&out_pThread->thread, pStartRoutine, in_pParams, out_pThread->pStackAlloc, out_pThread->uStackSize, in_threadProperties.nPriority);
254  if (!result.IsSuccess())
255  {
256  FreeVM((void *)out_pThread->pStackAlloc, out_pThread->uStackSize, out_pThread->uStackSize, out_pThread->sizExtra);
257  out_pThread->pStackAlloc = nullptr;
258  return;
259  }
260 
261  if (in_szThreadName)
262  {
263  nn::os::SetThreadName(&out_pThread->thread, in_szThreadName);
264  }
265 
266  nn::os::SetThreadCoreMask(&out_pThread->thread, in_threadProperties.iIdealCore, in_threadProperties.affinityMask);
267 
268  nn::os::StartThread(&out_pThread->thread);
269  }
270 
271  /// Platform Independent Helper
272  AkForceInline void AkWaitForSingleThread(AkThread * in_pThread)
273  {
274  nn::os::WaitThread(&in_pThread->thread);
275  }
276 
278  {
279  return nn::os::GetCurrentThread();
280  }
281 
282  /// Platform Independent Helper
283  AkForceInline void AkSleep(AkUInt32 in_ulMilliseconds)
284  {
285  nn::os::SleepThread(nn::TimeSpan::FromMilliSeconds(in_ulMilliseconds));
286  }
287 
288  // Optimized memory functions
289  // --------------------------------------------------------------------
290 
291  /// Platform Independent Helper
292  AkForceInline void AkMemCpy( void * pDest, const void * pSrc, AkUInt32 uSize )
293  {
294  memcpy( pDest, pSrc, uSize );
295  }
296 
297  /// Platform Independent Helper
298  AkForceInline void AkMemSet( void * pDest, AkInt32 iVal, AkUInt32 uSize )
299  {
300  memset( pDest, iVal, uSize );
301  }
302 
303  // Time functions
304  // ------------------------------------------------------------------
305 
306  /// Platform Independent Helper
307  inline void PerformanceCounter( AkInt64 * out_piLastTime )
308  {
309  *out_piLastTime = nn::os::GetSystemTick().GetInt64Value();
310  }
311 
312  /// Platform Independent Helper
313  inline void PerformanceFrequency( AkInt64 * out_piFreq )
314  {
315  *out_piFreq = nn::os::GetSystemTickFrequency();
316  }
317 
318  /// Platform Independent Helper
319  inline void UpdatePerformanceFrequency()
320  {
321  AkInt64 iFreq;
322  PerformanceFrequency(&iFreq);
323  AK::g_fFreqRatio = (AkReal32)((AkReal64)iFreq / 1000);
324  }
325 
326  /// Platform Independent Helper
327  /// Returns a time range in milliseconds, using the sound engine's updated count->milliseconds ratio.
328  inline AkReal32 Elapsed( const AkInt64 & in_iNow, const AkInt64 & in_iStart )
329  {
330  return ( in_iNow - in_iStart ) / AK::g_fFreqRatio;
331  }
332 
333  template<class destType, class srcType>
334  inline size_t AkSimpleConvertString( destType* in_pdDest, const srcType* in_pSrc, size_t in_MaxSize, size_t destStrLen(const destType *), size_t srcStrLen(const srcType *) )
335  {
336  size_t i;
337  size_t lenToCopy = srcStrLen(in_pSrc);
338 
339  lenToCopy = (lenToCopy > in_MaxSize-1) ? in_MaxSize-1 : lenToCopy;
340  for(i = 0; i < lenToCopy; i++)
341  {
342  in_pdDest[i] = (destType) in_pSrc[i];
343  }
344  in_pdDest[lenToCopy] = (destType)0;
345 
346  return lenToCopy;
347  }
348 
349  /// Get the length, in characters, of a NULL-terminated AkUtf16 string
350  /// \return The length, in characters, of the specified string (excluding terminating NULL)
351  inline size_t AkUtf16StrLen(const AkUtf16* in_pStr)
352  {
353  size_t len = 0;
354  while (*in_pStr != 0)
355  {
356  in_pStr++;
357  len++;
358  }
359  return len;
360  }
361 
362  /// Get the length, in characters, of a NULL-terminated AkOSChar string
363  /// \return The length, in characters, of the specified string (excluding terminating NULL)
364  AkForceInline size_t OsStrLen(const AkOSChar* in_pszString)
365  {
366  return (strlen(in_pszString));
367  }
368 
369  /// AkOSChar version of snprintf().
370  #define AK_OSPRINTF snprintf
371 
372 #define CONVERT_UTF16_TO_CHAR(_astring_, _charstring_) \
373  _charstring_ = (char*)AkAlloca( (1 + AKPLATFORM::AkUtf16StrLen((const AkUtf16*)_astring_)) * sizeof(char) ); \
374  AK_UTF16_TO_CHAR( _charstring_, (const AkUtf16*)_astring_, AKPLATFORM::AkUtf16StrLen((const AkUtf16*)_astring_)+1 )
375 
376  #define AK_UTF16_TO_CHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, strlen, AKPLATFORM::AkUtf16StrLen )
377  #define AK_UTF8_TO_OSCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, strlen, strlen )
378  #define AK_UTF16_TO_OSCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, strlen, AKPLATFORM::AkUtf16StrLen )
379  #define AK_UTF16_TO_WCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, wcslen, AKPLATFORM::AkUtf16StrLen )
380  #define AK_CHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, AKPLATFORM::AkUtf16StrLen, strlen )
381  #define AK_OSCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, AKPLATFORM::AkUtf16StrLen, strlen )
382  #define AK_WCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, AKPLATFORM::AkUtf16StrLen, wcslen )
383 
384  // Use with AkOSChar.
385  #define AK_PATH_SEPARATOR ("/")
386 
387  inline int OsStrCmp(const AkOSChar* in_pszString1, const AkOSChar* in_pszString2)
388  {
389  return (strcmp(in_pszString1, in_pszString2));
390  }
391 
392  /// Compare two NULL-terminated AkOSChar strings up to the specified count of characters.
393  /// \return
394  /// - < 0 if in_pszString1 < in_pszString2
395  /// - 0 if the two strings are identical
396  /// - > 0 if in_pszString1 > in_pszString2
397  /// \remark The comparison is case-sensitive
398  inline int OsStrNCmp(const AkOSChar* in_pszString1, const AkOSChar* in_pszString2, size_t in_MaxCountSize)
399  {
400  return (strncmp(in_pszString1, in_pszString2, in_MaxCountSize));
401  }
402 
403  /// String conversion helper
404  inline AkInt32 AkWideCharToChar(const wchar_t* in_pszUnicodeString,
405  AkUInt32 in_uiOutBufferSize,
406  char* io_pszAnsiString)
407  {
408  AKASSERT(io_pszAnsiString != NULL);
409 
410  mbstate_t state;
411  memset(&state, '\0', sizeof(state));
412 
413  return wcsrtombs(io_pszAnsiString, // destination
414  &in_pszUnicodeString, // source
415  in_uiOutBufferSize, // destination length
416  &state); //
417 
418  }
419 
420  /// String conversion helper
421  inline AkInt32 AkCharToWideChar(const char* in_pszAnsiString,
422  AkUInt32 in_uiOutBufferSize,
423  void* io_pvUnicodeStringBuffer)
424  {
425  AKASSERT(io_pvUnicodeStringBuffer != NULL);
426 
427  mbstate_t state;
428  memset(&state, '\0', sizeof(state));
429 
430  return mbsrtowcs((wchar_t*)io_pvUnicodeStringBuffer, // destination
431  &in_pszAnsiString, // source
432  in_uiOutBufferSize, // destination length
433  &state); //
434  }
435 
436  inline AkInt32 AkUtf8ToWideChar(const char* in_pszUtf8String,
437  AkUInt32 in_uiOutBufferSize,
438  void* io_pvUnicodeStringBuffer)
439  {
440  return AkCharToWideChar(in_pszUtf8String, in_uiOutBufferSize, io_pvUnicodeStringBuffer);
441  }
442 
443  /// Safe unicode string copy.
444  inline void SafeStrCpy(wchar_t * in_pDest, const wchar_t* in_pSrc, size_t in_uDestMaxNumChars)
445  {
446  size_t iSizeCopy = AkMin(in_uDestMaxNumChars - 1, wcslen(in_pSrc) + 1);
447  wcsncpy(in_pDest, in_pSrc, iSizeCopy);
448  in_pDest[iSizeCopy] = '\0';
449  }
450 
451  /// Safe ansi string copy.
452  inline void SafeStrCpy(char * in_pDest, const char* in_pSrc, size_t in_uDestMaxNumChars)
453  {
454  size_t iSizeCopy = AkMin(in_uDestMaxNumChars - 1, strlen(in_pSrc) + 1);
455  strncpy(in_pDest, in_pSrc, iSizeCopy);
456  in_pDest[iSizeCopy] = '\0';
457  }
458 
459  /// Safe unicode string concatenation.
460  inline void SafeStrCat(wchar_t * in_pDest, const wchar_t* in_pSrc, size_t in_uDestMaxNumChars)
461  {
462  size_t iAvailableSize = (int)(in_uDestMaxNumChars - wcslen(in_pDest) - 1);
463  wcsncat(in_pDest, in_pSrc, AkMin(iAvailableSize, (int)wcslen(in_pSrc)));
464  }
465 
466  /// Safe ansi string concatenation.
467  inline void SafeStrCat(char * in_pDest, const char* in_pSrc, size_t in_uDestMaxNumChars)
468  {
469  size_t iAvailableSize = (int)(in_uDestMaxNumChars - strlen(in_pDest) - 1);
470  strncat(in_pDest, in_pSrc, AkMin(iAvailableSize, (int)strlen(in_pSrc)));
471  }
472 
473  inline int SafeStrFormat(wchar_t * in_pDest, size_t in_uDestMaxNumChars, const wchar_t* in_pszFmt, ...)
474  {
475  va_list args;
476  va_start(args, in_pszFmt);
477  int r = vswprintf(in_pDest, in_uDestMaxNumChars, in_pszFmt, args);
478  va_end(args);
479  return r;
480  }
481 
482  inline int SafeStrFormat(char * in_pDest, size_t in_uDestMaxNumChars, const char* in_pszFmt, ...)
483  {
484  va_list args;
485  va_start(args, in_pszFmt);
486  int r = vsnprintf(in_pDest, in_uDestMaxNumChars, in_pszFmt, args);
487  va_end(args);
488  return r;
489  }
490 
491  /// Stack allocations.
492  #define AkAlloca( _size_ ) __builtin_alloca( _size_ )
493 
494 #if __BIGGEST_ALIGNMENT__ < AK_SIMD_ALIGNMENT
495 #define AkAllocaSIMD( _size_ ) __builtin_alloca_with_align( _size_, AK_SIMD_ALIGNMENT*8 )
496 #endif
497 
498 #ifndef AK_OPTIMIZED
499  /// Output a debug message on the console (Unicode string)
500  inline void OutputDebugMsg(const wchar_t* in_pszMsg)
501  {
502  wprintf(L"%ls", in_pszMsg);
503  }
504  /// Output a debug message on the console (Ansi string)
505  inline void OutputDebugMsg(const char* in_pszMsg)
506  {
507  printf("%s", in_pszMsg);
508  }
509 
510  /// Output a debug message on the console (variadic function).
511  template <int MaxSize = 0> // Unused
512  inline void OutputDebugMsgV(const wchar_t* in_pszFmt, ...)
513  {
514  va_list args;
515  va_start(args, in_pszFmt);
516  vwprintf(in_pszFmt, args);
517  va_end(args);
518  }
519 
520  /// Output a debug message on the console (variadic function).
521  template <int MaxSize = 0> // Unused
522  inline void OutputDebugMsgV(const char* in_pszFmt, ...)
523  {
524  va_list args;
525  va_start(args, in_pszFmt);
526  vprintf(in_pszFmt, args);
527  va_end(args);
528  }
529 #else
530  inline void OutputDebugMsg(const wchar_t*){}
531  inline void OutputDebugMsg(const char*){}
532 
533  template <int MaxSize = 0>
534  inline void OutputDebugMsgV(const wchar_t*, ...) {}
535 
536  template <int MaxSize = 0>
537  inline void OutputDebugMsgV(const char*, ...) {}
538 #endif
539 
540  /// Converts a wchar_t string to an AkOSChar string.
541  /// \remark On some platforms the AkOSChar string simply points to the same string,
542  /// on others a new buffer is allocated on the stack using AkAlloca. This means
543  /// you must make sure that:
544  /// - The source string stays valid and unmodified for as long as you need the
545  /// AkOSChar string (for cases where they point to the same string)
546  /// - The AkOSChar string is used within this scope only -- for example, do NOT
547  /// return that string from a function (for cases where it is allocated on the stack)
548 #define CONVERT_WIDE_TO_OSCHAR( _wstring_, _oscharstring_ ) \
549  _oscharstring_ = (AkOSChar*)AkAlloca( (1 + wcslen( _wstring_ )) * sizeof(AkOSChar) ); \
550  AKPLATFORM::AkWideCharToChar( _wstring_ , (AkUInt32)(1 + wcslen( _wstring_ )), (AkOSChar*)( _oscharstring_ ) )
551 
552  /// Converts a char string to an AkOSChar string.
553  /// \remark On some platforms the AkOSChar string simply points to the same string,
554  /// on others a new buffer is allocated on the stack using AkAlloca. This means
555  /// you must make sure that:
556  /// - The source string stays valid and unmodified for as long as you need the
557  /// AkOSChar string (for cases where they point to the same string)
558  /// - The AkOSChar string is used within this scope only -- for example, do NOT
559  /// return that string from a function (for cases where it is allocated on the stack)
560 #define CONVERT_CHAR_TO_OSCHAR( _astring_, _oscharstring_ ) ( _oscharstring_ ) = (AkOSChar*)( _astring_ )
561 
562  /// Converts a AkOSChar string into wide char string.
563  /// \remark On some platforms the AkOSChar string simply points to the same string,
564  /// on others a new buffer is allocated on the stack using AkAlloca. This means
565  /// you must make sure that:
566  /// - The source string stays valid and unmodified for as long as you need the
567  /// AkOSChar string (for cases where they point to the same string)
568  /// - The AkOSChar string is used within this scope only -- for example, do NOT
569  /// return that string from a function (for cases where it is allocated on the stack)
570 #define CONVERT_OSCHAR_TO_WIDE( _osstring_, _wstring_ ) \
571  _wstring_ = (wchar_t*)AkAlloca((1+strlen(_osstring_)) * sizeof(wchar_t)); \
572  AKPLATFORM::AkCharToWideChar( _osstring_, (AkUInt32)(1 + strlen(_osstring_ )), _wstring_ )
573 
574  /// Converts a AkOSChar string into char string.
575  /// \remark On some platforms the AkOSChar string simply points to the same string,
576  /// on others a new buffer is allocated on the stack using AkAlloca. This means
577  /// you must make sure that:
578  /// - The source string stays valid and unmodified for as long as you need the
579  /// AkOSChar string (for cases where they point to the same string)
580  /// - The AkOSChar string is used within this scope only -- for example, do NOT
581  /// return that string from a function (for cases where it is allocated on the stack)
582 #define CONVERT_OSCHAR_TO_CHAR( _osstring_, _astring_ ) _astring_ = (char*)_osstring_
583 
584  #define AK_PATH_SEPARATOR ("/")
585  #define AK_LIBRARY_PREFIX ("")
586  #define AK_DYNAMIC_LIBRARY_EXTENSION ("")
587 
588 }
589 
590 #ifdef AK_ENABLE_INSTRUMENT
591 
592 #define NN_PERF_PROFILE_ENABLED
593 #include <nn/perf.h>
594 
595 #define AK_INSTRUMENT_BEGIN( _zone_name_ ) NN_PERF_BEGIN_MEASURE_NAME(_zone_name_)
596 #define AK_INSTRUMENT_BEGIN_C( _color_, _zone_name_ )
597 #define AK_INSTRUMENT_END( _zone_name_ ) NN_PERF_END_MEASURE()
598 #define AK_INSTRUMENT_SCOPE( _zone_name_ ) NN_PERF_AUTO_MEASURE_NAME(_zone_name_)
599 
600 #define AK_INSTRUMENT_IDLE_BEGIN( _zone_name_ )
601 #define AK_INSTRUMENT_IDLE_END( _zone_name_ )
602 #define AK_INSTRUMENT_IDLE_SCOPE( _zone_name_ )
603 
604 #define AK_INSTRUMENT_STALL_BEGIN( _zone_name_ )
605 #define AK_INSTRUMENT_STALL_END( _zone_name_ )
606 #define AK_INSTRUMENT_STALL_SCOPE( _zone_name_ )
607 
608 #define AK_INSTRUMENT_THREAD_START( _thread_name_ )
609 
610 #endif // AK_ENABLE_INSTRUMENT
float AkReal32
32-bit floating point
Definition: AkTypes.h:70
AkUInt8 * pStackAlloc
Definition: AkTypes.h:108
size_t AkUtf16StrLen(const AkUtf16 *in_pStr)
Definition: AkPlatformFuncs.h:576
Audiokinetic namespace.
semaphore_t AkEvent
Definition: AkTypes.h:73
AkForceInline void FreeVM(void *address, size_t size, size_t extra, size_t release)
Definition: AkPlatformFuncs.h:262
int nPriority
Thread priority.
Definition: AkPlatformFuncs.h:49
void AkClearEvent(AkEvent &out_event)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:52
Platform-dependent helpers.
Definition: AkPlatformFuncs.h:157
void AkWaitForEvent(AkEvent &in_event)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:80
pthread_t AkThreadID
Thread ID.
Definition: AkTypes.h:74
AkForceInline void UpdatePerformanceFrequency()
Platform Independent Helper.
Definition: AkPlatformFuncs.h:423
nn::Bit64 affinityMask
Affinity mask for each core: see nn::os::SetThreadCoreMask documentation.
Definition: AkPlatformFuncs.h:53
AKRESULT
Standard function call result.
Definition: AkTypes.h:132
void OutputDebugMsg(const char *in_pszMsg)
Output a debug message on the console (Ansi string)
Definition: AkPlatformFuncs.h:121
uint8_t AkUInt8
Unsigned 8-bit integer.
Definition: AkTypes.h:57
AkForceInline void * AllocVM(size_t size, size_t *extra)
Definition: AkPlatformFuncs.h:243
#define AK_THREAD_PRIORITY_NORMAL
Definition: AkPlatformFuncs.h:73
double AkReal64
64-bit floating point
Definition: AkTypes.h:71
void AkDestroySemaphore(AkSemaphore *io_semaphore)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:105
char AkOSChar
Generic character string.
Definition: AkTypes.h:68
int SafeStrFormat(wchar_t *in_pDest, size_t in_uDestMaxNumChars, const wchar_t *in_pszFmt,...)
Definition: AkPlatformFuncs.h:506
#define NULL
Definition: AkTypes.h:47
AkThreadID CurrentThread()
Returns the calling thread's ID.
Definition: AkPlatformFuncs.h:380
@ AK_Success
The operation was successful.
Definition: AkTypes.h:134
#define AkMin(x1, x2)
Definition: AkPlatformFuncs.h:42
void AkCreateThread(AkThreadRoutine pStartRoutine, void *pParams, const AkThreadProperties &in_threadProperties, AkThread *out_pThread, const char *)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:183
AkUInt16 AkUtf16
Definition: AkTypes.h:82
void OutputDebugMsgV(const char *in_pszFmt,...)
Output a debug message on the console (variadic function).
Definition: AkPlatformFuncs.h:130
void PerformanceCounter(AkInt64 *out_piLastTime)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:143
void AkDestroyEvent(AkEvent &io_event)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:70
nn::os::ThreadFunction AkThreadRoutine
Thread routine.
Definition: AkTypes.h:99
AkForceInline bool AkIsValidThread(AkThread *in_pThread)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:277
AkForceInline void AkMemCpy(void *pDest, const void *pSrc, AkUInt32 uSize)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:395
#define AKASSERT(Condition)
Definition: AkAssert.h:76
AkForceInline void AkSleep(AkUInt32 in_ulMilliseconds)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:386
AkForceInline void AkClearThread(AkThread *in_pThread)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:283
AkForceInline void AkGetDefaultThreadProperties(AkThreadProperties &out_threadProperties)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:302
int OsStrNCmp(const AkOSChar *in_pszString1, const AkOSChar *in_pszString2, size_t in_MaxCountSize)
Definition: AkPlatformFuncs.h:608
size_t sizExtra
Definition: AkTypes.h:109
AkForceInline void AkMemSet(void *pDest, AkInt32 iVal, AkUInt32 uSize)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:401
AkReal32 g_fFreqRatio
Definition: AkPlatformFuncs.h:63
AKRESULT AkCreateEvent(AkEvent &out_event)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:58
int iIdealCore
Preferred core number: see nn::os::SetThreadCoreMask documentation.
Definition: AkPlatformFuncs.h:52
AkForceInline void SafeStrCpy(wchar_t *in_pDest, const wchar_t *in_pSrc, size_t in_uDestMaxNumChars)
Safe unicode string copy.
Definition: AkPlatformFuncs.h:477
nn::os::ThreadType thread
Definition: AkTypes.h:107
AkUInt32 uStackSize
Definition: AkTypes.h:110
size_t uStackSize
Thread stack size.
Definition: AkPlatformFuncs.h:51
void PerformanceFrequency(AkInt64 *out_piFreq)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:46
AkForceInline AkInt32 AkCharToWideChar(const char *in_pszAnsiString, AkUInt32 in_uiOutBufferSize, void *io_pvUnicodeStringBuffer)
String conversion helper.
Definition: AkPlatformFuncs.h:454
AKRESULT AkCreateSemaphore(AkSemaphore *out_semaphore, AkUInt32 in_initialCount)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:93
uint32_t AkUInt32
Unsigned 32-bit integer.
Definition: AkTypes.h:59
AkForceInline void SafeStrCat(wchar_t *in_pDest, const wchar_t *in_pSrc, size_t in_uDestMaxNumChars)
Safe unicode string concatenation.
Definition: AkPlatformFuncs.h:493
void AkWaitForSemaphore(AkSemaphore *in_semaphore)
Platform Independent Helper - Semaphore wait, aka Operation P. Decrements value of semaphore,...
Definition: AkPlatformFuncs.h:115
AkForceInline AkInt32 AkWideCharToChar(const wchar_t *in_pszUnicodeString, AkUInt32 in_uiOutBufferSize, char *io_pszAnsiString)
String conversion helper.
Definition: AkPlatformFuncs.h:437
#define AK_DEFAULT_STACK_SIZE
Definition: AkPlatformFuncs.h:75
AkForceInline void AkWaitForSingleThread(AkThread *in_pThread)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:373
int32_t AkInt32
Signed 32-bit integer.
Definition: AkTypes.h:64
AkInt32 nPriority
Thread priority. 0=highest, 31=lowest.
Definition: AkPlatformFuncs.h:50
void AkSignalEvent(const AkEvent &in_event)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:87
size_t AkSimpleConvertString(destType *in_pdDest, const srcType *in_pSrc, size_t in_MaxSize, size_t destStrLen(const destType *), size_t srcStrLen(const srcType *))
Definition: AkPlatformFuncs.h:153
Definition: AkTypes.h:104
AkForceInline AkInt32 AkUtf8ToWideChar(const char *in_pszUtf8String, AkUInt32 in_uiOutBufferSize, void *io_pvUnicodeStringBuffer)
String conversion helper.
Definition: AkPlatformFuncs.h:469
semaphore_t AkSemaphore
Definition: AkTypes.h:74
AkForceInline void AkCloseThread(AkThread *in_pThread)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:289
AkForceInline int OsStrCmp(const AkOSChar *in_pszString1, const AkOSChar *in_pszString2)
Definition: AkPlatformFuncs.h:597
#define AkForceInline
Definition: AkTypes.h:60
void AkReleaseSemaphore(AkSemaphore *in_semaphore)
Platform Independent Helper - Semaphore signal, aka Operation V. Increments value of semaphore.
Definition: AkPlatformFuncs.h:121
AkForceInline size_t OsStrLen(const AkOSChar *in_pszString)
Definition: AkPlatformFuncs.h:583
AkForceInline AkReal32 Elapsed(const AkInt64 &in_iNow, const AkInt64 &in_iStart)
Returns a time range in milliseconds, using the sound engine's updated count->milliseconds ratio.
Definition: AkPlatformFuncs.h:431
int64_t AkInt64
Signed 64-bit integer.
Definition: AkTypes.h:65

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