4
* $Id: pa_process.h 1097 2006-08-26 08:27:53Z rossb $
5
* Portable Audio I/O Library callback buffer processing adapters
7
* Based on the Open Source API proposed by Ross Bencina
8
* Copyright (c) 1999-2002 Phil Burk, Ross Bencina
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:
18
* The above copyright notice and this permission notice shall be
19
* included in all copies or substantial portions of the Software.
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.
31
* The text above constitutes the entire PortAudio license; however,
32
* the PortAudio community also makes the following non-binding requests:
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
44
@brief Buffer Processor prototypes. A Buffer Processor performs buffer length
45
adaption, coordinates sample format conversion, and interleaves/deinterleaves
50
The "Buffer Processor" (PaUtilBufferProcessor) manages conversion of audio
51
data from host buffers to user buffers and back again. Where required, the
52
buffer processor takes care of converting between host and user sample formats,
53
interleaving and deinterleaving multichannel buffers, and adapting between host
54
and user buffers with different lengths. The buffer processor may be used with
55
full and half duplex streams, for both callback streams and blocking read/write
58
One of the important capabilities provided by the buffer processor is
59
the ability to adapt between user and host buffer sizes of different lengths
60
with minimum latency. Although this task is relatively easy to perform when
61
the host buffer size is an integer multiple of the user buffer size, the
62
problem is more complicated when this is not the case - especially for
63
full-duplex callback streams. Where necessary the adaption is implemented by
64
internally buffering some input and/or output data. The buffer adation
65
algorithm used by the buffer processor was originally implemented by
66
Stephan Letz for the ASIO version of PortAudio, and is described in his
67
Callback_adaption_.pdf which is included in the distribution.
69
The buffer processor performs sample conversion using the functions provided
72
The following sections provide an overview of how to use the buffer processor.
73
Interested readers are advised to consult the host API implementations for
74
examples of buffer processor usage.
77
<h4>Initialization, resetting and termination</h4>
79
When a stream is opened, the buffer processor should be initialized using
80
PaUtil_InitializeBufferProcessor. This function initializes internal state
81
and allocates temporary buffers as neccesary according to the supplied
82
configuration parameters. Some of the parameters correspond to those requested
83
by the user in their call to Pa_OpenStream(), others reflect the requirements
84
of the host API implementation - they indicate host buffer sizes, formats,
85
and the type of buffering which the Host API uses. The buffer processor should
86
be initialized for callback streams and blocking read/write streams.
88
Call PaUtil_ResetBufferProcessor to clear any sample data which is present
89
in the buffer processor before starting to use it (for example when
90
Pa_StartStream is called).
92
When the buffer processor is no longer used call
93
PaUtil_TerminateBufferProcessor.
96
<h4>Using the buffer processor for a callback stream</h4>
98
The buffer processor's role in a callback stream is to take host input buffers
99
process them with the stream callback, and fill host output buffers. For a
100
full duplex stream, the buffer processor handles input and output simultaneously
101
due to the requirements of the minimum-latency buffer adation algorithm.
103
When a host buffer becomes available, the implementation should call
104
the buffer processor to process the buffer. The buffer processor calls the
105
stream callback to consume and/or produce audio data as necessary. The buffer
106
processor will convert sample formats, interleave/deinterleave channels,
107
and slice or chunk the data to the appropriate buffer lengths according to
108
the requirements of the stream callback and the host API.
110
To process a host buffer (or a pair of host buffers for a full-duplex stream)
111
use the following calling sequence:
113
-# Call PaUtil_BeginBufferProcessing
114
-# For a stream which takes input:
115
- Call PaUtil_SetInputFrameCount with the number of frames in the host input
117
- Call one of the following functions one or more times to tell the
118
buffer processor about the host input buffer(s): PaUtil_SetInputChannel,
119
PaUtil_SetInterleavedInputChannels, PaUtil_SetNonInterleavedInputChannel.
120
Which function you call will depend on whether the host buffer(s) are
122
- If the available host data is split accross two buffers (for example a
123
data range at the end of a circular buffer and another range at the
124
beginning of the circular buffer), also call
125
PaUtil_Set2ndInputFrameCount, PaUtil_Set2ndInputChannel,
126
PaUtil_Set2ndInterleavedInputChannels,
127
PaUtil_Set2ndNonInterleavedInputChannel as necessary to tell the buffer
128
processor about the second buffer.
129
-# For a stream which generates output:
130
- Call PaUtil_SetOutputFrameCount with the number of frames in the host
132
- Call one of the following functions one or more times to tell the
133
buffer processor about the host output buffer(s): PaUtil_SetOutputChannel,
134
PaUtil_SetInterleavedOutputChannels, PaUtil_SetNonInterleavedOutputChannel.
135
Which function you call will depend on whether the host buffer(s) are
137
- If the available host output buffer space is split accross two buffers
138
(for example a data range at the end of a circular buffer and another
139
range at the beginning of the circular buffer), call
140
PaUtil_Set2ndOutputFrameCount, PaUtil_Set2ndOutputChannel,
141
PaUtil_Set2ndInterleavedOutputChannels,
142
PaUtil_Set2ndNonInterleavedOutputChannel as necessary to tell the buffer
143
processor about the second buffer.
144
-# Call PaUtil_EndBufferProcessing, this function performs the actual data
145
conversion and processing.
148
<h4>Using the buffer processor for a blocking read/write stream</h4>
150
Blocking read/write streams use the buffer processor to convert and copy user
151
output data to a host buffer, and to convert and copy host input data to
152
the user's buffer. The buffer processor does not perform any buffer adaption.
153
When using the buffer processor in a blocking read/write stream the input and
154
output conversion are performed separately by the PaUtil_CopyInput and
155
PaUtil_CopyOutput functions.
157
To copy data from a host input buffer to the buffer(s) which the user supplies
158
to Pa_ReadStream, use the following calling sequence.
160
- Repeat the following three steps until the user buffer(s) have been filled
161
with samples from the host input buffers:
162
-# Call PaUtil_SetInputFrameCount with the number of frames in the host
164
-# Call one of the following functions one or more times to tell the
165
buffer processor about the host input buffer(s): PaUtil_SetInputChannel,
166
PaUtil_SetInterleavedInputChannels, PaUtil_SetNonInterleavedInputChannel.
167
Which function you call will depend on whether the host buffer(s) are
169
-# Call PaUtil_CopyInput with the user buffer pointer (or a copy of the
170
array of buffer pointers for a non-interleaved stream) passed to
171
Pa_ReadStream, along with the number of frames in the user buffer(s).
172
Be careful to pass a <i>copy</i> of the user buffer pointers to
173
PaUtil_CopyInput because PaUtil_CopyInput advances the pointers to
174
the start of the next region to copy.
175
- PaUtil_CopyInput will not copy more data than is available in the
176
host buffer(s), so the above steps need to be repeated until the user
180
To copy data to the host output buffer from the user buffers(s) supplied
181
to Pa_WriteStream use the following calling sequence.
183
- Repeat the following three steps until all frames from the user buffer(s)
184
have been copied to the host API:
185
-# Call PaUtil_SetOutputFrameCount with the number of frames in the host
187
-# Call one of the following functions one or more times to tell the
188
buffer processor about the host output buffer(s): PaUtil_SetOutputChannel,
189
PaUtil_SetInterleavedOutputChannels, PaUtil_SetNonInterleavedOutputChannel.
190
Which function you call will depend on whether the host buffer(s) are
192
-# Call PaUtil_CopyOutput with the user buffer pointer (or a copy of the
193
array of buffer pointers for a non-interleaved stream) passed to
194
Pa_WriteStream, along with the number of frames in the user buffer(s).
195
Be careful to pass a <i>copy</i> of the user buffer pointers to
196
PaUtil_CopyOutput because PaUtil_CopyOutput advances the pointers to
197
the start of the next region to copy.
198
- PaUtil_CopyOutput will not copy more data than fits in the host buffer(s),
199
so the above steps need to be repeated until all user data is copied.
203
#include "portaudio.h"
204
#include "pa_converters.h"
205
#include "pa_dither.h"
210
#endif /* __cplusplus */
213
/** @brief Mode flag passed to PaUtil_InitializeBufferProcessor indicating the type
214
of buffering that the host API uses.
216
The mode used depends on whether the host API or the implementation manages
217
the buffers, and how these buffers are used (scatter gather, circular buffer).
220
/** The host buffer size is a fixed known size. */
221
paUtilFixedHostBufferSize,
223
/** The host buffer size may vary, but has a known maximum size. */
224
paUtilBoundedHostBufferSize,
226
/** Nothing is known about the host buffer size. */
227
paUtilUnknownHostBufferSize,
229
/** The host buffer size varies, and the client does not require the buffer
230
processor to consume all of the input and fill all of the output buffer. This
231
is useful when the implementation has access to the host API's circular buffer
232
and only needs to consume/fill some of it, not necessarily all of it, with each
233
call to the buffer processor. This is the only mode where
234
PaUtil_EndBufferProcessing() may not consume the whole buffer.
236
paUtilVariableHostBufferSizePartialUsageAllowed
237
}PaUtilHostBufferSizeMode;
240
/** @brief An auxilliary data structure used internally by the buffer processor
241
to represent host input and output buffers. */
242
typedef struct PaUtilChannelDescriptor{
244
unsigned int stride; /**< stride in samples, not bytes */
245
}PaUtilChannelDescriptor;
248
/** @brief The main buffer processor data structure.
250
Allocate one of these, initialize it with PaUtil_InitializeBufferProcessor
251
and terminate it with PaUtil_TerminateBufferProcessor.
254
unsigned long framesPerUserBuffer;
255
unsigned long framesPerHostBuffer;
257
PaUtilHostBufferSizeMode hostBufferSizeMode;
258
int useNonAdaptingProcess;
259
unsigned long framesPerTempBuffer;
261
unsigned int inputChannelCount;
262
unsigned int bytesPerHostInputSample;
263
unsigned int bytesPerUserInputSample;
264
int userInputIsInterleaved;
265
PaUtilConverter *inputConverter;
266
PaUtilZeroer *inputZeroer;
268
unsigned int outputChannelCount;
269
unsigned int bytesPerHostOutputSample;
270
unsigned int bytesPerUserOutputSample;
271
int userOutputIsInterleaved;
272
PaUtilConverter *outputConverter;
273
PaUtilZeroer *outputZeroer;
275
unsigned long initialFramesInTempInputBuffer;
276
unsigned long initialFramesInTempOutputBuffer;
278
void *tempInputBuffer; /**< used for slips, block adaption, and conversion. */
279
void **tempInputBufferPtrs; /**< storage for non-interleaved buffer pointers, NULL for interleaved user input */
280
unsigned long framesInTempInputBuffer; /**< frames remaining in input buffer from previous adaption iteration */
282
void *tempOutputBuffer; /**< used for slips, block adaption, and conversion. */
283
void **tempOutputBufferPtrs; /**< storage for non-interleaved buffer pointers, NULL for interleaved user output */
284
unsigned long framesInTempOutputBuffer; /**< frames remaining in input buffer from previous adaption iteration */
286
PaStreamCallbackTimeInfo *timeInfo;
288
PaStreamCallbackFlags callbackStatusFlags;
290
unsigned long hostInputFrameCount[2];
291
PaUtilChannelDescriptor *hostInputChannels[2]; /**< pointers to arrays of channel descriptors.
292
pointers are NULL for half-duplex output processing.
293
hostInputChannels[i].data is NULL when the caller
294
calls PaUtil_SetNoInput()
296
unsigned long hostOutputFrameCount[2];
297
PaUtilChannelDescriptor *hostOutputChannels[2]; /**< pointers to arrays of channel descriptors.
298
pointers are NULL for half-duplex input processing.
299
hostOutputChannels[i].data is NULL when the caller
300
calls PaUtil_SetNoOutput()
303
PaUtilTriangularDitherGenerator ditherGenerator;
307
PaStreamCallback *streamCallback;
309
} PaUtilBufferProcessor;
312
/** @name Initialization, termination, resetting and info */
315
/** Initialize a buffer processor's representation stored in a
316
PaUtilBufferProcessor structure. Be sure to call
317
PaUtil_TerminateBufferProcessor after finishing with a buffer processor.
319
@param bufferProcessor The buffer processor structure to initialize.
321
@param inputChannelCount The number of input channels as passed to
322
Pa_OpenStream or 0 for an output-only stream.
324
@param userInputSampleFormat Format of user input samples, as passed to
325
Pa_OpenStream. This parameter is ignored for ouput-only streams.
327
@param hostInputSampleFormat Format of host input samples. This parameter is
328
ignored for output-only streams. See note about host buffer interleave below.
330
@param outputChannelCount The number of output channels as passed to
331
Pa_OpenStream or 0 for an input-only stream.
333
@param userOutputSampleFormat Format of user output samples, as passed to
334
Pa_OpenStream. This parameter is ignored for input-only streams.
336
@param hostOutputSampleFormat Format of host output samples. This parameter is
337
ignored for input-only streams. See note about host buffer interleave below.
339
@param sampleRate Sample rate of the stream. The more accurate this is the
340
better - it is used for updating time stamps when adapting buffers.
342
@param streamFlags Stream flags as passed to Pa_OpenStream, this parameter is
343
used for selecting special sample conversion options such as clipping and
346
@param framesPerUserBuffer Number of frames per user buffer, as requested
347
by the framesPerBuffer parameter to Pa_OpenStream. This parameter may be
348
zero to indicate that the user will accept any (and varying) buffer sizes.
350
@param framesPerHostBuffer Specifies the number of frames per host buffer
351
for the fixed buffer size mode, and the maximum number of frames
352
per host buffer for the bounded host buffer size mode. It is ignored for
355
@param hostBufferSizeMode A mode flag indicating the size variability of
356
host buffers that will be passed to the buffer processor. See
357
PaUtilHostBufferSizeMode for further details.
359
@param streamCallback The user stream callback passed to Pa_OpenStream.
361
@param userData The user data field passed to Pa_OpenStream.
363
@note The interleave flag is ignored for host buffer formats. Host
364
interleave is determined by the use of different SetInput and SetOutput
367
@return An error code indicating whether the initialization was successful.
368
If the error code is not PaNoError, the buffer processor was not initialized
369
and should not be used.
371
@see Pa_OpenStream, PaUtilHostBufferSizeMode, PaUtil_TerminateBufferProcessor
373
PaError PaUtil_InitializeBufferProcessor( PaUtilBufferProcessor* bufferProcessor,
374
int inputChannelCount, PaSampleFormat userInputSampleFormat,
375
PaSampleFormat hostInputSampleFormat,
376
int outputChannelCount, PaSampleFormat userOutputSampleFormat,
377
PaSampleFormat hostOutputSampleFormat,
379
PaStreamFlags streamFlags,
380
unsigned long framesPerUserBuffer, /* 0 indicates don't care */
381
unsigned long framesPerHostBuffer,
382
PaUtilHostBufferSizeMode hostBufferSizeMode,
383
PaStreamCallback *streamCallback, void *userData );
386
/** Terminate a buffer processor's representation. Deallocates any temporary
387
buffers allocated by PaUtil_InitializeBufferProcessor.
389
@param bufferProcessor The buffer processor structure to terminate.
391
@see PaUtil_InitializeBufferProcessor.
393
void PaUtil_TerminateBufferProcessor( PaUtilBufferProcessor* bufferProcessor );
396
/** Clear any internally buffered data. If you call
397
PaUtil_InitializeBufferProcessor in your OpenStream routine, make sure you
398
call PaUtil_ResetBufferProcessor in your StartStream call.
400
@param bufferProcessor The buffer processor to reset.
402
void PaUtil_ResetBufferProcessor( PaUtilBufferProcessor* bufferProcessor );
405
/** Retrieve the input latency of a buffer processor.
407
@param bufferProcessor The buffer processor examine.
409
@return The input latency introduced by the buffer processor, in frames.
411
@see PaUtil_GetBufferProcessorOutputLatency
413
unsigned long PaUtil_GetBufferProcessorInputLatency( PaUtilBufferProcessor* bufferProcessor );
415
/** Retrieve the output latency of a buffer processor.
417
@param bufferProcessor The buffer processor examine.
419
@return The output latency introduced by the buffer processor, in frames.
421
@see PaUtil_GetBufferProcessorInputLatency
423
unsigned long PaUtil_GetBufferProcessorOutputLatency( PaUtilBufferProcessor* bufferProcessor );
428
/** @name Host buffer pointer configuration
430
Functions to set host input and output buffers, used by both callback streams
431
and blocking read/write streams.
436
/** Set the number of frames in the input host buffer(s) specified by the
437
PaUtil_Set*InputChannel functions.
439
@param bufferProcessor The buffer processor.
441
@param frameCount The number of host input frames. A 0 frameCount indicates to
442
use the framesPerHostBuffer value passed to PaUtil_InitializeBufferProcessor.
444
@see PaUtil_SetNoInput, PaUtil_SetInputChannel,
445
PaUtil_SetInterleavedInputChannels, PaUtil_SetNonInterleavedInputChannel
447
void PaUtil_SetInputFrameCount( PaUtilBufferProcessor* bufferProcessor,
448
unsigned long frameCount );
451
/** Indicate that no input is avalable. This function should be used when
452
priming the output of a full-duplex stream opened with the
453
paPrimeOutputBuffersUsingStreamCallback flag. Note that it is not necessary
454
to call this or any othe PaUtil_Set*Input* functions for ouput-only streams.
456
@param bufferProcessor The buffer processor.
458
void PaUtil_SetNoInput( PaUtilBufferProcessor* bufferProcessor );
461
/** Provide the buffer processor with a pointer to a host input channel.
463
@param bufferProcessor The buffer processor.
464
@param channel The channel number.
465
@param data The buffer.
466
@param stride The stride from one sample to the next, in samples. For
467
interleaved host buffers, the stride will usually be the same as the number of
468
channels in the buffer.
470
void PaUtil_SetInputChannel( PaUtilBufferProcessor* bufferProcessor,
471
unsigned int channel, void *data, unsigned int stride );
474
/** Provide the buffer processor with a pointer to an number of interleaved
477
@param bufferProcessor The buffer processor.
478
@param firstChannel The first channel number.
479
@param data The buffer.
480
@param channelCount The number of interleaved channels in the buffer. If
481
channelCount is zero, the number of channels specified to
482
PaUtil_InitializeBufferProcessor will be used.
484
void PaUtil_SetInterleavedInputChannels( PaUtilBufferProcessor* bufferProcessor,
485
unsigned int firstChannel, void *data, unsigned int channelCount );
488
/** Provide the buffer processor with a pointer to one non-interleaved host
491
@param bufferProcessor The buffer processor.
492
@param channel The channel number.
493
@param data The buffer.
495
void PaUtil_SetNonInterleavedInputChannel( PaUtilBufferProcessor* bufferProcessor,
496
unsigned int channel, void *data );
499
/** Use for the second buffer half when the input buffer is split in two halves.
500
@see PaUtil_SetInputFrameCount
502
void PaUtil_Set2ndInputFrameCount( PaUtilBufferProcessor* bufferProcessor,
503
unsigned long frameCount );
505
/** Use for the second buffer half when the input buffer is split in two halves.
506
@see PaUtil_SetInputChannel
508
void PaUtil_Set2ndInputChannel( PaUtilBufferProcessor* bufferProcessor,
509
unsigned int channel, void *data, unsigned int stride );
511
/** Use for the second buffer half when the input buffer is split in two halves.
512
@see PaUtil_SetInterleavedInputChannels
514
void PaUtil_Set2ndInterleavedInputChannels( PaUtilBufferProcessor* bufferProcessor,
515
unsigned int firstChannel, void *data, unsigned int channelCount );
517
/** Use for the second buffer half when the input buffer is split in two halves.
518
@see PaUtil_SetNonInterleavedInputChannel
520
void PaUtil_Set2ndNonInterleavedInputChannel( PaUtilBufferProcessor* bufferProcessor,
521
unsigned int channel, void *data );
524
/** Set the number of frames in the output host buffer(s) specified by the
525
PaUtil_Set*OutputChannel functions.
527
@param bufferProcessor The buffer processor.
529
@param frameCount The number of host output frames. A 0 frameCount indicates to
530
use the framesPerHostBuffer value passed to PaUtil_InitializeBufferProcessor.
532
@see PaUtil_SetOutputChannel, PaUtil_SetInterleavedOutputChannels,
533
PaUtil_SetNonInterleavedOutputChannel
535
void PaUtil_SetOutputFrameCount( PaUtilBufferProcessor* bufferProcessor,
536
unsigned long frameCount );
539
/** Indicate that the output will be discarded. This function should be used
540
when implementing the paNeverDropInput mode for full duplex streams.
542
@param bufferProcessor The buffer processor.
544
void PaUtil_SetNoOutput( PaUtilBufferProcessor* bufferProcessor );
547
/** Provide the buffer processor with a pointer to a host output channel.
549
@param bufferProcessor The buffer processor.
550
@param channel The channel number.
551
@param data The buffer.
552
@param stride The stride from one sample to the next, in samples. For
553
interleaved host buffers, the stride will usually be the same as the number of
554
channels in the buffer.
556
void PaUtil_SetOutputChannel( PaUtilBufferProcessor* bufferProcessor,
557
unsigned int channel, void *data, unsigned int stride );
560
/** Provide the buffer processor with a pointer to a number of interleaved
561
host output channels.
563
@param bufferProcessor The buffer processor.
564
@param firstChannel The first channel number.
565
@param data The buffer.
566
@param channelCount The number of interleaved channels in the buffer. If
567
channelCount is zero, the number of channels specified to
568
PaUtil_InitializeBufferProcessor will be used.
570
void PaUtil_SetInterleavedOutputChannels( PaUtilBufferProcessor* bufferProcessor,
571
unsigned int firstChannel, void *data, unsigned int channelCount );
574
/** Provide the buffer processor with a pointer to one non-interleaved host
577
@param bufferProcessor The buffer processor.
578
@param channel The channel number.
579
@param data The buffer.
581
void PaUtil_SetNonInterleavedOutputChannel( PaUtilBufferProcessor* bufferProcessor,
582
unsigned int channel, void *data );
585
/** Use for the second buffer half when the output buffer is split in two halves.
586
@see PaUtil_SetOutputFrameCount
588
void PaUtil_Set2ndOutputFrameCount( PaUtilBufferProcessor* bufferProcessor,
589
unsigned long frameCount );
591
/** Use for the second buffer half when the output buffer is split in two halves.
592
@see PaUtil_SetOutputChannel
594
void PaUtil_Set2ndOutputChannel( PaUtilBufferProcessor* bufferProcessor,
595
unsigned int channel, void *data, unsigned int stride );
597
/** Use for the second buffer half when the output buffer is split in two halves.
598
@see PaUtil_SetInterleavedOutputChannels
600
void PaUtil_Set2ndInterleavedOutputChannels( PaUtilBufferProcessor* bufferProcessor,
601
unsigned int firstChannel, void *data, unsigned int channelCount );
603
/** Use for the second buffer half when the output buffer is split in two halves.
604
@see PaUtil_SetNonInterleavedOutputChannel
606
void PaUtil_Set2ndNonInterleavedOutputChannel( PaUtilBufferProcessor* bufferProcessor,
607
unsigned int channel, void *data );
612
/** @name Buffer processing functions for callback streams
616
/** Commence processing a host buffer (or a pair of host buffers in the
617
full-duplex case) for a callback stream.
619
@param bufferProcessor The buffer processor.
621
@param timeInfo Timing information for the first sample of the host
622
buffer(s). This information may be adjusted when buffer adaption is being
625
@param callbackStatusFlags Flags indicating whether underruns and overruns
626
have occurred since the last time the buffer processor was called.
628
void PaUtil_BeginBufferProcessing( PaUtilBufferProcessor* bufferProcessor,
629
PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags callbackStatusFlags );
632
/** Finish processing a host buffer (or a pair of host buffers in the
633
full-duplex case) for a callback stream.
635
@param bufferProcessor The buffer processor.
637
@param callbackResult On input, indicates a previous callback result, and on
638
exit, the result of the user stream callback, if it is called.
639
On entry callbackResult should contain one of { paContinue, paComplete, or
640
paAbort}. If paComplete is passed, the stream callback will not be called
641
but any audio that was generated by previous stream callbacks will be copied
642
to the output buffer(s). You can check whether the buffer processor's internal
643
buffer is empty by calling PaUtil_IsBufferProcessorOutputEmpty.
645
If the stream callback is called its result is stored in *callbackResult. If
646
the stream callback returns paComplete or paAbort, all output buffers will be
647
full of valid data - some of which may be zeros to acount for data that
648
wasn't generated by the terminating callback.
650
@return The number of frames processed. This usually corresponds to the
651
number of frames specified by the PaUtil_Set*FrameCount functions, exept in
652
the paUtilVariableHostBufferSizePartialUsageAllowed buffer size mode when a
653
smaller value may be returned.
655
unsigned long PaUtil_EndBufferProcessing( PaUtilBufferProcessor* bufferProcessor,
656
int *callbackResult );
659
/** Determine whether any callback generated output remains in the bufffer
660
processor's internal buffers. This method may be used to determine when to
661
continue calling PaUtil_EndBufferProcessing() after the callback has returned
662
a callbackResult of paComplete.
664
@param bufferProcessor The buffer processor.
666
@return Returns non-zero when callback generated output remains in the internal
667
buffer and zero (0) when there internal buffer contains no callback generated
670
int PaUtil_IsBufferProcessorOutputEmpty( PaUtilBufferProcessor* bufferProcessor );
675
/** @name Buffer processing functions for blocking read/write streams
679
/** Copy samples from host input channels set up by the PaUtil_Set*InputChannels
680
functions to a user supplied buffer. This function is intended for use with
681
blocking read/write streams. Copies the minimum of the number of
682
user frames (specified by the frameCount parameter) and the number of available
683
host frames (specified in a previous call to SetInputFrameCount()).
685
@param bufferProcessor The buffer processor.
687
@param buffer A pointer to the user buffer pointer, or a pointer to a pointer
688
to an array of user buffer pointers for a non-interleaved stream. It is
689
important that this parameter points to a copy of the user buffer pointers,
690
not to the actual user buffer pointers, because this function updates the
691
pointers before returning.
693
@param frameCount The number of frames of data in the buffer(s) pointed to by
694
the buffer parameter.
696
@return The number of frames copied. The buffer pointer(s) pointed to by the
697
buffer parameter are advanced to point to the frame(s) following the last one
700
unsigned long PaUtil_CopyInput( PaUtilBufferProcessor* bufferProcessor,
701
void **buffer, unsigned long frameCount );
704
/* Copy samples from a user supplied buffer to host output channels set up by
705
the PaUtil_Set*OutputChannels functions. This function is intended for use with
706
blocking read/write streams. Copies the minimum of the number of
707
user frames (specified by the frameCount parameter) and the number of
708
host frames (specified in a previous call to SetOutputFrameCount()).
710
@param bufferProcessor The buffer processor.
712
@param buffer A pointer to the user buffer pointer, or a pointer to a pointer
713
to an array of user buffer pointers for a non-interleaved stream. It is
714
important that this parameter points to a copy of the user buffer pointers,
715
not to the actual user buffer pointers, because this function updates the
716
pointers before returning.
718
@param frameCount The number of frames of data in the buffer(s) pointed to by
719
the buffer parameter.
721
@return The number of frames copied. The buffer pointer(s) pointed to by the
722
buffer parameter are advanced to point to the frame(s) following the last one
725
unsigned long PaUtil_CopyOutput( PaUtilBufferProcessor* bufferProcessor,
726
const void ** buffer, unsigned long frameCount );
729
/* Zero samples in host output channels set up by the PaUtil_Set*OutputChannels
730
functions. This function is useful for flushing streams.
731
Zeros the minimum of frameCount and the number of host frames specified in a
732
previous call to SetOutputFrameCount().
734
@param bufferProcessor The buffer processor.
736
@param frameCount The maximum number of frames to zero.
738
@return The number of frames zeroed.
740
unsigned long PaUtil_ZeroOutput( PaUtilBufferProcessor* bufferProcessor,
741
unsigned long frameCount );
749
#endif /* __cplusplus */
750
#endif /* PA_PROCESS_H */