Version
menu_open
link
Target Platform(s):
Wwise SDK 2019.2.15
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  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 "malloc.h"
34 #include <windows.h>
35 //#define AK_ENABLE_PERF_RECORDING
36 #if defined(AK_ENABLE_PERF_RECORDING)
37 #include <stdio.h>
38 #endif
39 
40 #if defined(_WIN64)
41 // on 64 bit, removes warning C4985: 'ceil': attributes not present on previous declaration.
42 // see http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=294649
43 #include <math.h>
44 #endif // _WIN64
45 #include <intrin.h>
46 
47 //-----------------------------------------------------------------------------
48 // Platform-specific thread properties definition.
49 //-----------------------------------------------------------------------------
50 struct AkThreadProperties
51 {
52  int nPriority; ///< Thread priority
53 #ifdef AK_WIN_UNIVERSAL_APP
54  PROCESSOR_NUMBER processorNumber;///< Ideal processor (passed to SetThreadIdealProcessorEx)
55 #else
56  AkUInt32 dwAffinityMask; ///< Affinity mask
57 #endif
58  AkUInt32 uStackSize; ///< Thread stack size.
59 };
60 
61 //-----------------------------------------------------------------------------
62 // External variables.
63 //-----------------------------------------------------------------------------
64 // g_fFreqRatio is used by time helpers to return time values in milliseconds.
65 // It is declared and updated by the sound engine.
66 namespace AK
67 {
68  extern AkReal32 g_fFreqRatio;
69 }
70 
71 //-----------------------------------------------------------------------------
72 // Defines for Win32.
73 //-----------------------------------------------------------------------------
74 #define AK_DECLARE_THREAD_ROUTINE( FuncName ) DWORD WINAPI FuncName(LPVOID lpParameter)
75 #define AK_THREAD_RETURN( _param_ ) return (_param_);
76 #define AK_THREAD_ROUTINE_PARAMETER lpParameter
77 #define AK_GET_THREAD_ROUTINE_PARAMETER_PTR(type) reinterpret_cast<type*>( AK_THREAD_ROUTINE_PARAMETER )
78 #define AK_RETURN_THREAD_OK 0x00000000
79 #define AK_RETURN_THREAD_ERROR 0x00000001
80 #define AK_DEFAULT_STACK_SIZE (128*1024)
81 #define AK_THREAD_PRIORITY_NORMAL THREAD_PRIORITY_NORMAL
82 #define AK_THREAD_PRIORITY_ABOVE_NORMAL THREAD_PRIORITY_ABOVE_NORMAL
83 #define AK_THREAD_PRIORITY_TIME_CRITICAL THREAD_PRIORITY_TIME_CRITICAL
84 #define AK_THREAD_MODE_BACKGROUND_BEGIN THREAD_MODE_BACKGROUND_BEGIN
85 
86 // NULL objects
87 #define AK_NULL_THREAD NULL
88 
89 #define AK_INFINITE INFINITE
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  // Simple automatic event API
98  // ------------------------------------------------------------------
99 
100  /// Platform Independent Helper
101  inline void AkClearEvent( AkEvent & out_event )
102  {
103  out_event = NULL;
104  }
105 
106  /// Platform Independent Helper
107  inline AKRESULT AkCreateEvent( AkEvent & out_event )
108  {
109 #ifdef AK_USE_UWP_API
110  out_event = CreateEventEx(nullptr, nullptr, 0, STANDARD_RIGHTS_ALL|EVENT_MODIFY_STATE);
111 #else
112  out_event = ::CreateEvent( NULL, // No security attributes
113  false, // Reset type: automatic
114  false, // Initial signaled state: not signaled
115  NULL // No name
116  );
117 #endif
118  return ( out_event ) ? AK_Success : AK_Fail;
119  }
120 
121  /// Platform Independent Helper
122  inline void AkDestroyEvent( AkEvent & io_event )
123  {
124  if ( io_event )
125  ::CloseHandle( io_event );
126  io_event = NULL;
127  }
128 
129  /// Platform Independent Helper
130  inline void AkWaitForEvent( AkEvent & in_event )
131  {
132 #ifdef AK_USE_UWP_API
133 #ifdef AK_ENABLE_ASSERTS
134  DWORD dwWaitResult =
135 #endif // AK_ENABLE_ASSERTS
136  ::WaitForSingleObjectEx( in_event, INFINITE, FALSE );
137  AKASSERT( dwWaitResult == WAIT_OBJECT_0 );
138 #else
139  AKVERIFY( ::WaitForSingleObject( in_event, INFINITE ) == WAIT_OBJECT_0 );
140 #endif
141  }
142 
143  /// Platform Independent Helper
144  inline void AkSignalEvent( const AkEvent & in_event )
145  {
146  AKVERIFY( ::SetEvent( in_event ) );
147  }
148 
149  // Virtual Memory
150  // ------------------------------------------------------------------
151 
152 #ifdef AK_WIN_UNIVERSAL_APP
153  AkForceInline void* AllocVM(size_t size, size_t* /*extra*/)
154  {
155  return VirtualAllocFromApp(NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
156  }
157 #else
158  AkForceInline void* AllocVM(size_t size, size_t* /*extra*/)
159  {
160  return VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
161  }
162 
163 #endif
164  AkForceInline void FreeVM(void* address, size_t size, size_t /*extra*/, size_t release)
165  {
166  VirtualFree(address, release ? 0 : size, release ? MEM_RELEASE : MEM_DECOMMIT);
167  }
168 
169  // Threads
170  // ------------------------------------------------------------------
171 
172  /// Platform Independent Helper
173  inline bool AkIsValidThread( AkThread * in_pThread )
174  {
175  return (*in_pThread != AK_NULL_THREAD);
176  }
177 
178  /// Platform Independent Helper
179  inline void AkClearThread( AkThread * in_pThread )
180  {
181  *in_pThread = AK_NULL_THREAD;
182  }
183 
184  /// Platform Independent Helper
185  inline void AkCloseThread( AkThread * in_pThread )
186  {
187  AKASSERT( in_pThread );
188  AKASSERT( *in_pThread );
189  AKVERIFY( ::CloseHandle( *in_pThread ) );
190  AkClearThread( in_pThread );
191  }
192 
193 #define AkExitThread( _result ) return _result;
194 
195  /// Platform Independent Helper
196  inline void AkGetDefaultThreadProperties( AkThreadProperties & out_threadProperties )
197  {
198  out_threadProperties.nPriority = AK_THREAD_PRIORITY_NORMAL;
199  out_threadProperties.uStackSize= AK_DEFAULT_STACK_SIZE;
200 #ifdef AK_WIN_UNIVERSAL_APP
201  out_threadProperties.processorNumber.Group = 0;
202  out_threadProperties.processorNumber.Number = MAXIMUM_PROCESSORS;
203  out_threadProperties.processorNumber.Reserved = 0;
204 #else
205  out_threadProperties.dwAffinityMask = 0;
206 #endif
207  }
208 
209  /// Set the name of a thread: see http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
210  inline void AkSetThreadName( DWORD in_dwThreadID, LPCSTR in_szThreadName )
211  {
212  const DWORD MS_VC_EXCEPTION=0x406D1388;
213 
214 #pragma pack(push,8)
215  typedef struct tagTHREADNAME_INFO
216  {
217  DWORD dwType;
218  LPCSTR szName;
219  DWORD dwThreadID;
220  DWORD dwFlags;
221  } THREADNAME_INFO;
222 #pragma pack(pop)
223 
224  THREADNAME_INFO info;
225  info.dwType = 0x1000;
226  info.szName = in_szThreadName;
227  info.dwThreadID = in_dwThreadID;
228  info.dwFlags = 0;
229 
230  __try
231  {
232  RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
233  }
234 #pragma warning(suppress: 6312 6322)
235  __except(EXCEPTION_CONTINUE_EXECUTION)
236  {
237  }
238  }
239 
240  /// Platform Independent Helper
241  inline void AkCreateThread(
242  AkThreadRoutine pStartRoutine, // Thread routine.
243  void * pParams, // Routine params.
244  const AkThreadProperties & in_threadProperties, // Properties. NULL for default.
245  AkThread * out_pThread, // Returned thread handle.
246  const char * in_szThreadName ) // Opt thread name.
247  {
248  AKASSERT( out_pThread != NULL );
249  AKASSERT( (in_threadProperties.nPriority >= THREAD_PRIORITY_LOWEST && in_threadProperties.nPriority <= THREAD_PRIORITY_HIGHEST)
250  || ( in_threadProperties.nPriority == THREAD_PRIORITY_TIME_CRITICAL )
251  || ( in_threadProperties.nPriority == THREAD_MODE_BACKGROUND_BEGIN ) );
252 
253  DWORD dwThreadID;
254  *out_pThread = ::CreateThread( NULL, // No security attributes
255  in_threadProperties.uStackSize, // StackSize (0 uses system default)
256  pStartRoutine, // Thread start routine
257  pParams, // Thread function parameter
258  0, // Creation flags: create running
259  &dwThreadID );
260 
261  // ::CreateThread() return NULL if it fails.
262  if ( !*out_pThread )
263  {
264  AkClearThread( out_pThread );
265  return;
266  }
267 
268  // Set thread name.
269  AkSetThreadName( dwThreadID, in_szThreadName );
270 
271  // Set properties.
272  if ( !::SetThreadPriority( *out_pThread, in_threadProperties.nPriority ) &&
273  in_threadProperties.nPriority != THREAD_MODE_BACKGROUND_BEGIN )
274  {
275  AKASSERT( !"Failed setting thread priority" );
276  AkCloseThread( out_pThread );
277  return;
278  }
279 #ifdef AK_WIN_UNIVERSAL_APP
280  if ( in_threadProperties.processorNumber.Number != MAXIMUM_PROCESSORS)
281  {
282  if ( !SetThreadIdealProcessorEx( *out_pThread, const_cast<PPROCESSOR_NUMBER>(&in_threadProperties.processorNumber), NULL) )
283  {
284  AKASSERT( !"Failed setting thread ideal processor" );
285  AkCloseThread( out_pThread );
286  }
287  }
288 #else
289  if (in_threadProperties.dwAffinityMask)
290  {
291  if (!::SetThreadAffinityMask(*out_pThread, in_threadProperties.dwAffinityMask))
292  {
293  AKASSERT(!"Failed setting thread affinity mask");
294  AkCloseThread(out_pThread);
295  }
296  }
297 #endif
298  }
299 
300  /// Platform Independent Helper
301  inline void AkWaitForSingleThread( AkThread * in_pThread )
302  {
303  AKASSERT( in_pThread );
304  AKASSERT( *in_pThread );
305 #ifdef AK_USE_UWP_API
306  ::WaitForSingleObjectEx( *in_pThread, INFINITE, FALSE );
307 #else
308  ::WaitForSingleObject( *in_pThread, INFINITE );
309 #endif
310  }
311 
312  /// Returns the calling thread's ID.
313  inline AkThreadID CurrentThread()
314  {
315  return ::GetCurrentThreadId();
316  }
317 
318  /// Platform Independent Helper
319  inline void AkSleep( AkUInt32 in_ulMilliseconds )
320  {
321  ::Sleep( in_ulMilliseconds );
322  }
323 
324  // Optimized memory functions
325  // --------------------------------------------------------------------
326 
327  /// Platform Independent Helper
328  inline void AkMemCpy( void * pDest, const void * pSrc, AkUInt32 uSize )
329  {
330  memcpy( pDest, pSrc, uSize );
331  }
332 
333  /// Platform Independent Helper
334  inline void AkMemSet( void * pDest, AkInt32 iVal, AkUInt32 uSize )
335  {
336  memset( pDest, iVal, uSize );
337  }
338 
339  // Time functions
340  // ------------------------------------------------------------------
341 
342  /// Platform Independent Helper
343  inline void PerformanceCounter( AkInt64 * out_piLastTime )
344  {
345  ::QueryPerformanceCounter( (LARGE_INTEGER*)out_piLastTime );
346  }
347 
348  /// Platform Independent Helper
349  inline void PerformanceFrequency( AkInt64 * out_piFreq )
350  {
351  ::QueryPerformanceFrequency( (LARGE_INTEGER*)out_piFreq );
352  }
353 
354  /// Platform Independent Helper
355  inline void UpdatePerformanceFrequency()
356  {
357  AkInt64 iFreq;
358  PerformanceFrequency( &iFreq );
359  AK::g_fFreqRatio = (AkReal32)((AkReal64)iFreq / 1000);
360  }
361 
362  /// Returns a time range in milliseconds, using the sound engine's updated count->milliseconds ratio.
363  inline AkReal32 Elapsed( const AkInt64 & in_iNow, const AkInt64 & in_iStart )
364  {
365  return ( in_iNow - in_iStart ) / AK::g_fFreqRatio;
366  }
367 
368  /// String conversion helper. If io_pszAnsiString is null, the function returns the required size.
369  inline AkInt32 AkWideCharToChar( const wchar_t* in_pszUnicodeString,
370  AkUInt32 in_uiOutBufferSize,
371  char* io_pszAnsiString )
372  {
373  if(!io_pszAnsiString)
374  return WideCharToMultiByte(CP_UTF8, 0, in_pszUnicodeString, -1, NULL, 0, NULL, NULL);
375 
376  int iWritten = ::WideCharToMultiByte(CP_UTF8, // code page
377  0, // performance and mapping flags
378  in_pszUnicodeString, // wide-character string
379  (int)AkMin( ( (AkUInt32)wcslen( in_pszUnicodeString )), in_uiOutBufferSize-1 ), // number of chars in string : -1 = NULL terminated string.
380  io_pszAnsiString, // buffer for new string
381  in_uiOutBufferSize, // size of buffer
382  NULL, // default for unmappable chars
383  NULL); // set when default char used
384  io_pszAnsiString[iWritten] = 0;
385  return iWritten;
386  }
387 
388  /// String conversion helper
389  inline AkInt32 AkCharToWideChar( const char* in_pszAnsiString,
390  AkUInt32 in_uiOutBufferSize,
391  void* io_pvUnicodeStringBuffer )
392  {
393  return ::MultiByteToWideChar( CP_UTF8, // code page
394  0, // performance and mapping flags
395  in_pszAnsiString, // wide-character string
396  -1, // number of chars in string : -1 = NULL terminated string.
397  (wchar_t*)io_pvUnicodeStringBuffer, // buffer for new string
398  in_uiOutBufferSize); // size of buffer
399  }
400 
401  /// String conversion helper
402  inline AkInt32 AkUtf8ToWideChar( const char* in_pszUtf8String,
403  AkUInt32 in_uiOutBufferSize,
404  void* io_pvUnicodeStringBuffer )
405  {
406  return ::MultiByteToWideChar( CP_UTF8, // code page
407  0, // performance and mapping flags
408  in_pszUtf8String, // wide-character string
409  -1, // number of chars in string : -1 = NULL terminated string.
410  (wchar_t*)io_pvUnicodeStringBuffer, // buffer for new string
411  in_uiOutBufferSize); // size of buffer
412  }
413 
414  /// Safe unicode string copy.
415  inline void SafeStrCpy( wchar_t * in_pDest, const wchar_t* in_pSrc, size_t in_uDestMaxNumChars )
416  {
417  size_t iSizeCopy = AkMin( in_uDestMaxNumChars - 1, wcslen( in_pSrc ) + 1 );
418  wcsncpy_s( in_pDest, in_uDestMaxNumChars, in_pSrc, iSizeCopy );
419  in_pDest[iSizeCopy] = '\0';
420  }
421 
422  /// Safe string copy.
423  inline void SafeStrCpy( char * in_pDest, const char* in_pSrc, size_t in_uDestMaxNumChars )
424  {
425  size_t iSizeCopy = AkMin( in_uDestMaxNumChars - 1, strlen( in_pSrc ) + 1 );
426  strncpy_s( in_pDest, in_uDestMaxNumChars, in_pSrc, iSizeCopy );
427  in_pDest[iSizeCopy] = '\0';
428  }
429 
430  /// Safe unicode string concatenation.
431  inline void SafeStrCat( wchar_t * in_pDest, const wchar_t* in_pSrc, size_t in_uDestMaxNumChars )
432  {
433  int iAvailableSize = (int)( in_uDestMaxNumChars - wcslen( in_pDest ) - 1 );
434  wcsncat_s( in_pDest, in_uDestMaxNumChars, in_pSrc, AkMin( iAvailableSize, (int)wcslen( in_pSrc ) ) );
435  }
436 
437  /// Safe string concatenation.
438  inline void SafeStrCat( char * in_pDest, const char* in_pSrc, size_t in_uDestMaxNumChars )
439  {
440  int iAvailableSize = (int)( in_uDestMaxNumChars - strlen( in_pDest ) - 1 );
441  strncat_s( in_pDest, in_uDestMaxNumChars, in_pSrc, AkMin( iAvailableSize, (int)strlen( in_pSrc ) ) );
442  }
443 
444  /// Stack allocations.
445  #define AkAlloca( _size_ ) _alloca( _size_ )
446 
447  /// Output a debug message on the console
448 #if ! defined(AK_OPTIMIZED)
449  inline void OutputDebugMsg( const wchar_t* in_pszMsg )
450  {
451  OutputDebugStringW( in_pszMsg );
452  }
453 
454  /// Output a debug message on the console
455  inline void OutputDebugMsg( const char* in_pszMsg )
456  {
457  OutputDebugStringA( in_pszMsg );
458  }
459 #else
460  inline void OutputDebugMsg( const wchar_t* ){}
461  inline void OutputDebugMsg( const char* ){}
462 #endif
463 
464  /// Converts a wchar_t string to an AkOSChar string.
465  /// \remark On some platforms the AkOSChar string simply points to the same string,
466  /// on others a new buffer is allocated on the stack using AkAlloca. This means
467  /// you must make sure that:
468  /// - The source string stays valid and unmodified for as long as you need the
469  /// AkOSChar string (for cases where they point to the same string)
470  /// - The AkOSChar string is used within this scope only -- for example, do NOT
471  /// return that string from a function (for cases where it is allocated on the stack)
472  #define CONVERT_WIDE_TO_OSCHAR( _wstring_, _oscharstring_ ) ( _oscharstring_ ) = (AkOSChar*)( _wstring_ )
473 
474  /// Converts a char string to an AkOSChar string.
475  /// \remark On some platforms the AkOSChar string simply points to the same string,
476  /// on others a new buffer is allocated on the stack using AkAlloca. This means
477  /// you must make sure that:
478  /// - The source string stays valid and unmodified for as long as you need the
479  /// AkOSChar string (for cases where they point to the same string)
480  /// - The AkOSChar string is used within this scope only -- for example, do NOT
481  /// return that string from a function (for cases where it is allocated on the stack)
482  #define CONVERT_CHAR_TO_OSCHAR( _astring_, _oscharstring_ ) \
483  _oscharstring_ = (AkOSChar*)AkAlloca( (1 + strlen( _astring_ )) * sizeof(AkOSChar)); \
484  AKPLATFORM::AkCharToWideChar( _astring_, (AkUInt32)(1 + strlen(_astring_ )), (AkOSChar*)( _oscharstring_ ) )
485 
486  /// Converts a AkOSChar string into wide char string.
487  /// \remark On some platforms the AkOSChar string simply points to the same string,
488  /// on others a new buffer is allocated on the stack using AkAlloca. This means
489  /// you must make sure that:
490  /// - The source string stays valid and unmodified for as long as you need the
491  /// AkOSChar string (for cases where they point to the same string)
492  /// - The AkOSChar string is used within this scope only -- for example, do NOT
493  /// return that string from a function (for cases where it is allocated on the stack)
494  #define CONVERT_OSCHAR_TO_WIDE( _osstring_, _wstring_ ) _wstring_ = _osstring_
495 
496  /// Converts a AkOSChar string into char string.
497  /// \remark On some platforms the AkOSChar string simply points to the same string,
498  /// on others a new buffer is allocated on the stack using AkAlloca. This means
499  /// you must make sure that:
500  /// - The source string stays valid and unmodified for as long as you need the
501  /// AkOSChar string (for cases where they point to the same string)
502  /// - The AkOSChar string is used within this scope only -- for example, do NOT
503  /// return that string from a function (for cases where it is allocated on the stack)
504  #define CONVERT_OSCHAR_TO_CHAR( _osstring_, _astring_ ) \
505  _astring_ = (char*)AkAlloca( 1 + AKPLATFORM::AkWideCharToChar( _osstring_, 0, NULL )); \
506  AKPLATFORM::AkWideCharToChar( _osstring_, AkUInt32(1 + AKPLATFORM::AkWideCharToChar( _osstring_, 0, NULL )), _astring_ );
507 
508  /// Get the length, in characters, of a NULL-terminated AkUtf16 string
509  /// \return The length, in characters, of the specified string (excluding terminating NULL)
510  inline size_t AkUtf16StrLen( const AkUtf16* in_pStr )
511  {
512  return ( wcslen( in_pStr ) );
513  }
514 
515  /// Get the length, in characters, of a NULL-terminated AkOSChar string
516  /// \return The length, in characters, of the specified string (excluding terminating NULL)
517  inline size_t OsStrLen( const AkOSChar* in_pszString )
518  {
519  return ( wcslen( in_pszString ) );
520  }
521 
522  /// AkOSChar version of sprintf().
523  #define AK_OSPRINTF swprintf_s
524 
525  /// Compare two NULL-terminated AkOSChar strings
526  /// \return
527  /// - < 0 if in_pszString1 < in_pszString2
528  /// - 0 if the two strings are identical
529  /// - > 0 if in_pszString1 > in_pszString2
530  /// \remark The comparison is case-sensitive
531  inline int OsStrCmp( const AkOSChar* in_pszString1, const AkOSChar* in_pszString2 )
532  {
533  return ( wcscmp( in_pszString1, in_pszString2 ) );
534  }
535 
536  /// Compare two NULL-terminated AkOSChar strings up to the specified count of characters.
537  /// \return
538  /// - < 0 if in_pszString1 < in_pszString2
539  /// - 0 if the two strings are identical
540  /// - > 0 if in_pszString1 > in_pszString2
541  /// \remark The comparison is case-sensitive
542  inline int OsStrNCmp( const AkOSChar* in_pszString1, const AkOSChar* in_pszString2, size_t in_MaxCountSize)
543  {
544  return wcsncmp(in_pszString1, in_pszString2, in_MaxCountSize);
545  }
546 
547  #define AK_UTF16_TO_WCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::SafeStrCpy( in_pdDest, in_pSrc, in_MaxSize )
548  #define AK_WCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::SafeStrCpy( in_pdDest, in_pSrc, in_MaxSize )
549  #define AK_UTF16_TO_OSCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::SafeStrCpy( in_pdDest, in_pSrc, in_MaxSize )
550  #define AK_UTF16_TO_CHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkWideCharToChar( in_pSrc, in_MaxSize, in_pdDest )
551  #define AK_CHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkCharToWideChar( in_pSrc, in_MaxSize, in_pdDest )
552  #define AK_OSCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::SafeStrCpy( in_pdDest, in_pSrc, in_MaxSize )
553 
554  // Use with AkOSChar.
555  #define AK_PATH_SEPARATOR (L"\\")
556  #define AK_LIBRARY_PREFIX (L"")
557  #define AK_DYNAMIC_LIBRARY_EXTENSION (L".dll")
558 
559  #if defined(AK_ENABLE_PERF_RECORDING)
560 
561  static AkUInt32 g_uAkPerfRecExecCount = 0;
562  static AkReal32 g_fAkPerfRecExecTime = 0.f;
563 
564  #define AK_PERF_RECORDING_RESET() \
565  AKPLATFORM::g_uAkPerfRecExecCount = 0;\
566  AKPLATFORM::g_fAkPerfRecExecTime = 0.f;
567 
568  #define AK_PERF_RECORDING_START( __StorageName__, __uExecutionCountStart__, __uExecutionCountStop__ ) \
569  AkInt64 iAkPerfRecTimeBefore; \
570  if ( (AKPLATFORM::g_uAkPerfRecExecCount >= (__uExecutionCountStart__)) && (AKPLATFORM::g_uAkPerfRecExecCount <= (__uExecutionCountStop__)) ) \
571  AKPLATFORM::PerformanceCounter( &iAkPerfRecTimeBefore );
572 
573  #define AK_PERF_RECORDING_STOP( __StorageName__, __uExecutionCountStart__, __uExecutionCountStop__ ) \
574  if ( (AKPLATFORM::g_uAkPerfRecExecCount >= (__uExecutionCountStart__)) && (AKPLATFORM::g_uAkPerfRecExecCount <= (__uExecutionCountStop__)) ) \
575  { \
576  AkInt64 iAkPerfRecTimeAfter; \
577  AKPLATFORM::PerformanceCounter( &iAkPerfRecTimeAfter ); \
578  AKPLATFORM::g_fAkPerfRecExecTime += AKPLATFORM::Elapsed( iAkPerfRecTimeAfter, iAkPerfRecTimeBefore ); \
579  if ( AKPLATFORM::g_uAkPerfRecExecCount == (__uExecutionCountStop__) ) \
580  { \
581  AkReal32 fAverageExecutionTime = AKPLATFORM::g_fAkPerfRecExecTime/((__uExecutionCountStop__)-(__uExecutionCountStart__)); \
582  char str[256]; \
583  sprintf_s(str, 256, "%s average execution time: %f\n", __StorageName__, fAverageExecutionTime); \
584  AKPLATFORM::OutputDebugMsg( str ); \
585  } \
586  } \
587  AKPLATFORM::g_uAkPerfRecExecCount++;
588  #endif // AK_ENABLE_PERF_RECORDING
589 
590 #if (defined(AK_CPU_X86_64) || defined(AK_CPU_X86))
591  /// Support to fetch the CPUID for the platform. Only valid for X86 targets
592  /// \remark Note that IAkProcessorFeatures should be preferred to fetch this data
593  /// as it will have already translated the feature bits into AK-relevant enums
594  inline void CPUID(AkUInt32 in_uLeafOpcode, AkUInt32 in_uSubLeafOpcode, unsigned int out_uCPUFeatures[4])
595  {
596  __cpuidex((int*)out_uCPUFeatures, in_uLeafOpcode, in_uSubLeafOpcode);
597  }
598 #endif
599 }
600 
601 #endif // _AK_PLATFORM_FUNCS_H_
size_t AkUtf16StrLen(const AkUtf16 *in_pStr)
Definition: AkPlatformFuncs.h:496
Audiokinetic namespace.
@ AK_Fail
The operation failed.
Definition: AkTypes.h:125
#define AK_THREAD_PRIORITY_NORMAL
Definition: AkPlatformFuncs.h:81
semaphore_t AkEvent
Definition: AkTypes.h:77
#define AK_DEFAULT_STACK_SIZE
Definition: AkPlatformFuncs.h:80
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:49
void AkClearEvent(AkEvent &out_event)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:52
ScePthread AkThreadID
Thread ID.
Definition: AkTypes.h:107
void AkWaitForEvent(AkEvent &in_event)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:101
void *(* AkThreadRoutine)(void *lpThreadParameter)
Thread routine.
Definition: AkTypes.h:108
AkForceInline void UpdatePerformanceFrequency()
Platform Independent Helper.
Definition: AkPlatformFuncs.h:361
wchar_t AkUtf16
Definition: AkTypes.h:113
AKRESULT
Standard function call result.
Definition: AkTypes.h:122
void OutputDebugMsg(const char *in_pszMsg)
Output a debug message on the console (Ansi string)
Definition: AkPlatformFuncs.h:70
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
char AkOSChar
Generic character string.
Definition: AkTypes.h:101
#define NULL
Definition: AkTypes.h:49
AkThreadID CurrentThread()
Returns the calling thread's ID.
Definition: AkPlatformFuncs.h:318
@ AK_Success
The operation was successful.
Definition: AkTypes.h:124
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
AkUInt32 uStackSize
Thread stack size.
Definition: AkPlatformFuncs.h:58
double AkReal64
64-bit floating point
Definition: AkTypes.h:104
void AkDestroyEvent(AkEvent &io_event)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:81
AkForceInline bool AkIsValidThread(AkThread *in_pThread)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:215
int64_t AkInt64
Signed 64-bit integer.
Definition: AkTypes.h:99
AkForceInline void AkMemCpy(void *pDest, const void *pSrc, AkUInt32 uSize)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:333
#define AKASSERT(Condition)
Definition: AkAssert.h:76
#define AKVERIFY(x)
Definition: AkAssert.h:78
AkForceInline void AkSleep(AkUInt32 in_ulMilliseconds)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:324
int32_t AkInt32
Signed 32-bit integer.
Definition: AkTypes.h:98
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
#define AK_NULL_THREAD
Definition: AkPlatformFuncs.h:87
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:50
AkReal32 g_fFreqRatio
Definition: AkPlatformFuncs.h:63
#define AkMin(x1, x2)
Definition: AkPlatformFuncs.h:92
AKRESULT AkCreateEvent(AkEvent &out_event)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:58
AkForceInline void SafeStrCpy(wchar_t *in_pDest, const wchar_t *in_pSrc, size_t in_uDestMaxNumChars)
Safe unicode string copy.
Definition: AkPlatformFuncs.h:415
AkUInt32 dwAffinityMask
Affinity mask.
Definition: AkPlatformFuncs.h:56
size_t uStackSize
Thread stack size.
Definition: AkPlatformFuncs.h:51
void PerformanceFrequency(AkInt64 *out_piFreq)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:46
float AkReal32
32-bit floating point
Definition: AkTypes.h:103
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 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:112
AkForceInline AkInt32 AkUtf8ToWideChar(const char *in_pszUtf8String, AkUInt32 in_uiOutBufferSize, void *io_pvUnicodeStringBuffer)
String conversion helper.
Definition: AkPlatformFuncs.h:407
uint32_t AkUInt32
Unsigned 32-bit integer.
Definition: AkTypes.h:85
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
#define AkForceInline
Definition: AkTypes.h:62
void AkSetThreadName(DWORD in_dwThreadID, LPCSTR in_szThreadName)
Set the name of a thread: see http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx.
Definition: AkPlatformFuncs.h:210
AkForceInline size_t OsStrLen(const AkOSChar *in_pszString)
Definition: AkPlatformFuncs.h:503
ScePthread AkThread
Thread handle.
Definition: AkTypes.h:106
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

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