FAPOBase.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* FAudio - XAudio Reimplementation for FNA
  2. *
  3. * Copyright (c) 2011-2021 Ethan Lee, Luigi Auriemma, and the MonoGame Team
  4. *
  5. * This software is provided 'as-is', without any express or implied warranty.
  6. * In no event will the authors be held liable for any damages arising from
  7. * the use of this software.
  8. *
  9. * Permission is granted to anyone to use this software for any purpose,
  10. * including commercial applications, and to alter it and redistribute it
  11. * freely, subject to the following restrictions:
  12. *
  13. * 1. The origin of this software must not be misrepresented; you must not
  14. * claim that you wrote the original software. If you use this software in a
  15. * product, an acknowledgment in the product documentation would be
  16. * appreciated but is not required.
  17. *
  18. * 2. Altered source versions must be plainly marked as such, and must not be
  19. * misrepresented as being the original software.
  20. *
  21. * 3. This notice may not be removed or altered from any source distribution.
  22. *
  23. * Ethan "flibitijibibo" Lee <flibitijibibo@flibitijibibo.com>
  24. *
  25. */
  26. /* This file has no documentation since the MSDN docs are still perfectly fine:
  27. * https://docs.microsoft.com/en-us/windows/desktop/api/xapobase/
  28. *
  29. * Of course, the APIs aren't exactly the same since XAPO is super dependent on
  30. * C++. Instead, we use a struct full of functions to mimic a vtable.
  31. *
  32. * To mimic the CXAPOParametersBase experience, initialize the object like this:
  33. *
  34. * extern FAPORegistrationProperties MyFAPOProperties;
  35. * extern int32_t producer;
  36. * typedef struct MyFAPOParams
  37. * {
  38. * uint32_t something;
  39. * } MyFAPOParams;
  40. * typedef struct MyFAPO
  41. * {
  42. * FAPOBase base;
  43. * uint32_t somethingElse;
  44. * } MyFAPO;
  45. * void MyFAPO_Free(void* fapo)
  46. * {
  47. * MyFAPO *mine = (MyFAPO*) fapo;
  48. * mine->base.pFree(mine->base.m_pParameterBlocks);
  49. * mine->base.pFree(fapo);
  50. * }
  51. *
  52. * MyFAPO *result = (MyFAPO*) SDL_malloc(sizeof(MyFAPO));
  53. * uint8_t *params = (uint8_t*) SDL_malloc(sizeof(MyFAPOParams) * 3);
  54. * CreateFAPOBase(
  55. * &result->base,
  56. * &MyFAPOProperties,
  57. * params,
  58. * sizeof(MyFAPOParams),
  59. * producer
  60. * );
  61. * result->base.base.Initialize = (InitializeFunc) MyFAPO_Initialize;
  62. * result->base.base.Process = (ProcessFunc) MyFAPO_Process;
  63. * result->base.Destructor = MyFAPO_Free;
  64. */
  65. #ifndef FAPOBASE_H
  66. #define FAPOBASE_H
  67. #include "FAPO.h"
  68. #ifdef __cplusplus
  69. extern "C" {
  70. #endif /* __cplusplus */
  71. /* Constants */
  72. #define FAPOBASE_DEFAULT_FORMAT_TAG FAUDIO_FORMAT_IEEE_FLOAT
  73. #define FAPOBASE_DEFAULT_FORMAT_MIN_CHANNELS FAPO_MIN_CHANNELS
  74. #define FAPOBASE_DEFAULT_FORMAT_MAX_CHANNELS FAPO_MAX_CHANNELS
  75. #define FAPOBASE_DEFAULT_FORMAT_MIN_FRAMERATE FAPO_MIN_FRAMERATE
  76. #define FAPOBASE_DEFAULT_FORMAT_MAX_FRAMERATE FAPO_MAX_FRAMERATE
  77. #define FAPOBASE_DEFAULT_FORMAT_BITSPERSAMPLE 32
  78. #define FAPOBASE_DEFAULT_FLAG ( \
  79. FAPO_FLAG_CHANNELS_MUST_MATCH | \
  80. FAPO_FLAG_FRAMERATE_MUST_MATCH | \
  81. FAPO_FLAG_BITSPERSAMPLE_MUST_MATCH | \
  82. FAPO_FLAG_BUFFERCOUNT_MUST_MATCH | \
  83. FAPO_FLAG_INPLACE_SUPPORTED \
  84. )
  85. #define FAPOBASE_DEFAULT_BUFFER_COUNT 1
  86. /* FAPOBase Interface */
  87. typedef struct FAPOBase FAPOBase;
  88. typedef void (FAPOCALL * OnSetParametersFunc)(
  89. FAPOBase *fapo,
  90. const void* parameters,
  91. uint32_t parametersSize
  92. );
  93. #pragma pack(push, 8)
  94. struct FAPOBase
  95. {
  96. /* Base Classes/Interfaces */
  97. FAPO base;
  98. void (FAPOCALL *Destructor)(void*);
  99. /* Public Virtual Functions */
  100. OnSetParametersFunc OnSetParameters;
  101. /* Private Variables */
  102. const FAPORegistrationProperties *m_pRegistrationProperties;
  103. void* m_pfnMatrixMixFunction;
  104. float *m_pfl32MatrixCoefficients;
  105. uint32_t m_nSrcFormatType;
  106. uint8_t m_fIsScalarMatrix;
  107. uint8_t m_fIsLocked;
  108. uint8_t *m_pParameterBlocks;
  109. uint8_t *m_pCurrentParameters;
  110. uint8_t *m_pCurrentParametersInternal;
  111. uint32_t m_uCurrentParametersIndex;
  112. uint32_t m_uParameterBlockByteSize;
  113. uint8_t m_fNewerResultsReady;
  114. uint8_t m_fProducer;
  115. /* Protected Variables */
  116. int32_t m_lReferenceCount; /* LONG */
  117. /* Allocator callbacks, NOT part of XAPOBase spec! */
  118. FAudioMallocFunc pMalloc;
  119. FAudioFreeFunc pFree;
  120. FAudioReallocFunc pRealloc;
  121. };
  122. #pragma pack(pop)
  123. FAPOAPI void CreateFAPOBase(
  124. FAPOBase *fapo,
  125. const FAPORegistrationProperties *pRegistrationProperties,
  126. uint8_t *pParameterBlocks,
  127. uint32_t uParameterBlockByteSize,
  128. uint8_t fProducer
  129. );
  130. /* See "extensions/CustomAllocatorEXT.txt" for more information. */
  131. FAPOAPI void CreateFAPOBaseWithCustomAllocatorEXT(
  132. FAPOBase *fapo,
  133. const FAPORegistrationProperties *pRegistrationProperties,
  134. uint8_t *pParameterBlocks,
  135. uint32_t uParameterBlockByteSize,
  136. uint8_t fProducer,
  137. FAudioMallocFunc customMalloc,
  138. FAudioFreeFunc customFree,
  139. FAudioReallocFunc customRealloc
  140. );
  141. FAPOAPI int32_t FAPOBase_AddRef(FAPOBase *fapo);
  142. FAPOAPI int32_t FAPOBase_Release(FAPOBase *fapo);
  143. FAPOAPI uint32_t FAPOBase_GetRegistrationProperties(
  144. FAPOBase *fapo,
  145. FAPORegistrationProperties **ppRegistrationProperties
  146. );
  147. FAPOAPI uint32_t FAPOBase_IsInputFormatSupported(
  148. FAPOBase *fapo,
  149. const FAudioWaveFormatEx *pOutputFormat,
  150. const FAudioWaveFormatEx *pRequestedInputFormat,
  151. FAudioWaveFormatEx **ppSupportedInputFormat
  152. );
  153. FAPOAPI uint32_t FAPOBase_IsOutputFormatSupported(
  154. FAPOBase *fapo,
  155. const FAudioWaveFormatEx *pInputFormat,
  156. const FAudioWaveFormatEx *pRequestedOutputFormat,
  157. FAudioWaveFormatEx **ppSupportedOutputFormat
  158. );
  159. FAPOAPI uint32_t FAPOBase_Initialize(
  160. FAPOBase *fapo,
  161. const void* pData,
  162. uint32_t DataByteSize
  163. );
  164. FAPOAPI void FAPOBase_Reset(FAPOBase *fapo);
  165. FAPOAPI uint32_t FAPOBase_LockForProcess(
  166. FAPOBase *fapo,
  167. uint32_t InputLockedParameterCount,
  168. const FAPOLockForProcessBufferParameters *pInputLockedParameters,
  169. uint32_t OutputLockedParameterCount,
  170. const FAPOLockForProcessBufferParameters *pOutputLockedParameters
  171. );
  172. FAPOAPI void FAPOBase_UnlockForProcess(FAPOBase *fapo);
  173. FAPOAPI uint32_t FAPOBase_CalcInputFrames(
  174. FAPOBase *fapo,
  175. uint32_t OutputFrameCount
  176. );
  177. FAPOAPI uint32_t FAPOBase_CalcOutputFrames(
  178. FAPOBase *fapo,
  179. uint32_t InputFrameCount
  180. );
  181. FAPOAPI uint32_t FAPOBase_ValidateFormatDefault(
  182. FAPOBase *fapo,
  183. FAudioWaveFormatEx *pFormat,
  184. uint8_t fOverwrite
  185. );
  186. FAPOAPI uint32_t FAPOBase_ValidateFormatPair(
  187. FAPOBase *fapo,
  188. const FAudioWaveFormatEx *pSupportedFormat,
  189. FAudioWaveFormatEx *pRequestedFormat,
  190. uint8_t fOverwrite
  191. );
  192. FAPOAPI void FAPOBase_ProcessThru(
  193. FAPOBase *fapo,
  194. void* pInputBuffer,
  195. float *pOutputBuffer,
  196. uint32_t FrameCount,
  197. uint16_t InputChannelCount,
  198. uint16_t OutputChannelCount,
  199. uint8_t MixWithOutput
  200. );
  201. FAPOAPI void FAPOBase_SetParameters(
  202. FAPOBase *fapo,
  203. const void* pParameters,
  204. uint32_t ParameterByteSize
  205. );
  206. FAPOAPI void FAPOBase_GetParameters(
  207. FAPOBase *fapo,
  208. void* pParameters,
  209. uint32_t ParameterByteSize
  210. );
  211. FAPOAPI void FAPOBase_OnSetParameters(
  212. FAPOBase *fapo,
  213. const void* parameters,
  214. uint32_t parametersSize
  215. );
  216. FAPOAPI uint8_t FAPOBase_ParametersChanged(FAPOBase *fapo);
  217. FAPOAPI uint8_t* FAPOBase_BeginProcess(FAPOBase *fapo);
  218. FAPOAPI void FAPOBase_EndProcess(FAPOBase *fapo);
  219. #ifdef __cplusplus
  220. }
  221. #endif /* __cplusplus */
  222. #endif /* FAPOBASE_H */
  223. /* vim: set noexpandtab shiftwidth=8 tabstop=8: */