pa_process.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. #ifndef PA_PROCESS_H
  2. #define PA_PROCESS_H
  3. /*
  4. * $Id: pa_process.h 1668 2011-05-02 17:07:11Z rossb $
  5. * Portable Audio I/O Library callback buffer processing adapters
  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 Buffer Processor prototypes. A Buffer Processor performs buffer length
  42. adaption, coordinates sample format conversion, and interleaves/deinterleaves
  43. channels.
  44. <h3>Overview</h3>
  45. The "Buffer Processor" (PaUtilBufferProcessor) manages conversion of audio
  46. data from host buffers to user buffers and back again. Where required, the
  47. buffer processor takes care of converting between host and user sample formats,
  48. interleaving and deinterleaving multichannel buffers, and adapting between host
  49. and user buffers with different lengths. The buffer processor may be used with
  50. full and half duplex streams, for both callback streams and blocking read/write
  51. streams.
  52. One of the important capabilities provided by the buffer processor is
  53. the ability to adapt between user and host buffer sizes of different lengths
  54. with minimum latency. Although this task is relatively easy to perform when
  55. the host buffer size is an integer multiple of the user buffer size, the
  56. problem is more complicated when this is not the case - especially for
  57. full-duplex callback streams. Where necessary the adaption is implemented by
  58. internally buffering some input and/or output data. The buffer adation
  59. algorithm used by the buffer processor was originally implemented by
  60. Stephan Letz for the ASIO version of PortAudio, and is described in his
  61. Callback_adaption_.pdf which is included in the distribution.
  62. The buffer processor performs sample conversion using the functions provided
  63. by pa_converters.c.
  64. The following sections provide an overview of how to use the buffer processor.
  65. Interested readers are advised to consult the host API implementations for
  66. examples of buffer processor usage.
  67. <h4>Initialization, resetting and termination</h4>
  68. When a stream is opened, the buffer processor should be initialized using
  69. PaUtil_InitializeBufferProcessor. This function initializes internal state
  70. and allocates temporary buffers as neccesary according to the supplied
  71. configuration parameters. Some of the parameters correspond to those requested
  72. by the user in their call to Pa_OpenStream(), others reflect the requirements
  73. of the host API implementation - they indicate host buffer sizes, formats,
  74. and the type of buffering which the Host API uses. The buffer processor should
  75. be initialized for callback streams and blocking read/write streams.
  76. Call PaUtil_ResetBufferProcessor to clear any sample data which is present
  77. in the buffer processor before starting to use it (for example when
  78. Pa_StartStream is called).
  79. When the buffer processor is no longer used call
  80. PaUtil_TerminateBufferProcessor.
  81. <h4>Using the buffer processor for a callback stream</h4>
  82. The buffer processor's role in a callback stream is to take host input buffers
  83. process them with the stream callback, and fill host output buffers. For a
  84. full duplex stream, the buffer processor handles input and output simultaneously
  85. due to the requirements of the minimum-latency buffer adation algorithm.
  86. When a host buffer becomes available, the implementation should call
  87. the buffer processor to process the buffer. The buffer processor calls the
  88. stream callback to consume and/or produce audio data as necessary. The buffer
  89. processor will convert sample formats, interleave/deinterleave channels,
  90. and slice or chunk the data to the appropriate buffer lengths according to
  91. the requirements of the stream callback and the host API.
  92. To process a host buffer (or a pair of host buffers for a full-duplex stream)
  93. use the following calling sequence:
  94. -# Call PaUtil_BeginBufferProcessing
  95. -# For a stream which takes input:
  96. - Call PaUtil_SetInputFrameCount with the number of frames in the host input
  97. buffer.
  98. - Call one of the following functions one or more times to tell the
  99. buffer processor about the host input buffer(s): PaUtil_SetInputChannel,
  100. PaUtil_SetInterleavedInputChannels, PaUtil_SetNonInterleavedInputChannel.
  101. Which function you call will depend on whether the host buffer(s) are
  102. interleaved or not.
  103. - If the available host data is split accross two buffers (for example a
  104. data range at the end of a circular buffer and another range at the
  105. beginning of the circular buffer), also call
  106. PaUtil_Set2ndInputFrameCount, PaUtil_Set2ndInputChannel,
  107. PaUtil_Set2ndInterleavedInputChannels,
  108. PaUtil_Set2ndNonInterleavedInputChannel as necessary to tell the buffer
  109. processor about the second buffer.
  110. -# For a stream which generates output:
  111. - Call PaUtil_SetOutputFrameCount with the number of frames in the host
  112. output buffer.
  113. - Call one of the following functions one or more times to tell the
  114. buffer processor about the host output buffer(s): PaUtil_SetOutputChannel,
  115. PaUtil_SetInterleavedOutputChannels, PaUtil_SetNonInterleavedOutputChannel.
  116. Which function you call will depend on whether the host buffer(s) are
  117. interleaved or not.
  118. - If the available host output buffer space is split accross two buffers
  119. (for example a data range at the end of a circular buffer and another
  120. range at the beginning of the circular buffer), call
  121. PaUtil_Set2ndOutputFrameCount, PaUtil_Set2ndOutputChannel,
  122. PaUtil_Set2ndInterleavedOutputChannels,
  123. PaUtil_Set2ndNonInterleavedOutputChannel as necessary to tell the buffer
  124. processor about the second buffer.
  125. -# Call PaUtil_EndBufferProcessing, this function performs the actual data
  126. conversion and processing.
  127. <h4>Using the buffer processor for a blocking read/write stream</h4>
  128. Blocking read/write streams use the buffer processor to convert and copy user
  129. output data to a host buffer, and to convert and copy host input data to
  130. the user's buffer. The buffer processor does not perform any buffer adaption.
  131. When using the buffer processor in a blocking read/write stream the input and
  132. output conversion are performed separately by the PaUtil_CopyInput and
  133. PaUtil_CopyOutput functions.
  134. To copy data from a host input buffer to the buffer(s) which the user supplies
  135. to Pa_ReadStream, use the following calling sequence.
  136. - Repeat the following three steps until the user buffer(s) have been filled
  137. with samples from the host input buffers:
  138. -# Call PaUtil_SetInputFrameCount with the number of frames in the host
  139. input buffer.
  140. -# Call one of the following functions one or more times to tell the
  141. buffer processor about the host input buffer(s): PaUtil_SetInputChannel,
  142. PaUtil_SetInterleavedInputChannels, PaUtil_SetNonInterleavedInputChannel.
  143. Which function you call will depend on whether the host buffer(s) are
  144. interleaved or not.
  145. -# Call PaUtil_CopyInput with the user buffer pointer (or a copy of the
  146. array of buffer pointers for a non-interleaved stream) passed to
  147. Pa_ReadStream, along with the number of frames in the user buffer(s).
  148. Be careful to pass a <i>copy</i> of the user buffer pointers to
  149. PaUtil_CopyInput because PaUtil_CopyInput advances the pointers to
  150. the start of the next region to copy.
  151. - PaUtil_CopyInput will not copy more data than is available in the
  152. host buffer(s), so the above steps need to be repeated until the user
  153. buffer(s) are full.
  154. To copy data to the host output buffer from the user buffers(s) supplied
  155. to Pa_WriteStream use the following calling sequence.
  156. - Repeat the following three steps until all frames from the user buffer(s)
  157. have been copied to the host API:
  158. -# Call PaUtil_SetOutputFrameCount with the number of frames in the host
  159. output buffer.
  160. -# Call one of the following functions one or more times to tell the
  161. buffer processor about the host output buffer(s): PaUtil_SetOutputChannel,
  162. PaUtil_SetInterleavedOutputChannels, PaUtil_SetNonInterleavedOutputChannel.
  163. Which function you call will depend on whether the host buffer(s) are
  164. interleaved or not.
  165. -# Call PaUtil_CopyOutput with the user buffer pointer (or a copy of the
  166. array of buffer pointers for a non-interleaved stream) passed to
  167. Pa_WriteStream, along with the number of frames in the user buffer(s).
  168. Be careful to pass a <i>copy</i> of the user buffer pointers to
  169. PaUtil_CopyOutput because PaUtil_CopyOutput advances the pointers to
  170. the start of the next region to copy.
  171. - PaUtil_CopyOutput will not copy more data than fits in the host buffer(s),
  172. so the above steps need to be repeated until all user data is copied.
  173. */
  174. #include "portaudio.h"
  175. #include "pa_converters.h"
  176. #include "pa_dither.h"
  177. #ifdef __cplusplus
  178. extern "C"
  179. {
  180. #endif /* __cplusplus */
  181. /** @brief Mode flag passed to PaUtil_InitializeBufferProcessor indicating the type
  182. of buffering that the host API uses.
  183. The mode used depends on whether the host API or the implementation manages
  184. the buffers, and how these buffers are used (scatter gather, circular buffer).
  185. */
  186. typedef enum {
  187. /** The host buffer size is a fixed known size. */
  188. paUtilFixedHostBufferSize,
  189. /** The host buffer size may vary, but has a known maximum size. */
  190. paUtilBoundedHostBufferSize,
  191. /** Nothing is known about the host buffer size. */
  192. paUtilUnknownHostBufferSize,
  193. /** The host buffer size varies, and the client does not require the buffer
  194. processor to consume all of the input and fill all of the output buffer. This
  195. is useful when the implementation has access to the host API's circular buffer
  196. and only needs to consume/fill some of it, not necessarily all of it, with each
  197. call to the buffer processor. This is the only mode where
  198. PaUtil_EndBufferProcessing() may not consume the whole buffer.
  199. */
  200. paUtilVariableHostBufferSizePartialUsageAllowed
  201. }PaUtilHostBufferSizeMode;
  202. /** @brief An auxilliary data structure used internally by the buffer processor
  203. to represent host input and output buffers. */
  204. typedef struct PaUtilChannelDescriptor{
  205. void *data;
  206. unsigned int stride; /**< stride in samples, not bytes */
  207. }PaUtilChannelDescriptor;
  208. /** @brief The main buffer processor data structure.
  209. Allocate one of these, initialize it with PaUtil_InitializeBufferProcessor
  210. and terminate it with PaUtil_TerminateBufferProcessor.
  211. */
  212. typedef struct {
  213. unsigned long framesPerUserBuffer;
  214. unsigned long framesPerHostBuffer;
  215. PaUtilHostBufferSizeMode hostBufferSizeMode;
  216. int useNonAdaptingProcess;
  217. int userOutputSampleFormatIsEqualToHost;
  218. int userInputSampleFormatIsEqualToHost;
  219. unsigned long framesPerTempBuffer;
  220. unsigned int inputChannelCount;
  221. unsigned int bytesPerHostInputSample;
  222. unsigned int bytesPerUserInputSample;
  223. int userInputIsInterleaved;
  224. PaUtilConverter *inputConverter;
  225. PaUtilZeroer *inputZeroer;
  226. unsigned int outputChannelCount;
  227. unsigned int bytesPerHostOutputSample;
  228. unsigned int bytesPerUserOutputSample;
  229. int userOutputIsInterleaved;
  230. PaUtilConverter *outputConverter;
  231. PaUtilZeroer *outputZeroer;
  232. unsigned long initialFramesInTempInputBuffer;
  233. unsigned long initialFramesInTempOutputBuffer;
  234. void *tempInputBuffer; /**< used for slips, block adaption, and conversion. */
  235. void **tempInputBufferPtrs; /**< storage for non-interleaved buffer pointers, NULL for interleaved user input */
  236. unsigned long framesInTempInputBuffer; /**< frames remaining in input buffer from previous adaption iteration */
  237. void *tempOutputBuffer; /**< used for slips, block adaption, and conversion. */
  238. void **tempOutputBufferPtrs; /**< storage for non-interleaved buffer pointers, NULL for interleaved user output */
  239. unsigned long framesInTempOutputBuffer; /**< frames remaining in input buffer from previous adaption iteration */
  240. PaStreamCallbackTimeInfo *timeInfo;
  241. PaStreamCallbackFlags callbackStatusFlags;
  242. int hostInputIsInterleaved;
  243. unsigned long hostInputFrameCount[2];
  244. PaUtilChannelDescriptor *hostInputChannels[2]; /**< pointers to arrays of channel descriptors.
  245. pointers are NULL for half-duplex output processing.
  246. hostInputChannels[i].data is NULL when the caller
  247. calls PaUtil_SetNoInput()
  248. */
  249. int hostOutputIsInterleaved;
  250. unsigned long hostOutputFrameCount[2];
  251. PaUtilChannelDescriptor *hostOutputChannels[2]; /**< pointers to arrays of channel descriptors.
  252. pointers are NULL for half-duplex input processing.
  253. hostOutputChannels[i].data is NULL when the caller
  254. calls PaUtil_SetNoOutput()
  255. */
  256. PaUtilTriangularDitherGenerator ditherGenerator;
  257. double samplePeriod;
  258. PaStreamCallback *streamCallback;
  259. void *userData;
  260. } PaUtilBufferProcessor;
  261. /** @name Initialization, termination, resetting and info */
  262. /*@{*/
  263. /** Initialize a buffer processor's representation stored in a
  264. PaUtilBufferProcessor structure. Be sure to call
  265. PaUtil_TerminateBufferProcessor after finishing with a buffer processor.
  266. @param bufferProcessor The buffer processor structure to initialize.
  267. @param inputChannelCount The number of input channels as passed to
  268. Pa_OpenStream or 0 for an output-only stream.
  269. @param userInputSampleFormat Format of user input samples, as passed to
  270. Pa_OpenStream. This parameter is ignored for ouput-only streams.
  271. @param hostInputSampleFormat Format of host input samples. This parameter is
  272. ignored for output-only streams. See note about host buffer interleave below.
  273. @param outputChannelCount The number of output channels as passed to
  274. Pa_OpenStream or 0 for an input-only stream.
  275. @param userOutputSampleFormat Format of user output samples, as passed to
  276. Pa_OpenStream. This parameter is ignored for input-only streams.
  277. @param hostOutputSampleFormat Format of host output samples. This parameter is
  278. ignored for input-only streams. See note about host buffer interleave below.
  279. @param sampleRate Sample rate of the stream. The more accurate this is the
  280. better - it is used for updating time stamps when adapting buffers.
  281. @param streamFlags Stream flags as passed to Pa_OpenStream, this parameter is
  282. used for selecting special sample conversion options such as clipping and
  283. dithering.
  284. @param framesPerUserBuffer Number of frames per user buffer, as requested
  285. by the framesPerBuffer parameter to Pa_OpenStream. This parameter may be
  286. zero to indicate that the user will accept any (and varying) buffer sizes.
  287. @param framesPerHostBuffer Specifies the number of frames per host buffer
  288. for the fixed buffer size mode, and the maximum number of frames
  289. per host buffer for the bounded host buffer size mode. It is ignored for
  290. the other modes.
  291. @param hostBufferSizeMode A mode flag indicating the size variability of
  292. host buffers that will be passed to the buffer processor. See
  293. PaUtilHostBufferSizeMode for further details.
  294. @param streamCallback The user stream callback passed to Pa_OpenStream.
  295. @param userData The user data field passed to Pa_OpenStream.
  296. @note The interleave flag is ignored for host buffer formats. Host
  297. interleave is determined by the use of different SetInput and SetOutput
  298. functions.
  299. @return An error code indicating whether the initialization was successful.
  300. If the error code is not PaNoError, the buffer processor was not initialized
  301. and should not be used.
  302. @see Pa_OpenStream, PaUtilHostBufferSizeMode, PaUtil_TerminateBufferProcessor
  303. */
  304. PaError PaUtil_InitializeBufferProcessor( PaUtilBufferProcessor* bufferProcessor,
  305. int inputChannelCount, PaSampleFormat userInputSampleFormat,
  306. PaSampleFormat hostInputSampleFormat,
  307. int outputChannelCount, PaSampleFormat userOutputSampleFormat,
  308. PaSampleFormat hostOutputSampleFormat,
  309. double sampleRate,
  310. PaStreamFlags streamFlags,
  311. unsigned long framesPerUserBuffer, /* 0 indicates don't care */
  312. unsigned long framesPerHostBuffer,
  313. PaUtilHostBufferSizeMode hostBufferSizeMode,
  314. PaStreamCallback *streamCallback, void *userData );
  315. /** Terminate a buffer processor's representation. Deallocates any temporary
  316. buffers allocated by PaUtil_InitializeBufferProcessor.
  317. @param bufferProcessor The buffer processor structure to terminate.
  318. @see PaUtil_InitializeBufferProcessor.
  319. */
  320. void PaUtil_TerminateBufferProcessor( PaUtilBufferProcessor* bufferProcessor );
  321. /** Clear any internally buffered data. If you call
  322. PaUtil_InitializeBufferProcessor in your OpenStream routine, make sure you
  323. call PaUtil_ResetBufferProcessor in your StartStream call.
  324. @param bufferProcessor The buffer processor to reset.
  325. */
  326. void PaUtil_ResetBufferProcessor( PaUtilBufferProcessor* bufferProcessor );
  327. /** Retrieve the input latency of a buffer processor, in frames.
  328. @param bufferProcessor The buffer processor examine.
  329. @return The input latency introduced by the buffer processor, in frames.
  330. @see PaUtil_GetBufferProcessorOutputLatencyFrames
  331. */
  332. unsigned long PaUtil_GetBufferProcessorInputLatencyFrames( PaUtilBufferProcessor* bufferProcessor );
  333. /** Retrieve the output latency of a buffer processor, in frames.
  334. @param bufferProcessor The buffer processor examine.
  335. @return The output latency introduced by the buffer processor, in frames.
  336. @see PaUtil_GetBufferProcessorInputLatencyFrames
  337. */
  338. unsigned long PaUtil_GetBufferProcessorOutputLatencyFrames( PaUtilBufferProcessor* bufferProcessor );
  339. /*@}*/
  340. /** @name Host buffer pointer configuration
  341. Functions to set host input and output buffers, used by both callback streams
  342. and blocking read/write streams.
  343. */
  344. /*@{*/
  345. /** Set the number of frames in the input host buffer(s) specified by the
  346. PaUtil_Set*InputChannel functions.
  347. @param bufferProcessor The buffer processor.
  348. @param frameCount The number of host input frames. A 0 frameCount indicates to
  349. use the framesPerHostBuffer value passed to PaUtil_InitializeBufferProcessor.
  350. @see PaUtil_SetNoInput, PaUtil_SetInputChannel,
  351. PaUtil_SetInterleavedInputChannels, PaUtil_SetNonInterleavedInputChannel
  352. */
  353. void PaUtil_SetInputFrameCount( PaUtilBufferProcessor* bufferProcessor,
  354. unsigned long frameCount );
  355. /** Indicate that no input is avalable. This function should be used when
  356. priming the output of a full-duplex stream opened with the
  357. paPrimeOutputBuffersUsingStreamCallback flag. Note that it is not necessary
  358. to call this or any othe PaUtil_Set*Input* functions for ouput-only streams.
  359. @param bufferProcessor The buffer processor.
  360. */
  361. void PaUtil_SetNoInput( PaUtilBufferProcessor* bufferProcessor );
  362. /** Provide the buffer processor with a pointer to a host input channel.
  363. @param bufferProcessor The buffer processor.
  364. @param channel The channel number.
  365. @param data The buffer.
  366. @param stride The stride from one sample to the next, in samples. For
  367. interleaved host buffers, the stride will usually be the same as the number of
  368. channels in the buffer.
  369. */
  370. void PaUtil_SetInputChannel( PaUtilBufferProcessor* bufferProcessor,
  371. unsigned int channel, void *data, unsigned int stride );
  372. /** Provide the buffer processor with a pointer to an number of interleaved
  373. host input channels.
  374. @param bufferProcessor The buffer processor.
  375. @param firstChannel The first channel number.
  376. @param data The buffer.
  377. @param channelCount The number of interleaved channels in the buffer. If
  378. channelCount is zero, the number of channels specified to
  379. PaUtil_InitializeBufferProcessor will be used.
  380. */
  381. void PaUtil_SetInterleavedInputChannels( PaUtilBufferProcessor* bufferProcessor,
  382. unsigned int firstChannel, void *data, unsigned int channelCount );
  383. /** Provide the buffer processor with a pointer to one non-interleaved host
  384. output channel.
  385. @param bufferProcessor The buffer processor.
  386. @param channel The channel number.
  387. @param data The buffer.
  388. */
  389. void PaUtil_SetNonInterleavedInputChannel( PaUtilBufferProcessor* bufferProcessor,
  390. unsigned int channel, void *data );
  391. /** Use for the second buffer half when the input buffer is split in two halves.
  392. @see PaUtil_SetInputFrameCount
  393. */
  394. void PaUtil_Set2ndInputFrameCount( PaUtilBufferProcessor* bufferProcessor,
  395. unsigned long frameCount );
  396. /** Use for the second buffer half when the input buffer is split in two halves.
  397. @see PaUtil_SetInputChannel
  398. */
  399. void PaUtil_Set2ndInputChannel( PaUtilBufferProcessor* bufferProcessor,
  400. unsigned int channel, void *data, unsigned int stride );
  401. /** Use for the second buffer half when the input buffer is split in two halves.
  402. @see PaUtil_SetInterleavedInputChannels
  403. */
  404. void PaUtil_Set2ndInterleavedInputChannels( PaUtilBufferProcessor* bufferProcessor,
  405. unsigned int firstChannel, void *data, unsigned int channelCount );
  406. /** Use for the second buffer half when the input buffer is split in two halves.
  407. @see PaUtil_SetNonInterleavedInputChannel
  408. */
  409. void PaUtil_Set2ndNonInterleavedInputChannel( PaUtilBufferProcessor* bufferProcessor,
  410. unsigned int channel, void *data );
  411. /** Set the number of frames in the output host buffer(s) specified by the
  412. PaUtil_Set*OutputChannel functions.
  413. @param bufferProcessor The buffer processor.
  414. @param frameCount The number of host output frames. A 0 frameCount indicates to
  415. use the framesPerHostBuffer value passed to PaUtil_InitializeBufferProcessor.
  416. @see PaUtil_SetOutputChannel, PaUtil_SetInterleavedOutputChannels,
  417. PaUtil_SetNonInterleavedOutputChannel
  418. */
  419. void PaUtil_SetOutputFrameCount( PaUtilBufferProcessor* bufferProcessor,
  420. unsigned long frameCount );
  421. /** Indicate that the output will be discarded. This function should be used
  422. when implementing the paNeverDropInput mode for full duplex streams.
  423. @param bufferProcessor The buffer processor.
  424. */
  425. void PaUtil_SetNoOutput( PaUtilBufferProcessor* bufferProcessor );
  426. /** Provide the buffer processor with a pointer to a host output channel.
  427. @param bufferProcessor The buffer processor.
  428. @param channel The channel number.
  429. @param data The buffer.
  430. @param stride The stride from one sample to the next, in samples. For
  431. interleaved host buffers, the stride will usually be the same as the number of
  432. channels in the buffer.
  433. */
  434. void PaUtil_SetOutputChannel( PaUtilBufferProcessor* bufferProcessor,
  435. unsigned int channel, void *data, unsigned int stride );
  436. /** Provide the buffer processor with a pointer to a number of interleaved
  437. host output channels.
  438. @param bufferProcessor The buffer processor.
  439. @param firstChannel The first channel number.
  440. @param data The buffer.
  441. @param channelCount The number of interleaved channels in the buffer. If
  442. channelCount is zero, the number of channels specified to
  443. PaUtil_InitializeBufferProcessor will be used.
  444. */
  445. void PaUtil_SetInterleavedOutputChannels( PaUtilBufferProcessor* bufferProcessor,
  446. unsigned int firstChannel, void *data, unsigned int channelCount );
  447. /** Provide the buffer processor with a pointer to one non-interleaved host
  448. output channel.
  449. @param bufferProcessor The buffer processor.
  450. @param channel The channel number.
  451. @param data The buffer.
  452. */
  453. void PaUtil_SetNonInterleavedOutputChannel( PaUtilBufferProcessor* bufferProcessor,
  454. unsigned int channel, void *data );
  455. /** Use for the second buffer half when the output buffer is split in two halves.
  456. @see PaUtil_SetOutputFrameCount
  457. */
  458. void PaUtil_Set2ndOutputFrameCount( PaUtilBufferProcessor* bufferProcessor,
  459. unsigned long frameCount );
  460. /** Use for the second buffer half when the output buffer is split in two halves.
  461. @see PaUtil_SetOutputChannel
  462. */
  463. void PaUtil_Set2ndOutputChannel( PaUtilBufferProcessor* bufferProcessor,
  464. unsigned int channel, void *data, unsigned int stride );
  465. /** Use for the second buffer half when the output buffer is split in two halves.
  466. @see PaUtil_SetInterleavedOutputChannels
  467. */
  468. void PaUtil_Set2ndInterleavedOutputChannels( PaUtilBufferProcessor* bufferProcessor,
  469. unsigned int firstChannel, void *data, unsigned int channelCount );
  470. /** Use for the second buffer half when the output buffer is split in two halves.
  471. @see PaUtil_SetNonInterleavedOutputChannel
  472. */
  473. void PaUtil_Set2ndNonInterleavedOutputChannel( PaUtilBufferProcessor* bufferProcessor,
  474. unsigned int channel, void *data );
  475. /*@}*/
  476. /** @name Buffer processing functions for callback streams
  477. */
  478. /*@{*/
  479. /** Commence processing a host buffer (or a pair of host buffers in the
  480. full-duplex case) for a callback stream.
  481. @param bufferProcessor The buffer processor.
  482. @param timeInfo Timing information for the first sample of the host
  483. buffer(s). This information may be adjusted when buffer adaption is being
  484. performed.
  485. @param callbackStatusFlags Flags indicating whether underruns and overruns
  486. have occurred since the last time the buffer processor was called.
  487. */
  488. void PaUtil_BeginBufferProcessing( PaUtilBufferProcessor* bufferProcessor,
  489. PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags callbackStatusFlags );
  490. /** Finish processing a host buffer (or a pair of host buffers in the
  491. full-duplex case) for a callback stream.
  492. @param bufferProcessor The buffer processor.
  493. @param callbackResult On input, indicates a previous callback result, and on
  494. exit, the result of the user stream callback, if it is called.
  495. On entry callbackResult should contain one of { paContinue, paComplete, or
  496. paAbort}. If paComplete is passed, the stream callback will not be called
  497. but any audio that was generated by previous stream callbacks will be copied
  498. to the output buffer(s). You can check whether the buffer processor's internal
  499. buffer is empty by calling PaUtil_IsBufferProcessorOutputEmpty.
  500. If the stream callback is called its result is stored in *callbackResult. If
  501. the stream callback returns paComplete or paAbort, all output buffers will be
  502. full of valid data - some of which may be zeros to acount for data that
  503. wasn't generated by the terminating callback.
  504. @return The number of frames processed. This usually corresponds to the
  505. number of frames specified by the PaUtil_Set*FrameCount functions, exept in
  506. the paUtilVariableHostBufferSizePartialUsageAllowed buffer size mode when a
  507. smaller value may be returned.
  508. */
  509. unsigned long PaUtil_EndBufferProcessing( PaUtilBufferProcessor* bufferProcessor,
  510. int *callbackResult );
  511. /** Determine whether any callback generated output remains in the bufffer
  512. processor's internal buffers. This method may be used to determine when to
  513. continue calling PaUtil_EndBufferProcessing() after the callback has returned
  514. a callbackResult of paComplete.
  515. @param bufferProcessor The buffer processor.
  516. @return Returns non-zero when callback generated output remains in the internal
  517. buffer and zero (0) when there internal buffer contains no callback generated
  518. data.
  519. */
  520. int PaUtil_IsBufferProcessorOutputEmpty( PaUtilBufferProcessor* bufferProcessor );
  521. /*@}*/
  522. /** @name Buffer processing functions for blocking read/write streams
  523. */
  524. /*@{*/
  525. /** Copy samples from host input channels set up by the PaUtil_Set*InputChannels
  526. functions to a user supplied buffer. This function is intended for use with
  527. blocking read/write streams. Copies the minimum of the number of
  528. user frames (specified by the frameCount parameter) and the number of available
  529. host frames (specified in a previous call to SetInputFrameCount()).
  530. @param bufferProcessor The buffer processor.
  531. @param buffer A pointer to the user buffer pointer, or a pointer to a pointer
  532. to an array of user buffer pointers for a non-interleaved stream. It is
  533. important that this parameter points to a copy of the user buffer pointers,
  534. not to the actual user buffer pointers, because this function updates the
  535. pointers before returning.
  536. @param frameCount The number of frames of data in the buffer(s) pointed to by
  537. the buffer parameter.
  538. @return The number of frames copied. The buffer pointer(s) pointed to by the
  539. buffer parameter are advanced to point to the frame(s) following the last one
  540. filled.
  541. */
  542. unsigned long PaUtil_CopyInput( PaUtilBufferProcessor* bufferProcessor,
  543. void **buffer, unsigned long frameCount );
  544. /* Copy samples from a user supplied buffer to host output channels set up by
  545. the PaUtil_Set*OutputChannels functions. This function is intended for use with
  546. blocking read/write streams. Copies the minimum of the number of
  547. user frames (specified by the frameCount parameter) and the number of
  548. host frames (specified in a previous call to SetOutputFrameCount()).
  549. @param bufferProcessor The buffer processor.
  550. @param buffer A pointer to the user buffer pointer, or a pointer to a pointer
  551. to an array of user buffer pointers for a non-interleaved stream. It is
  552. important that this parameter points to a copy of the user buffer pointers,
  553. not to the actual user buffer pointers, because this function updates the
  554. pointers before returning.
  555. @param frameCount The number of frames of data in the buffer(s) pointed to by
  556. the buffer parameter.
  557. @return The number of frames copied. The buffer pointer(s) pointed to by the
  558. buffer parameter are advanced to point to the frame(s) following the last one
  559. copied.
  560. */
  561. unsigned long PaUtil_CopyOutput( PaUtilBufferProcessor* bufferProcessor,
  562. const void ** buffer, unsigned long frameCount );
  563. /* Zero samples in host output channels set up by the PaUtil_Set*OutputChannels
  564. functions. This function is useful for flushing streams.
  565. Zeros the minimum of frameCount and the number of host frames specified in a
  566. previous call to SetOutputFrameCount().
  567. @param bufferProcessor The buffer processor.
  568. @param frameCount The maximum number of frames to zero.
  569. @return The number of frames zeroed.
  570. */
  571. unsigned long PaUtil_ZeroOutput( PaUtilBufferProcessor* bufferProcessor,
  572. unsigned long frameCount );
  573. /*@}*/
  574. #ifdef __cplusplus
  575. }
  576. #endif /* __cplusplus */
  577. #endif /* PA_PROCESS_H */