pa_util.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #ifndef PA_UTIL_H
  2. #define PA_UTIL_H
  3. /*
  4. * $Id: pa_util.h 1584 2011-02-02 18:58:17Z rossb $
  5. * Portable Audio I/O Library implementation utilities header
  6. * common implementation utilities and interfaces
  7. *
  8. * Based on the Open Source API proposed by Ross Bencina
  9. * Copyright (c) 1999-2008 Ross Bencina, Phil Burk
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining
  12. * a copy of this software and associated documentation files
  13. * (the "Software"), to deal in the Software without restriction,
  14. * including without limitation the rights to use, copy, modify, merge,
  15. * publish, distribute, sublicense, and/or sell copies of the Software,
  16. * and to permit persons to whom the Software is furnished to do so,
  17. * subject to the following conditions:
  18. *
  19. * The above copyright notice and this permission notice shall be
  20. * included in all copies or substantial portions of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  25. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  26. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  27. * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. */
  30. /*
  31. * The text above constitutes the entire PortAudio license; however,
  32. * the PortAudio community also makes the following non-binding requests:
  33. *
  34. * Any person wishing to distribute modifications to the Software is
  35. * requested to send the modifications to the original developer so that
  36. * they can be incorporated into the canonical version. It is also
  37. * requested that these non-binding requests be included along with the
  38. * license above.
  39. */
  40. /** @file
  41. @ingroup common_src
  42. @brief Prototypes for utility functions used by PortAudio implementations.
  43. Some functions declared here are defined in pa_front.c while others
  44. are implemented separately for each platform.
  45. */
  46. #include "portaudio.h"
  47. #ifdef __cplusplus
  48. extern "C"
  49. {
  50. #endif /* __cplusplus */
  51. struct PaUtilHostApiRepresentation;
  52. /** Retrieve a specific host API representation. This function can be used
  53. by implementations to retrieve a pointer to their representation in
  54. host api specific extension functions which aren't passed a rep pointer
  55. by pa_front.c.
  56. @param hostApi A pointer to a host API represenation pointer. Apon success
  57. this will receive the requested representation pointer.
  58. @param type A valid host API type identifier.
  59. @returns An error code. If the result is PaNoError then a pointer to the
  60. requested host API representation will be stored in *hostApi. If the host API
  61. specified by type is not found, this function returns paHostApiNotFound.
  62. */
  63. PaError PaUtil_GetHostApiRepresentation( struct PaUtilHostApiRepresentation **hostApi,
  64. PaHostApiTypeId type );
  65. /** Convert a PortAudio device index into a host API specific device index.
  66. @param hostApiDevice Pointer to a device index, on success this will recieve the
  67. converted device index value.
  68. @param device The PortAudio device index to convert.
  69. @param hostApi The host api which the index should be converted for.
  70. @returns On success returns PaNoError and places the converted index in the
  71. hostApiDevice parameter.
  72. */
  73. PaError PaUtil_DeviceIndexToHostApiDeviceIndex(
  74. PaDeviceIndex *hostApiDevice, PaDeviceIndex device,
  75. struct PaUtilHostApiRepresentation *hostApi );
  76. /** Set the host error information returned by Pa_GetLastHostErrorInfo. This
  77. function and the paUnanticipatedHostError error code should be used as a
  78. last resort. Implementors should use existing PA error codes where possible,
  79. or nominate new ones. Note that at it is always better to use
  80. PaUtil_SetLastHostErrorInfo() and paUnanticipatedHostError than to return an
  81. ambiguous or inaccurate PaError code.
  82. @param hostApiType The host API which encountered the error (ie of the caller)
  83. @param errorCode The error code returned by the native API function.
  84. @param errorText A string describing the error. PaUtil_SetLastHostErrorInfo
  85. makes a copy of the string, so it is not necessary for the pointer to remain
  86. valid after the call to PaUtil_SetLastHostErrorInfo() returns.
  87. */
  88. void PaUtil_SetLastHostErrorInfo( PaHostApiTypeId hostApiType, long errorCode,
  89. const char *errorText );
  90. /* the following functions are implemented in a platform platform specific
  91. .c file
  92. */
  93. /** Allocate size bytes, guaranteed to be aligned to a FIXME byte boundary */
  94. void *PaUtil_AllocateMemory( long size );
  95. /** Realease block if non-NULL. block may be NULL */
  96. void PaUtil_FreeMemory( void *block );
  97. /** Return the number of currently allocated blocks. This function can be
  98. used for detecting memory leaks.
  99. @note Allocations will only be tracked if PA_TRACK_MEMORY is #defined. If
  100. it isn't, this function will always return 0.
  101. */
  102. int PaUtil_CountCurrentlyAllocatedBlocks( void );
  103. /** Initialize the clock used by PaUtil_GetTime(). Call this before calling
  104. PaUtil_GetTime.
  105. @see PaUtil_GetTime
  106. */
  107. void PaUtil_InitializeClock( void );
  108. /** Return the system time in seconds. Used to implement CPU load functions
  109. @see PaUtil_InitializeClock
  110. */
  111. double PaUtil_GetTime( void );
  112. /* void Pa_Sleep( long msec ); must also be implemented in per-platform .c file */
  113. #ifdef __cplusplus
  114. }
  115. #endif /* __cplusplus */
  116. #endif /* PA_UTIL_H */