Table of Contents

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