Go to the documentation of this file.
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)))
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 )
70 #define AK_NULL_THREAD nullptr
72 #define AK_DEFAULT_STACK_SIZE (128*1024)
73 #define AK_THREAD_PRIORITY_NORMAL (nn::os::DefaultThreadPriority)
74 #define AK_THREAD_PRIORITY_ABOVE_NORMAL (nn::os::DefaultThreadPriority-1)
75 #define AK_THREAD_PRIORITY_BELOW_NORMAL (nn::os::LowestThreadPriority)
76 #define AK_THREAD_PRIORITY_TIME_CRITICAL (nn::os::HighestThreadPriority+1)
79 #define AK_THREAD_AFFINITY_ALL 7 // from binary 0b0111 setting the 3 available cores to available
80 #define AK_THREAD_AFFINITY_DEFAULT AK_THREAD_AFFINITY_ALL
81 #define AK_VM_PAGE_SIZE (64*1024)
82 #define AK_VM_HUGE_PAGE_SIZE (2*1024*1024)
84 #define AK_INFINITE (-1)
92 wprintf(L
"%ls", in_pszMsg);
97 printf(
"%s", in_pszMsg);
101 template <
int MaxSize = 0>
105 va_start(args, in_pszFmt);
106 vwprintf(in_pszFmt, args);
111 template <
int MaxSize = 0>
115 va_start(args, in_pszFmt);
116 vprintf(in_pszFmt, args);
123 template <
int MaxSize = 0>
126 template <
int MaxSize = 0>
136 memset(&out_event, 0,
sizeof(out_event));
142 nn::os::InitializeEvent(&out_event,
false, nn::os::EventClearMode_AutoClear);
149 if (io_event._state == nn::os::EventType::State_Initialized)
150 nn::os::FinalizeEvent(&io_event);
156 AKASSERT(in_event._state == nn::os::EventType::State_Initialized);
157 nn::os::WaitEvent(&in_event);
163 AKASSERT(in_event._state == nn::os::EventType::State_Initialized);
164 nn::os::SignalEvent(&in_event);
176 nn::os::InitializeSemaphore(
186 AKASSERT(io_semaphore._state == nn::os::SemaphoreType::State_Initialized);
187 nn::os::FinalizeSemaphore(&io_semaphore);
193 AKASSERT(in_semaphore._state == nn::os::SemaphoreType::State_Initialized);
194 nn::os::AcquireSemaphore(&in_semaphore);
200 AKASSERT(in_semaphore._state == nn::os::SemaphoreType::State_Initialized);
201 nn::os::ReleaseSemaphore(&in_semaphore, in_count);
262 return in_pThread->
thread._state != nn::os::ThreadType::State_NotInitialized;
268 in_pThread->
thread._state = nn::os::ThreadType::State_NotInitialized;
274 nn::os::DestroyThread(&in_pThread->
thread);
279 #define AkExitThread( _result ) return
286 out_threadProperties.
iIdealCore = nn::os::IdealCoreUseDefaultValue;
296 const char * in_szThreadName)
300 AKASSERT(in_threadProperties.
nPriority >= nn::os::HighestThreadPriority && in_threadProperties.
nPriority <= nn::os::LowestThreadPriority);
311 if (!result.IsSuccess())
320 nn::os::SetThreadName(&out_pThread->
thread, in_szThreadName);
325 nn::os::StartThread(&out_pThread->
thread);
331 nn::os::WaitThread(&in_pThread->
thread);
336 return nn::os::GetCurrentThread();
342 nn::os::SleepThread(nn::TimeSpan::FromMilliSeconds(in_ulMilliseconds));
351 memcpy( pDest, pSrc, uSize );
357 memmove( pDest, pSrc, uSize );
363 memset( pDest, iVal, uSize );
372 *out_piLastTime = nn::os::GetSystemTick().GetInt64Value();
378 *out_piFreq = nn::os::GetSystemTickFrequency();
400 char* io_pszAnsiString)
405 memset(&state,
'\0',
sizeof(state));
407 return wcsrtombs(io_pszAnsiString,
408 &in_pszUnicodeString,
417 void* io_pvUnicodeStringBuffer)
422 memset(&state,
'\0',
sizeof(state));
424 return mbsrtowcs((
wchar_t*)io_pvUnicodeStringBuffer,
432 void* io_pvUnicodeStringBuffer)
434 return AkCharToWideChar(in_pszUtf8String, in_uiOutBufferSize, io_pvUnicodeStringBuffer);
440 size_t iSizeCopy =
AkMin(in_uDestMaxNumChars - 1, wcslen(in_pSrc) + 1);
441 wcsncpy(in_pDest, in_pSrc, iSizeCopy);
442 in_pDest[iSizeCopy] =
'\0';
448 size_t iSizeCopy =
AkMin(in_uDestMaxNumChars - 1, strlen(in_pSrc) + 1);
449 strncpy(in_pDest, in_pSrc, iSizeCopy);
450 in_pDest[iSizeCopy] =
'\0';
456 size_t iAvailableSize = (int)(in_uDestMaxNumChars - wcslen(in_pDest) - 1);
457 wcsncat(in_pDest, in_pSrc,
AkMin(iAvailableSize, (
int)wcslen(in_pSrc)));
463 size_t iAvailableSize = (int)(in_uDestMaxNumChars - strlen(in_pDest) - 1);
464 strncat(in_pDest, in_pSrc,
AkMin(iAvailableSize, (
int)strlen(in_pSrc)));
467 inline int SafeStrFormat(
wchar_t * in_pDest,
size_t in_uDestMaxNumChars,
const wchar_t* in_pszFmt, ...)
470 va_start(args, in_pszFmt);
471 int r = vswprintf(in_pDest, in_uDestMaxNumChars, in_pszFmt, args);
476 inline int SafeStrFormat(
char * in_pDest,
size_t in_uDestMaxNumChars,
const char* in_pszFmt, ...)
479 va_start(args, in_pszFmt);
480 int r = vsnprintf(in_pDest, in_uDestMaxNumChars, in_pszFmt, args);
486 #define AkAlloca( _size_ ) __builtin_alloca( _size_ )
488 #if __BIGGEST_ALIGNMENT__ < AK_SIMD_ALIGNMENT
489 #define AkAllocaSIMD( _size_ ) __builtin_alloca_with_align( _size_, AK_SIMD_ALIGNMENT*8 )
500 #define CONVERT_WIDE_TO_OSCHAR( _wstring_, _oscharstring_ ) \
501 _oscharstring_ = (AkOSChar*)AkAlloca( (1 + wcslen( _wstring_ )) * sizeof(AkOSChar) ); \
502 AKPLATFORM::AkWideCharToChar( _wstring_ , (AkUInt32)(1 + wcslen( _wstring_ )), (AkOSChar*)( _oscharstring_ ) )
512 #define CONVERT_CHAR_TO_OSCHAR( _astring_, _oscharstring_ ) ( _oscharstring_ ) = (AkOSChar*)( _astring_ )
522 #define CONVERT_OSCHAR_TO_WIDE( _osstring_, _wstring_ ) \
523 _wstring_ = (wchar_t*)AkAlloca((1+strlen(_osstring_)) * sizeof(wchar_t)); \
524 AKPLATFORM::AkCharToWideChar( _osstring_, (AkUInt32)(1 + strlen(_osstring_ )), _wstring_ )
534 #define CONVERT_OSCHAR_TO_CHAR( _osstring_, _astring_ ) _astring_ = (char*)_osstring_
542 while (*in_pStr != 0)
554 return (strlen(in_pszString));
558 #define AK_OSPRINTF snprintf
563 return (strcmp(in_pszString1, in_pszString2));
574 return (strncmp(in_pszString1, in_pszString2, in_MaxCountSize));
581 return strstr(in_pszPath,
":/") !=
nullptr;
584 template<
class destType,
class srcType>
585 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 *) )
588 size_t lenToCopy = srcStrLen(in_pSrc);
590 lenToCopy = (lenToCopy > in_MaxSize-1) ? in_MaxSize-1 : lenToCopy;
591 for(i = 0; i < lenToCopy; i++)
593 in_pdDest[i] = (destType) in_pSrc[i];
595 in_pdDest[lenToCopy] = (destType)0;
600 #define CONVERT_UTF16_TO_CHAR(_astring_, _charstring_) \
601 _charstring_ = (char*)AkAlloca( (1 + AKPLATFORM::AkUtf16StrLen((const AkUtf16*)_astring_)) * sizeof(char) ); \
602 AK_UTF16_TO_CHAR( _charstring_, (const AkUtf16*)_astring_, AKPLATFORM::AkUtf16StrLen((const AkUtf16*)_astring_)+1 )
604 #define AK_UTF16_TO_WCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, wcslen, AKPLATFORM::AkUtf16StrLen )
605 #define AK_WCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, AKPLATFORM::AkUtf16StrLen, wcslen )
606 #define AK_UTF8_TO_OSCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, strlen, strlen )
607 #define AK_UTF16_TO_OSCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, strlen, AKPLATFORM::AkUtf16StrLen )
608 #define AK_UTF16_TO_CHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, strlen, AKPLATFORM::AkUtf16StrLen )
609 #define AK_CHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, AKPLATFORM::AkUtf16StrLen, strlen )
610 #define AK_OSCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, AKPLATFORM::AkUtf16StrLen, strlen )
613 #define AK_PATH_SEPARATOR ("/")
614 #define AK_LIBRARY_PREFIX ("")
615 #define AK_DYNAMIC_LIBRARY_EXTENSION ("")
617 #define AK_FILEHANDLE_TO_UINTPTR(_h) ((AkUIntPtr)_h.handle)
618 #define AK_SET_FILEHANDLE_TO_UINTPTR(_h,_u) _h.handle = (void*)_u
AKRESULT AkCreateSemaphore(AkSemaphore &out_semaphore, AkUInt32 in_initialCount)
Platform Independent Helper.
size_t AkUtf16StrLen(const AkUtf16 *in_pStr)
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.
nn::Bit64 affinityMask
Affinity mask for each core: see nn::os::SetThreadCoreMask documentation.
AKRESULT
Standard function call result.
void OutputDebugMsg(const char *in_pszMsg)
Output a debug message on the console (Ansi string)
AkForceInline void * AllocVM(size_t size, size_t *extra)
uint8_t AkUInt8
Unsigned 8-bit integer.
int SafeStrFormat(wchar_t *in_pDest, size_t in_uDestMaxNumChars, const wchar_t *in_pszFmt,...)
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.
int32_t AkInt32
Signed 32-bit integer.
void AkCreateThread(AkThreadRoutine pStartRoutine, void *pParams, const AkThreadProperties &in_threadProperties, AkThread *out_pThread, const char *)
Platform Independent Helper.
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.
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)
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)
AkForceInline void AkMemSet(void *pDest, AkInt32 iVal, AkUInt32 uSize)
Platform Independent Helper.
void AkMemMove(void *pDest, const void *pSrc, AkUInt32 uSize)
Platform Independent Helper.
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
void AkWaitForSemaphore(AkSemaphore &in_semaphore)
Platform Independent Helper - Semaphore wait, aka Operation P. Decrements value of semaphore,...
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.
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.
AkForceInline void AkCloseThread(AkThread *in_pThread)
Platform Independent Helper.
AkForceInline int OsStrCmp(const AkOSChar *in_pszString1, const AkOSChar *in_pszString2)
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.
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