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

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