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

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