Version
menu_open
Wwise SDK 2023.1.5
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  // Time functions
358  // ------------------------------------------------------------------
359 
360  /// Platform Independent Helper
361  AkForceInline void PerformanceCounter( AkInt64 * out_piLastTime )
362  {
363  uint64_t uTime = sceKernelGetProcessTimeCounter();
364  *out_piLastTime = (AkInt64)uTime;
365  }
366 
367  /// Frequency of the PerformanceCounter() (ticks per second)
368  AkForceInline void PerformanceFrequency( AkInt64 * out_piFreq )
369  {
370  *out_piFreq = (AkInt64)sceKernelGetProcessTimeCounterFrequency();
371  }
372 
373  /// Platform Independent Helper
375  {
376  AkInt64 iFreq;
377  PerformanceFrequency( &iFreq );
378  AK::g_fFreqRatio = (AkReal32)((AkReal64)iFreq / 1000);
379  }
380 
381  /// Returns a time range in milliseconds, using the sound engine's updated count->milliseconds ratio.
382  AkForceInline AkReal32 Elapsed( const AkInt64 & in_iNow, const AkInt64 & in_iStart )
383  {
384  return ( in_iNow - in_iStart ) / AK::g_fFreqRatio;
385  }
386 
387  /// String conversion helper
388  AkForceInline AkInt32 AkWideCharToChar( const wchar_t* in_pszUnicodeString,
389  AkUInt32 in_uiOutBufferSize,
390  char* io_pszAnsiString )
391  {
392  AKASSERT( io_pszAnsiString != NULL );
393 
394  mbstate_t state;
395  memset (&state, '\0', sizeof (state));
396 
397  return (AkInt32)wcsrtombs(io_pszAnsiString, // destination
398  &in_pszUnicodeString, // source
399  in_uiOutBufferSize, // destination length
400  &state); //
401 
402  }
403 
404  /// String conversion helper
405  AkForceInline AkInt32 AkCharToWideChar( const char* in_pszAnsiString,
406  AkUInt32 in_uiOutBufferSize,
407  void* io_pvUnicodeStringBuffer )
408  {
409  AKASSERT( io_pvUnicodeStringBuffer != NULL );
410 
411  mbstate_t state;
412  memset (&state, '\0', sizeof (state));
413 
414  return (AkInt32)mbsrtowcs((wchar_t*)io_pvUnicodeStringBuffer, // destination
415  &in_pszAnsiString, // source
416  in_uiOutBufferSize, // destination length
417  &state); //
418  }
419 
420  AkForceInline AkInt32 AkUtf8ToWideChar( const char* in_pszUtf8String,
421  AkUInt32 in_uiOutBufferSize,
422  void* io_pvUnicodeStringBuffer )
423  {
424  return AkCharToWideChar( in_pszUtf8String, in_uiOutBufferSize, (wchar_t*)io_pvUnicodeStringBuffer );
425  }
426 
427  /// Safe unicode string copy.
428  AkForceInline void SafeStrCpy( wchar_t * in_pDest, const wchar_t* in_pSrc, size_t in_uDestMaxNumChars )
429  {
430  size_t uSizeCopy = AkMin( in_uDestMaxNumChars - 1, wcslen( in_pSrc ) + 1 );
431  wcsncpy( in_pDest, in_pSrc, uSizeCopy );
432  in_pDest[uSizeCopy] = '\0';
433  }
434 
435  /// Safe ansi string copy.
436  AkForceInline void SafeStrCpy( char * in_pDest, const char* in_pSrc, size_t in_uDestMaxNumChars )
437  {
438  size_t uSizeCopy = AkMin( in_uDestMaxNumChars - 1, strlen( in_pSrc ) + 1 );
439  strncpy( in_pDest, in_pSrc, uSizeCopy );
440  in_pDest[uSizeCopy] = '\0';
441  }
442 
443  /// Safe unicode string concatenation.
444  AkForceInline void SafeStrCat( wchar_t * in_pDest, const wchar_t* in_pSrc, size_t in_uDestMaxNumChars )
445  {
446  size_t uAvailableSize = ( in_uDestMaxNumChars - wcslen( in_pDest ) - 1 );
447  wcsncat( in_pDest, in_pSrc, AkMin( uAvailableSize, wcslen( in_pSrc ) ) );
448  }
449 
450  /// Safe ansi string concatenation.
451  AkForceInline void SafeStrCat( char * in_pDest, const char* in_pSrc, size_t in_uDestMaxNumChars )
452  {
453  size_t uAvailableSize = ( in_uDestMaxNumChars - strlen( in_pDest ) - 1 );
454  strncat( in_pDest, in_pSrc, AkMin( uAvailableSize, strlen( in_pSrc ) ) );
455  }
456 
457  inline int SafeStrFormat(wchar_t * in_pDest, size_t in_uDestMaxNumChars, const wchar_t* in_pszFmt, ...)
458  {
459  va_list args;
460  va_start(args, in_pszFmt);
461  int r = vswprintf(in_pDest, in_uDestMaxNumChars, in_pszFmt, args);
462  va_end(args);
463  return r;
464  }
465 
466  inline int SafeStrFormat(char * in_pDest, size_t in_uDestMaxNumChars, const char* in_pszFmt, ...)
467  {
468  va_list args;
469  va_start(args, in_pszFmt);
470  int r = vsnprintf(in_pDest, in_uDestMaxNumChars, in_pszFmt, args);
471  va_end(args);
472  return r;
473  }
474 
475  /// Stack allocations.
476  #define AkAlloca( _size_ ) alloca( _size_ )
477 
478 
479 
480  /// Converts a wchar_t string to an AkOSChar string.
481  /// \remark On some platforms the AkOSChar string simply points to the same string,
482  /// on others a new buffer is allocated on the stack using AkAlloca. This means
483  /// you must make sure that:
484  /// - The source string stays valid and unmodified for as long as you need the
485  /// AkOSChar string (for cases where they point to the same string)
486  /// - The AkOSChar string is used within this scope only -- for example, do NOT
487  /// return that string from a function (for cases where it is allocated on the stack)
488  #define CONVERT_WIDE_TO_OSCHAR( _wstring_, _oscharstring_ ) \
489  _oscharstring_ = (AkOSChar*)AkAlloca( (1 + wcslen( _wstring_ )) * sizeof(AkOSChar) ); \
490  AKPLATFORM::AkWideCharToChar( _wstring_ , (AkUInt32)(1 + wcslen( _wstring_ )), (AkOSChar*)( _oscharstring_ ) )
491 
492 
493  /// Converts a char string to an AkOSChar string.
494  /// \remark On some platforms the AkOSChar string simply points to the same string,
495  /// on others a new buffer is allocated on the stack using AkAlloca. This means
496  /// you must make sure that:
497  /// - The source string stays valid and unmodified for as long as you need the
498  /// AkOSChar string (for cases where they point to the same string)
499  /// - The AkOSChar string is used within this scope only -- for example, do NOT
500  /// return that string from a function (for cases where it is allocated on the stack)
501  #define CONVERT_CHAR_TO_OSCHAR( _astring_, _oscharstring_ ) ( _oscharstring_ ) = (AkOSChar*)( _astring_ )
502 
503  /// Converts a AkOSChar string into wide char string.
504  /// \remark On some platforms the AkOSChar string simply points to the same string,
505  /// on others a new buffer is allocated on the stack using AkAlloca. This means
506  /// you must make sure that:
507  /// - The source string stays valid and unmodified for as long as you need the
508  /// AkOSChar string (for cases where they point to the same string)
509  /// - The AkOSChar string is used within this scope only -- for example, do NOT
510  /// return that string from a function (for cases where it is allocated on the stack)
511  #define CONVERT_OSCHAR_TO_WIDE( _osstring_, _wstring_ ) \
512  _wstring_ = (wchar_t*)AkAlloca((1+strlen(_osstring_)) * sizeof(wchar_t)); \
513  AKPLATFORM::AkCharToWideChar( _osstring_, (AkUInt32)(1 + strlen(_osstring_ )), _wstring_ )
514 
515  /// Converts a AkOSChar string into char string.
516  /// \remark On some platforms the AkOSChar string simply points to the same string,
517  /// on others a new buffer is allocated on the stack using AkAlloca. This means
518  /// you must make sure that:
519  /// - The source string stays valid and unmodified for as long as you need the
520  /// AkOSChar string (for cases where they point to the same string)
521  /// - The AkOSChar string is used within this scope only -- for example, do NOT
522  /// return that string from a function (for cases where it is allocated on the stack)
523  #define CONVERT_OSCHAR_TO_CHAR( _osstring_, _astring_ ) _astring_ = (char*)_osstring_
524 
525  /// Get the length, in characters, of a NULL-terminated AkUtf16 string
526  /// \return The length, in characters, of the specified string (excluding terminating NULL)
527  AkForceInline size_t AkUtf16StrLen( const AkUtf16* in_pStr )
528  {
529  return ( wcslen( in_pStr ) );
530  }
531 
532  /// Get the length, in characters, of a NULL-terminated AkOSChar string
533  /// \return The length, in characters, of the specified string (excluding terminating NULL)
534  AkForceInline size_t OsStrLen( const AkOSChar* in_pszString )
535  {
536  return ( strlen( in_pszString ) );
537  }
538 
539  /// AkOSChar version of sprintf().
540  #define AK_OSPRINTF snprintf
541 
542  /// Compare two NULL-terminated AkOSChar strings
543  /// \return
544  /// - < 0 if in_pszString1 < in_pszString2
545  /// - 0 if the two strings are identical
546  /// - > 0 if in_pszString1 > in_pszString2
547  /// \remark The comparison is case-sensitive
548  AkForceInline int OsStrCmp( const AkOSChar* in_pszString1, const AkOSChar* in_pszString2 )
549  {
550  return ( strcmp( in_pszString1, in_pszString2 ) );
551  }
552 
553  /// Compare two NULL-terminated AkOSChar strings up to the specified count of characters.
554  /// \return
555  /// - < 0 if in_pszString1 < in_pszString2
556  /// - 0 if the two strings are identical
557  /// - > 0 if in_pszString1 > in_pszString2
558  /// \remark The comparison is case-sensitive
559  inline int OsStrNCmp( const AkOSChar* in_pszString1, const AkOSChar* in_pszString2, size_t in_MaxCountSize )
560  {
561  return ( strncmp(in_pszString1, in_pszString2, in_MaxCountSize) );
562  }
563 
564  /// Detects whether the string represents an absolute path to a file
565  inline bool IsAbsolutePath(const AkOSChar* in_pszPath, size_t in_pathLen)
566  {
567  return in_pathLen >= 1 && in_pszPath[0] == '/';
568  }
569 
570  #define AK_UTF8_TO_OSCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::SafeStrCpy( in_pdDest, in_pSrc, in_MaxSize )
571  #define AK_UTF16_TO_WCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::SafeStrCpy( in_pdDest, in_pSrc, in_MaxSize )
572  #define AK_WCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::SafeStrCpy( in_pdDest, in_pSrc, in_MaxSize )
573  #define AK_UTF16_TO_OSCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkWideCharToChar( in_pSrc, in_MaxSize, in_pdDest )
574  #define AK_UTF16_TO_CHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkWideCharToChar( in_pSrc, in_MaxSize, in_pdDest )
575  #define AK_CHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkCharToWideChar( in_pSrc, in_MaxSize, in_pdDest )
576  #define AK_OSCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkCharToWideChar( in_pSrc, in_MaxSize, in_pdDest )
577 
578  // Use with AkOSChar.
579  #define AK_PATH_SEPARATOR "/"
580  #define AK_HOST_PATH_SEPARATOR "\\"
581  #define AK_LIBRARY_PREFIX ""
582  #define AK_DYNAMIC_LIBRARY_EXTENSION ".prx"
583 
584  #define AK_FILEHANDLE_TO_UINTPTR(_h) ((AkUIntPtr)_h)
585  #define AK_SET_FILEHANDLE_TO_UINTPTR(_h,_u) _h = (AkFileHandle)_u
586 
587  /// Support to fetch the CPUID for the platform. Only valid for X86 targets
588  /// \remark Note that IAkProcessorFeatures should be preferred to fetch this data
589  /// as it will have already translated the feature bits into AK-relevant enums
590  inline void CPUID(AkUInt32 in_uLeafOpcode, AkUInt32 in_uSubLeafOpcode, unsigned int out_uCPUFeatures[4])
591  {
592  __get_cpuid_count( in_uLeafOpcode, in_uSubLeafOpcode,
593  &out_uCPUFeatures[0],
594  &out_uCPUFeatures[1],
595  &out_uCPUFeatures[2],
596  &out_uCPUFeatures[3]);
597  }
598 }
599 
600 #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:134
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:131
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:133
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:90
AkForceInline bool AkIsValidThread(AkThread *in_pThread)
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)
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