Version
menu_open
link
Wwise SDK 2023.1.2
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 #ifndef _AK_PLATFORM_FUNCS_H_
28 #define _AK_PLATFORM_FUNCS_H_
29 
31 #include <sce_atomic.h>
32 #include <sceerror.h>
33 #include <wchar.h>
34 #include <string.h>
35 #include <stdio.h>
36 #include <time.h>
37 #include <kernel/eventflag.h>
38 #include <unistd.h>
39 #include <sys/time.h>
40 #include <stdlib.h>
41 #include <cpuid.h>
42 
43 //-----------------------------------------------------------------------------
44 // Platform-specific thread properties definition.
45 //-----------------------------------------------------------------------------
47 {
48  int nPriority; ///< Thread priority
49  SceKernelCpumask dwAffinityMask; ///< Affinity mask
50  size_t uStackSize; ///< Thread stack size
51  int uSchedPolicy; ///< Thread scheduling policy
52 };
53 
54 //-----------------------------------------------------------------------------
55 // External variables.
56 //-----------------------------------------------------------------------------
57 // g_fFreqRatio is used by time helpers to return time values in milliseconds.
58 // It is declared and updated by the sound engine.
59 namespace AK
60 {
61  extern AkReal32 g_fFreqRatio;
62 }
63 
64 //-----------------------------------------------------------------------------
65 // Defines for PS4.
66 //-----------------------------------------------------------------------------
67 #define AK_DECLARE_THREAD_ROUTINE( FuncName ) void* FuncName(void* lpParameter)
68 #define AK_THREAD_RETURN( _param_ ) return (_param_);
69 #define AK_THREAD_ROUTINE_PARAMETER lpParameter
70 #define AK_GET_THREAD_ROUTINE_PARAMETER_PTR(type) reinterpret_cast<type*>( AK_THREAD_ROUTINE_PARAMETER )
71 
72 #define AK_RETURN_THREAD_OK 0x00000000
73 #define AK_RETURN_THREAD_ERROR 0x00000001
74 #define AK_DEFAULT_STACK_SIZE (128*1024)
75 #define AK_THREAD_DEFAULT_SCHED_POLICY SCE_KERNEL_SCHED_FIFO
76 #define AK_THREAD_PRIORITY_NORMAL SCE_KERNEL_PRIO_FIFO_DEFAULT
77 #define AK_THREAD_PRIORITY_ABOVE_NORMAL SCE_KERNEL_PRIO_FIFO_HIGHEST
78 #define AK_THREAD_PRIORITY_BELOW_NORMAL SCE_KERNEL_PRIO_FIFO_LOWEST
79 
80 #define AK_THREAD_AFFINITY_ALL 63 // from binary 111111 setting the 6 available core to true. (ex: 4 << 1)
81 #define AK_THREAD_AFFINITY_DEFAULT AK_THREAD_AFFINITY_ALL
82 
83 // On PS4 this needs to be called regularly.
84 #define AK_RELEASE_GPU_OFFLINE_FRAME sce::Gnm::submitDone();
85 
86 // NULL objects
87 #define AK_NULL_THREAD NULL
88 
89 #define AK_INFINITE (AK_UINT_MAX)
90 
91 #define AkMax(x1, x2) (((x1) > (x2))? (x1): (x2))
92 #define AkMin(x1, x2) (((x1) < (x2))? (x1): (x2))
93 #define AkClamp(x, min, max) ((x) < (min)) ? (min) : (((x) > (max) ? (max) : (x)))
94 
95 namespace AKPLATFORM
96 {
97 #ifndef AK_OPTIMIZED
98  // The same orientation must be used for all
99  // OutputDebugMsg (either char or wchar_t) since
100  // using both in the same stream is undefined behavior.
101 
102  /// Output a debug message on the console (Ansi string)
103  AkForceInline void OutputDebugMsg( const char* in_pszMsg )
104  {
105  fputs( in_pszMsg, stderr );
106  }
107  /// Output a debug message on the console (Unicode string)
108  AkForceInline void OutputDebugMsg( const wchar_t* in_pszMsg )
109  {
110  fputws( in_pszMsg, stderr );
111  }
112 
113  /// Output a debug message on the console (Unicode string) (variadic function)
114  template <int MaxSize = 0> // Unused
115  AkForceInline void OutputDebugMsgV( const wchar_t* in_pszFmt, ... )
116  {
117  va_list args;
118  va_start(args, in_pszFmt);
119  vfwprintf(stderr, in_pszFmt, args);
120  va_end(args);
121  }
122 
123  /// Output a debug message on the console (Ansi string) (variadic function)
124  template <int MaxSize = 0> // Unused
125  AkForceInline void OutputDebugMsgV( const char* in_pszFmt, ... )
126  {
127  va_list args;
128  va_start(args, in_pszFmt);
129  vfprintf(stderr, in_pszFmt, args);
130  va_end(args);
131  }
132 #else
133  inline void OutputDebugMsg( const wchar_t* ){}
134  inline void OutputDebugMsg( const char* ){}
135 
136  template <int MaxSize = 0> // Unused
137  inline void OutputDebugMsgV( const wchar_t*, ... ){}
138 
139  template <int MaxSize = 0> // Unused
140  inline void OutputDebugMsgV( const char*, ... ){}
141 #endif
142 
143 
144  // Simple automatic event API
145  // ------------------------------------------------------------------
146 
147  /// Platform Independent Helper
148  AkForceInline void AkClearEvent( AkEvent & out_event )
149  {
150  out_event = NULL;
151  }
152 
153  AkForceInline AKRESULT AkCreateNamedEvent( AkEvent & out_event, const char* in_szName )
154  {
155  // NOTE: AkWaitForEvent uses the SCE_KERNEL_EVF_WAITMODE_CLEAR_PAT flag
156  // to get the same behavior as an auto-reset Win32 event
157  int ret = sceKernelCreateEventFlag(
158  &out_event,
159  in_szName,
160  SCE_KERNEL_EVF_ATTR_MULTI,
161  0 /* not signalled by default */,
162  NULL /* No optional params */ );
163 
164  if( ret == SCE_OK )
165  return AK_Success;
166 
167  AkClearEvent( out_event );
168  return AK_Fail;
169  }
170 
171  /// Platform Independent Helper
173  {
174  return AkCreateNamedEvent( out_event, "AkEvent" );
175  }
176 
177  /// Platform Independent Helper
178  AkForceInline void AkDestroyEvent( AkEvent & io_event )
179  {
180  sceKernelDeleteEventFlag(io_event);
181  AkClearEvent( io_event );
182  }
183 
184  /// Platform Independent Helper
185  AkForceInline void AkWaitForEvent( AkEvent & in_event )
186  {
187  AKVERIFY( sceKernelWaitEventFlag(
188  in_event,
189  1,
190  SCE_KERNEL_EVF_WAITMODE_OR | SCE_KERNEL_EVF_WAITMODE_CLEAR_ALL,
191  SCE_NULL,
192  SCE_NULL) == 0 );
193  }
194 
195  /// Platform Independent Helper
196  AkForceInline void AkSignalEvent( const AkEvent & in_event )
197  {
198  AKVERIFY( sceKernelSetEventFlag( in_event, 1 ) == 0 );
199  }
200 
201  /// Platform Independent Helper
202  AkForceInline void AkClearSemaphore(AkSemaphore& io_semaphore)
203  {
204  io_semaphore = NULL;
205  }
206 
207  /// Platform Independent Helper
208  inline AKRESULT AkCreateSemaphore( AkSemaphore& out_semaphore, AkUInt32 in_initialCount )
209  {
210  int ret = sceKernelCreateSema(
211  &out_semaphore,
212  "AkSemaphore",
213  0,
214  in_initialCount,
215  INT_MAX,
216  NULL );
217 
218  return ( ret == SCE_OK ) ? AK_Success : AK_Fail;
219  }
220 
221  /// Platform Independent Helper
222  inline void AkDestroySemaphore(AkSemaphore& io_semaphore)
223  {
224  AKVERIFY(sceKernelDeleteSema(io_semaphore) == SCE_OK);
225  }
226 
227  /// 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.
228  inline void AkWaitForSemaphore(AkSemaphore& in_semaphore)
229  {
230  AKVERIFY(sceKernelWaitSema(in_semaphore, 1, NULL) == SCE_OK);
231  }
232 
233  /// Platform Independent Helper - Semaphore signal, aka Operation V. Increments value of semaphore by an arbitrary count.
234  inline void AkReleaseSemaphore(AkSemaphore& in_semaphore, AkUInt32 in_count)
235  {
236  AKVERIFY(sceKernelSignalSema(in_semaphore, in_count) == SCE_OK);
237  }
238 
239  // Threads
240  // ------------------------------------------------------------------
241 
242  /// Platform Independent Helper
244  {
245  return ( *in_pThread != AK_NULL_THREAD );
246  }
247 
248  /// Platform Independent Helper
249  AkForceInline void AkClearThread( AkThread * in_pThread )
250  {
251  *in_pThread = AK_NULL_THREAD;
252  }
253 
254  /// Platform Independent Helper
255  AkForceInline void AkCloseThread( AkThread * in_pThread )
256  {
257  AKASSERT( in_pThread );
258  AKASSERT( *in_pThread );
259 
260  // #define KILL_THREAD(t) do { void *ret; scePthreadJoin(t,&ret); } while(false)
261  // AKVERIFY( SCE_OK == sceKernelDeleteThread( *in_pThread ) );
262  AkClearThread( in_pThread );
263  }
264 
265  #define AkExitThread( _result ) return _result;
266 
267  /// Platform Independent Helper
269  {
270  out_threadProperties.uStackSize = AK_DEFAULT_STACK_SIZE;
271  out_threadProperties.uSchedPolicy = AK_THREAD_DEFAULT_SCHED_POLICY;
272  out_threadProperties.nPriority = AK_THREAD_PRIORITY_NORMAL;
273  out_threadProperties.dwAffinityMask = AK_THREAD_AFFINITY_DEFAULT;
274  }
275 
276  /// Platform Independent Helper
277  inline void AkCreateThread(
278  AkThreadRoutine pStartRoutine, // Thread routine.
279  void * pParams, // Routine params.
280  const AkThreadProperties & in_threadProperties, // Properties. NULL for default.
281  AkThread * out_pThread, // Returned thread handle.
282  const char * in_szThreadName ) // Opt thread name.
283  {
284  AKASSERT( out_pThread != NULL );
285 
286  ScePthreadAttr attr;
287 
288  // Create the attr
289  AKVERIFY(!scePthreadAttrInit(&attr));
290  // Set the stack size
291  AKVERIFY(!scePthreadAttrSetstacksize(&attr,in_threadProperties.uStackSize));
292  AKVERIFY(!scePthreadAttrSetdetachstate(&attr, SCE_PTHREAD_CREATE_JOINABLE));
293  AKVERIFY(!scePthreadAttrSetinheritsched(&attr, SCE_PTHREAD_EXPLICIT_SCHED));
294  AKVERIFY(!scePthreadAttrSetaffinity(&attr,in_threadProperties.dwAffinityMask));
295 
296  // Try to set the thread policy
297  int sched_policy = in_threadProperties.uSchedPolicy;
298  if( scePthreadAttrSetschedpolicy( &attr, sched_policy ) )
299  {
300  AKASSERT( !"AKCreateThread invalid sched policy, will automatically set it to FIFO scheduling" );
301  sched_policy = AK_THREAD_DEFAULT_SCHED_POLICY;
302  AKVERIFY( !scePthreadAttrSetschedpolicy( &attr, sched_policy ));
303  }
304 
305  int minPriority, maxPriority;
306  minPriority = SCE_KERNEL_PRIO_FIFO_HIGHEST;
307  maxPriority = SCE_KERNEL_PRIO_FIFO_LOWEST;
308 
309  // Set the thread priority if valid
310  AKASSERT( in_threadProperties.nPriority >= minPriority && in_threadProperties.nPriority <= maxPriority );
311  if( in_threadProperties.nPriority >= minPriority && in_threadProperties.nPriority <= maxPriority )
312  {
313  SceKernelSchedParam schedParam;
314  AKVERIFY( scePthreadAttrGetschedparam(&attr, &schedParam) == 0 );
315  schedParam.sched_priority = in_threadProperties.nPriority;
316  AKVERIFY( scePthreadAttrSetschedparam(&attr, &schedParam) == 0 );
317  }
318 
319  // Create the tread
320  int threadError = scePthreadCreate(out_pThread, &attr, pStartRoutine, pParams, in_szThreadName);
321  AKASSERT( threadError == 0 );
322  AKVERIFY(!scePthreadAttrDestroy(&attr));
323 
324  if( threadError != 0 )
325  {
326  AkClearThread( out_pThread );
327  return;
328  }
329 
330  // ::CreateThread() return NULL if it fails.
331  if ( !*out_pThread )
332  {
333  AkClearThread( out_pThread );
334  return;
335  }
336  }
337 
338  /// Platform Independent Helper
340  {
341  AKASSERT( in_pThread );
342  AKASSERT( *in_pThread );
343  AKVERIFY(!scePthreadJoin( *in_pThread, NULL ));
344  }
345 
347  {
348  return scePthreadSelf();
349  }
350 
351  /// Platform Independent Helper
352  AkForceInline void AkSleep( AkUInt32 in_ulMilliseconds )
353  {
354  usleep( in_ulMilliseconds * 1000 );
355  }
356 
357  // Optimized memory functions
358  // --------------------------------------------------------------------
359 
360  /// Platform Independent Helper
361  AkForceInline void AkMemCpy( void * pDest, const void * pSrc, AkUInt32 uSize )
362  {
363  memcpy( pDest, pSrc, uSize );
364  }
365 
366  /// Platform Independent Helper
367  inline void AkMemMove( void* pDest, const void* pSrc, AkUInt32 uSize )
368  {
369  memmove( pDest, pSrc, uSize );
370  }
371 
372  /// Platform Independent Helper
373  AkForceInline void AkMemSet( void * pDest, AkInt32 iVal, AkUInt32 uSize )
374  {
375  memset( pDest, iVal, uSize );
376  }
377 
378  // Time functions
379  // ------------------------------------------------------------------
380 
381  /// Platform Independent Helper
382  AkForceInline void PerformanceCounter( AkInt64 * out_piLastTime )
383  {
384  uint64_t uTime = sceKernelGetProcessTimeCounter();
385  *out_piLastTime = (AkInt64)uTime;
386  }
387 
388  /// Frequency of the PerformanceCounter() (ticks per second)
389  AkForceInline void PerformanceFrequency( AkInt64 * out_piFreq )
390  {
391  *out_piFreq = (AkInt64)sceKernelGetProcessTimeCounterFrequency();
392  }
393 
394  /// Platform Independent Helper
396  {
397  AkInt64 iFreq;
398  PerformanceFrequency( &iFreq );
399  AK::g_fFreqRatio = (AkReal32)((AkReal64)iFreq / 1000);
400  }
401 
402  /// Returns a time range in milliseconds, using the sound engine's updated count->milliseconds ratio.
403  AkForceInline AkReal32 Elapsed( const AkInt64 & in_iNow, const AkInt64 & in_iStart )
404  {
405  return ( in_iNow - in_iStart ) / AK::g_fFreqRatio;
406  }
407 
408  /// String conversion helper
409  AkForceInline AkInt32 AkWideCharToChar( const wchar_t* in_pszUnicodeString,
410  AkUInt32 in_uiOutBufferSize,
411  char* io_pszAnsiString )
412  {
413  AKASSERT( io_pszAnsiString != NULL );
414 
415  mbstate_t state;
416  memset (&state, '\0', sizeof (state));
417 
418  return (AkInt32)wcsrtombs(io_pszAnsiString, // destination
419  &in_pszUnicodeString, // source
420  in_uiOutBufferSize, // destination length
421  &state); //
422 
423  }
424 
425  /// String conversion helper
426  AkForceInline AkInt32 AkCharToWideChar( const char* in_pszAnsiString,
427  AkUInt32 in_uiOutBufferSize,
428  void* io_pvUnicodeStringBuffer )
429  {
430  AKASSERT( io_pvUnicodeStringBuffer != NULL );
431 
432  mbstate_t state;
433  memset (&state, '\0', sizeof (state));
434 
435  return (AkInt32)mbsrtowcs((wchar_t*)io_pvUnicodeStringBuffer, // destination
436  &in_pszAnsiString, // source
437  in_uiOutBufferSize, // destination length
438  &state); //
439  }
440 
441  AkForceInline AkInt32 AkUtf8ToWideChar( const char* in_pszUtf8String,
442  AkUInt32 in_uiOutBufferSize,
443  void* io_pvUnicodeStringBuffer )
444  {
445  return AkCharToWideChar( in_pszUtf8String, in_uiOutBufferSize, (wchar_t*)io_pvUnicodeStringBuffer );
446  }
447 
448  /// Safe unicode string copy.
449  AkForceInline void SafeStrCpy( wchar_t * in_pDest, const wchar_t* in_pSrc, size_t in_uDestMaxNumChars )
450  {
451  size_t uSizeCopy = AkMin( in_uDestMaxNumChars - 1, wcslen( in_pSrc ) + 1 );
452  wcsncpy( in_pDest, in_pSrc, uSizeCopy );
453  in_pDest[uSizeCopy] = '\0';
454  }
455 
456  /// Safe ansi string copy.
457  AkForceInline void SafeStrCpy( char * in_pDest, const char* in_pSrc, size_t in_uDestMaxNumChars )
458  {
459  size_t uSizeCopy = AkMin( in_uDestMaxNumChars - 1, strlen( in_pSrc ) + 1 );
460  strncpy( in_pDest, in_pSrc, uSizeCopy );
461  in_pDest[uSizeCopy] = '\0';
462  }
463 
464  /// Safe unicode string concatenation.
465  AkForceInline void SafeStrCat( wchar_t * in_pDest, const wchar_t* in_pSrc, size_t in_uDestMaxNumChars )
466  {
467  size_t uAvailableSize = ( in_uDestMaxNumChars - wcslen( in_pDest ) - 1 );
468  wcsncat( in_pDest, in_pSrc, AkMin( uAvailableSize, wcslen( in_pSrc ) ) );
469  }
470 
471  /// Safe ansi string concatenation.
472  AkForceInline void SafeStrCat( char * in_pDest, const char* in_pSrc, size_t in_uDestMaxNumChars )
473  {
474  size_t uAvailableSize = ( in_uDestMaxNumChars - strlen( in_pDest ) - 1 );
475  strncat( in_pDest, in_pSrc, AkMin( uAvailableSize, strlen( in_pSrc ) ) );
476  }
477 
478  inline int SafeStrFormat(wchar_t * in_pDest, size_t in_uDestMaxNumChars, const wchar_t* in_pszFmt, ...)
479  {
480  va_list args;
481  va_start(args, in_pszFmt);
482  int r = vswprintf(in_pDest, in_uDestMaxNumChars, in_pszFmt, args);
483  va_end(args);
484  return r;
485  }
486 
487  inline int SafeStrFormat(char * in_pDest, size_t in_uDestMaxNumChars, const char* in_pszFmt, ...)
488  {
489  va_list args;
490  va_start(args, in_pszFmt);
491  int r = vsnprintf(in_pDest, in_uDestMaxNumChars, in_pszFmt, args);
492  va_end(args);
493  return r;
494  }
495 
496  /// Stack allocations.
497  #define AkAlloca( _size_ ) alloca( _size_ )
498 
499 
500 
501  /// Converts a wchar_t string to an AkOSChar string.
502  /// \remark On some platforms the AkOSChar string simply points to the same string,
503  /// on others a new buffer is allocated on the stack using AkAlloca. This means
504  /// you must make sure that:
505  /// - The source string stays valid and unmodified for as long as you need the
506  /// AkOSChar string (for cases where they point to the same string)
507  /// - The AkOSChar string is used within this scope only -- for example, do NOT
508  /// return that string from a function (for cases where it is allocated on the stack)
509  #define CONVERT_WIDE_TO_OSCHAR( _wstring_, _oscharstring_ ) \
510  _oscharstring_ = (AkOSChar*)AkAlloca( (1 + wcslen( _wstring_ )) * sizeof(AkOSChar) ); \
511  AKPLATFORM::AkWideCharToChar( _wstring_ , (AkUInt32)(1 + wcslen( _wstring_ )), (AkOSChar*)( _oscharstring_ ) )
512 
513 
514  /// Converts a char string to an AkOSChar string.
515  /// \remark On some platforms the AkOSChar string simply points to the same string,
516  /// on others a new buffer is allocated on the stack using AkAlloca. This means
517  /// you must make sure that:
518  /// - The source string stays valid and unmodified for as long as you need the
519  /// AkOSChar string (for cases where they point to the same string)
520  /// - The AkOSChar string is used within this scope only -- for example, do NOT
521  /// return that string from a function (for cases where it is allocated on the stack)
522  #define CONVERT_CHAR_TO_OSCHAR( _astring_, _oscharstring_ ) ( _oscharstring_ ) = (AkOSChar*)( _astring_ )
523 
524  /// Converts a AkOSChar string into wide char string.
525  /// \remark On some platforms the AkOSChar string simply points to the same string,
526  /// on others a new buffer is allocated on the stack using AkAlloca. This means
527  /// you must make sure that:
528  /// - The source string stays valid and unmodified for as long as you need the
529  /// AkOSChar string (for cases where they point to the same string)
530  /// - The AkOSChar string is used within this scope only -- for example, do NOT
531  /// return that string from a function (for cases where it is allocated on the stack)
532  #define CONVERT_OSCHAR_TO_WIDE( _osstring_, _wstring_ ) \
533  _wstring_ = (wchar_t*)AkAlloca((1+strlen(_osstring_)) * sizeof(wchar_t)); \
534  AKPLATFORM::AkCharToWideChar( _osstring_, (AkUInt32)(1 + strlen(_osstring_ )), _wstring_ )
535 
536  /// Converts a AkOSChar string into char string.
537  /// \remark On some platforms the AkOSChar string simply points to the same string,
538  /// on others a new buffer is allocated on the stack using AkAlloca. This means
539  /// you must make sure that:
540  /// - The source string stays valid and unmodified for as long as you need the
541  /// AkOSChar string (for cases where they point to the same string)
542  /// - The AkOSChar string is used within this scope only -- for example, do NOT
543  /// return that string from a function (for cases where it is allocated on the stack)
544  #define CONVERT_OSCHAR_TO_CHAR( _osstring_, _astring_ ) _astring_ = (char*)_osstring_
545 
546  /// Get the length, in characters, of a NULL-terminated AkUtf16 string
547  /// \return The length, in characters, of the specified string (excluding terminating NULL)
548  AkForceInline size_t AkUtf16StrLen( const AkUtf16* in_pStr )
549  {
550  return ( wcslen( in_pStr ) );
551  }
552 
553  /// Get the length, in characters, of a NULL-terminated AkOSChar string
554  /// \return The length, in characters, of the specified string (excluding terminating NULL)
555  AkForceInline size_t OsStrLen( const AkOSChar* in_pszString )
556  {
557  return ( strlen( in_pszString ) );
558  }
559 
560  /// AkOSChar version of sprintf().
561  #define AK_OSPRINTF snprintf
562 
563  /// Compare two NULL-terminated AkOSChar strings
564  /// \return
565  /// - < 0 if in_pszString1 < in_pszString2
566  /// - 0 if the two strings are identical
567  /// - > 0 if in_pszString1 > in_pszString2
568  /// \remark The comparison is case-sensitive
569  AkForceInline int OsStrCmp( const AkOSChar* in_pszString1, const AkOSChar* in_pszString2 )
570  {
571  return ( strcmp( in_pszString1, in_pszString2 ) );
572  }
573 
574  /// Compare two NULL-terminated AkOSChar strings up to the specified count of characters.
575  /// \return
576  /// - < 0 if in_pszString1 < in_pszString2
577  /// - 0 if the two strings are identical
578  /// - > 0 if in_pszString1 > in_pszString2
579  /// \remark The comparison is case-sensitive
580  inline int OsStrNCmp( const AkOSChar* in_pszString1, const AkOSChar* in_pszString2, size_t in_MaxCountSize )
581  {
582  return ( strncmp(in_pszString1, in_pszString2, in_MaxCountSize) );
583  }
584 
585  /// Detects whether the string represents an absolute path to a file
586  inline bool IsAbsolutePath(const AkOSChar* in_pszPath, size_t in_pathLen)
587  {
588  return in_pathLen >= 1 && in_pszPath[0] == '/';
589  }
590 
591  #define AK_UTF8_TO_OSCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::SafeStrCpy( in_pdDest, in_pSrc, in_MaxSize )
592  #define AK_UTF16_TO_WCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::SafeStrCpy( in_pdDest, in_pSrc, in_MaxSize )
593  #define AK_WCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::SafeStrCpy( in_pdDest, in_pSrc, in_MaxSize )
594  #define AK_UTF16_TO_OSCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkWideCharToChar( in_pSrc, in_MaxSize, in_pdDest )
595  #define AK_UTF16_TO_CHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkWideCharToChar( in_pSrc, in_MaxSize, in_pdDest )
596  #define AK_CHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkCharToWideChar( in_pSrc, in_MaxSize, in_pdDest )
597  #define AK_OSCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkCharToWideChar( in_pSrc, in_MaxSize, in_pdDest )
598 
599  // Use with AkOSChar.
600  #define AK_PATH_SEPARATOR "/"
601  #define AK_HOST_PATH_SEPARATOR "\\"
602  #define AK_LIBRARY_PREFIX ""
603  #define AK_DYNAMIC_LIBRARY_EXTENSION ".prx"
604 
605  #define AK_FILEHANDLE_TO_UINTPTR(_h) ((AkUIntPtr)_h)
606  #define AK_SET_FILEHANDLE_TO_UINTPTR(_h,_u) _h = (AkFileHandle)_u
607 
608  /// Support to fetch the CPUID for the platform. Only valid for X86 targets
609  /// \remark Note that IAkProcessorFeatures should be preferred to fetch this data
610  /// as it will have already translated the feature bits into AK-relevant enums
611  inline void CPUID(AkUInt32 in_uLeafOpcode, AkUInt32 in_uSubLeafOpcode, unsigned int out_uCPUFeatures[4])
612  {
613  __get_cpuid_count( in_uLeafOpcode, in_uSubLeafOpcode,
614  &out_uCPUFeatures[0],
615  &out_uCPUFeatures[1],
616  &out_uCPUFeatures[2],
617  &out_uCPUFeatures[3]);
618  }
619 }
620 
621 #endif // _AK_PLATFORM_FUNCS_H_
#define AK_THREAD_DEFAULT_SCHED_POLICY
#define AkMin(x1, x2)
AKRESULT AkCreateSemaphore(AkSemaphore &out_semaphore, AkUInt32 in_initialCount)
Platform Independent Helper.
size_t AkUtf16StrLen(const AkUtf16 *in_pStr)
Audiokinetic namespace.
@ AK_Fail
The operation failed.
Definition: AkTypes.h:216
semaphore_t AkEvent
Definition: AkTypes.h:84
int nPriority
Thread priority.
void AkClearEvent(AkEvent &out_event)
Platform Independent Helper.
AkForceInline void AkClearSemaphore(AkSemaphore &io_semaphore)
Platform Independent Helper.
Platform-dependent helpers.
Definition: AkBitFuncs.h:43
void AkWaitForEvent(AkEvent &in_event)
Platform Independent Helper.
AkForceInline void UpdatePerformanceFrequency()
Platform Independent Helper.
int AkThreadID
Definition: AkTypes.h:69
#define AK_NULL_THREAD
AKRESULT
Standard function call result.
Definition: AkTypes.h:213
void OutputDebugMsg(const char *in_pszMsg)
Output a debug message on the console (Ansi string)
void CPUID(AkUInt32 in_uLeafOpcode, AkUInt32 in_uSubLeafOpcode, unsigned int out_uCPUFeatures[4])
char AkOSChar
Generic character string.
Definition: AkTypes.h:60
int SafeStrFormat(wchar_t *in_pDest, size_t in_uDestMaxNumChars, const wchar_t *in_pszFmt,...)
#define NULL
Definition: AkTypes.h:46
#define AK_THREAD_PRIORITY_NORMAL
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:215
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.
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
#define AK_DEFAULT_STACK_SIZE
#define AKVERIFY(x)
Definition: AkAssert.h:69
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.
SceKernelCpumask dwAffinityMask
Affinity mask.
AkReal32 g_fFreqRatio
double AkReal64
64-bit floating point
AKRESULT AkCreateEvent(AkEvent &out_event)
Platform Independent Helper.
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.
#define AK_THREAD_AFFINITY_DEFAULT
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.
int uSchedPolicy
Thread scheduling policy.
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 AKRESULT AkCreateNamedEvent(AkEvent &out_event, const char *in_szName)
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.
void AkSignalEvent(const AkEvent &in_event)
Platform Independent Helper.
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