pa_converters.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. #ifndef PA_CONVERTERS_H
  2. #define PA_CONVERTERS_H
  3. /*
  4. * $Id: pa_converters.h 1097 2006-08-26 08:27:53Z rossb $
  5. * Portable Audio I/O Library sample conversion mechanism
  6. *
  7. * Based on the Open Source API proposed by Ross Bencina
  8. * Copyright (c) 1999-2002 Phil Burk, Ross Bencina
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining
  11. * a copy of this software and associated documentation files
  12. * (the "Software"), to deal in the Software without restriction,
  13. * including without limitation the rights to use, copy, modify, merge,
  14. * publish, distribute, sublicense, and/or sell copies of the Software,
  15. * and to permit persons to whom the Software is furnished to do so,
  16. * subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be
  19. * included in all copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  24. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  25. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  26. * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. */
  29. /*
  30. * The text above constitutes the entire PortAudio license; however,
  31. * the PortAudio community also makes the following non-binding requests:
  32. *
  33. * Any person wishing to distribute modifications to the Software is
  34. * requested to send the modifications to the original developer so that
  35. * they can be incorporated into the canonical version. It is also
  36. * requested that these non-binding requests be included along with the
  37. * license above.
  38. */
  39. /** @file
  40. @ingroup common_src
  41. @brief Conversion functions used to convert buffers of samples from one
  42. format to another.
  43. */
  44. #include "portaudio.h" /* for PaSampleFormat */
  45. #ifdef __cplusplus
  46. extern "C"
  47. {
  48. #endif /* __cplusplus */
  49. struct PaUtilTriangularDitherGenerator;
  50. /** Choose an available sample format which is most appropriate for
  51. representing the requested format. If the requested format is not available
  52. higher quality formats are considered before lower quality formates.
  53. @param availableFormats A variable containing the logical OR of all available
  54. formats.
  55. @param format The desired format.
  56. @return The most appropriate available format for representing the requested
  57. format.
  58. */
  59. PaSampleFormat PaUtil_SelectClosestAvailableFormat(
  60. PaSampleFormat availableFormats, PaSampleFormat format );
  61. /* high level conversions functions for use by implementations */
  62. /** The generic sample converter prototype. Sample converters convert count
  63. samples from sourceBuffer to destinationBuffer. The actual type of the data
  64. pointed to by these parameters varys for different converter functions.
  65. @param destinationBuffer A pointer to the first sample of the destination.
  66. @param destinationStride An offset between successive destination samples
  67. expressed in samples (not bytes.) It may be negative.
  68. @param sourceBuffer A pointer to the first sample of the source.
  69. @param sourceStride An offset between successive source samples
  70. expressed in samples (not bytes.) It may be negative.
  71. @param count The number of samples to convert.
  72. @param ditherState State information used to calculate dither. Converters
  73. that do not perform dithering will ignore this parameter, in which case
  74. NULL or invalid dither state may be passed.
  75. */
  76. typedef void PaUtilConverter(
  77. void *destinationBuffer, signed int destinationStride,
  78. void *sourceBuffer, signed int sourceStride,
  79. unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator );
  80. /** Find a sample converter function for the given source and destinations
  81. formats and flags (clip and dither.)
  82. @return
  83. A pointer to a PaUtilConverter which will perform the requested
  84. conversion, or NULL if the given format conversion is not supported.
  85. For conversions where clipping or dithering is not necessary, the
  86. clip and dither flags are ignored and a non-clipping or dithering
  87. version is returned.
  88. If the source and destination formats are the same, a function which
  89. copies data of the appropriate size will be returned.
  90. */
  91. PaUtilConverter* PaUtil_SelectConverter( PaSampleFormat sourceFormat,
  92. PaSampleFormat destinationFormat, PaStreamFlags flags );
  93. /** The generic buffer zeroer prototype. Buffer zeroers copy count zeros to
  94. destinationBuffer. The actual type of the data pointed to varys for
  95. different zeroer functions.
  96. @param destinationBuffer A pointer to the first sample of the destination.
  97. @param destinationStride An offset between successive destination samples
  98. expressed in samples (not bytes.) It may be negative.
  99. @param count The number of samples to zero.
  100. */
  101. typedef void PaUtilZeroer(
  102. void *destinationBuffer, signed int destinationStride, unsigned int count );
  103. /** Find a buffer zeroer function for the given destination format.
  104. @return
  105. A pointer to a PaUtilZeroer which will perform the requested
  106. zeroing.
  107. */
  108. PaUtilZeroer* PaUtil_SelectZeroer( PaSampleFormat destinationFormat );
  109. /*----------------------------------------------------------------------------*/
  110. /* low level functions and data structures which may be used for
  111. substituting conversion functions */
  112. /** The type used to store all sample conversion functions.
  113. @see paConverters;
  114. */
  115. typedef struct{
  116. PaUtilConverter *Float32_To_Int32;
  117. PaUtilConverter *Float32_To_Int32_Dither;
  118. PaUtilConverter *Float32_To_Int32_Clip;
  119. PaUtilConverter *Float32_To_Int32_DitherClip;
  120. PaUtilConverter *Float32_To_Int24;
  121. PaUtilConverter *Float32_To_Int24_Dither;
  122. PaUtilConverter *Float32_To_Int24_Clip;
  123. PaUtilConverter *Float32_To_Int24_DitherClip;
  124. PaUtilConverter *Float32_To_Int16;
  125. PaUtilConverter *Float32_To_Int16_Dither;
  126. PaUtilConverter *Float32_To_Int16_Clip;
  127. PaUtilConverter *Float32_To_Int16_DitherClip;
  128. PaUtilConverter *Float32_To_Int8;
  129. PaUtilConverter *Float32_To_Int8_Dither;
  130. PaUtilConverter *Float32_To_Int8_Clip;
  131. PaUtilConverter *Float32_To_Int8_DitherClip;
  132. PaUtilConverter *Float32_To_UInt8;
  133. PaUtilConverter *Float32_To_UInt8_Dither;
  134. PaUtilConverter *Float32_To_UInt8_Clip;
  135. PaUtilConverter *Float32_To_UInt8_DitherClip;
  136. PaUtilConverter *Int32_To_Float32;
  137. PaUtilConverter *Int32_To_Int24;
  138. PaUtilConverter *Int32_To_Int24_Dither;
  139. PaUtilConverter *Int32_To_Int16;
  140. PaUtilConverter *Int32_To_Int16_Dither;
  141. PaUtilConverter *Int32_To_Int8;
  142. PaUtilConverter *Int32_To_Int8_Dither;
  143. PaUtilConverter *Int32_To_UInt8;
  144. PaUtilConverter *Int32_To_UInt8_Dither;
  145. PaUtilConverter *Int24_To_Float32;
  146. PaUtilConverter *Int24_To_Int32;
  147. PaUtilConverter *Int24_To_Int16;
  148. PaUtilConverter *Int24_To_Int16_Dither;
  149. PaUtilConverter *Int24_To_Int8;
  150. PaUtilConverter *Int24_To_Int8_Dither;
  151. PaUtilConverter *Int24_To_UInt8;
  152. PaUtilConverter *Int24_To_UInt8_Dither;
  153. PaUtilConverter *Int16_To_Float32;
  154. PaUtilConverter *Int16_To_Int32;
  155. PaUtilConverter *Int16_To_Int24;
  156. PaUtilConverter *Int16_To_Int8;
  157. PaUtilConverter *Int16_To_Int8_Dither;
  158. PaUtilConverter *Int16_To_UInt8;
  159. PaUtilConverter *Int16_To_UInt8_Dither;
  160. PaUtilConverter *Int8_To_Float32;
  161. PaUtilConverter *Int8_To_Int32;
  162. PaUtilConverter *Int8_To_Int24;
  163. PaUtilConverter *Int8_To_Int16;
  164. PaUtilConverter *Int8_To_UInt8;
  165. PaUtilConverter *UInt8_To_Float32;
  166. PaUtilConverter *UInt8_To_Int32;
  167. PaUtilConverter *UInt8_To_Int24;
  168. PaUtilConverter *UInt8_To_Int16;
  169. PaUtilConverter *UInt8_To_Int8;
  170. PaUtilConverter *Copy_8_To_8; /* copy without any conversion */
  171. PaUtilConverter *Copy_16_To_16; /* copy without any conversion */
  172. PaUtilConverter *Copy_24_To_24; /* copy without any conversion */
  173. PaUtilConverter *Copy_32_To_32; /* copy without any conversion */
  174. } PaUtilConverterTable;
  175. /** A table of pointers to all required converter functions.
  176. PaUtil_SelectConverter() uses this table to lookup the appropriate
  177. conversion functions. The fields of this structure are initialized
  178. with default conversion functions. Fields may be NULL, indicating that
  179. no conversion function is available. User code may substitue optimised
  180. conversion functions by assigning different function pointers to
  181. these fields.
  182. @note
  183. If the PA_NO_STANDARD_CONVERTERS preprocessor variable is defined,
  184. PortAudio's standard converters will not be compiled, and all fields
  185. of this structure will be initialized to NULL. In such cases, users
  186. should supply their own conversion functions if the require PortAudio
  187. to open a stream that requires sample conversion.
  188. @see PaUtilConverterTable, PaUtilConverter, PaUtil_SelectConverter
  189. */
  190. extern PaUtilConverterTable paConverters;
  191. /** The type used to store all buffer zeroing functions.
  192. @see paZeroers;
  193. */
  194. typedef struct{
  195. PaUtilZeroer *ZeroU8; /* unsigned 8 bit, zero == 128 */
  196. PaUtilZeroer *Zero8;
  197. PaUtilZeroer *Zero16;
  198. PaUtilZeroer *Zero24;
  199. PaUtilZeroer *Zero32;
  200. } PaUtilZeroerTable;
  201. /** A table of pointers to all required zeroer functions.
  202. PaUtil_SelectZeroer() uses this table to lookup the appropriate
  203. conversion functions. The fields of this structure are initialized
  204. with default conversion functions. User code may substitue optimised
  205. conversion functions by assigning different function pointers to
  206. these fields.
  207. @note
  208. If the PA_NO_STANDARD_ZEROERS preprocessor variable is defined,
  209. PortAudio's standard zeroers will not be compiled, and all fields
  210. of this structure will be initialized to NULL. In such cases, users
  211. should supply their own zeroing functions for the sample sizes which
  212. they intend to use.
  213. @see PaUtilZeroerTable, PaUtilZeroer, PaUtil_SelectZeroer
  214. */
  215. extern PaUtilZeroerTable paZeroers;
  216. #ifdef __cplusplus
  217. }
  218. #endif /* __cplusplus */
  219. #endif /* PA_CONVERTERS_H */